Search in sources :

Example 56 with NXCSession

use of org.netxms.client.NXCSession in project netxms by netxms.

the class ObjectBrowser method restoreSelection.

/**
 * Restore selection in the tree
 */
private void restoreSelection() {
    if (// $NON-NLS-1$
    (initialObjectSelection == null) || initialObjectSelection.isEmpty() || !initialObjectSelection.startsWith("/"))
        return;
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    // $NON-NLS-1$
    final String[] parts = initialObjectSelection.split("/");
    final Object[] elements = new Object[parts.length - 1];
    for (int i = 1; i < parts.length; i++) {
        long id;
        try {
            id = Long.parseLong(parts[i]);
        } catch (NumberFormatException e) {
            return;
        }
        elements[i - 1] = session.findObjectById(id);
        if (elements[i - 1] == null)
            // path element is missing
            return;
    }
    objectTree.getTreeViewer().setSelection(new TreeSelection(new TreePath(elements)), true);
    final Display display = getSite().getShell().getDisplay();
    display.asyncExec(new Runnable() {

        @Override
        public void run() {
            // wait for events to finish before continue
            while (display.readAndDispatch()) ;
            // $NON-NLS-1$
            CommandBridge.getInstance().execute("TabbedObjectView/changeObject", ((AbstractObject) elements[elements.length - 1]).getObjectId());
        }
    });
}
Also used : NXCSession(org.netxms.client.NXCSession) TreePath(org.eclipse.jface.viewers.TreePath) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreeSelection(org.eclipse.jface.viewers.TreeSelection) AbstractObject(org.netxms.client.objects.AbstractObject) AbstractObject(org.netxms.client.objects.AbstractObject) Display(org.eclipse.swt.widgets.Display)

Example 57 with NXCSession

use of org.netxms.client.NXCSession in project netxms by netxms.

the class ObjectBrowser method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    FormLayout formLayout = new FormLayout();
    parent.setLayout(formLayout);
    // Read custom root objects
    long[] rootObjects = null;
    objectTree = new ObjectTree(parent, SWT.NONE, ObjectTree.MULTI, rootObjects, null, true, true);
    FormData fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(0, 0);
    fd.right = new FormAttachment(100, 0);
    fd.bottom = new FormAttachment(100, 0);
    objectTree.setLayoutData(fd);
    objectTree.setHideSubInterfaces(initHideSubInterfaces);
    objectTree.setHideTemplateChecks(initHideTemplateChecks);
    objectTree.setHideUnmanaged(initHideUnmanaged);
    objectTree.enableFilter(initShowFilter);
    objectTree.enableStatusIndicator(initShowStatus);
    objectTree.addOpenListener(new ObjectOpenListener() {

        @Override
        public boolean openObject(AbstractObject object) {
            return callOpenObjectHandler(object);
        }
    });
    createActions();
    createMenu();
    createToolBar();
    createPopupMenu();
    objectTree.enableDropSupport(this);
    objectTree.enableDragSupport();
    getSite().setSelectionProvider(objectTree.getTreeViewer());
    objectTree.getTreeViewer().addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            int size = ((IStructuredSelection) objectTree.getTreeViewer().getSelection()).size();
            actionMoveObject.setEnabled(size == 1);
        }
    });
    objectTree.setFilterCloseAction(new Action() {

        @Override
        public void run() {
            actionShowFilter.setChecked(false);
            objectTree.enableFilter(false);
        }
    });
    final TreeViewer tree = objectTree.getTreeViewer();
    TreeViewerEditor.create(tree, new ColumnViewerEditorActivationStrategy(tree) {

        @Override
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
        }
    }, ColumnViewerEditor.DEFAULT);
    TextCellEditor editor = new TextCellEditor(tree.getTree(), SWT.BORDER);
    editor.addListener(new ICellEditorListener() {

        @Override
        public void editorValueChanged(boolean oldValidState, boolean newValidState) {
        }

        @Override
        public void cancelEditor() {
            objectTree.enableRefresh();
        }

        @Override
        public void applyEditorValue() {
        }
    });
    // TODO: override editor method that creates control to disable refresh
    tree.setCellEditors(new CellEditor[] { editor });
    // $NON-NLS-1$
    tree.setColumnProperties(new String[] { "name" });
    tree.setCellModifier(new ICellModifier() {

        @Override
        public void modify(Object element, String property, Object value) {
            final Object data = (element instanceof Item) ? ((Item) element).getData() : element;
            if (// $NON-NLS-1$
            property.equals("name")) {
                if (data instanceof AbstractObject) {
                    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
                    final String newName = value.toString();
                    new ConsoleJob(Messages.get().ObjectBrowser_RenameJobName, null, Activator.PLUGIN_ID, null) {

                        @Override
                        protected void runInternal(IProgressMonitor monitor) throws Exception {
                            session.setObjectName(((AbstractObject) data).getObjectId(), newName);
                        }

                        @Override
                        protected String getErrorMessage() {
                            return String.format(Messages.get().ObjectBrowser_RenameJobError, ((AbstractObject) data).getObjectName());
                        }
                    }.start();
                }
            }
            objectTree.enableRefresh();
        }

        @Override
        public Object getValue(Object element, String property) {
            if (// $NON-NLS-1$
            property.equals("name")) {
                if (element instanceof AbstractObject) {
                    return ((AbstractObject) element).getObjectName();
                }
            }
            return null;
        }

        @Override
        public boolean canModify(Object element, String property) {
            if (// $NON-NLS-1$
            property.equals("name")) {
                objectTree.disableRefresh();
                return true;
            }
            // $NON-NLS-1$
            return false;
        }
    });
    activateContext();
    restoreSelection();
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ObjectOpenListener(org.netxms.ui.eclipse.objectbrowser.api.ObjectOpenListener) RefreshAction(org.netxms.ui.eclipse.actions.RefreshAction) Action(org.eclipse.jface.action.Action) NXCSession(org.netxms.client.NXCSession) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) Item(org.eclipse.swt.widgets.Item) TreeItem(org.eclipse.swt.widgets.TreeItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) ICellEditorListener(org.eclipse.jface.viewers.ICellEditorListener) ObjectTree(org.netxms.ui.eclipse.objectbrowser.widgets.ObjectTree) AbstractObject(org.netxms.client.objects.AbstractObject) ICellModifier(org.eclipse.jface.viewers.ICellModifier) AbstractObject(org.netxms.client.objects.AbstractObject) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 58 with NXCSession

