Search in sources :

Example 1 with Subnet

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

the class SummaryTablesDynamicMenu 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) {
    final Object selection = evalService.getCurrentState().getVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
    if ((selection == null) || !(selection instanceof IStructuredSelection))
        return;
    final AbstractObject baseObject = (AbstractObject) ((IStructuredSelection) selection).getFirstElement();
    if (!(baseObject instanceof Container) && !(baseObject instanceof Cluster) && !(baseObject instanceof ServiceRoot) && !(baseObject instanceof Subnet) && !(baseObject instanceof Zone) && !(baseObject instanceof EntireNetwork))
        return;
    final Menu tablesMenu = new Menu(menu);
    DciSummaryTableDescriptor[] tables = SummaryTablesCache.getInstance().getTables();
    Arrays.sort(tables, new Comparator<DciSummaryTableDescriptor>() {

        @Override
        public int compare(DciSummaryTableDescriptor arg0, DciSummaryTableDescriptor arg1) {
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            return arg0.getMenuPath().replace("&", "").compareToIgnoreCase(arg1.getMenuPath().replace("&", ""));
        }
    });
    Map<String, Menu> menus = new HashMap<String, Menu>();
    int added = 0;
    for (int i = 0; i < tables.length; i++) {
        if (tables[i].getMenuPath().isEmpty())
            continue;
        // $NON-NLS-1$
        String[] path = tables[i].getMenuPath().split("\\-\\>");
        Menu rootMenu = tablesMenu;
        for (int j = 0; j < path.length - 1; j++) {
            // $NON-NLS-1$ //$NON-NLS-2$
            String key = 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(tables[i]);
        item.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                queryTable(baseObject.getObjectId(), ((DciSummaryTableDescriptor) item.getData()).getId());
            }
        });
        added++;
    }
    if (added > 0) {
        MenuItem tablesMenuItem = new MenuItem(menu, SWT.CASCADE, index);
        tablesMenuItem.setText(Messages.get().SummaryTablesDynamicMenu_MenuName);
        tablesMenuItem.setMenu(tablesMenu);
    } else {
        tablesMenu.dispose();
    }
}
Also used : HashMap(java.util.HashMap) Zone(org.netxms.client.objects.Zone) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Cluster(org.netxms.client.objects.Cluster) MenuItem(org.eclipse.swt.widgets.MenuItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EntireNetwork(org.netxms.client.objects.EntireNetwork) DciSummaryTableDescriptor(org.netxms.client.datacollection.DciSummaryTableDescriptor) ServiceRoot(org.netxms.client.objects.ServiceRoot) Container(org.netxms.client.objects.Container) AbstractObject(org.netxms.client.objects.AbstractObject) SelectionEvent(org.eclipse.swt.events.SelectionEvent) AbstractObject(org.netxms.client.objects.AbstractObject) Menu(org.eclipse.swt.widgets.Menu) Subnet(org.netxms.client.objects.Subnet)

Example 2 with Subnet

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

the class DashboardsDynamicMenu 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) {
    final Object selection = evalService.getCurrentState().getVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
    if ((selection == null) || !(selection instanceof IStructuredSelection))
        return;
    final AbstractObject object = (AbstractObject) ((IStructuredSelection) selection).getFirstElement();
    if (!(object instanceof Container) && !(object instanceof Cluster) && !(object instanceof Node) && !(object instanceof MobileDevice) && !(object instanceof ServiceRoot) && !(object instanceof Subnet) && !(object instanceof Zone) && !(object instanceof Condition) && !(object instanceof EntireNetwork) && !(object instanceof Sensor))
        return;
    List<AbstractObject> dashboards = object.getDashboards(true);
    if (dashboards.isEmpty())
        return;
    Collections.sort(dashboards, new Comparator<AbstractObject>() {

        @Override
        public int compare(AbstractObject o1, AbstractObject o2) {
            return o1.getObjectName().compareToIgnoreCase(o2.getObjectName());
        }
    });
    final Menu dashboardsMenu = new Menu(menu);
    for (AbstractObject d : dashboards) {
        final MenuItem item = new MenuItem(dashboardsMenu, SWT.PUSH);
        item.setText(d.getObjectName());
        item.setData(d.getObjectId());
        item.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                try {
                    window.getActivePage().showView(DashboardView.ID, item.getData().toString(), IWorkbenchPage.VIEW_ACTIVATE);
                } catch (PartInitException ex) {
                    MessageDialogHelper.openError(window.getShell(), Messages.get().OpenDashboard_Error, Messages.get().OpenDashboard_ErrorText + ex.getMessage());
                }
            }
        });
    }
    MenuItem dashboardsMenuItem = new MenuItem(menu, SWT.CASCADE, index);
    dashboardsMenuItem.setText(Messages.get().DashboardsDynamicMenu_Dashboards);
    dashboardsMenuItem.setMenu(dashboardsMenu);
}
Also used : Condition(org.netxms.client.objects.Condition) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Zone(org.netxms.client.objects.Zone) Node(org.netxms.client.objects.Node) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Cluster(org.netxms.client.objects.Cluster) MenuItem(org.eclipse.swt.widgets.MenuItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EntireNetwork(org.netxms.client.objects.EntireNetwork) ServiceRoot(org.netxms.client.objects.ServiceRoot) Container(org.netxms.client.objects.Container) MobileDevice(org.netxms.client.objects.MobileDevice) AbstractObject(org.netxms.client.objects.AbstractObject) SelectionEvent(org.eclipse.swt.events.SelectionEvent) AbstractObject(org.netxms.client.objects.AbstractObject) Menu(org.eclipse.swt.widgets.Menu) PartInitException(org.eclipse.ui.PartInitException) Subnet(org.netxms.client.objects.Subnet) Sensor(org.netxms.client.objects.Sensor)

Example 3 with Subnet

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

the class IPNeighbors method addSubnets.

/**
 * Add subnets connected by given node
 *
 * @param root
 * @param rootElementId
 */
private void addSubnets(AbstractObject root, long rootElementId) {
    for (long objectId : root.getParentIdList()) {
        AbstractObject object = session.findObjectById(objectId);
        if ((object != null) && (object instanceof Subnet)) {
            long elementId = mapPage.createElementId();
            mapPage.addElement(new NetworkMapObject(elementId, objectId));
            mapPage.addLink(new NetworkMapLink(NetworkMapLink.NORMAL, rootElementId, elementId));
            addNodesFromSubnet((Subnet) object, elementId, root.getObjectId());
        }
    }
}
Also used : AbstractObject(org.netxms.client.objects.AbstractObject) Subnet(org.netxms.client.objects.Subnet) NetworkMapObject(org.netxms.client.maps.elements.NetworkMapObject) NetworkMapLink(org.netxms.client.maps.NetworkMapLink)

Example 4 with Subnet

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

the class ObjectBrowser method registerActionValidators.

/**
 * Register object action validators
 */
private void registerActionValidators() {
    List<ActionValidatorData> list = new ArrayList<ActionValidatorData>();
    // Read all registered extensions and create validators
    final IExtensionRegistry reg = Platform.getExtensionRegistry();
    // $NON-NLS-1$
    IConfigurationElement[] elements = reg.getConfigurationElementsFor("org.netxms.ui.eclipse.objectbrowser.objectActionValidators");
    for (int i = 0; i < elements.length; i++) {
        try {
            final ActionValidatorData v = new ActionValidatorData();
            // $NON-NLS-1$
            v.validator = (ObjectActionValidator) elements[i].createExecutableExtension("class");
            // $NON-NLS-1$
            v.priority = safeParseInt(elements[i].getAttribute("priority"));
            list.add(v);
        } catch (CoreException e) {
            e.printStackTrace();
        }
    }
    // Sort handlers by priority
    Collections.sort(list, new Comparator<ActionValidatorData>() {

        @Override
        public int compare(ActionValidatorData arg0, ActionValidatorData arg1) {
            return arg0.priority - arg1.priority;
        }
    });
    actionValidators = new ObjectActionValidator[list.size() + 1];
    int i = 0;
    for (ActionValidatorData v : list) actionValidators[i++] = v.validator;
    // Default validator
    actionValidators[i] = new ObjectActionValidator() {

        @Override
        public int isValidSelectionForMove(SubtreeType subtree, AbstractObject currentObject, AbstractObject parentObject) {
            switch(subtree) {
                case INFRASTRUCTURE:
                    return ((currentObject instanceof Node) || (currentObject instanceof Cluster) || (currentObject instanceof Subnet) || (currentObject instanceof Condition) || (currentObject instanceof Rack) || (currentObject instanceof MobileDevice) || (currentObject instanceof Container) || (currentObject instanceof Sensor)) && ((parentObject instanceof Container) || (parentObject instanceof ServiceRoot)) ? APPROVE : REJECT;
                case TEMPLATES:
                    return ((currentObject instanceof Template) || (currentObject instanceof TemplateGroup)) && ((parentObject instanceof TemplateGroup) || (parentObject instanceof TemplateRoot)) ? APPROVE : REJECT;
                case BUSINESS_SERVICES:
                    return (currentObject instanceof BusinessService) && ((parentObject instanceof BusinessService) || (parentObject instanceof BusinessServiceRoot)) ? APPROVE : REJECT;
                case MAPS:
                    return ((currentObject instanceof NetworkMap) || (currentObject instanceof NetworkMapGroup)) && ((parentObject instanceof NetworkMapGroup) || (parentObject instanceof NetworkMapRoot)) ? APPROVE : REJECT;
                case DASHBOARDS:
                    return (((currentObject instanceof Dashboard) || (currentObject instanceof DashboardGroup)) && ((parentObject instanceof DashboardRoot) || (parentObject instanceof DashboardGroup) || (parentObject instanceof Dashboard))) ? APPROVE : REJECT;
                case POLICIES:
                    return ((currentObject instanceof AgentPolicy) || (currentObject instanceof PolicyGroup)) && ((parentObject instanceof PolicyGroup) || (parentObject instanceof PolicyRoot)) ? APPROVE : REJECT;
                default:
                    return REJECT;
            }
        }
    };
}
Also used : TemplateRoot(org.netxms.client.objects.TemplateRoot) DashboardGroup(org.netxms.client.objects.DashboardGroup) Node(org.netxms.client.objects.Node) DashboardRoot(org.netxms.client.objects.DashboardRoot) ArrayList(java.util.ArrayList) NetworkMapGroup(org.netxms.client.objects.NetworkMapGroup) Dashboard(org.netxms.client.objects.Dashboard) Template(org.netxms.client.objects.Template) SubtreeType(org.netxms.ui.eclipse.objectbrowser.api.SubtreeType) Rack(org.netxms.client.objects.Rack) Container(org.netxms.client.objects.Container) BusinessServiceRoot(org.netxms.client.objects.BusinessServiceRoot) MobileDevice(org.netxms.client.objects.MobileDevice) TemplateGroup(org.netxms.client.objects.TemplateGroup) PolicyRoot(org.netxms.client.objects.PolicyRoot) ObjectActionValidator(org.netxms.ui.eclipse.objectbrowser.api.ObjectActionValidator) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) Condition(org.netxms.client.objects.Condition) PolicyGroup(org.netxms.client.objects.PolicyGroup) Cluster(org.netxms.client.objects.Cluster) NetworkMapRoot(org.netxms.client.objects.NetworkMapRoot) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) ServiceRoot(org.netxms.client.objects.ServiceRoot) BusinessServiceRoot(org.netxms.client.objects.BusinessServiceRoot) BusinessService(org.netxms.client.objects.BusinessService) AgentPolicy(org.netxms.client.objects.AgentPolicy) CoreException(org.eclipse.core.runtime.CoreException) AbstractObject(org.netxms.client.objects.AbstractObject) Subnet(org.netxms.client.objects.Subnet) NetworkMap(org.netxms.client.objects.NetworkMap) Sensor(org.netxms.client.objects.Sensor)

