Search in sources :

Example 21 with ObjectSelectionDialog

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

the class DataCollectionEditor method convertToTemplate.

/**
 * Convert selected item(s) to template items
 */
private void convertToTemplate() {
    final ObjectSelectionDialog dlg = new ObjectSelectionDialog(getSite().getShell(), null, ObjectSelectionDialog.createTemplateSelectionFilter());
    dlg.showFilterToolTip(false);
    if (dlg.open() != Window.OK)
        return;
    AbstractObject[] objects = dlg.getSelectedObjects(Template.class);
    if (objects.length == 0)
        return;
    final Template template = (Template) objects[0];
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    Iterator<?> it = selection.iterator();
    final long[] dciList = new long[selection.size()];
    for (int i = 0; (i < dciList.length) && it.hasNext(); i++) dciList[i] = ((DataCollectionObject) it.next()).getId();
    new ConsoleJob(Messages.get().DataCollectionEditor_ConvertJob_TitlePrefix + object.getObjectName() + Messages.get().DataCollectionEditor_ConvertJob_TitleSuffix, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            monitor.beginTask(Messages.get(getDisplay()).DataCollectionEditor_ConvertJob_TaskName, 4);
            boolean needApply = true;
            for (long id : template.getChildIdList()) {
                if (id == dciConfig.getNodeId()) {
                    needApply = false;
                    break;
                }
            }
            monitor.worked(1);
            dciConfig.copyObjects(template.getObjectId(), dciList);
            for (long id : dciList) dciConfig.deleteObject(id);
            dciConfig.close();
            monitor.worked(1);
            if (needApply) {
                boolean success = false;
                int retries = 5;
                do {
                    try {
                        session.applyTemplate(template.getObjectId(), dciConfig.getNodeId());
                        success = true;
                    } catch (NXCException e) {
                        if (e.getErrorCode() != RCC.COMPONENT_LOCKED)
                            throw e;
                        Thread.sleep(200);
                    }
                    retries--;
                } while (!success && (retries > 0));
            }
            monitor.worked(1);
            boolean success = false;
            int retries = 5;
            do {
                try {
                    Thread.sleep(500);
                    dciConfig.open();
                    success = true;
                } catch (NXCException e) {
                    if (e.getErrorCode() != RCC.COMPONENT_LOCKED)
                        throw e;
                }
                retries--;
            } while (!success && (retries > 0));
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    viewer.setInput(dciConfig.getItems());
                }
            });
            monitor.done();
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().DataCollectionEditor_ConvertJob_ErrorPrefix + object.getObjectName() + Messages.get().DataCollectionEditor_ConvertJob_ErrorSuffix;
        }
    }.start();
}
Also used : DataCollectionObject(org.netxms.client.datacollection.DataCollectionObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException) Template(org.netxms.client.objects.Template) ObjectSelectionDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AbstractObject(org.netxms.client.objects.AbstractObject) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 22 with ObjectSelectionDialog

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

the class RuleSourceObjects method addSourceObject.

/**
 * Add new source object
 */
private void addSourceObject() {
    ObjectSelectionDialog dlg = new ObjectSelectionDialog(getShell(), null, null);
    dlg.enableMultiSelection(true);
    if (dlg.open() == Window.OK) {
        for (AbstractObject o : dlg.getSelectedObjects()) objects.put(o.getObjectId(), o);
    }
    viewer.setInput(objects.values().toArray());
}
Also used : ObjectSelectionDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog) AbstractObject(org.netxms.client.objects.AbstractObject)

Example 23 with ObjectSelectionDialog

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

the class SelectAgentParamDlg method querySelectedParameter.

/**
 * Query current value of selected parameter
 */
protected void querySelectedParameter() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() != 1)
        return;
    // Opens Object Selection Dialog if object is not chosen
    if (queryObject instanceof Template) {
        final ObjectSelectionDialog sDlg = new ObjectSelectionDialog(getShell(), null, ObjectSelectionDialog.createNodeSelectionFilter(false));
        sDlg.enableMultiSelection(false);
        if (sDlg.open() == Window.OK) {
            queryObject = sDlg.getSelectedObjects().get(0);
        }
    }
    AgentParameter p = (AgentParameter) selection.getFirstElement();
    String n;
    if (// $NON-NLS-1$
    p.getName().contains("(*)")) {
        InputDialog dlg = new InputDialog(getShell(), Messages.get().SelectAgentParamDlg_InstanceTitle, Messages.get().SelectAgentParamDlg_InstanceMessage, "", // $NON-NLS-1$
        null);
        if (dlg.open() != Window.OK)
            return;
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        n = p.getName().replace("(*)", "(" + dlg.getValue() + ")");
    } else {
        n = p.getName();
    }
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    final String name = n;
    new ConsoleJob(Messages.get().SelectAgentParamDlg_QueryJobTitle, null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final String value = session.queryParameter(queryObject.getObjectId(), origin, name);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    MessageDialogHelper.openInformation(getShell(), Messages.get().SelectAgentParamDlg_CurrentValueTitle, String.format(Messages.get().SelectAgentParamDlg_CurrentValue, value));
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().SelectAgentParamDlg_QueryError;
        }
    }.start();
}
Also used : ObjectSelectionDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) InputDialog(org.eclipse.jface.dialogs.InputDialog) NXCSession(org.netxms.client.NXCSession) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) AgentParameter(org.netxms.client.AgentParameter) Template(org.netxms.client.objects.Template)

Example 24 with ObjectSelectionDialog

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

the class AddClusterNode method run.

/**
 * @see IActionDelegate#run(IAction)
 */
public void run(IAction action) {
    final ObjectSelectionDialog dlg = new ObjectSelectionDialog(shell, null, ObjectSelectionDialog.createNodeSelectionFilter(false));
    dlg.open();
    if (dlg.getReturnCode() == Window.OK) {
        final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
        new ConsoleJob(Messages.get().AddClusterNode_JobTitle, wbPart, Activator.PLUGIN_ID, null) {

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

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                List<AbstractObject> objects = dlg.getSelectedObjects();
                for (AbstractObject o : objects) session.addClusterNode(clusterId, o.getObjectId());
            }
        }.start();
    }
}
Also used : ObjectSelectionDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) AbstractObject(org.netxms.client.objects.AbstractObject) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 25 with ObjectSelectionDialog

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

the class BindObject method run.

/**
 * @see IActionDelegate#run(IAction)
 */
public void run(IAction action) {
    final ObjectSelectionDialog dlg = new ObjectSelectionDialog(shell, null, ObjectSelectionDialog.createNodeSelectionFilter(true));
    if (dlg.open() == Window.OK) {
        final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
        new ConsoleJob(Messages.get().BindObject_JobTitle, viewPart, Activator.PLUGIN_ID, null) {

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

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                List<AbstractObject> objects = dlg.getSelectedObjects();
                for (AbstractObject o : objects) session.bindObject(parentId, o.getObjectId());
            }
        }.start();
    }
}
Also used : ObjectSelectionDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) AbstractObject(org.netxms.client.objects.AbstractObject) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

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