use of org.netxms.client.NXCSession in project netxms by netxms.

the class ApplyPolicy method run.

@Override
public void run(IAction action) {
    final ObjectSelectionDialog dlg = new ObjectSelectionDialog(shell, null, ObjectSelectionDialog.createPolicySelectionFilter());
    dlg.showFilterToolTip(false);
    if (dlg.open() == Window.OK) {
        final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
        new ConsoleJob("Deploy agent policy", null, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                for (int i = 0; i < selectedObjects.size(); i++) {
                    for (int n = 0; n < dlg.getSelectedObjects().size(); n++) {
                        session.deployAgentPolicy(dlg.getSelectedObjects().get(n).getObjectId(), selectedObjects.get(i).getObjectId());
                    }
                }
            }

            @Override
            protected String getErrorMessage() {
                return "Cannot deploy agent policy";
            }
        }.start();
    }
}
Also used : ObjectSelectionDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 59 with NXCSession

use of org.netxms.client.NXCSession in project netxms by netxms.

the class BindObjectTo method run.

/**
 * @see IActionDelegate#run(IAction)
 */
public void run(IAction action) {
    final ObjectSelectionDialog dlg = new ObjectSelectionDialog(shell, null, ObjectSelectionDialog.createContainerSelectionFilter());
    dlg.showFilterToolTip(false);
    if (dlg.open() == Window.OK) {
        final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
        final Long[] childIdList = objects.toArray(new Long[objects.size()]);
        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 parent : objects) {
                    for (Long childId : childIdList) {
                        session.bindObject(parent.getObjectId(), childId);
                    }
                }
            }
        }.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 60 with NXCSession

use of org.netxms.client.NXCSession in project netxms by netxms.

the class CreateCluster method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@Override
public void run(IAction action) {
    final CreateObjectDialog dlg = new CreateObjectDialog(window.getShell(), Messages.get().CreateCluster_Cluster);
    if (dlg.open() != Window.OK)
        return;
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().CreateCluster_JobTitle, part, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            NXCObjectCreationData cd = new NXCObjectCreationData(AbstractObject.OBJECT_CLUSTER, dlg.getObjectName(), parentId);
            session.createObject(cd);
        }

        @Override
        protected String getErrorMessage() {
            return String.format(Messages.get().CreateCluster_JobError, dlg.getObjectName());
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CreateObjectDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.CreateObjectDialog) NXCSession(org.netxms.client.NXCSession) NXCObjectCreationData(org.netxms.client.NXCObjectCreationData) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Aggregations

NXCSession (org.netxms.client.NXCSession)248 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)167 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)163 AbstractObject (org.netxms.client.objects.AbstractObject)54 NXCObjectModificationData (org.netxms.client.NXCObjectModificationData)45 PartInitException (org.eclipse.ui.PartInitException)31 NXCObjectCreationData (org.netxms.client.NXCObjectCreationData)28 List (java.util.List)26 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 NXCException (org.netxms.client.NXCException)22 ArrayList (java.util.ArrayList)19 GridData (org.eclipse.swt.layout.GridData)18 GridLayout (org.eclipse.swt.layout.GridLayout)17 Composite (org.eclipse.swt.widgets.Composite)17 CreateObjectDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.CreateObjectDialog)15 AbstractNode (org.netxms.client.objects.AbstractNode)14 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)13 IOException (java.io.IOException)11 ObjectSelectionDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10