Search in sources :

Example 21 with AbstractNode

use of org.netxms.client.objects.AbstractNode in project netxms by netxms.

the class TableLastValuesView method init.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite)
	 */
@Override
public void init(IViewSite site) throws PartInitException {
    super.init(site);
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    // Secondary ID must by in form nodeId&dciId
    // $NON-NLS-1$
    String[] parts = site.getSecondaryId().split("&");
    if (parts.length != 2)
        // $NON-NLS-1$
        throw new PartInitException("Internal error");
    objectId = Long.parseLong(parts[0]);
    AbstractObject object = session.findObjectById(objectId);
    if ((object == null) || (!(object instanceof AbstractNode) && !(object instanceof Cluster) && !(object instanceof MobileDevice) && !(object instanceof Sensor)))
        throw new PartInitException(Messages.get().TableLastValuesView_InvalidObjectID);
    dciId = Long.parseLong(parts[1]);
    // $NON-NLS-1$ //$NON-NLS-2$
    setPartName(object.getObjectName() + ": [" + Long.toString(dciId) + "]");
}
Also used : NXCSession(org.netxms.client.NXCSession) MobileDevice(org.netxms.client.objects.MobileDevice) AbstractNode(org.netxms.client.objects.AbstractNode) AbstractObject(org.netxms.client.objects.AbstractObject) Cluster(org.netxms.client.objects.Cluster) PartInitException(org.eclipse.ui.PartInitException) Sensor(org.netxms.client.objects.Sensor)

Example 22 with AbstractNode

use of org.netxms.client.objects.AbstractNode in project netxms by netxms.

the class NodeListComparator method compare.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
	 */
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    final AbstractNode node1 = (AbstractNode) e1;
    final AbstractNode node2 = (AbstractNode) e2;
    // $NON-NLS-1$
    final int column = (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID");
    int result;
    switch(column) {
        case NodesTab.COLUMN_SYS_DESCRIPTION:
            result = node1.getSystemDescription().compareToIgnoreCase(node2.getSystemDescription());
            break;
        case NodesTab.COLUMN_PLATFORM:
            result = node1.getPlatformName().compareToIgnoreCase(node2.getPlatformName());
            break;
        case NodesTab.COLUMN_AGENT_VERSION:
            result = node1.getAgentVersion().compareToIgnoreCase(node2.getAgentVersion());
            break;
        case NodesTab.COLUMN_ID:
            result = Long.signum(node1.getObjectId() - node2.getObjectId());
            break;
        case NodesTab.COLUMN_NAME:
            result = node1.getObjectName().compareToIgnoreCase(node2.getObjectName());
            break;
        case NodesTab.COLUMN_STATUS:
            result = node1.getStatus().compareTo(node2.getStatus());
            break;
        case NodesTab.COLUMN_IP_ADDRESS:
            result = ComparatorHelper.compareInetAddresses(node1.getPrimaryIP().getAddress(), node2.getPrimaryIP().getAddress());
            break;
        case NodesTab.COLUMN_RACK:
            Rack rack1 = session.findObjectById(node1.getRackId(), Rack.class);
            Rack rack2 = session.findObjectById(node2.getRackId(), Rack.class);
            if ((rack1 != null) && (rack2 != null)) {
                result = rack1.getObjectName().compareToIgnoreCase(rack2.getObjectName());
                if (result == 0) {
                    result = node1.getRackPosition() - node2.getRackPosition();
                }
            } else {
                result = Long.signum(node1.getRackId() - node2.getRackId());
            }
            break;
        default:
            result = 0;
            break;
    }
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : Rack(org.netxms.client.objects.Rack) AbstractNode(org.netxms.client.objects.AbstractNode) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer)

Example 23 with AbstractNode

use of org.netxms.client.objects.AbstractNode in project netxms by netxms.

the class ObjectStatusWidget method paintControl.

/* (non-Javadoc)
	 * @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent)
	 */
@Override
public void paintControl(PaintEvent e) {
    Rectangle rect = getClientArea();
    rect.width--;
    rect.height--;
    e.gc.setAntialias(SWT.ON);
    e.gc.setTextAntialias(SWT.ON);
    e.gc.setForeground(SharedColors.getColor(SharedColors.TEXT_NORMAL, getDisplay()));
    e.gc.setLineWidth(1);
    e.gc.setBackground(StatusDisplayInfo.getStatusColor(object.getStatus()));
    e.gc.setAlpha(127);
    e.gc.fillRoundRectangle(rect.x, rect.y, rect.width, rect.height, 8, 8);
    e.gc.setAlpha(255);
    e.gc.drawRoundRectangle(rect.x, rect.y, rect.width, rect.height, 8, 8);
    final String text = (object instanceof AbstractNode) ? // $NON-NLS-1$
    (object.getObjectName() + "\n" + ((AbstractNode) object).getPrimaryIP().getHostAddress()) : object.getObjectName();
    rect.x += 4;
    rect.y += 4;
    rect.width -= 8;
    rect.height -= 8;
    int h = e.gc.textExtent(text).y;
    e.gc.drawText(text, rect.x, rect.y + (rect.height - h) / 2, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
}
Also used : AbstractNode(org.netxms.client.objects.AbstractNode) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point)

