Search in sources :

Example 1 with ObjectOpenListener

use of org.netxms.ui.eclipse.objectbrowser.api.ObjectOpenListener 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)

Aggregations

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Action (org.eclipse.jface.action.Action)1 ColumnViewerEditorActivationEvent (org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent)1 ColumnViewerEditorActivationStrategy (org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy)1 ICellEditorListener (org.eclipse.jface.viewers.ICellEditorListener)1 ICellModifier (org.eclipse.jface.viewers.ICellModifier)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 FormAttachment (org.eclipse.swt.layout.FormAttachment)1 FormData (org.eclipse.swt.layout.FormData)1 FormLayout (org.eclipse.swt.layout.FormLayout)1 Item (org.eclipse.swt.widgets.Item)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1 NXCSession (org.netxms.client.NXCSession)1 AbstractObject (org.netxms.client.objects.AbstractObject)1 RefreshAction (org.netxms.ui.eclipse.actions.RefreshAction)1 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)1 ObjectOpenListener (org.netxms.ui.eclipse.objectbrowser.api.ObjectOpenListener)1