Search in sources :

Example 1 with BendpointEditor

use of org.netxms.ui.eclipse.networkmaps.views.helpers.BendpointEditor in project netxms by netxms.

the class AbstractNetworkMapView method createPartControl.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.part.ViewPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public final void createPartControl(Composite parent) {
    FillLayout layout = new FillLayout();
    parent.setLayout(layout);
    viewer = new ExtendedGraphViewer(parent, SWT.NONE);
    viewer.setContentProvider(new MapContentProvider(viewer));
    labelProvider = new MapLabelProvider(viewer);
    viewer.setLabelProvider(labelProvider);
    viewer.setBackgroundColor(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB());
    IDialogSettings settings = Activator.getDefault().getDialogSettings();
    try {
        // $NON-NLS-1$
        alwaysFitLayout = settings.getBoolean(viewId + ".alwaysFitLayout");
    } catch (Exception e) {
    }
    // Zoom level restore and save
    try {
        // $NON-NLS-1$
        viewer.zoomTo(settings.getDouble(viewId + ".zoom"));
    } catch (NumberFormatException e) {
    }
    viewer.getGraphControl().addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            IDialogSettings settings = Activator.getDefault().getDialogSettings();
            // $NON-NLS-1$
            settings.put(viewId + ".zoom", viewer.getZoom());
        }
    });
    getSite().setSelectionProvider(this);
    ISelectionChangedListener listener = new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent e) {
            if (bendpointEditor != null) {
                bendpointEditor.stop();
                bendpointEditor = null;
            }
            currentSelection = transformSelection(e.getSelection());
            if (currentSelection.size() == 1) {
                int selectionType = analyzeSelection(currentSelection);
                if (selectionType == SELECTION_OBJECTS) {
                    AbstractObject object = (AbstractObject) currentSelection.getFirstElement();
                    actionOpenDrillDownObject.setEnabled(object.getDrillDownObjectId() != 0);
                } else {
                    actionOpenDrillDownObject.setEnabled(false);
                    if (selectionType == SELECTION_LINKS) {
                        NetworkMapLink link = (NetworkMapLink) currentSelection.getFirstElement();
                        actionLockLink.setChecked(link.isLocked());
                        if (!link.isLocked() && link.getRouting() == NetworkMapLink.ROUTING_BENDPOINTS) {
                            bendpointEditor = new BendpointEditor(link, (GraphConnection) viewer.getGraphControl().getSelection().get(0), viewer);
                        }
                    }
                }
            } else {
                actionOpenDrillDownObject.setEnabled(false);
            }
            if (selectionListeners.isEmpty())
                return;
            SelectionChangedEvent event = new SelectionChangedEvent(AbstractNetworkMapView.this, currentSelection);
            for (ISelectionChangedListener l : selectionListeners) {
                l.selectionChanged(event);
            }
        }
    };
    viewer.addPostSelectionChangedListener(listener);
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            int selectionType = analyzeSelection(currentSelection);
            if (selectionType == SELECTION_EMPTY)
                return;
            if (selectionType == SELECTION_OBJECTS) {
                AbstractObject object = (AbstractObject) currentSelection.getFirstElement();
                if (object instanceof Rack) {
                    openRackView(Long.toString(object.getObjectId()));
                    return;
                }
                for (DoubleClickHandlerData h : doubleClickHandlers) {
                    if ((h.enabledFor == null) || (h.enabledFor.isInstance(object))) {
                        if (h.handler.onDoubleClick(object)) {
                            return;
                        }
                    }
                }
            } else if (((NetworkMapLink) currentSelection.getFirstElement()).isLocked() && selectionType == SELECTION_LINKS) {
                openLinkDci();
            }
            // Default behavior
            actionOpenDrillDownObject.run();
        }
    });
    sessionListener = new SessionListener() {

        @Override
        public void notificationHandler(final SessionNotification n) {
            if (n.getCode() == SessionNotification.OBJECT_CHANGED) {
                viewer.getControl().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        onObjectChange((AbstractObject) n.getObject());
                    }
                });
            }
        }
    };
    session.addListener(sessionListener);
    createActions();
    contributeToActionBars();
    createPopupMenu();
    if (automaticLayoutEnabled) {
        setLayoutAlgorithm(layoutAlgorithm, true);
    } else {
        viewer.setLayoutAlgorithm(new ManualLayout());
    }
    activateContext();
    registerDoubleClickHandlers();
    setupMapControl();
    refreshMap();
}
Also used : ExtendedGraphViewer(org.netxms.ui.eclipse.networkmaps.views.helpers.ExtendedGraphViewer) DisposeListener(org.eclipse.swt.events.DisposeListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) MapLabelProvider(org.netxms.ui.eclipse.networkmaps.views.helpers.MapLabelProvider) Rack(org.netxms.client.objects.Rack) MapContentProvider(org.netxms.ui.eclipse.networkmaps.views.helpers.MapContentProvider) GraphConnection(org.eclipse.gef4.zest.core.widgets.GraphConnection) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SessionNotification(org.netxms.client.SessionNotification) NetworkMapLink(org.netxms.client.maps.NetworkMapLink) BendpointEditor(org.netxms.ui.eclipse.networkmaps.views.helpers.BendpointEditor) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FillLayout(org.eclipse.swt.layout.FillLayout) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) Point(org.eclipse.draw2d.geometry.Point) ManualLayout(org.netxms.ui.eclipse.networkmaps.algorithms.ManualLayout) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) AbstractObject(org.netxms.client.objects.AbstractObject) SessionListener(org.netxms.client.SessionListener)

Example 2 with BendpointEditor

use of org.netxms.ui.eclipse.networkmaps.views.helpers.BendpointEditor in project netxms by netxms.

the class AbstractNetworkMapView method changeLinkLock.

/**
 * Set link locked or unlocked
 */
protected void changeLinkLock() {
    if ((currentSelection.size() != 1) || !(currentSelection.getFirstElement() instanceof NetworkMapLink))
        return;
    NetworkMapLink link = (NetworkMapLink) currentSelection.getFirstElement();
    link.setLocked(actionLockLink.isChecked());
    if (link.isLocked() && bendpointEditor != null) {
        bendpointEditor.stop();
        bendpointEditor = null;
    } else if (link.getRouting() == NetworkMapLink.ROUTING_BENDPOINTS) {
        bendpointEditor = new BendpointEditor(link, (GraphConnection) viewer.getGraphControl().getSelection().get(0), viewer);
    }
}
Also used : BendpointEditor(org.netxms.ui.eclipse.networkmaps.views.helpers.BendpointEditor) NetworkMapLink(org.netxms.client.maps.NetworkMapLink)

Aggregations

NetworkMapLink (org.netxms.client.maps.NetworkMapLink)2 BendpointEditor (org.netxms.ui.eclipse.networkmaps.views.helpers.BendpointEditor)2 CoreException (org.eclipse.core.runtime.CoreException)1 Point (org.eclipse.draw2d.geometry.Point)1 GraphConnection (org.eclipse.gef4.zest.core.widgets.GraphConnection)1 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 PartInitException (org.eclipse.ui.PartInitException)1 SessionListener (org.netxms.client.SessionListener)1 SessionNotification (org.netxms.client.SessionNotification)1 AbstractObject (org.netxms.client.objects.AbstractObject)1 Rack (org.netxms.client.objects.Rack)1 ManualLayout (org.netxms.ui.eclipse.networkmaps.algorithms.ManualLayout)1 ExtendedGraphViewer (org.netxms.ui.eclipse.networkmaps.views.helpers.ExtendedGraphViewer)1