Search in sources :

Example 26 with ObjectSelectionDialog

use of org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog in project netxms by netxms.

the class UninstallPolicy method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@Override
public void run(IAction action) {
    // Read custom root objects
    long[] rootObjects = null;
    // $NON-NLS-1$
    Object value = ConsoleSharedData.getProperty("PolicyManager.rootObjects");
    if ((value != null) && (value instanceof long[])) {
        rootObjects = (long[]) value;
    }
    final ObjectSelectionDialog dlg = new ObjectSelectionDialog(shell, rootObjects, ObjectSelectionDialog.createNodeSelectionFilter(false));
    if (dlg.open() == Window.OK) {
        final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
        for (final AgentPolicy policy : currentSelection) {
            new ConsoleJob(String.format(Messages.get().UninstallPolicy_JobName, policy.getObjectName()), null, Activator.PLUGIN_ID, null) {

                @Override
                protected void runInternal(IProgressMonitor monitor) throws Exception {
                    AbstractObject[] nodeList = dlg.getSelectedObjects(Node.class);
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < nodeList.length; i++) {
                        try {
                            session.uninstallAgentPolicy(policy.getObjectId(), nodeList[i].getObjectId());
                        } catch (NXCException e) {
                            if (e.getErrorCode() == CommonRCC.INCOMPATIBLE_OPERATION || e.getErrorCode() == CommonRCC.INTERNAL_ERROR || e.getErrorCode() == CommonRCC.ACCESS_DENIED || e.getErrorCode() == CommonRCC.INVALID_OBJECT_ID) {
                                if (sb.length() == 0)
                                    sb.append("Could not apply policy to the node(s):\n");
                                sb.append(nodeList[i].getObjectName());
                                sb.append(" - ");
                                sb.append(e.getLocalizedMessage());
                                sb.append("\n");
                            } else {
                                throw (e);
                            }
                        }
                    }
                    if (sb.length() != 0) {
                        final String error = sb.toString();
                        runInUIThread(new Runnable() {

                            @Override
                            public void run() {
                                MessageDialog.openError(shell, "Error", error);
                            }
                        });
                    }
                }

                @Override
                protected String getErrorMessage() {
                    return String.format(Messages.get().UninstallPolicy_JobError, policy.getObjectName());
                }
            }.start();
        }
    }
}
Also used : NXCSession(org.netxms.client.NXCSession) Node(org.netxms.client.objects.Node) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException) ObjectSelectionDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AgentPolicy(org.netxms.client.objects.AgentPolicy) AbstractObject(org.netxms.client.objects.AbstractObject) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 27 with ObjectSelectionDialog

use of org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog in project netxms by netxms.

the class ShowIPRouteFrom method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@Override
public void run(IAction action) {
    if (node == null)
        return;
    ObjectSelectionDialog dlg = new ObjectSelectionDialog(window.getShell(), null, ObjectSelectionDialog.createNodeSelectionFilter(false));
    if (dlg.open() != Window.OK)
        return;
    AbstractObject[] selection = dlg.getSelectedObjects(Node.class);
    if (selection.length == 0) {
        MessageDialogHelper.openError(window.getShell(), Messages.get().ShowIPRoute_Error, Messages.get().ShowIPRoute_InvalidTarget);
        return;
    }
    try {
        // $NON-NLS-1$
        window.getActivePage().showView(IPRouteMap.ID, Long.toString(selection[0].getObjectId()) + "&" + Long.toString(node.getObjectId()), IWorkbenchPage.VIEW_ACTIVATE);
    } catch (PartInitException e) {
        MessageDialogHelper.openError(window.getShell(), Messages.get().ShowIPRoute_Error, String.format(Messages.get().ShowIPRoute_ErrorOpenView, e.getLocalizedMessage()));
    }
}
Also used : ObjectSelectionDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog) AbstractObject(org.netxms.client.objects.AbstractObject) PartInitException(org.eclipse.ui.PartInitException)

Example 28 with ObjectSelectionDialog

use of org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog in project netxms by netxms.

the class MibExplorer method createActions.

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

        @Override
        public void run() {
            mibBrowser.refreshTree();
        }
    };
    actionWalk = new Action(Messages.get().MibExplorer_Walk) {

        @Override
        public void run() {
            doWalk();
        }
    };
    actionWalk.setEnabled(currentNode != null);
    actionSetNode = new Action(Messages.get().MibExplorer_SetNodeObject) {

        @Override
        public void run() {
            ObjectSelectionDialog dlg = new ObjectSelectionDialog(MibExplorer.this.getSite().getShell(), null, ObjectSelectionDialog.createNodeSelectionFilter(false));
            dlg.enableMultiSelection(false);
            if (dlg.open() == Window.OK) {
                setNode((AbstractNode) dlg.getSelectedObjects().get(0));
            }
        }
    };
    actionSelect = new Action("Select in MIB tree") {

        @Override
        public void run() {
            selectInTree();
        }
    };
    actionSelect.setEnabled(false);
    actionExportToCsv = new ExportToCsvAction(this, viewer, true);
    actionShowFilter = new Action("Show filter", Action.AS_CHECK_BOX) {

        @Override
        public void run() {
            enableFilter(!initShowFilter);
            actionShowFilter.setChecked(initShowFilter);
        }
    };
    actionShowFilter.setChecked(initShowFilter);
    // $NON-NLS-1$
    actionShowFilter.setActionDefinitionId("org.netxms.ui.eclipse.snmp.commands.showFilter");
    handlerService.activateHandler(actionShowFilter.getActionDefinitionId(), new ActionHandler(actionShowFilter));
}
Also used : ObjectSelectionDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog) ExportToCsvAction(org.netxms.ui.eclipse.actions.ExportToCsvAction) 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) AbstractNode(org.netxms.client.objects.AbstractNode) ExportToCsvAction(org.netxms.ui.eclipse.actions.ExportToCsvAction) ActionHandler(org.eclipse.jface.commands.ActionHandler)

Example 29 with ObjectSelectionDialog

use of org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog in project netxms by netxms.

the class ObjectFieldEditor method selectObject.

/**
 * Select object
 */
private void selectObject() {
    ObjectSelectionDialog dlg = new ObjectSelectionDialog(getShell(), null, null);
    dlg.enableMultiSelection(false);
    if (dlg.open() == Window.OK) {
        AbstractObject[] objects = dlg.getSelectedObjects(AbstractObject.class);
        if (objects.length > 0) {
            objectId = objects[0].getObjectId();
            text.setText(objects[0].getObjectName());
            text.setImage(labelProvider.getImage(objects[0]));
        } else {
            objectId = 0;
            text.setText(EMPTY_SELECTION_TEXT);
            text.setImage(null);
        }
    }
}
Also used : ObjectSelectionDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog) AbstractObject(org.netxms.client.objects.AbstractObject)

Aggregations

ObjectSelectionDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog)29 AbstractObject (org.netxms.client.objects.AbstractObject)22 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)13 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)13 NXCSession (org.netxms.client.NXCSession)11 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 List (java.util.List)6 PartInitException (org.eclipse.ui.PartInitException)5 Template (org.netxms.client.objects.Template)5 ArrayList (java.util.ArrayList)3 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 SelectionListener (org.eclipse.swt.events.SelectionListener)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 RowData (org.eclipse.swt.layout.RowData)3 RowLayout (org.eclipse.swt.layout.RowLayout)3 Button (org.eclipse.swt.widgets.Button)3 Composite (org.eclipse.swt.widgets.Composite)3 NXCException (org.netxms.client.NXCException)3