Search in sources :

Example 1 with MapLayoutAlgorithm

use of org.netxms.client.maps.MapLayoutAlgorithm 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 2 with MapLayoutAlgorithm

use of org.netxms.client.maps.MapLayoutAlgorithm 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)

Example 3 with MapLayoutAlgorithm

use of org.netxms.client.maps.MapLayoutAlgorithm in project netxms by netxms.

the class AbstractNetworkMapView method createActions.

/**
 * Create actions
 */
protected void createActions() {
    final IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
    actionRefresh = new RefreshAction(this) {

        @Override
        public void run() {
            refreshMap();
        }
    };
    actionShowLinkDirection = new Action("Show link direction", Action.AS_CHECK_BOX) {

        @Override
        public void run() {
            labelProvider.setShowLinkDirection(!labelProvider.isShowLinkDirection());
            setChecked(labelProvider.isShowLinkDirection());
            updateObjectPositions();
            saveLayout();
            viewer.refresh();
        }
    };
    actionShowLinkDirection.setChecked(labelProvider.isShowLinkDirection());
    actionShowStatusBackground = new Action(Messages.get().AbstractNetworkMapView_ShowStatusBkgnd, Action.AS_CHECK_BOX) {

        @Override
        public void run() {
            labelProvider.setShowStatusBackground(!labelProvider.isShowStatusBackground());
            setChecked(labelProvider.isShowStatusBackground());
            updateObjectPositions();
            saveLayout();
            viewer.refresh();
        }
    };
    actionShowStatusBackground.setChecked(labelProvider.isShowStatusBackground());
    actionShowStatusBackground.setEnabled(labelProvider.getObjectFigureType() == MapObjectDisplayMode.ICON);
    actionShowStatusIcon = new Action(Messages.get().AbstractNetworkMapView_ShowStatusIcon, Action.AS_CHECK_BOX) {

        @Override
        public void run() {
            labelProvider.setShowStatusIcons(!labelProvider.isShowStatusIcons());
            setChecked(labelProvider.isShowStatusIcons());
            updateObjectPositions();
            saveLayout();
            viewer.refresh();
        }
    };
    actionShowStatusIcon.setChecked(labelProvider.isShowStatusIcons());
    actionShowStatusIcon.setEnabled(labelProvider.getObjectFigureType() == MapObjectDisplayMode.ICON);
    actionShowStatusFrame = new Action(Messages.get().AbstractNetworkMapView_ShowStatusFrame, Action.AS_CHECK_BOX) {

        @Override
        public void run() {
            labelProvider.setShowStatusFrame(!labelProvider.isShowStatusFrame());
            setChecked(labelProvider.isShowStatusFrame());
            updateObjectPositions();
            saveLayout();
            viewer.refresh();
        }
    };
    actionShowStatusFrame.setChecked(labelProvider.isShowStatusFrame());
    actionShowStatusFrame.setEnabled(labelProvider.getObjectFigureType() == MapObjectDisplayMode.ICON);
    actionZoomIn = new Action(Messages.get().AbstractNetworkMapView_ZoomIn, SharedIcons.ZOOM_IN) {

        @Override
        public void run() {
            viewer.zoomIn();
        }
    };
    // $NON-NLS-1$
    actionZoomIn.setId("org.netxms.ui.eclipse.networkmaps.localActions.AbstractMap.ZoomIn");
    // $NON-NLS-1$
    actionZoomIn.setActionDefinitionId("org.netxms.ui.eclipse.networkmaps.localCommands.AbstractMap.ZoomIn");
    handlerService.activateHandler(actionZoomIn.getActionDefinitionId(), new ActionHandler(actionZoomIn));
    actionZoomOut = new Action(Messages.get().AbstractNetworkMapView_ZoomOut, SharedIcons.ZOOM_OUT) {

        @Override
        public void run() {
            viewer.zoomOut();
        }
    };
    // $NON-NLS-1$
    actionZoomOut.setId("org.netxms.ui.eclipse.networkmaps.localActions.AbstractMap.ZoomOut");
    // $NON-NLS-1$
    actionZoomOut.setActionDefinitionId("org.netxms.ui.eclipse.networkmaps.localCommands.AbstractMap.ZoomOut");
    handlerService.activateHandler(actionZoomOut.getActionDefinitionId(), new ActionHandler(actionZoomOut));
    actionZoomFit = new // $NON-NLS-1$
    Action(// $NON-NLS-1$
    Messages.get().AbstractNetworkMapView_ZoomFit, // $NON-NLS-1$
    Activator.getImageDescriptor("icons/fit.png")) {

        @Override
        public void run() {
            viewer.zoomFit();
        }
    };
    // $NON-NLS-1$
    actionZoomFit.setId("org.netxms.ui.eclipse.networkmaps.localActions.AbstractMap.ZoomToFit");
    // $NON-NLS-1$
    actionZoomFit.setActionDefinitionId("org.netxms.ui.eclipse.networkmaps.localCommands.AbstractMap.ZoomToFit");
    handlerService.activateHandler(actionZoomFit.getActionDefinitionId(), new ActionHandler(actionZoomFit));
    actionZoomTo = viewer.createZoomActions(handlerService);
    actionSetAlgorithm = new Action[layoutAlgorithmNames.length];
    for (int i = 0; i < layoutAlgorithmNames.length; i++) {
        final MapLayoutAlgorithm alg = MapLayoutAlgorithm.getByValue(i);
        actionSetAlgorithm[i] = new Action(layoutAlgorithmNames[i], Action.AS_RADIO_BUTTON) {

            @Override
            public void run() {
                setLayoutAlgorithm(alg, true);
                viewer.setInput(mapPage);
            }
        };
        actionSetAlgorithm[i].setChecked(layoutAlgorithm.getValue() == i);
        actionSetAlgorithm[i].setEnabled(automaticLayoutEnabled);
    }
    actionAlwaysFitLayout = new Action(Messages.get().AbstractNetworkMapView_AlwaysFitLayout, Action.AS_CHECK_BOX) {

        @Override
        public void run() {
            alwaysFitLayout = actionAlwaysFitLayout.isChecked();
            setLayoutAlgorithm(layoutAlgorithm, true);
            IDialogSettings settings = Activator.getDefault().getDialogSettings();
            // $NON-NLS-1$
            settings.put(viewId + ".alwaysFitLayout", alwaysFitLayout);
        }
    };
    actionAlwaysFitLayout.setChecked(alwaysFitLayout);
    actionSetRouter = new Action[connectionRouterNames.length];
    for (int i = 0; i < connectionRouterNames.length; i++) {
        final int alg = i + 1;
        actionSetRouter[i] = new Action(connectionRouterNames[i], Action.AS_RADIO_BUTTON) {

            @Override
            public void run() {
                setConnectionRouter(alg, true);
            }
        };
        actionSetRouter[i].setChecked(routingAlgorithm == alg);
    }
    actionEnableAutomaticLayout = new Action(Messages.get().AbstractNetworkMapView_EnableAutoLayout, Action.AS_CHECK_BOX) {

        @Override
        public void run() {
            if (automaticLayoutEnabled) {
                setManualLayout();
            } else {
                setAutomaticLayout();
            }
            setChecked(automaticLayoutEnabled);
        }
    };
    actionEnableAutomaticLayout.setChecked(automaticLayoutEnabled);
    actionSaveLayout = new Action(Messages.get().AbstractNetworkMapView_SaveLayout) {

        @Override
        public void run() {
            updateObjectPositions();
            saveLayout();
        }
    };
    actionSaveLayout.setImageDescriptor(SharedIcons.SAVE);
    actionSaveLayout.setEnabled(!automaticLayoutEnabled);
    actionOpenDrillDownObject = new Action("Open drill-down object") {

        @Override
        public void run() {
            openDrillDownObject();
        }
    };
    actionOpenDrillDownObject.setEnabled(false);
    actionFiguresIcons = new Action(Messages.get().AbstractNetworkMapView_Icons, Action.AS_RADIO_BUTTON) {

        @Override
        public void run() {
            setObjectDisplayMode(MapObjectDisplayMode.ICON, true);
        }
    };
    actionFiguresSmallLabels = new Action(Messages.get().AbstractNetworkMapView_SmallLabels, Action.AS_RADIO_BUTTON) {

        @Override
        public void run() {
            setObjectDisplayMode(MapObjectDisplayMode.SMALL_LABEL, true);
        }
    };
    actionFiguresLargeLabels = new Action(Messages.get().AbstractNetworkMapView_LargeLabels, Action.AS_RADIO_BUTTON) {

        @Override
        public void run() {
            setObjectDisplayMode(MapObjectDisplayMode.LARGE_LABEL, true);
        }
    };
    actionFiguresStatusIcons = new Action(Messages.get().AbstractNetworkMapView_StatusIcons, Action.AS_RADIO_BUTTON) {

        @Override
        public void run() {
            setObjectDisplayMode(MapObjectDisplayMode.STATUS, true);
        }
    };
    actionFiguresFloorPlan = new Action("Floor plan", Action.AS_RADIO_BUTTON) {

        @Override
        public void run() {
            setObjectDisplayMode(MapObjectDisplayMode.FLOOR_PLAN, true);
        }
    };
    actionShowGrid = new Action(Messages.get().AbstractNetworkMapView_ShowGrid, Action.AS_CHECK_BOX) {

        @Override
        public void run() {
            viewer.showGrid(actionShowGrid.isChecked());
        }
    };
    // $NON-NLS-1$
    actionShowGrid.setImageDescriptor(Activator.getImageDescriptor("icons/grid.png"));
    actionShowGrid.setChecked(viewer.isGridVisible());
    // $NON-NLS-1$
    actionShowGrid.setId("org.netxms.ui.eclipse.networkmaps.localActions.AbstractMap.ShowGrid");
    // $NON-NLS-1$
    actionShowGrid.setActionDefinitionId("org.netxms.ui.eclipse.networkmaps.localCommands.AbstractMap.ShowGrid");
    handlerService.activateHandler(actionShowGrid.getActionDefinitionId(), new ActionHandler(actionShowGrid));
    actionSnapToGrid = new Action(Messages.get().AbstractNetworkMapView_SnapToGrid, Action.AS_CHECK_BOX) {

        @Override
        public void run() {
            viewer.setSnapToGrid(actionSnapToGrid.isChecked());
        }
    };
    // $NON-NLS-1$
    actionSnapToGrid.setImageDescriptor(Activator.getImageDescriptor("icons/snap_to_grid.png"));
    actionSnapToGrid.setChecked(viewer.isSnapToGrid());
    actionAlignToGrid = new // $NON-NLS-1$
    Action(// $NON-NLS-1$
    Messages.get().AbstractNetworkMapView_AlignToGrid, // $NON-NLS-1$
    Activator.getImageDescriptor("icons/align_to_grid.gif")) {

        @Override
        public void run() {
            viewer.alignToGrid(false);
            updateObjectPositions();
        }
    };
    // $NON-NLS-1$
    actionAlignToGrid.setId("org.netxms.ui.eclipse.networkmaps.localActions.AbstractMap.AlignToGrid");
    // $NON-NLS-1$
    actionAlignToGrid.setActionDefinitionId("org.netxms.ui.eclipse.networkmaps.localCommands.AbstractMap.AlignToGrid");
    handlerService.activateHandler(actionAlignToGrid.getActionDefinitionId(), new ActionHandler(actionAlignToGrid));
    actionShowObjectDetails = new Action(Messages.get().AbstractNetworkMapView_ShowObjDetails) {

        @Override
        public void run() {
            showObjectDetails();
        }
    };
    actionHideLinkLabels = new Action(Messages.get().AbstractNetworkMapView_HideLinkLabels, Action.AS_CHECK_BOX) {

        @Override
        public void run() {
            labelProvider.setConnectionLabelsVisible(!actionHideLinkLabels.isChecked());
            viewer.refresh(true);
        }
    };
    // $NON-NLS-1$
    actionHideLinkLabels.setImageDescriptor(Activator.getImageDescriptor("icons/hide_link.png"));
    actionHideLinks = new Action(Messages.get().AbstractNetworkMapView_HideLinks, Action.AS_CHECK_BOX) {

        @Override
        public void run() {
            labelProvider.setConnectionsVisible(!actionHideLinks.isChecked());
            viewer.refresh(true);
        }
    };
    // $NON-NLS-1$
    actionHideLinks.setImageDescriptor(Activator.getImageDescriptor("icons/hide_net_link.png"));
    actionSelectAllObjects = new Action(Messages.get().AbstractNetworkMapView_SelectAllObjects) {

        @Override
        public void run() {
            viewer.setSelection(new StructuredSelection(mapPage.getObjectElements()));
        }
    };
    // $NON-NLS-1$
    actionSelectAllObjects.setId("org.netxms.ui.eclipse.networkmaps.localActions.AbstractMap.SelectAllObjects");
    // $NON-NLS-1$
    actionSelectAllObjects.setActionDefinitionId("org.netxms.ui.eclipse.networkmaps.localCommands.AbstractMap.SelectAllObjects");
    handlerService.activateHandler(actionSelectAllObjects.getActionDefinitionId(), new ActionHandler(actionSelectAllObjects));
    actionLockLink = new Action("Locked") {

        @Override
        public void run() {
            changeLinkLock();
        }
    };
}
Also used : RefreshAction(org.netxms.ui.eclipse.actions.RefreshAction) Action(org.eclipse.jface.action.Action) IHandlerService(org.eclipse.ui.handlers.IHandlerService) RefreshAction(org.netxms.ui.eclipse.actions.RefreshAction) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) MapLayoutAlgorithm(org.netxms.client.maps.MapLayoutAlgorithm) ActionHandler(org.eclipse.jface.commands.ActionHandler) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

MapLayoutAlgorithm (org.netxms.client.maps.MapLayoutAlgorithm)3 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 Dimension (org.eclipse.draw2d.geometry.Dimension)1 Point (org.eclipse.draw2d.geometry.Point)1 Action (org.eclipse.jface.action.Action)1 ActionHandler (org.eclipse.jface.commands.ActionHandler)1 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)1 IHandlerService (org.eclipse.ui.handlers.IHandlerService)1 NetworkMapObject (org.netxms.client.maps.elements.NetworkMapObject)1 AbstractObject (org.netxms.client.objects.AbstractObject)1 RefreshAction (org.netxms.ui.eclipse.actions.RefreshAction)1