Search in sources :

Example 1 with NetworkMapLink

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

the class AbstractNetworkMapView method openLinkDci.

/**
 * Handler for opening network map dci on double click
 */
private void openLinkDci() {
    final NetworkMapLink link = (NetworkMapLink) currentSelection.getFirstElement();
    if (!link.hasDciData())
        return;
    new ConsoleJob("Open link dci job", this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

        /* (non-Javadoc)
          * @see org.netxms.ui.eclipse.jobs.ConsoleJob#runInternal(org.eclipse.core.runtime.IProgressMonitor)
          */
        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            DciValue[] values = session.getLastValues(link.getDciAsList());
            final StringBuilder sb = new StringBuilder();
            for (DciValue v : values) {
                sb.append("&");
                sb.append(Integer.toString(v instanceof SimpleDciValue ? ChartDciConfig.ITEM : ChartDciConfig.TABLE));
                sb.append("@");
                sb.append(Long.toString(v.getNodeId()));
                sb.append("@");
                sb.append(Long.toString(v.getId()));
                sb.append("@");
                sb.append(URLEncoder.encode(v.getDescription(), "UTF-8"));
                sb.append("@");
                sb.append(URLEncoder.encode(v.getName(), "UTF-8"));
            }
            runInUIThread(new Runnable() {

                /* (non-Javadoc)
                * @see java.lang.Runnable#run()
                */
                @Override
                public void run() {
                    try {
                        getSite().getPage().showView(HistoricalGraphView.ID, sb.toString(), IWorkbenchPage.VIEW_ACTIVATE);
                    } catch (PartInitException e) {
                        MessageDialogHelper.openError(getSite().getShell(), "Error", String.format("Error opening view: %s", e.getLocalizedMessage()));
                    }
                }
            });
        }

        /* (non-Javadoc)
          * @see org.netxms.ui.eclipse.jobs.ConsoleJob#getErrorMessage()
          */
        @Override
        protected String getErrorMessage() {
            return "Cannot open dci link historical graph view";
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DciValue(org.netxms.client.datacollection.DciValue) SimpleDciValue(org.netxms.client.datacollection.SimpleDciValue) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) SimpleDciValue(org.netxms.client.datacollection.SimpleDciValue) PartInitException(org.eclipse.ui.PartInitException) NetworkMapLink(org.netxms.client.maps.NetworkMapLink) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException)

Example 2 with NetworkMapLink

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

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

the class AbstractNetworkMapView method onObjectChange.

/**
 * Called by session listener when NetXMS object was changed.
 *
 * @param object changed NetXMS object
 */
protected void onObjectChange(final AbstractObject object) {
    NetworkMapObject element = mapPage.findObjectElement(object.getObjectId());
    if (element != null)
        viewer.refresh(element, true);
    List<NetworkMapLink> links = mapPage.findLinksWithStatusObject(object.getObjectId());
    if (links != null) {
        for (NetworkMapLink l : links) viewer.refresh(l);
        addDciToRequestList();
    }
    if (object.getObjectId() == rootObject.getObjectId())
        rootObject = object;
}
Also used : NetworkMapObject(org.netxms.client.maps.elements.NetworkMapObject) NetworkMapLink(org.netxms.client.maps.NetworkMapLink)

Example 4 with NetworkMapLink

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

the class AbstractNetworkMapView method analyzeSelection.

/**
 * Tests if given selection contains only NetXMS objects
 *
 * @param selection
 * @return
 */
@SuppressWarnings("rawtypes")
private int analyzeSelection(IStructuredSelection selection) {
    if (selection.isEmpty())
        return SELECTION_EMPTY;
    Iterator it = selection.iterator();
    Object first = it.next();
    int type;
    Class firstClass;
    if (first instanceof AbstractObject) {
        type = SELECTION_OBJECTS;
        firstClass = AbstractObject.class;
    } else if (first instanceof NetworkMapElement) {
        type = SELECTION_ELEMENTS;
        firstClass = NetworkMapElement.class;
    } else if (first instanceof NetworkMapLink) {
        type = SELECTION_LINKS;
        firstClass = NetworkMapLink.class;
    } else {
        return SELECTION_MIXED;
    }
    while (it.hasNext()) {
        final Object o = it.next();
        if (!firstClass.isInstance(o))
            return SELECTION_MIXED;
    }
    return type;
}
Also used : AbstractObject(org.netxms.client.objects.AbstractObject) NetworkMapElement(org.netxms.client.maps.elements.NetworkMapElement) Iterator(java.util.Iterator) NetworkMapObject(org.netxms.client.maps.elements.NetworkMapObject) AbstractObject(org.netxms.client.objects.AbstractObject) Point(org.eclipse.draw2d.geometry.Point) NetworkMapLink(org.netxms.client.maps.NetworkMapLink)

Example 5 with NetworkMapLink

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

the class PredefinedMap method linkSelectedObjects.

/**
 * Link currently selected objects
 */
private void linkSelectedObjects() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() != 2)
        return;
    Object[] objects = selection.toArray();
    long id1 = ((NetworkMapObject) objects[0]).getId();
    long id2 = ((NetworkMapObject) objects[1]).getId();
    mapPage.addLink(new NetworkMapLink(NetworkMapLink.NORMAL, id1, id2));
    saveMap();
}
Also used : AbstractObject(org.netxms.client.objects.AbstractObject) NetworkMapObject(org.netxms.client.maps.elements.NetworkMapObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) NetworkMapObject(org.netxms.client.maps.elements.NetworkMapObject) NetworkMapLink(org.netxms.client.maps.NetworkMapLink)

Aggregations

NetworkMapLink (org.netxms.client.maps.NetworkMapLink)27 NetworkMapObject (org.netxms.client.maps.elements.NetworkMapObject)16 AbstractObject (org.netxms.client.objects.AbstractObject)12 NetworkMapPage (org.netxms.client.maps.NetworkMapPage)6 NetworkMapElement (org.netxms.client.maps.elements.NetworkMapElement)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 NXCPMessage (org.netxms.base.NXCPMessage)3 AccessPoint (org.netxms.client.objects.AccessPoint)3 Cluster (org.netxms.client.objects.Cluster)3 Container (org.netxms.client.objects.Container)3 Node (org.netxms.client.objects.Node)3 CoreException (org.eclipse.core.runtime.CoreException)2 Point (org.eclipse.draw2d.geometry.Point)2 PartInitException (org.eclipse.ui.PartInitException)2 ObjectStatus (org.netxms.client.constants.ObjectStatus)2 DCIImageConfiguration (org.netxms.client.maps.configs.DCIImageConfiguration)2 SingleDciConfig (org.netxms.client.maps.configs.SingleDciConfig)2 NetworkMapDCIContainer (org.netxms.client.maps.elements.NetworkMapDCIContainer)2 NetworkMapDCIImage (org.netxms.client.maps.elements.NetworkMapDCIImage)2 ClusterResource (org.netxms.client.objects.ClusterResource)2