2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2015 Victor Kirhenshtein
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 package org
.netxms
.ui
.eclipse
.objectview
.objecttabs
;
21 import org
.eclipse
.core
.commands
.Command
;
22 import org
.eclipse
.core
.commands
.State
;
23 import org
.eclipse
.jface
.action
.Action
;
24 import org
.eclipse
.jface
.action
.IMenuListener
;
25 import org
.eclipse
.jface
.action
.IMenuManager
;
26 import org
.eclipse
.jface
.action
.MenuManager
;
27 import org
.eclipse
.jface
.action
.Separator
;
28 import org
.eclipse
.jface
.viewers
.ArrayContentProvider
;
29 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
30 import org
.eclipse
.swt
.SWT
;
31 import org
.eclipse
.swt
.events
.DisposeEvent
;
32 import org
.eclipse
.swt
.events
.DisposeListener
;
33 import org
.eclipse
.swt
.events
.ModifyEvent
;
34 import org
.eclipse
.swt
.events
.ModifyListener
;
35 import org
.eclipse
.swt
.layout
.FormAttachment
;
36 import org
.eclipse
.swt
.layout
.FormData
;
37 import org
.eclipse
.swt
.layout
.FormLayout
;
38 import org
.eclipse
.swt
.widgets
.Composite
;
39 import org
.eclipse
.swt
.widgets
.Menu
;
40 import org
.eclipse
.ui
.PlatformUI
;
41 import org
.eclipse
.ui
.commands
.ICommandService
;
42 import org
.eclipse
.ui
.contexts
.IContextService
;
43 import org
.netxms
.client
.objects
.AbstractNode
;
44 import org
.netxms
.client
.objects
.AbstractObject
;
45 import org
.netxms
.client
.objects
.Interface
;
46 import org
.netxms
.ui
.eclipse
.actions
.ExportToCsvAction
;
47 import org
.netxms
.ui
.eclipse
.objectbrowser
.api
.ObjectContextMenu
;
48 import org
.netxms
.ui
.eclipse
.objectview
.Activator
;
49 import org
.netxms
.ui
.eclipse
.objectview
.Messages
;
50 import org
.netxms
.ui
.eclipse
.objectview
.objecttabs
.helpers
.InterfaceListComparator
;
51 import org
.netxms
.ui
.eclipse
.objectview
.objecttabs
.helpers
.InterfaceListLabelProvider
;
52 import org
.netxms
.ui
.eclipse
.objectview
.objecttabs
.helpers
.InterfacesTabFilter
;
53 import org
.netxms
.ui
.eclipse
.tools
.WidgetHelper
;
54 import org
.netxms
.ui
.eclipse
.widgets
.FilterText
;
55 import org
.netxms
.ui
.eclipse
.widgets
.SortableTableViewer
;
60 public class InterfacesTab
extends ObjectTab
62 public static final int COLUMN_ID
= 0;
63 public static final int COLUMN_NAME
= 1;
64 public static final int COLUMN_ALIAS
= 2;
65 public static final int COLUMN_TYPE
= 3;
66 public static final int COLUMN_INDEX
= 4;
67 public static final int COLUMN_SLOT
= 5;
68 public static final int COLUMN_PORT
= 6;
69 public static final int COLUMN_MTU
= 7;
70 public static final int COLUMN_SPEED
= 8;
71 public static final int COLUMN_DESCRIPTION
= 9;
72 public static final int COLUMN_MAC_ADDRESS
= 10;
73 public static final int COLUMN_IP_ADDRESS
= 11;
74 public static final int COLUMN_PEER_NAME
= 12;
75 public static final int COLUMN_PEER_MAC_ADDRESS
= 13;
76 public static final int COLUMN_PEER_IP_ADDRESS
= 14;
77 public static final int COLUMN_PEER_PROTOCOL
= 15;
78 public static final int COLUMN_ADMIN_STATE
= 16;
79 public static final int COLUMN_OPER_STATE
= 17;
80 public static final int COLUMN_EXPECTED_STATE
= 18;
81 public static final int COLUMN_STATUS
= 19;
82 public static final int COLUMN_8021X_PAE_STATE
= 20;
83 public static final int COLUMN_8021X_BACKEND_STATE
= 21;
85 private SortableTableViewer viewer
;
86 private InterfaceListLabelProvider labelProvider
;
87 private Action actionExportToCsv
;
89 private boolean filterEnabled
= false;
90 private FilterText filterText
;
91 private InterfacesTabFilter filter
;
92 private Composite interfacesArea
;
95 * @see org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab#createTabContent(org.eclipse.swt.widgets.Composite)
98 protected void createTabContent(Composite parent
)
100 // Create interface area
101 interfacesArea
= new Composite(parent
, SWT
.BORDER
);
102 FormLayout formLayout
= new FormLayout();
103 interfacesArea
.setLayout(formLayout
);
105 filterText
= new FilterText(interfacesArea
, SWT
.BORDER
);
106 filterText
.addModifyListener(new ModifyListener() {
108 public void modifyText(ModifyEvent e
)
113 filterText
.setCloseAction(new Action() {
121 Action action
= new Action() {
126 ICommandService service
= (ICommandService
)PlatformUI
.getWorkbench().getService(ICommandService
.class);
127 Command command
= service
.getCommand("org.netxms.ui.eclipse.objectview.commands.show_filter");
128 State state
= command
.getState("org.netxms.ui.eclipse.objectview.commands.show_filter.state");
129 state
.setValue(false);
130 service
.refreshElements(command
.getId(), null);
133 setFilterCloseAction(action
);
136 FormData fd
= new FormData();
137 fd
.left
= new FormAttachment(0, 0);
138 fd
.top
= new FormAttachment(0, 0);
139 fd
.right
= new FormAttachment(100, 0);
140 filterText
.setLayoutData(fd
);
142 final String
[] names
= {
143 Messages
.get().InterfacesTab_ColId
,
144 Messages
.get().InterfacesTab_ColName
,
145 Messages
.get().InterfacesTab_Alias
,
146 Messages
.get().InterfacesTab_ColIfType
,
147 Messages
.get().InterfacesTab_ColIfIndex
,
148 Messages
.get().InterfacesTab_ColSlot
,
149 Messages
.get().InterfacesTab_ColPort
,
150 Messages
.get().InterfacesTab_MTU
,
151 Messages
.get().InterfacesTab_Speed
,
152 Messages
.get().InterfacesTab_ColDescription
,
153 Messages
.get().InterfacesTab_ColMacAddr
,
154 Messages
.get().InterfacesTab_ColIpAddr
,
155 Messages
.get().InterfacesTab_ColPeerNode
,
156 Messages
.get().InterfacesTab_ColPeerMAC
,
157 Messages
.get().InterfacesTab_ColPeerIP
,
158 Messages
.get().InterfacesTab_PeerDiscoveryProtocol
,
159 Messages
.get().InterfacesTab_ColAdminState
,
160 Messages
.get().InterfacesTab_ColOperState
,
161 Messages
.get().InterfacesTab_ColExpState
,
162 Messages
.get().InterfacesTab_ColStatus
,
163 Messages
.get().InterfacesTab_Col8021xPAE
,
164 Messages
.get().InterfacesTab_Col8021xBackend
166 final int[] widths
= { 60, 150, 150, 150, 70, 70, 70, 70, 90, 150, 100, 90, 150, 100, 90, 80, 80, 80, 80, 80, 80, 80 };
167 viewer
= new SortableTableViewer(interfacesArea
, names
, widths
, COLUMN_NAME
, SWT
.UP
, SWT
.FULL_SELECTION
| SWT
.MULTI
);
168 labelProvider
= new InterfaceListLabelProvider();
169 viewer
.setLabelProvider(labelProvider
);
170 viewer
.setContentProvider(new ArrayContentProvider());
171 viewer
.setComparator(new InterfaceListComparator());
172 viewer
.getTable().setHeaderVisible(true);
173 viewer
.getTable().setLinesVisible(true);
174 filter
= new InterfacesTabFilter();
175 viewer
.addFilter(filter
);
176 WidgetHelper
.restoreTableViewerSettings(viewer
, Activator
.getDefault().getDialogSettings(), "InterfaceTable.V4"); //$NON-NLS-1$
177 viewer
.getTable().addDisposeListener(new DisposeListener() {
179 public void widgetDisposed(DisposeEvent e
)
181 WidgetHelper
.saveColumnSettings(viewer
.getTable(), Activator
.getDefault().getDialogSettings(), "InterfaceTable.V4"); //$NON-NLS-1$
187 fd
.left
= new FormAttachment(0, 0);
189 fd
.top
= new FormAttachment(filterText
, 0, SWT
.BOTTOM
);
190 fd
.bottom
= new FormAttachment(100, 0);
191 fd
.right
= new FormAttachment(100, 0);
192 viewer
.getControl().setLayoutData(fd
);
197 // Set initial focus to filter input line
199 filterText
.setFocus();
201 enableFilter(false); // Will hide filter area correctly
204 private void setFilterCloseAction(Action action
)
206 filterText
.setCloseAction(action
);
210 * Enable or disable filter
212 * @param enable New filter state
214 public void enableFilter(boolean enable
)
216 filterEnabled
= enable
;
217 filterText
.setVisible(filterEnabled
);
218 FormData fd
= (FormData
)viewer
.getTable().getLayoutData();
219 fd
.top
= enable ?
new FormAttachment(filterText
, 0, SWT
.BOTTOM
) : new FormAttachment(0, 0);
220 interfacesArea
.layout();
223 filterText
.setFocus();
227 filterText
.setText("");
233 * Handler for filter modification
235 public void onFilterModify()
237 final String text
= filterText
.getText();
238 filter
.setFilterString(text
);
239 viewer
.refresh(false);
245 private void createActions()
247 actionExportToCsv
= new ExportToCsvAction(getViewPart(), viewer
, true);
253 private void createPopupMenu()
255 // Create menu manager.
256 MenuManager menuMgr
= new MenuManager();
257 menuMgr
.setRemoveAllWhenShown(true);
258 menuMgr
.addMenuListener(new IMenuListener() {
259 public void menuAboutToShow(IMenuManager manager
)
261 fillContextMenu(manager
);
266 Menu menu
= menuMgr
.createContextMenu(viewer
.getControl());
267 viewer
.getControl().setMenu(menu
);
269 // Register menu for extension.
270 if (getViewPart() != null)
271 getViewPart().getSite().registerContextMenu(menuMgr
, viewer
);
276 * @param mgr Menu manager
278 protected void fillContextMenu(IMenuManager manager
)
280 manager
.add(actionExportToCsv
);
281 manager
.add(new Separator());
282 ObjectContextMenu
.fill(manager
, getViewPart().getSite(), viewer
);
286 * @see org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab#currentObjectUpdated(org.netxms.client.objects.AbstractObject)
289 public void currentObjectUpdated(AbstractObject object
)
291 objectChanged(object
);
295 * @see org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab#refresh()
298 public void refresh()
300 if (getObject() != null)
301 viewer
.setInput(getObject().getAllChilds(AbstractObject
.OBJECT_INTERFACE
).toArray());
303 viewer
.setInput(new Interface
[0]);
307 * @see org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab#objectChanged(org.netxms.client.objects.AbstractObject)
310 public void objectChanged(final AbstractObject object
)
312 labelProvider
.setNode((AbstractNode
)object
);
317 * @see org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab#showForObject(org.netxms.client.objects.AbstractObject)
320 public boolean showForObject(AbstractObject object
)
322 return (object
instanceof AbstractNode
);
326 * @see org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab#getSelectionProvider()
329 public ISelectionProvider
getSelectionProvider()
335 * @see org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab#selected()
338 public void selected()
341 IContextService contextService
= (IContextService
)getViewPart().getSite().getService(IContextService
.class);
342 if (contextService
!= null)
344 contextService
.activateContext("org.netxms.ui.eclipse.objectview.context.InterfacesTab"); //$NON-NLS-1$