Example 24 with AbstractNode

use of org.netxms.client.objects.AbstractNode in project netxms by netxms.

the class TemplateGraphDynamicMenu method fill.

/* (non-Javadoc)
    * @see org.eclipse.jface.action.ContributionItem#fill(org.eclipse.swt.widgets.Menu, int)
    */
@Override
public void fill(Menu menu, int index) {
    Object selection = evalService.getCurrentState().getVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
    if ((selection == null) || !(selection instanceof IStructuredSelection) || ((IStructuredSelection) selection).size() != 1)
        return;
    AbstractNode firstNode = null;
    for (Object o : ((IStructuredSelection) selection).toList()) {
        if (o instanceof AbstractNode) {
            firstNode = (AbstractNode) o;
            break;
        }
    }
    if (firstNode == null)
        return;
    final AbstractNode node = firstNode;
    // array should be already sorted
    GraphSettings[] settings = GraphTemplateCache.getInstance().getGraphTemplates();
    final Menu graphMenu = new Menu(menu);
    Map<String, Menu> menus = new HashMap<String, Menu>();
    int added = 0;
    for (int i = 0; i < settings.length; i++) {
        if (settings[i].isApplicableForNode(node)) {
            // $NON-NLS-1$
            String[] path = settings[i].getName().split("\\-\\>");
            Menu rootMenu = graphMenu;
            for (int j = 0; j < path.length - 1; j++) {
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                final String key = rootMenu.hashCode() + "@" + path[j].replace("&", "");
                Menu currMenu = menus.get(key);
                if (currMenu == null) {
                    currMenu = new Menu(rootMenu);
                    MenuItem item = new MenuItem(rootMenu, SWT.CASCADE);
                    item.setText(path[j]);
                    item.setMenu(currMenu);
                    menus.put(key, currMenu);
                }
                rootMenu = currMenu;
            }
            final MenuItem item = new MenuItem(rootMenu, SWT.PUSH);
            item.setText(path[path.length - 1]);
            item.setData(settings[i]);
            item.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
                    final GraphSettings gs = (GraphSettings) item.getData();
                    ConsoleJob job = new ConsoleJob("Get last values of " + node.getObjectName(), null, Activator.PLUGIN_ID, null) {

                        @Override
                        protected String getErrorMessage() {
                            return "Not possible to get last values for node" + node.getObjectName();
                        }

                        @Override
                        protected void runInternal(IProgressMonitor monitor) throws Exception {
                            final DciValue[] data = session.getLastValues(node.getObjectId());
                            GraphTemplateCache.execute(node, gs, data, getDisplay());
                        }
                    };
                    job.setUser(false);
                    job.start();
                }
            });
            added++;
        }
    }
    if (added > 0) {
        MenuItem graphMenuItem = new MenuItem(menu, SWT.CASCADE, index);
        graphMenuItem.setText("Graphs");
        graphMenuItem.setMenu(graphMenu);
    } else {
        graphMenu.dispose();
    }
}
Also used : NXCSession(org.netxms.client.NXCSession) AbstractNode(org.netxms.client.objects.AbstractNode) HashMap(java.util.HashMap) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GraphSettings(org.netxms.client.datacollection.GraphSettings) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 25 with AbstractNode

use of org.netxms.client.objects.AbstractNode in project netxms by netxms.

the class ShowVlans method selectionChanged.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
	 */
@Override
public void selectionChanged(IAction action, ISelection selection) {
    if ((selection instanceof IStructuredSelection) && (((IStructuredSelection) selection).size() == 1)) {
        Object obj = ((IStructuredSelection) selection).getFirstElement();
        if (obj instanceof AbstractNode) {
            action.setEnabled(true);
            objectId = ((AbstractObject) obj).getObjectId();
        } else {
            action.setEnabled(false);
            objectId = 0;
        }
    } else {
        action.setEnabled(false);
        objectId = 0;
    }
}
Also used : AbstractNode(org.netxms.client.objects.AbstractNode) AbstractObject(org.netxms.client.objects.AbstractObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

AbstractNode (org.netxms.client.objects.AbstractNode)47 AbstractObject (org.netxms.client.objects.AbstractObject)27 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)14 NXCSession (org.netxms.client.NXCSession)13 ArrayList (java.util.ArrayList)12 Cluster (org.netxms.client.objects.Cluster)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 Composite (org.eclipse.swt.widgets.Composite)6 PartInitException (org.eclipse.ui.PartInitException)6 MobileDevice (org.netxms.client.objects.MobileDevice)6 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)6 NXCException (org.netxms.client.NXCException)5 Interface (org.netxms.client.objects.Interface)5 Sensor (org.netxms.client.objects.Sensor)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 DataCollectionItem (org.netxms.client.datacollection.DataCollectionItem)4 Subnet (org.netxms.client.objects.Subnet)4 ISelection (org.eclipse.jface.viewers.ISelection)3