Example 5 with Subnet

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

the class BindObjectTo method selectionChanged.

/**
 * @see IActionDelegate#selectionChanged(IAction, ISelection)
 */
public void selectionChanged(IAction action, ISelection selection) {
    if ((selection instanceof IStructuredSelection) && (((IStructuredSelection) selection).size() > 0)) {
        objects = new HashSet<Long>();
        for (Object o : ((IStructuredSelection) selection).toList()) {
            if ((o instanceof AbstractNode) || (o instanceof Subnet) || (o instanceof MobileDevice) || (o instanceof Rack) || (o instanceof Cluster) || (o instanceof Sensor))
                objects.add(((AbstractObject) o).getObjectId());
        }
    } else {
        action.setEnabled(false);
        objects = null;
    }
}
Also used : Rack(org.netxms.client.objects.Rack) MobileDevice(org.netxms.client.objects.MobileDevice) AbstractNode(org.netxms.client.objects.AbstractNode) AbstractObject(org.netxms.client.objects.AbstractObject) Cluster(org.netxms.client.objects.Cluster) AbstractObject(org.netxms.client.objects.AbstractObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Subnet(org.netxms.client.objects.Subnet) Sensor(org.netxms.client.objects.Sensor)

Aggregations

AbstractObject (org.netxms.client.objects.AbstractObject)10 Subnet (org.netxms.client.objects.Subnet)10 Cluster (org.netxms.client.objects.Cluster)6 Container (org.netxms.client.objects.Container)6 ServiceRoot (org.netxms.client.objects.ServiceRoot)6 AbstractNode (org.netxms.client.objects.AbstractNode)5 MobileDevice (org.netxms.client.objects.MobileDevice)5 Sensor (org.netxms.client.objects.Sensor)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 EntireNetwork (org.netxms.client.objects.EntireNetwork)4 Node (org.netxms.client.objects.Node)4 Rack (org.netxms.client.objects.Rack)4 Condition (org.netxms.client.objects.Condition)3 Zone (org.netxms.client.objects.Zone)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Menu (org.eclipse.swt.widgets.Menu)2 MenuItem (org.eclipse.swt.widgets.MenuItem)2