Search in sources :

Example 1 with ObjectTool

use of org.netxms.client.objecttools.ObjectTool in project netxms by netxms.

the class ExecObjectToolTask method doInBackground.

/* (non-Javadoc)
     * @see android.os.AsyncTask#doInBackground(Params[])
     */
@Override
protected Exception doInBackground(Object... params) {
    service = (ClientConnectorService) params[3];
    try {
        ObjectTool objectTool = (ObjectTool) params[2];
        NXCSession session = (NXCSession) params[0];
        Long objectId = (Long) params[1];
        switch(objectTool.getToolType()) {
            case ObjectTool.TYPE_INTERNAL:
                if (objectTool.getData().equals("wakeup")) {
                    session.wakeupNode(objectId);
                    break;
                }
            case ObjectTool.TYPE_ACTION:
                session.executeAction(objectId, objectTool.getData(), null);
                break;
            case ObjectTool.TYPE_SERVER_COMMAND:
                session.executeServerCommand(objectId, objectTool.getData(), null);
                break;
            case ObjectTool.TYPE_SERVER_SCRIPT:
                session.executeLibraryScript(objectId, objectTool.getData(), null, null);
                break;
        }
    } catch (Exception e) {
        return e;
    }
    return null;
}
Also used : NXCSession(org.netxms.client.NXCSession) ObjectTool(org.netxms.client.objecttools.ObjectTool)

Example 2 with ObjectTool

use of org.netxms.client.objecttools.ObjectTool in project netxms by netxms.

the class NXCSession method getObjectTools.

/**
 * Get list of configured object tools
 *
 * @return List of object tools
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public List<ObjectTool> getObjectTools() throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_OBJECT_TOOLS);
    sendMessage(msg);
    final NXCPMessage response = waitForRCC(msg.getMessageId());
    int count = response.getFieldAsInt32(NXCPCodes.VID_NUM_TOOLS);
    final List<ObjectTool> list = new ArrayList<ObjectTool>(count);
    long varId = NXCPCodes.VID_OBJECT_TOOLS_BASE;
    for (int i = 0; i < count; i++) {
        list.add(new ObjectTool(response, varId));
        varId += 10000;
    }
    return list;
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage) ArrayList(java.util.ArrayList) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint) ObjectTool(org.netxms.client.objecttools.ObjectTool)

Example 3 with ObjectTool

use of org.netxms.client.objecttools.ObjectTool in project netxms by netxms.

the class ObjectToolsDynamicMenu 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))
        return;
    final Set<ObjectContext> nodes = buildNodeSet((IStructuredSelection) selection);
    final Menu toolsMenu = new Menu(menu);
    final ImageCache imageCache = new ImageCache();
    toolsMenu.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            imageCache.dispose();
        }
    });
    ObjectTool[] tools = ObjectToolsCache.getInstance().getTools();
    Arrays.sort(tools, new Comparator<ObjectTool>() {

        @Override
        public int compare(ObjectTool arg0, ObjectTool arg1) {
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            return arg0.getName().replace("&", "").compareToIgnoreCase(arg1.getName().replace("&", ""));
        }
    });
    Map<String, Menu> menus = new HashMap<String, Menu>();
    int added = 0;
    for (int i = 0; i < tools.length; i++) {
        boolean enabled = (tools[i].getFlags() & ObjectTool.DISABLED) == 0;
        if (enabled && ObjectToolExecutor.isToolAllowed(tools[i], nodes) && ObjectToolExecutor.isToolApplicable(tools[i], nodes)) {
            // $NON-NLS-1$
            String[] path = tools[i].getName().split("\\-\\>");
            Menu rootMenu = toolsMenu;
            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]);
            ImageDescriptor icon = ObjectToolsCache.getInstance().findIcon(tools[i].getId());
            if (icon != null)
                item.setImage(imageCache.add(icon));
            item.setData(tools[i]);
            item.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    ObjectToolExecutor.execute(nodes, (ObjectTool) item.getData());
                }
            });
            added++;
        }
    }
    if (added > 0) {
        MenuItem toolsMenuItem = new MenuItem(menu, SWT.CASCADE, index);
        toolsMenuItem.setText(Messages.get().ObjectToolsDynamicMenu_TopLevelLabel);
        toolsMenuItem.setMenu(toolsMenu);
    } else {
        toolsMenu.dispose();
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) HashMap(java.util.HashMap) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ImageCache(org.netxms.ui.eclipse.tools.ImageCache) SelectionEvent(org.eclipse.swt.events.SelectionEvent) AbstractObject(org.netxms.client.objects.AbstractObject) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) ObjectContext(org.netxms.ui.eclipse.objects.ObjectContext) Menu(org.eclipse.swt.widgets.Menu) ObjectTool(org.netxms.client.objecttools.ObjectTool)

Example 4 with ObjectTool

use of org.netxms.client.objecttools.ObjectTool in project netxms by netxms.

the class ObjectToolSelectionDialog method createDialogArea.

/* (non-Javadoc)
    * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
    */
@Override
protected Control createDialogArea(Composite parent) {
    final Composite dialogArea = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
    layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
    dialogArea.setLayout(layout);
    viewer = new TableViewer(dialogArea, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((ObjectTool) element).getName();
        }
    });
    viewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            return ((ObjectTool) e1).getName().compareToIgnoreCase(((ObjectTool) e2).getName());
        }
    });
    viewer.setInput(ObjectToolsCache.getInstance().getTools());
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.heightHint = 400;
    viewer.getControl().setLayoutData(gd);
    return dialogArea;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) TableViewer(org.eclipse.jface.viewers.TableViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider) ObjectTool(org.netxms.client.objecttools.ObjectTool)

Example 5 with ObjectTool

use of org.netxms.client.objecttools.ObjectTool in project netxms by netxms.

the class ObjectToolsEditor method setSelectedEnabled.

private void setSelectedEnabled() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.isEmpty())
        return;
    if (!MessageDialogHelper.openConfirm(getSite().getShell(), Messages.get().ObjectToolsEditor_Confirmation, Messages.get().ObjectToolsEditor_AckToEnableObjTool))
        return;
    final Object[] objects = selection.toArray();
    new ConsoleJob(Messages.get(viewer.getControl().getDisplay()).ObjectToolsEditor_EnableObjTool, this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

        @Override
        protected String getErrorMessage() {
            return Messages.get(getDisplay()).ObjectToolsEditor_ErrorDisablingObjTools;
        }

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            for (int i = 0; i < objects.length; i++) {
                if ((((ObjectTool) objects[i]).getFlags() & ObjectTool.DISABLED) > 0)
                    session.changeObjecToolDisableStatuss(((ObjectTool) objects[i]).getId(), true);
            }
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) ObjectTool(org.netxms.client.objecttools.ObjectTool)

Aggregations

ObjectTool (org.netxms.client.objecttools.ObjectTool)19 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 PartInitException (org.eclipse.ui.PartInitException)5 ObjectToolDetails (org.netxms.client.objecttools.ObjectToolDetails)3 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 GeoLocation (org.netxms.base.GeoLocation)2 Node (org.netxms.client.objects.Node)2 AlertDialog (android.app.AlertDialog)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 DialogInterface (android.content.DialogInterface)1 OnClickListener (android.content.DialogInterface.OnClickListener)1 Intent (android.content.Intent)1 SubMenu (android.view.SubMenu)1 AdapterView (android.widget.AdapterView)1