Search in sources :

Example 1 with LayoutAlgorithm

use of org.eclipse.gef4.zest.layouts.LayoutAlgorithm 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 LayoutAlgorithm

use of org.eclipse.gef4.zest.layouts.LayoutAlgorithm in project netxms by netxms.

the class AbstractNetworkMapView method setLayoutAlgorithm.

/**
 * Set layout algorithm for map
 *
 * @param alg Layout algorithm
 * @param forceChange
 */
protected void setLayoutAlgorithm(MapLayoutAlgorithm alg, boolean forceChange) {
    if (alg == MapLayoutAlgorithm.MANUAL) {
        if (!automaticLayoutEnabled)
            // manual layout already
            return;
        automaticLayoutEnabled = false;
        // TODO: rewrite, enum value should not be used as index
        actionSetAlgorithm[layoutAlgorithm.getValue()].setChecked(false);
        actionEnableAutomaticLayout.setChecked(false);
        return;
    }
    if (automaticLayoutEnabled && (alg == layoutAlgorithm) && !forceChange)
        // nothing to change
        return;
    if (!automaticLayoutEnabled) {
        actionEnableAutomaticLayout.setChecked(true);
        automaticLayoutEnabled = true;
    }
    LayoutAlgorithm algorithm;
    switch(alg) {
        case SPRING:
            algorithm = new SpringLayoutAlgorithm();
            break;
        case RADIAL:
            algorithm = new RadialLayoutAlgorithm();
            break;
        case HTREE:
            algorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.LEFT_RIGHT);
            break;
        case VTREE:
            algorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.TOP_DOWN);
            break;
        case SPARSE_VTREE:
            algorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.TOP_DOWN);
            ((TreeLayoutAlgorithm) algorithm).setNodeSpace(new Dimension(100, 100));
            break;
        default:
            algorithm = new GridLayoutAlgorithm();
            break;
    }
    viewer.setLayoutAlgorithm(alwaysFitLayout ? algorithm : new CompositeLayoutAlgorithm(new LayoutAlgorithm[] { algorithm, new ExpansionAlgorithm() }));
    actionSetAlgorithm[layoutAlgorithm.getValue()].setChecked(false);
    layoutAlgorithm = alg;
    actionSetAlgorithm[layoutAlgorithm.getValue()].setChecked(true);
}
Also used : SpringLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.SpringLayoutAlgorithm) LayoutAlgorithm(org.eclipse.gef4.zest.layouts.LayoutAlgorithm) RadialLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.RadialLayoutAlgorithm) SpringLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.SpringLayoutAlgorithm) GridLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.GridLayoutAlgorithm) TreeLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.TreeLayoutAlgorithm) CompositeLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.CompositeLayoutAlgorithm) MapLayoutAlgorithm(org.netxms.client.maps.MapLayoutAlgorithm) TreeLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.TreeLayoutAlgorithm) ExpansionAlgorithm(org.netxms.ui.eclipse.networkmaps.algorithms.ExpansionAlgorithm) CompositeLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.CompositeLayoutAlgorithm) RadialLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.RadialLayoutAlgorithm) Dimension(org.eclipse.draw2d.geometry.Dimension) GridLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.GridLayoutAlgorithm)

Example 3 with LayoutAlgorithm

use of org.eclipse.gef4.zest.layouts.LayoutAlgorithm in project netxms by netxms.

the class NetworkMapWidget method setLayoutAlgorithm.

/**
 * Set layout algorithm for map
 * @param alg
 */
public void setLayoutAlgorithm(MapLayoutAlgorithm alg) {
    LayoutAlgorithm algorithm;
    switch(alg) {
        case SPRING:
            algorithm = new SpringLayoutAlgorithm();
            break;
        case RADIAL:
            algorithm = new RadialLayoutAlgorithm();
            break;
        case HTREE:
            algorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.LEFT_RIGHT);
            break;
        case VTREE:
            algorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.TOP_DOWN);
            break;
        case SPARSE_VTREE:
            TreeLayoutAlgorithm mainLayoutAlgorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.TOP_DOWN);
            viewer.setComparator(new ViewerComparator() {

                @Override
                public int compare(Viewer viewer, Object e1, Object e2) {
                    return e1.toString().compareToIgnoreCase(e2.toString());
                }
            });
            algorithm = new CompositeLayoutAlgorithm(new LayoutAlgorithm[] { mainLayoutAlgorithm, new SparseTree() });
            break;
        default:
            algorithm = new GridLayoutAlgorithm();
            break;
    }
    viewer.setLayoutAlgorithm(algorithm);
}
Also used : SpringLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.SpringLayoutAlgorithm) SparseTree(org.netxms.ui.eclipse.networkmaps.algorithms.SparseTree) RadialLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.RadialLayoutAlgorithm) SpringLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.SpringLayoutAlgorithm) GridLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.GridLayoutAlgorithm) TreeLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.TreeLayoutAlgorithm) CompositeLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.CompositeLayoutAlgorithm) MapLayoutAlgorithm(org.netxms.client.maps.MapLayoutAlgorithm) LayoutAlgorithm(org.eclipse.gef4.zest.layouts.LayoutAlgorithm) TreeLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.TreeLayoutAlgorithm) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) CompositeLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.CompositeLayoutAlgorithm) ExtendedGraphViewer(org.netxms.ui.eclipse.networkmaps.views.helpers.ExtendedGraphViewer) Viewer(org.eclipse.jface.viewers.Viewer) AbstractObject(org.netxms.client.objects.AbstractObject) NetworkMapObject(org.netxms.client.maps.elements.NetworkMapObject) RadialLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.RadialLayoutAlgorithm) GridLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.GridLayoutAlgorithm)

Aggregations

LayoutAlgorithm (org.eclipse.gef4.zest.layouts.LayoutAlgorithm)2 CompositeLayoutAlgorithm (org.eclipse.gef4.zest.layouts.algorithms.CompositeLayoutAlgorithm)2 GridLayoutAlgorithm (org.eclipse.gef4.zest.layouts.algorithms.GridLayoutAlgorithm)2 RadialLayoutAlgorithm (org.eclipse.gef4.zest.layouts.algorithms.RadialLayoutAlgorithm)2 SpringLayoutAlgorithm (org.eclipse.gef4.zest.layouts.algorithms.SpringLayoutAlgorithm)2 TreeLayoutAlgorithm (org.eclipse.gef4.zest.layouts.algorithms.TreeLayoutAlgorithm)2 MapLayoutAlgorithm (org.netxms.client.maps.MapLayoutAlgorithm)2 AbstractObject (org.netxms.client.objects.AbstractObject)2 ExtendedGraphViewer (org.netxms.ui.eclipse.networkmaps.views.helpers.ExtendedGraphViewer)2 CoreException (org.eclipse.core.runtime.CoreException)1 Dimension (org.eclipse.draw2d.geometry.Dimension)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 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)1