a50786c9fd293a06c08b94de7eb4ca8c59b51b8d
[public/netxms.git] / webui / webapp / NetworkMaps / src / org / netxms / ui / eclipse / networkmaps / views / AbstractNetworkMapView.java
1 /**
2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2015 Victor Kirhenshtein
4 *
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.
9 *
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.
14 *
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.
18 */
19 package org.netxms.ui.eclipse.networkmaps.views;
20
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.Comparator;
25 import java.util.HashSet;
26 import java.util.Iterator;
27 import java.util.List;
28 import java.util.Set;
29 import org.eclipse.core.runtime.CoreException;
30 import org.eclipse.core.runtime.IConfigurationElement;
31 import org.eclipse.core.runtime.IExtensionRegistry;
32 import org.eclipse.core.runtime.Platform;
33 import org.eclipse.draw2d.ManhattanConnectionRouter;
34 import org.eclipse.draw2d.geometry.Dimension;
35 import org.eclipse.draw2d.geometry.Point;
36 import org.eclipse.gef4.zest.core.viewers.AbstractZoomableViewer;
37 import org.eclipse.gef4.zest.core.viewers.IZoomableWorkbenchPart;
38 import org.eclipse.gef4.zest.core.widgets.Graph;
39 import org.eclipse.gef4.zest.core.widgets.GraphConnection;
40 import org.eclipse.gef4.zest.core.widgets.GraphNode;
41 import org.eclipse.gef4.zest.layouts.LayoutAlgorithm;
42 import org.eclipse.gef4.zest.layouts.algorithms.CompositeLayoutAlgorithm;
43 import org.eclipse.gef4.zest.layouts.algorithms.GridLayoutAlgorithm;
44 import org.eclipse.gef4.zest.layouts.algorithms.RadialLayoutAlgorithm;
45 import org.eclipse.gef4.zest.layouts.algorithms.SpringLayoutAlgorithm;
46 import org.eclipse.gef4.zest.layouts.algorithms.TreeLayoutAlgorithm;
47 import org.eclipse.jface.action.Action;
48 import org.eclipse.jface.action.GroupMarker;
49 import org.eclipse.jface.action.IContributionItem;
50 import org.eclipse.jface.action.IMenuListener;
51 import org.eclipse.jface.action.IMenuManager;
52 import org.eclipse.jface.action.IToolBarManager;
53 import org.eclipse.jface.action.MenuManager;
54 import org.eclipse.jface.action.Separator;
55 import org.eclipse.jface.commands.ActionHandler;
56 import org.eclipse.jface.dialogs.IDialogSettings;
57 import org.eclipse.jface.preference.IPreferenceStore;
58 import org.eclipse.jface.viewers.DoubleClickEvent;
59 import org.eclipse.jface.viewers.IDoubleClickListener;
60 import org.eclipse.jface.viewers.ISelection;
61 import org.eclipse.jface.viewers.ISelectionChangedListener;
62 import org.eclipse.jface.viewers.ISelectionProvider;
63 import org.eclipse.jface.viewers.IStructuredSelection;
64 import org.eclipse.jface.viewers.SelectionChangedEvent;
65 import org.eclipse.jface.viewers.StructuredSelection;
66 import org.eclipse.swt.SWT;
67 import org.eclipse.swt.events.DisposeEvent;
68 import org.eclipse.swt.events.DisposeListener;
69 import org.eclipse.swt.layout.FillLayout;
70 import org.eclipse.swt.widgets.Composite;
71 import org.eclipse.swt.widgets.Display;
72 import org.eclipse.swt.widgets.Menu;
73 import org.eclipse.ui.IActionBars;
74 import org.eclipse.ui.IViewSite;
75 import org.eclipse.ui.IWorkbenchActionConstants;
76 import org.eclipse.ui.IWorkbenchPage;
77 import org.eclipse.ui.PartInitException;
78 import org.eclipse.ui.PlatformUI;
79 import org.eclipse.ui.contexts.IContextService;
80 import org.eclipse.ui.handlers.IHandlerService;
81 import org.eclipse.ui.part.ViewPart;
82 import org.netxms.client.NXCSession;
83 import org.netxms.client.SessionListener;
84 import org.netxms.client.SessionNotification;
85 import org.netxms.client.maps.MapLayoutAlgorithm;
86 import org.netxms.client.maps.MapObjectDisplayMode;
87 import org.netxms.client.maps.NetworkMapLink;
88 import org.netxms.client.maps.NetworkMapPage;
89 import org.netxms.client.maps.configs.DCIImageConfiguration;
90 import org.netxms.client.maps.configs.SingleDciConfig;
91 import org.netxms.client.maps.elements.NetworkMapDCIContainer;
92 import org.netxms.client.maps.elements.NetworkMapDCIImage;
93 import org.netxms.client.maps.elements.NetworkMapElement;
94 import org.netxms.client.maps.elements.NetworkMapObject;
95 import org.netxms.client.objects.AbstractObject;
96 import org.netxms.client.objects.Dashboard;
97 import org.netxms.client.objects.NetworkMap;
98 import org.netxms.ui.eclipse.actions.RefreshAction;
99 import org.netxms.ui.eclipse.console.resources.GroupMarkers;
100 import org.netxms.ui.eclipse.console.resources.SharedIcons;
101 import org.netxms.ui.eclipse.networkmaps.Activator;
102 import org.netxms.ui.eclipse.networkmaps.Messages;
103 import org.netxms.ui.eclipse.networkmaps.algorithms.ExpansionAlgorithm;
104 import org.netxms.ui.eclipse.networkmaps.algorithms.ManualLayout;
105 import org.netxms.ui.eclipse.networkmaps.api.ObjectDoubleClickHandler;
106 import org.netxms.ui.eclipse.networkmaps.views.helpers.BendpointEditor;
107 import org.netxms.ui.eclipse.networkmaps.views.helpers.ExtendedGraphViewer;
108 import org.netxms.ui.eclipse.networkmaps.views.helpers.LinkDciValueProvider;
109 import org.netxms.ui.eclipse.networkmaps.views.helpers.MapContentProvider;
110 import org.netxms.ui.eclipse.networkmaps.views.helpers.MapLabelProvider;
111 import org.netxms.ui.eclipse.objectbrowser.api.ObjectContextMenu;
112 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
113 import org.netxms.ui.eclipse.tools.CommandBridge;
114 import org.netxms.ui.eclipse.tools.FilteringMenuManager;
115 import org.netxms.ui.eclipse.tools.MessageDialogHelper;
116
117 /**
118 * Base class for network map views
119 */
120 public abstract class AbstractNetworkMapView extends ViewPart implements ISelectionProvider, IZoomableWorkbenchPart
121 {
122 protected static final int LAYOUT_SPRING = 0;
123 protected static final int LAYOUT_RADIAL = 1;
124 protected static final int LAYOUT_HTREE = 2;
125 protected static final int LAYOUT_VTREE = 3;
126 protected static final int LAYOUT_SPARSE_VTREE = 4;
127
128 private final String[] layoutAlgorithmNames = {
129 Messages.get().AbstractNetworkMapView_LayoutSpring,
130 Messages.get().AbstractNetworkMapView_LayoutRadial,
131 Messages.get().AbstractNetworkMapView_LayoutHorzTree,
132 Messages.get().AbstractNetworkMapView_LayoutVertTree,
133 Messages.get().AbstractNetworkMapView_LayoutSparseVertTree
134 };
135 private final String[] connectionRouterNames = { Messages.get().AbstractNetworkMapView_RouterDirect, Messages.get().AbstractNetworkMapView_RouterManhattan };
136
137 private static final int SELECTION_EMPTY = 0;
138 private static final int SELECTION_MIXED = 1;
139 private static final int SELECTION_OBJECTS = 2;
140 private static final int SELECTION_ELEMENTS = 3;
141 private static final int SELECTION_LINKS = 4;
142
143 protected NXCSession session;
144 protected AbstractObject rootObject;
145 protected NetworkMapPage mapPage;
146 protected ExtendedGraphViewer viewer;
147 protected MapLabelProvider labelProvider;
148 protected MapLayoutAlgorithm layoutAlgorithm = MapLayoutAlgorithm.SPRING;
149 protected int routingAlgorithm = NetworkMapLink.ROUTING_DIRECT;
150 protected boolean allowManualLayout = false; // True if manual layout can be switched on
151 protected boolean automaticLayoutEnabled = true; // Current layout mode - automatic or manual
152 protected boolean alwaysFitLayout = false;
153 protected boolean disableGeolocationBackground = false;
154
155 protected Action actionRefresh;
156 protected Action actionShowStatusIcon;
157 protected Action actionShowStatusBackground;
158 protected Action actionShowStatusFrame;
159 protected Action actionZoomIn;
160 protected Action actionZoomOut;
161 protected Action actionZoomFit;
162 protected Action[] actionZoomTo;
163 protected Action[] actionSetAlgorithm;
164 protected Action[] actionSetRouter;
165 protected Action actionAlwaysFitLayout;
166 protected Action actionEnableAutomaticLayout;
167 protected Action actionSaveLayout;
168 protected Action actionOpenDrillDownObject;
169 protected Action actionFiguresIcons;
170 protected Action actionFiguresSmallLabels;
171 protected Action actionFiguresLargeLabels;
172 protected Action actionFiguresStatusIcons;
173 protected Action actionShowGrid;
174 protected Action actionAlignToGrid;
175 protected Action actionSnapToGrid;
176 protected Action actionShowObjectDetails;
177 protected Action actionHideLinkLabels;
178 protected Action actionHideLinks;
179 protected Action actionSelectAllObjects;
180
181 private String viewId;
182 private IStructuredSelection currentSelection = new StructuredSelection(new Object[0]);
183 private Set<ISelectionChangedListener> selectionListeners = new HashSet<ISelectionChangedListener>();
184 private BendpointEditor bendpointEditor = null;
185 private SessionListener sessionListener;
186 private List<DoubleClickHandlerData> doubleClickHandlers = new ArrayList<DoubleClickHandlerData>(0);
187 private LinkDciValueProvider dciValueProvider;
188
189 /*
190 * (non-Javadoc)
191 *
192 * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite)
193 */
194 @Override
195 public void init(IViewSite site) throws PartInitException
196 {
197 super.init(site);
198
199 dciValueProvider = LinkDciValueProvider.getInstance();
200
201 final IPreferenceStore ps = Activator.getDefault().getPreferenceStore();
202 disableGeolocationBackground = ps.getBoolean("DISABLE_GEOLOCATION_BACKGROUND"); //$NON-NLS-1$
203
204 session = (NXCSession)ConsoleSharedData.getSession();
205 String[] parts = site.getSecondaryId().split("&"); //$NON-NLS-1$
206 rootObject = session.findObjectById(Long.parseLong((parts.length > 0) ? parts[0] : site.getSecondaryId()));
207 if (rootObject == null)
208 throw new PartInitException(Messages.get().AbstractNetworkMapView_RootObjectNotFound);
209
210 viewId = site.getId() + "."; //$NON-NLS-1$
211 viewId += (parts.length > 0) ? parts[0] : site.getSecondaryId();
212
213 parseSecondaryId(parts);
214 }
215
216 /**
217 * Parse secondary ID (already splitted by & characters). Intended to be overrided in subclasses.
218 *
219 * @param parts secondary ID divided at & characters
220 * @throws PartInitException
221 */
222 protected void parseSecondaryId(String[] parts) throws PartInitException
223 {
224 }
225
226 /**
227 * Build map page containing data to display. Should be implemented in derived classes.
228 */
229 protected abstract void buildMapPage();
230
231 /*
232 * (non-Javadoc)
233 *
234 * @see org.eclipse.ui.part.ViewPart#createPartControl(org.eclipse.swt.widgets.Composite)
235 */
236 @Override
237 public final void createPartControl(Composite parent)
238 {
239 FillLayout layout = new FillLayout();
240 parent.setLayout(layout);
241
242 viewer = new ExtendedGraphViewer(parent, SWT.NONE);
243 viewer.setContentProvider(new MapContentProvider(viewer));
244 labelProvider = new MapLabelProvider(viewer);
245 viewer.setLabelProvider(labelProvider);
246 viewer.setBackgroundColor(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB());
247
248 IDialogSettings settings = Activator.getDefault().getDialogSettings();
249 try
250 {
251 alwaysFitLayout = settings.getBoolean(viewId + ".alwaysFitLayout"); //$NON-NLS-1$
252 labelProvider.setObjectFigureType(MapObjectDisplayMode.getByValue(settings.getInt(viewId + ".objectFigureType"))); //$NON-NLS-1$
253 }
254 catch(Exception e)
255 {
256 }
257
258 // Zoom level restore and save
259 try
260 {
261 viewer.zoomTo(settings.getDouble(viewId + ".zoom")); //$NON-NLS-1$
262 }
263 catch(NumberFormatException e)
264 {
265 }
266 viewer.getGraphControl().addDisposeListener(new DisposeListener() {
267 @Override
268 public void widgetDisposed(DisposeEvent e)
269 {
270 IDialogSettings settings = Activator.getDefault().getDialogSettings();
271 settings.put(viewId + ".zoom", viewer.getZoom()); //$NON-NLS-1$
272 }
273 });
274
275 getSite().setSelectionProvider(this);
276
277 ISelectionChangedListener listener = new ISelectionChangedListener() {
278 @Override
279 public void selectionChanged(SelectionChangedEvent e)
280 {
281 if (bendpointEditor != null)
282 {
283 bendpointEditor.stop();
284 bendpointEditor = null;
285 }
286
287 currentSelection = transformSelection(e.getSelection());
288
289 if (currentSelection.size() == 1)
290 {
291 int selectionType = analyzeSelection(currentSelection);
292 if (selectionType == SELECTION_OBJECTS)
293 {
294 AbstractObject object = (AbstractObject)currentSelection.getFirstElement();
295 actionOpenDrillDownObject.setEnabled(object.getDrillDownObjectId() != 0);
296 }
297 else
298 {
299 actionOpenDrillDownObject.setEnabled(false);
300 if (selectionType == SELECTION_LINKS)
301 {
302 NetworkMapLink link = (NetworkMapLink)currentSelection.getFirstElement();
303 if (link.getRouting() == NetworkMapLink.ROUTING_BENDPOINTS)
304 {
305 bendpointEditor = new BendpointEditor(link,
306 (GraphConnection)viewer.getGraphControl().getSelection().get(0), viewer);
307 }
308 }
309 }
310 }
311 else
312 {
313 actionOpenDrillDownObject.setEnabled(false);
314 }
315
316 if (selectionListeners.isEmpty())
317 return;
318
319 SelectionChangedEvent event = new SelectionChangedEvent(AbstractNetworkMapView.this, currentSelection);
320 for(ISelectionChangedListener l : selectionListeners)
321 {
322 l.selectionChanged(event);
323 }
324 }
325 };
326 viewer.addPostSelectionChangedListener(listener);
327
328 viewer.addDoubleClickListener(new IDoubleClickListener() {
329 @Override
330 public void doubleClick(DoubleClickEvent event)
331 {
332 int selectionType = analyzeSelection(currentSelection);
333 if (selectionType == SELECTION_OBJECTS)
334 {
335 AbstractObject object = (AbstractObject)currentSelection.getFirstElement();
336
337 for(DoubleClickHandlerData h : doubleClickHandlers)
338 {
339 if ((h.enabledFor == null) || (h.enabledFor.isInstance(object)))
340 {
341 if (h.handler.onDoubleClick(object))
342 {
343 return;
344 }
345 }
346 }
347 }
348
349 // Default behavior
350 actionOpenDrillDownObject.run();
351 }
352 });
353
354 sessionListener = new SessionListener() {
355 @Override
356 public void notificationHandler(final SessionNotification n)
357 {
358 if (n.getCode() == SessionNotification.OBJECT_CHANGED)
359 {
360 viewer.getControl().getDisplay().asyncExec(new Runnable() {
361 @Override
362 public void run()
363 {
364 onObjectChange((AbstractObject)n.getObject());
365 }
366 });
367 }
368 }
369 };
370 session.addListener(sessionListener);
371
372 createActions();
373 contributeToActionBars();
374 createPopupMenu();
375
376 if (automaticLayoutEnabled)
377 {
378 setLayoutAlgorithm(layoutAlgorithm, true);
379 }
380 else
381 {
382 viewer.setLayoutAlgorithm(new ManualLayout());
383 }
384
385 activateContext();
386 registerDoubleClickHandlers();
387 setupMapControl();
388 refreshMap();
389 }
390
391 /**
392 * Called from createPartControl to allow subclasses to do additional map setup. Subclasses
393 * should override this method instead of createPartControl. Default implementation do nothing.
394 */
395 protected void setupMapControl()
396 {
397 }
398
399 /**
400 * Activate context
401 */
402 private void activateContext()
403 {
404 IContextService contextService = (IContextService)getSite().getService(IContextService.class);
405 if (contextService != null)
406 {
407 contextService.activateContext("org.netxms.ui.eclipse.networkmaps.context.NetworkMaps"); //$NON-NLS-1$
408 }
409 }
410
411 /**
412 * Register double click handlers
413 */
414 private void registerDoubleClickHandlers()
415 {
416 // Read all registered extensions and create handlers
417 final IExtensionRegistry reg = Platform.getExtensionRegistry();
418 IConfigurationElement[] elements = reg
419 .getConfigurationElementsFor("org.netxms.ui.eclipse.networkmaps.objectDoubleClickHandlers"); //$NON-NLS-1$
420 for(int i = 0; i < elements.length; i++)
421 {
422 try
423 {
424 final DoubleClickHandlerData h = new DoubleClickHandlerData();
425 h.handler = (ObjectDoubleClickHandler)elements[i].createExecutableExtension("class"); //$NON-NLS-1$
426 h.priority = safeParseInt(elements[i].getAttribute("priority")); //$NON-NLS-1$
427 final String className = elements[i].getAttribute("enabledFor"); //$NON-NLS-1$
428 try
429 {
430 h.enabledFor = (className != null) ? Class.forName(className) : null;
431 }
432 catch(Exception e)
433 {
434 h.enabledFor = null;
435 }
436 doubleClickHandlers.add(h);
437 }
438 catch(CoreException e)
439 {
440 e.printStackTrace();
441 }
442 }
443
444 // Sort handlers by priority
445 Collections.sort(doubleClickHandlers, new Comparator<DoubleClickHandlerData>() {
446 @Override
447 public int compare(DoubleClickHandlerData arg0, DoubleClickHandlerData arg1)
448 {
449 return arg0.priority - arg1.priority;
450 }
451 });
452 }
453
454 /**
455 * Do full map refresh
456 */
457 protected void refreshMap()
458 {
459 buildMapPage();
460 viewer.setInput(mapPage);
461 viewer.setSelection(StructuredSelection.EMPTY);
462 }
463
464 /**
465 * Replace current map page with new one
466 *
467 * @param page new map page
468 */
469 protected void replaceMapPage(final NetworkMapPage page, Display display)
470 {
471 display.asyncExec(new Runnable() {
472 @Override
473 public void run()
474 {
475 mapPage = page;
476 addDciToRequestList();
477 viewer.setInput(mapPage);
478 }
479 });
480 }
481
482 /**
483 * Set layout algorithm for map
484 *
485 * @param alg Layout algorithm
486 * @param forceChange
487 */
488 protected void setLayoutAlgorithm(MapLayoutAlgorithm alg, boolean forceChange)
489 {
490 if (alg == MapLayoutAlgorithm.MANUAL)
491 {
492 if (!automaticLayoutEnabled)
493 return; // manual layout already
494
495 automaticLayoutEnabled = false;
496 // TODO: rewrite, enum value should not be used as index
497 actionSetAlgorithm[layoutAlgorithm.getValue()].setChecked(false);
498 actionEnableAutomaticLayout.setChecked(false);
499 return;
500 }
501
502 if (automaticLayoutEnabled && (alg == layoutAlgorithm) && !forceChange)
503 return; // nothing to change
504
505 if (!automaticLayoutEnabled)
506 {
507 actionEnableAutomaticLayout.setChecked(true);
508 automaticLayoutEnabled = true;
509 }
510
511 LayoutAlgorithm algorithm;
512
513 switch(alg)
514 {
515 case SPRING:
516 algorithm = new SpringLayoutAlgorithm();
517 break;
518 case RADIAL:
519 algorithm = new RadialLayoutAlgorithm();
520 break;
521 case HTREE:
522 algorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.LEFT_RIGHT);
523 break;
524 case VTREE:
525 algorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.TOP_DOWN);
526 break;
527 case SPARSE_VTREE:
528 algorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.TOP_DOWN);
529 ((TreeLayoutAlgorithm)algorithm).setNodeSpace(new Dimension(100, 100));
530 break;
531 default:
532 algorithm = new GridLayoutAlgorithm();
533 break;
534 }
535
536 viewer.setLayoutAlgorithm(alwaysFitLayout ? algorithm : new CompositeLayoutAlgorithm(new LayoutAlgorithm[] { algorithm, new ExpansionAlgorithm() }));
537
538 actionSetAlgorithm[layoutAlgorithm.getValue()].setChecked(false);
539 layoutAlgorithm = alg;
540 actionSetAlgorithm[layoutAlgorithm.getValue()].setChecked(true);
541 }
542
543 /**
544 * Update stored object positions with actual positions read from graph control
545 */
546 protected void updateObjectPositions()
547 {
548 Graph graph = viewer.getGraphControl();
549 List<?> nodes = graph.getNodes();
550 for(Object o : nodes)
551 {
552 if (o instanceof GraphNode)
553 {
554 Object data = ((GraphNode)o).getData();
555 if (data instanceof NetworkMapElement)
556 {
557 Point loc = ((GraphNode)o).getLocation();
558 Dimension size = ((GraphNode)o).getSize();
559 ((NetworkMapElement)data).setLocation(loc.x + (size.width + 1) / 2, loc.y + (size.height + 1) / 2);
560 }
561 }
562 }
563 }
564
565 /**
566 * Set manual layout mode
567 */
568 protected void setManualLayout()
569 {
570 updateObjectPositions();
571
572 automaticLayoutEnabled = false;
573 viewer.setLayoutAlgorithm(new ManualLayout(), true);
574
575 for(int i = 0; i < actionSetAlgorithm.length; i++)
576 actionSetAlgorithm[i].setEnabled(false);
577 actionSaveLayout.setEnabled(true);
578 }
579
580 /**
581 * Set automatic layout mode
582 */
583 protected void setAutomaticLayout()
584 {
585 automaticLayoutEnabled = true;
586 setLayoutAlgorithm(layoutAlgorithm, true);
587
588 for(int i = 0; i < actionSetAlgorithm.length; i++)
589 actionSetAlgorithm[i].setEnabled(true);
590 actionSaveLayout.setEnabled(false);
591 }
592
593 /**
594 * Create actions
595 */
596 protected void createActions()
597 {
598 final IHandlerService handlerService = (IHandlerService)getSite().getService(IHandlerService.class);
599
600 actionRefresh = new RefreshAction(this) {
601 @Override
602 public void run()
603 {
604 refreshMap();
605 }
606 };
607
608 actionShowStatusBackground = new Action(Messages.get().AbstractNetworkMapView_ShowStatusBkgnd, Action.AS_CHECK_BOX) {
609 @Override
610 public void run()
611 {
612 labelProvider.setShowStatusBackground(!labelProvider.isShowStatusBackground());
613 setChecked(labelProvider.isShowStatusBackground());
614 updateObjectPositions();
615 saveLayout();
616 viewer.refresh();
617 }
618 };
619 actionShowStatusBackground.setChecked(labelProvider.isShowStatusBackground());
620 actionShowStatusBackground.setEnabled(labelProvider.getObjectFigureType() == MapObjectDisplayMode.ICON);
621
622 actionShowStatusIcon = new Action(Messages.get().AbstractNetworkMapView_ShowStatusIcon, Action.AS_CHECK_BOX) {
623 @Override
624 public void run()
625 {
626 labelProvider.setShowStatusIcons(!labelProvider.isShowStatusIcons());
627 setChecked(labelProvider.isShowStatusIcons());
628 updateObjectPositions();
629 saveLayout();
630 viewer.refresh();
631 }
632 };
633 actionShowStatusIcon.setChecked(labelProvider.isShowStatusIcons());
634 actionShowStatusIcon.setEnabled(labelProvider.getObjectFigureType() == MapObjectDisplayMode.ICON);
635
636 actionShowStatusFrame = new Action(Messages.get().AbstractNetworkMapView_ShowStatusFrame, Action.AS_CHECK_BOX) {
637 @Override
638 public void run()
639 {
640 labelProvider.setShowStatusFrame(!labelProvider.isShowStatusFrame());
641 setChecked(labelProvider.isShowStatusFrame());
642 updateObjectPositions();
643 saveLayout();
644 viewer.refresh();
645 }
646 };
647 actionShowStatusFrame.setChecked(labelProvider.isShowStatusFrame());
648 actionShowStatusFrame.setEnabled(labelProvider.getObjectFigureType() == MapObjectDisplayMode.ICON);
649
650 actionZoomIn = new Action(Messages.get().AbstractNetworkMapView_ZoomIn, SharedIcons.ZOOM_IN) {
651 @Override
652 public void run()
653 {
654 viewer.zoomIn();
655 }
656 };
657 actionZoomIn.setId("org.netxms.ui.eclipse.networkmaps.localActions.AbstractMap.ZoomIn"); //$NON-NLS-1$
658 actionZoomIn.setActionDefinitionId("org.netxms.ui.eclipse.networkmaps.localCommands.AbstractMap.ZoomIn"); //$NON-NLS-1$
659 handlerService.activateHandler(actionZoomIn.getActionDefinitionId(), new ActionHandler(actionZoomIn));
660
661 actionZoomOut = new Action(Messages.get().AbstractNetworkMapView_ZoomOut, SharedIcons.ZOOM_OUT) {
662 @Override
663 public void run()
664 {
665 viewer.zoomOut();
666 }
667 };
668 actionZoomOut.setId("org.netxms.ui.eclipse.networkmaps.localActions.AbstractMap.ZoomOut"); //$NON-NLS-1$
669 actionZoomOut.setActionDefinitionId("org.netxms.ui.eclipse.networkmaps.localCommands.AbstractMap.ZoomOut"); //$NON-NLS-1$
670 handlerService.activateHandler(actionZoomOut.getActionDefinitionId(), new ActionHandler(actionZoomOut));
671
672 actionZoomFit = new Action(Messages.get().AbstractNetworkMapView_ZoomFit, Activator.getImageDescriptor("icons/fit.png")) { //$NON-NLS-1$
673 @Override
674 public void run()
675 {
676 viewer.zoomFit();
677 }
678 };
679 actionZoomFit.setId("org.netxms.ui.eclipse.networkmaps.localActions.AbstractMap.ZoomToFit"); //$NON-NLS-1$
680 actionZoomFit.setActionDefinitionId("org.netxms.ui.eclipse.networkmaps.localCommands.AbstractMap.ZoomToFit"); //$NON-NLS-1$
681 handlerService.activateHandler(actionZoomFit.getActionDefinitionId(), new ActionHandler(actionZoomFit));
682
683 actionZoomTo = viewer.createZoomActions(handlerService);
684
685 actionSetAlgorithm = new Action[layoutAlgorithmNames.length];
686 for(int i = 0; i < layoutAlgorithmNames.length; i++)
687 {
688 final MapLayoutAlgorithm alg = MapLayoutAlgorithm.getByValue(i);
689 actionSetAlgorithm[i] = new Action(layoutAlgorithmNames[i], Action.AS_RADIO_BUTTON) {
690 @Override
691 public void run()
692 {
693 setLayoutAlgorithm(alg, true);
694 viewer.setInput(mapPage);
695 }
696 };
697 actionSetAlgorithm[i].setChecked(layoutAlgorithm.getValue() == i);
698 actionSetAlgorithm[i].setEnabled(automaticLayoutEnabled);
699 }
700
701 actionAlwaysFitLayout = new Action(Messages.get().AbstractNetworkMapView_AlwaysFitLayout, Action.AS_CHECK_BOX) {
702 @Override
703 public void run()
704 {
705 alwaysFitLayout = actionAlwaysFitLayout.isChecked();
706 setLayoutAlgorithm(layoutAlgorithm, true);
707 IDialogSettings settings = Activator.getDefault().getDialogSettings();
708 settings.put(viewId + ".alwaysFitLayout", alwaysFitLayout); //$NON-NLS-1$
709 }
710 };
711 actionAlwaysFitLayout.setChecked(alwaysFitLayout);
712
713 actionSetRouter = new Action[connectionRouterNames.length];
714 for(int i = 0; i < connectionRouterNames.length; i++)
715 {
716 final int alg = i + 1;
717 actionSetRouter[i] = new Action(connectionRouterNames[i], Action.AS_RADIO_BUTTON) {
718 @Override
719 public void run()
720 {
721 setConnectionRouter(alg, true);
722 }
723 };
724 actionSetRouter[i].setChecked(routingAlgorithm == alg);
725 }
726
727 actionEnableAutomaticLayout = new Action(Messages.get().AbstractNetworkMapView_EnableAutoLayout, Action.AS_CHECK_BOX) {
728 @Override
729 public void run()
730 {
731 if (automaticLayoutEnabled)
732 {
733 setManualLayout();
734 }
735 else
736 {
737 setAutomaticLayout();
738 }
739 setChecked(automaticLayoutEnabled);
740 }
741 };
742 actionEnableAutomaticLayout.setChecked(automaticLayoutEnabled);
743
744 actionSaveLayout = new Action(Messages.get().AbstractNetworkMapView_SaveLayout) {
745 @Override
746 public void run()
747 {
748 updateObjectPositions();
749 saveLayout();
750 }
751 };
752 actionSaveLayout.setImageDescriptor(SharedIcons.SAVE);
753 actionSaveLayout.setEnabled(!automaticLayoutEnabled);
754
755 actionOpenDrillDownObject = new Action("Open drill-down object") {
756 @Override
757 public void run()
758 {
759 openDrillDownObject();
760 }
761 };
762 actionOpenDrillDownObject.setEnabled(false);
763
764 actionFiguresIcons = new Action(Messages.get().AbstractNetworkMapView_Icons, Action.AS_RADIO_BUTTON) {
765 @Override
766 public void run()
767 {
768 setObjectDisplayMode(MapObjectDisplayMode.ICON, true);
769 }
770 };
771
772 actionFiguresSmallLabels = new Action(Messages.get().AbstractNetworkMapView_SmallLabels, Action.AS_RADIO_BUTTON) {
773 @Override
774 public void run()
775 {
776 setObjectDisplayMode(MapObjectDisplayMode.SMALL_LABEL, true);
777 }
778 };
779
780 actionFiguresLargeLabels = new Action(Messages.get().AbstractNetworkMapView_LargeLabels, Action.AS_RADIO_BUTTON) {
781 @Override
782 public void run()
783 {
784 setObjectDisplayMode(MapObjectDisplayMode.LARGE_LABEL, true);
785 }
786 };
787
788 actionFiguresStatusIcons = new Action(Messages.get().AbstractNetworkMapView_StatusIcons, Action.AS_RADIO_BUTTON) {
789 @Override
790 public void run()
791 {
792 setObjectDisplayMode(MapObjectDisplayMode.STATUS, true);
793 }
794 };
795
796 actionShowGrid = new Action(Messages.get().AbstractNetworkMapView_ShowGrid, Action.AS_CHECK_BOX) {
797 @Override
798 public void run()
799 {
800 viewer.showGrid(actionShowGrid.isChecked());
801 }
802 };
803 actionShowGrid.setImageDescriptor(Activator.getImageDescriptor("icons/grid.png")); //$NON-NLS-1$
804 actionShowGrid.setChecked(viewer.isGridVisible());
805 actionShowGrid.setId("org.netxms.ui.eclipse.networkmaps.localActions.AbstractMap.ShowGrid"); //$NON-NLS-1$
806 actionShowGrid.setActionDefinitionId("org.netxms.ui.eclipse.networkmaps.localCommands.AbstractMap.ShowGrid"); //$NON-NLS-1$
807 handlerService.activateHandler(actionShowGrid.getActionDefinitionId(), new ActionHandler(actionShowGrid));
808
809 actionSnapToGrid = new Action(Messages.get().AbstractNetworkMapView_SnapToGrid, Action.AS_CHECK_BOX) {
810 @Override
811 public void run()
812 {
813 viewer.setSnapToGrid(actionSnapToGrid.isChecked());
814 }
815 };
816 actionSnapToGrid.setImageDescriptor(Activator.getImageDescriptor("icons/snap_to_grid.png")); //$NON-NLS-1$
817 actionSnapToGrid.setChecked(viewer.isSnapToGrid());
818
819 actionAlignToGrid = new Action(Messages.get().AbstractNetworkMapView_AlignToGrid, Activator.getImageDescriptor("icons/align_to_grid.gif")) { //$NON-NLS-1$
820 @Override
821 public void run()
822 {
823 viewer.alignToGrid(false);
824 updateObjectPositions();
825 }
826 };
827 actionAlignToGrid.setId("org.netxms.ui.eclipse.networkmaps.localActions.AbstractMap.AlignToGrid"); //$NON-NLS-1$
828 actionAlignToGrid.setActionDefinitionId("org.netxms.ui.eclipse.networkmaps.localCommands.AbstractMap.AlignToGrid"); //$NON-NLS-1$
829 handlerService.activateHandler(actionAlignToGrid.getActionDefinitionId(), new ActionHandler(actionAlignToGrid));
830
831 actionShowObjectDetails = new Action(Messages.get().AbstractNetworkMapView_ShowObjDetails) {
832 @Override
833 public void run()
834 {
835 showObjectDetails();
836 }
837 };
838
839 actionHideLinkLabels = new Action(Messages.get().AbstractNetworkMapView_HideLinkLabels, Action.AS_CHECK_BOX) {
840 @Override
841 public void run()
842 {
843 labelProvider.setConnectionLabelsVisible(!actionHideLinkLabels.isChecked());
844 viewer.refresh(true);
845 }
846 };
847 actionHideLinkLabels.setImageDescriptor(Activator.getImageDescriptor("icons/hide_link.png")); //$NON-NLS-1$
848
849 actionHideLinks = new Action(Messages.get().AbstractNetworkMapView_HideLinks, Action.AS_CHECK_BOX) {
850 @Override
851 public void run()
852 {
853 labelProvider.setConnectionsVisible(!actionHideLinks.isChecked());
854 viewer.refresh(true);
855 }
856 };
857 actionHideLinks.setImageDescriptor(Activator.getImageDescriptor("icons/hide_net_link.png")); //$NON-NLS-1$
858
859 actionSelectAllObjects = new Action(Messages.get().AbstractNetworkMapView_SelectAllObjects) {
860 @Override
861 public void run()
862 {
863 viewer.setSelection(new StructuredSelection(mapPage.getObjectElements()));
864 }
865 };
866 actionSelectAllObjects.setId("org.netxms.ui.eclipse.networkmaps.localActions.AbstractMap.SelectAllObjects"); //$NON-NLS-1$
867 actionSelectAllObjects.setActionDefinitionId("org.netxms.ui.eclipse.networkmaps.localCommands.AbstractMap.SelectAllObjects"); //$NON-NLS-1$
868 handlerService.activateHandler(actionSelectAllObjects.getActionDefinitionId(), new ActionHandler(actionSelectAllObjects));
869 }
870
871 /**
872 * Create "Layout" submenu
873 *
874 * @return
875 */
876 protected IContributionItem createLayoutSubmenu()
877 {
878 MenuManager layout = new MenuManager(Messages.get().AbstractNetworkMapView_Layout);
879 if (allowManualLayout)
880 {
881 layout.add(actionEnableAutomaticLayout);
882 }
883 layout.add(actionAlwaysFitLayout);
884 layout.add(new Separator());
885 for(int i = 0; i < actionSetAlgorithm.length; i++)
886 layout.add(actionSetAlgorithm[i]);
887 if (allowManualLayout)
888 {
889 layout.add(new Separator());
890 layout.add(actionSaveLayout);
891 }
892 return layout;
893 }
894
895 /**
896 * Create "Routing" submenu
897 *
898 * @return
899 */
900 protected IContributionItem createRoutingSubmenu()
901 {
902 MenuManager submenu = new MenuManager(Messages.get().AbstractNetworkMapView_Routing);
903 for(int i = 0; i < actionSetRouter.length; i++)
904 submenu.add(actionSetRouter[i]);
905 return submenu;
906 }
907
908 /**
909 * Fill action bars
910 */
911 private void contributeToActionBars()
912 {
913 IActionBars bars = getViewSite().getActionBars();
914 fillLocalPullDown(bars.getMenuManager());
915 fillLocalToolBar(bars.getToolBarManager());
916 }
917
918 /**
919 * Fill local pull-down menu
920 *
921 * @param manager
922 */
923 protected void fillLocalPullDown(IMenuManager manager)
924 {
925 MenuManager zoom = new MenuManager(Messages.get().AbstractNetworkMapView_Zoom);
926 for(int i = 0; i < actionZoomTo.length; i++)
927 zoom.add(actionZoomTo[i]);
928
929 MenuManager figureType = new MenuManager(Messages.get().AbstractNetworkMapView_DisplayObjectAs);
930 figureType.add(actionFiguresIcons);
931 figureType.add(actionFiguresSmallLabels);
932 figureType.add(actionFiguresLargeLabels);
933 figureType.add(actionFiguresStatusIcons);
934
935 manager.add(actionShowStatusBackground);
936 manager.add(actionShowStatusIcon);
937 manager.add(actionShowStatusFrame);
938 manager.add(new Separator());
939 manager.add(createLayoutSubmenu());
940 manager.add(createRoutingSubmenu());
941 manager.add(figureType);
942 manager.add(new Separator());
943 manager.add(actionZoomIn);
944 manager.add(actionZoomOut);
945 manager.add(actionZoomFit);
946 manager.add(zoom);
947 manager.add(new Separator());
948 manager.add(actionAlignToGrid);
949 manager.add(actionSnapToGrid);
950 manager.add(actionShowGrid);
951 manager.add(new Separator());
952 manager.add(actionHideLinkLabels);
953 manager.add(actionHideLinks);
954 manager.add(new Separator());
955 manager.add(actionSelectAllObjects);
956 manager.add(new Separator());
957 manager.add(actionRefresh);
958 }
959
960 /**
961 * Fill local tool bar
962 *
963 * @param manager
964 */
965 protected void fillLocalToolBar(IToolBarManager manager)
966 {
967 manager.add(actionZoomIn);
968 manager.add(actionZoomOut);
969 manager.add(actionZoomFit);
970 manager.add(new Separator());
971 manager.add(actionAlignToGrid);
972 manager.add(actionSnapToGrid);
973 manager.add(actionShowGrid);
974 manager.add(new Separator());
975 manager.add(actionHideLinkLabels);
976 manager.add(actionHideLinks);
977 manager.add(new Separator());
978 if (allowManualLayout)
979 {
980 manager.add(actionSaveLayout);
981 }
982 manager.add(actionRefresh);
983 }
984
985 /**
986 * Create popup menu for map
987 */
988 private void createPopupMenu()
989 {
990 // Create menu manager.
991 MenuManager menuMgr = new FilteringMenuManager(Activator.PLUGIN_ID);
992 menuMgr.setRemoveAllWhenShown(true);
993 menuMgr.addMenuListener(new IMenuListener() {
994 public void menuAboutToShow(IMenuManager manager)
995 {
996 int selType = analyzeSelection(currentSelection);
997 switch(selType)
998 {
999 case SELECTION_EMPTY:
1000 fillMapContextMenu(manager);
1001 break;
1002 case SELECTION_OBJECTS:
1003 fillObjectContextMenu(manager);
1004 break;
1005 case SELECTION_ELEMENTS:
1006 fillElementContextMenu(manager);
1007 break;
1008 case SELECTION_LINKS:
1009 fillLinkContextMenu(manager);
1010 break;
1011 }
1012 }
1013 });
1014
1015 // Create menu.
1016 Menu menu = menuMgr.createContextMenu(viewer.getControl());
1017 viewer.getControl().setMenu(menu);
1018
1019 // Register menu for extension.
1020 getSite().registerContextMenu(menuMgr, this);
1021 }
1022
1023 /**
1024 * Fill context menu for map object
1025 *
1026 * @param manager Menu manager
1027 */
1028 protected void fillObjectContextMenu(IMenuManager manager)
1029 {
1030 manager.add(actionOpenDrillDownObject);
1031 manager.add(new Separator());
1032 ObjectContextMenu.fill(manager, getSite(), this);
1033 if (currentSelection.size() == 1)
1034 {
1035 manager.insertAfter(GroupMarkers.MB_PROPERTIES, actionShowObjectDetails);
1036 }
1037 }
1038
1039 /**
1040 * Fill context menu for map element
1041 *
1042 * @param manager Menu manager
1043 */
1044 protected void fillElementContextMenu(IMenuManager manager)
1045 {
1046 }
1047
1048 /**
1049 * Fill context menu for link between objects
1050 *
1051 * @param manager Menu manager
1052 */
1053 protected void fillLinkContextMenu(IMenuManager manager)
1054 {
1055 }
1056
1057 /**
1058 * Fill context menu for map view
1059 *
1060 * @param manager Menu manager
1061 */
1062 protected void fillMapContextMenu(IMenuManager manager)
1063 {
1064 MenuManager zoom = new MenuManager(Messages.get().AbstractNetworkMapView_Zoom);
1065 for(int i = 0; i < actionZoomTo.length; i++)
1066 zoom.add(actionZoomTo[i]);
1067
1068 MenuManager figureType = new MenuManager(Messages.get().AbstractNetworkMapView_DisplayObjectAs);
1069 figureType.add(actionFiguresIcons);
1070 figureType.add(actionFiguresSmallLabels);
1071 figureType.add(actionFiguresLargeLabels);
1072 figureType.add(actionFiguresStatusIcons);
1073
1074 manager.add(actionShowStatusBackground);
1075 manager.add(actionShowStatusIcon);
1076 manager.add(actionShowStatusFrame);
1077 manager.add(new Separator());
1078 manager.add(createLayoutSubmenu());
1079 manager.add(createRoutingSubmenu());
1080 manager.add(figureType);
1081 manager.add(new Separator());
1082 manager.add(actionZoomIn);
1083 manager.add(actionZoomOut);
1084 manager.add(actionZoomFit);
1085 manager.add(zoom);
1086 manager.add(new Separator());
1087 manager.add(actionAlignToGrid);
1088 manager.add(actionSnapToGrid);
1089 manager.add(actionShowGrid);
1090 manager.add(new Separator());
1091 manager.add(actionHideLinkLabels);
1092 manager.add(actionHideLinks);
1093 manager.add(new Separator());
1094 manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
1095 manager.add(new Separator());
1096 manager.add(actionSelectAllObjects);
1097 manager.add(new Separator());
1098 manager.add(actionRefresh);
1099 }
1100
1101 /**
1102 * Tests if given selection contains only NetXMS objects
1103 *
1104 * @param selection
1105 * @return
1106 */
1107 @SuppressWarnings("rawtypes")
1108 private int analyzeSelection(IStructuredSelection selection)
1109 {
1110 if (selection.isEmpty())
1111 return SELECTION_EMPTY;
1112
1113 Iterator it = selection.iterator();
1114 Object first = it.next();
1115 int type;
1116 Class firstClass;
1117 if (first instanceof AbstractObject)
1118 {
1119 type = SELECTION_OBJECTS;
1120 firstClass = AbstractObject.class;
1121 }
1122 else if (first instanceof NetworkMapElement)
1123 {
1124 type = SELECTION_ELEMENTS;
1125 firstClass = NetworkMapElement.class;
1126 }
1127 else if (first instanceof NetworkMapLink)
1128 {
1129 type = SELECTION_LINKS;
1130 firstClass = NetworkMapLink.class;
1131 }
1132 else
1133 {
1134 return SELECTION_MIXED;
1135 }
1136
1137 while(it.hasNext())
1138 {
1139 final Object o = it.next();
1140 if (!firstClass.isInstance(o))
1141 return SELECTION_MIXED;
1142 }
1143 return type;
1144 }
1145
1146 /**
1147 * Called by session listener when NetXMS object was changed.
1148 *
1149 * @param object changed NetXMS object
1150 */
1151 protected void onObjectChange(final AbstractObject object)
1152 {
1153 NetworkMapObject element = mapPage.findObjectElement(object.getObjectId());
1154 if (element != null)
1155 viewer.refresh(element, true);
1156
1157 List<NetworkMapLink> links = mapPage.findLinksWithStatusObject(object.getObjectId());
1158 if (links != null)
1159 {
1160 for(NetworkMapLink l : links)
1161 viewer.refresh(l);
1162 addDciToRequestList();
1163 }
1164
1165 if (object.getObjectId() == rootObject.getObjectId())
1166 rootObject = object;
1167 }
1168
1169 /**
1170 * Called when map layout has to be saved. Object positions already updated when this method is called. Default implementation
1171 * does nothing.
1172 */
1173 protected void saveLayout()
1174 {
1175 }
1176
1177 /*
1178 * (non-Javadoc)
1179 *
1180 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
1181 */
1182 @Override
1183 public void setFocus()
1184 {
1185 viewer.getControl().setFocus();
1186 }
1187
1188 /*
1189 * (non-Javadoc)
1190 *
1191 * @see org.eclipse.ui.part.WorkbenchPart#dispose()
1192 */
1193 @Override
1194 public void dispose()
1195 {
1196 if (sessionListener != null)
1197 session.removeListener(sessionListener);
1198 if (labelProvider != null)
1199 {
1200 IDialogSettings settings = Activator.getDefault().getDialogSettings();
1201 settings.put(viewId + ".objectFigureType", labelProvider.getObjectFigureType().ordinal()); //$NON-NLS-1$
1202 }
1203 removeDciFromRequestList();
1204 super.dispose();
1205 }
1206
1207 /*
1208 * (non-Javadoc)
1209 *
1210 * @see
1211 * org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
1212 */
1213 @Override
1214 public void addSelectionChangedListener(ISelectionChangedListener listener)
1215 {
1216 selectionListeners.add(listener);
1217 }
1218
1219 /**
1220 * Transform viewer's selection to form usable by another plugins by extracting NetXMS objects from map elements.
1221 *
1222 * @param viewerSelection viewer's selection
1223 * @return selection containing only NetXMS objects
1224 */
1225 @SuppressWarnings("rawtypes")
1226 private IStructuredSelection transformSelection(ISelection viewerSelection)
1227 {
1228 IStructuredSelection selection = (IStructuredSelection)viewerSelection;
1229 if (selection.isEmpty())
1230 return selection;
1231
1232 List<Object> objects = new ArrayList<Object>();
1233 Iterator it = selection.iterator();
1234 while(it.hasNext())
1235 {
1236 Object element = it.next();
1237 if (element instanceof NetworkMapObject)
1238 {
1239 AbstractObject object = session.findObjectById(((NetworkMapObject)element).getObjectId());
1240 if (object != null)
1241 {
1242 objects.add(object);
1243 }
1244 else
1245 {
1246 // Fix for issue NX-24
1247 // If object not found, add map element to selection
1248 // This will allow removal of unknown objects from map
1249 objects.add(element);
1250 }
1251 }
1252 else if (isSelectableElement(element))
1253 {
1254 objects.add(element);
1255 }
1256 }
1257
1258 return new StructuredSelection(objects.toArray());
1259 }
1260
1261 /**
1262 * Tests if given map element is selectable. Default implementation always returns false.
1263 *
1264 * @param element element to test
1265 * @return true if given element is selectable
1266 */
1267 protected boolean isSelectableElement(Object element)
1268 {
1269 return false;
1270 }
1271
1272 /*
1273 * (non-Javadoc)
1274 *
1275 * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection()
1276 */
1277 @Override
1278 public ISelection getSelection()
1279 {
1280 return currentSelection;
1281 }
1282
1283 /*
1284 * (non-Javadoc)
1285 *
1286 * @see
1287 * org.eclipse.jface.viewers.ISelectionProvider#removeSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener
1288 * )
1289 */
1290 @Override
1291 public void removeSelectionChangedListener(ISelectionChangedListener listener)
1292 {
1293 selectionListeners.remove(listener);
1294 }
1295
1296 /*
1297 * (non-Javadoc)
1298 *
1299 * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)
1300 */
1301 @Override
1302 public void setSelection(ISelection selection)
1303 {
1304 }
1305
1306 /*
1307 * (non-Javadoc)
1308 *
1309 * @see org.eclipse.gef4.zest.core.viewers.IZoomableWorkbenchPart#getZoomableViewer()
1310 */
1311 @Override
1312 public AbstractZoomableViewer getZoomableViewer()
1313 {
1314 return viewer;
1315 }
1316
1317 /**
1318 * Open drill-down object for currently selected object
1319 */
1320 private void openDrillDownObject()
1321 {
1322 if (currentSelection == null)
1323 return;
1324
1325 Object object = currentSelection.getFirstElement();
1326 if (object instanceof AbstractObject)
1327 {
1328 long objectId = (object instanceof NetworkMap) ? ((AbstractObject)object).getObjectId() : ((AbstractObject)object).getDrillDownObjectId();
1329 if (objectId != 0)
1330 {
1331 Object test = session.findObjectById(objectId);
1332 if (test instanceof NetworkMap)
1333 {
1334 try
1335 {
1336 getSite().getPage().showView(PredefinedMap.ID, Long.toString(objectId), IWorkbenchPage.VIEW_ACTIVATE);
1337 }
1338 catch(PartInitException e)
1339 {
1340 MessageDialogHelper.openError(getSite().getShell(), Messages.get().AbstractNetworkMapView_Error, String.format("Cannot open drill-down object view: %s", e.getMessage()));
1341 }
1342 }
1343 if (test instanceof Dashboard)
1344 {
1345 try
1346 {
1347 getSite().getPage().showView("org.netxms.ui.eclipse.dashboard.views.DashboardView", Long.toString(objectId), IWorkbenchPage.VIEW_ACTIVATE);
1348 }
1349 catch(PartInitException e)
1350 {
1351 MessageDialogHelper.openError(getSite().getShell(), Messages.get().AbstractNetworkMapView_Error, String.format("Cannot open drill-down object view: %s", e.getMessage()));
1352 }
1353 }
1354 }
1355 }
1356 }
1357
1358 /**
1359 * Set map default connection routing algorithm
1360 *
1361 * @param routingAlgorithm
1362 */
1363 public void setConnectionRouter(int routingAlgorithm, boolean doSave)
1364 {
1365 switch(routingAlgorithm)
1366 {
1367 case NetworkMapLink.ROUTING_MANHATTAN:
1368 this.routingAlgorithm = NetworkMapLink.ROUTING_MANHATTAN;
1369 viewer.getGraphControl().setRouter(new ManhattanConnectionRouter());
1370 break;
1371 default:
1372 this.routingAlgorithm = NetworkMapLink.ROUTING_DIRECT;
1373 viewer.getGraphControl().setRouter(null);
1374 break;
1375 }
1376 for(int i = 0; i < actionSetRouter.length; i++)
1377 actionSetRouter[i].setChecked(routingAlgorithm == (i + 1));
1378 if (doSave)
1379 {
1380 updateObjectPositions();
1381 saveLayout();
1382 }
1383 viewer.refresh();
1384 }
1385
1386 /**
1387 * Show details for selected object
1388 */
1389 private void showObjectDetails()
1390 {
1391 if ((currentSelection.size() != 1) || !(currentSelection.getFirstElement() instanceof AbstractObject))
1392 return;
1393
1394 AbstractObject object = (AbstractObject)currentSelection.getFirstElement();
1395 try
1396 {
1397 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
1398 .showView("org.netxms.ui.eclipse.objectview.view.tabbed_object_view"); //$NON-NLS-1$
1399 CommandBridge.getInstance().execute("TabbedObjectView/changeObject", object.getObjectId());
1400 }
1401 catch(PartInitException e)
1402 {
1403 MessageDialogHelper.openError(getSite().getShell(), Messages.get().AbstractNetworkMapView_Error,
1404 String.format(Messages.get().AbstractNetworkMapView_OpenObjDetailsError, e.getLocalizedMessage()));
1405 }
1406 }
1407
1408 /**
1409 * @param string
1410 * @return
1411 */
1412 private static int safeParseInt(String string)
1413 {
1414 if (string == null)
1415 return 65535;
1416 try
1417 {
1418 return Integer.parseInt(string);
1419 }
1420 catch(NumberFormatException e)
1421 {
1422 return 65535;
1423 }
1424 }
1425
1426 /**
1427 * Internal data for object double click handlers
1428 */
1429 private class DoubleClickHandlerData
1430 {
1431 ObjectDoubleClickHandler handler;
1432 int priority;
1433 Class<?> enabledFor;
1434 }
1435
1436 /**
1437 * Goes thought all links and trys to add to request list required DCIs.
1438 */
1439 protected void addDciToRequestList()
1440 {
1441 Collection<NetworkMapLink> linkList = mapPage.getLinks();
1442 for (NetworkMapLink item : linkList)
1443 {
1444 if(item.hasDciData())
1445 {
1446 for (SingleDciConfig value :item.getDciAsList())
1447 {
1448 if(value.type == SingleDciConfig.ITEM)
1449 {
1450 dciValueProvider.addDci(value.getNodeId(), value.dciId, mapPage);
1451 }
1452 else
1453 {
1454 dciValueProvider.addDci(value.getNodeId(), value.dciId, value.column, value.instance, mapPage);
1455 }
1456 }
1457 }
1458 }
1459 Collection<NetworkMapElement> mapElements = mapPage.getElements();
1460 for (NetworkMapElement element : mapElements)
1461 {
1462 if(element instanceof NetworkMapDCIContainer)
1463 {
1464 NetworkMapDCIContainer item = (NetworkMapDCIContainer)element;
1465 if(item.hasDciData())
1466 {
1467 for (SingleDciConfig value : item.getObjectDCIArray())
1468 {
1469 if(value.type == SingleDciConfig.ITEM)
1470 {
1471 dciValueProvider.addDci(value.getNodeId(), value.dciId, mapPage);
1472 }
1473 else
1474 {
1475 dciValueProvider.addDci(value.getNodeId(), value.dciId, value.column, value.instance, mapPage);
1476 }
1477 }
1478 }
1479 }
1480
1481 if(element instanceof NetworkMapDCIImage)
1482 {
1483 NetworkMapDCIImage item = (NetworkMapDCIImage)element;
1484 DCIImageConfiguration config = item.getImageOptions();
1485 SingleDciConfig value = config.getDci();
1486 if(value.type == SingleDciConfig.ITEM)
1487 {
1488 dciValueProvider.addDci(value.getNodeId(), value.dciId, mapPage);
1489 }
1490 else
1491 {
1492 dciValueProvider.addDci(value.getNodeId(), value.dciId, value.column, value.instance, mapPage);
1493 }
1494 }
1495 }
1496 }
1497
1498 /**
1499 * Removes DCIs from request list
1500 */
1501 protected void removeDciFromRequestList()
1502 {
1503 Collection<NetworkMapLink> linkList = mapPage.getLinks();
1504 for (NetworkMapLink item : linkList)
1505 {
1506 if(item.hasDciData())
1507 {
1508 dciValueProvider.removeDcis(mapPage);
1509 }
1510 }
1511 }
1512
1513 /**
1514 * @param mode
1515 * @param saveLayout
1516 */
1517 protected void setObjectDisplayMode(MapObjectDisplayMode mode, boolean saveLayout)
1518 {
1519 labelProvider.setObjectFigureType(mode);
1520 if (saveLayout)
1521 {
1522 updateObjectPositions();
1523 saveLayout();
1524 }
1525 viewer.refresh(true);
1526 actionShowStatusBackground.setEnabled(mode == MapObjectDisplayMode.ICON);
1527 actionShowStatusFrame.setEnabled(mode == MapObjectDisplayMode.ICON);
1528 actionShowStatusIcon.setEnabled(mode == MapObjectDisplayMode.ICON);
1529 actionFiguresIcons.setChecked(labelProvider.getObjectFigureType() == MapObjectDisplayMode.ICON);
1530 actionFiguresSmallLabels.setChecked(labelProvider.getObjectFigureType() == MapObjectDisplayMode.SMALL_LABEL);
1531 actionFiguresLargeLabels.setChecked(labelProvider.getObjectFigureType() == MapObjectDisplayMode.LARGE_LABEL);
1532 actionFiguresStatusIcons.setChecked(labelProvider.getObjectFigureType() == MapObjectDisplayMode.STATUS);
1533 }
1534 }