Search in sources :

Example 1 with ObjectTree

use of org.netxms.ui.eclipse.objectbrowser.widgets.ObjectTree in project netxms by netxms.

the class SelectDciDialog method createDialogArea.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createDialogArea(Composite parent) {
    IDialogSettings settings = Activator.getDefault().getDialogSettings();
    Composite dialogArea = (Composite) super.createDialogArea(parent);
    dialogArea.setLayout(new FillLayout());
    if (fixedNode == 0) {
        splitter = new SashForm(dialogArea, SWT.HORIZONTAL);
        objectTree = new ObjectTree(splitter, SWT.BORDER, ObjectTree.NONE, null, ObjectSelectionDialog.createNodeSelectionFilter(true), true, false);
        // $NON-NLS-1$
        String text = settings.get("SelectDciDialog.Filter");
        if (text != null)
            objectTree.setFilter(text);
    }
    dciList = new DciList(null, (fixedNode == 0) ? splitter : dialogArea, SWT.BORDER, null, "SelectDciDialog.dciList", dcObjectType, allowSingleSelection ? SWT.NONE : SWT.MULTI, // $NON-NLS-1$
    allowNoValueObjects);
    dciList.setDcObjectType(dcObjectType);
    dciList.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            okPressed();
        }
    });
    if (fixedNode == 0) {
        try {
            int[] weights = new int[2];
            // $NON-NLS-1$
            weights[0] = settings.getInt("SelectDciDialog.weight1");
            // $NON-NLS-1$
            weights[1] = settings.getInt("SelectDciDialog.weight2");
            splitter.setWeights(weights);
        } catch (NumberFormatException e) {
            splitter.setWeights(new int[] { 30, 70 });
        }
        objectTree.getTreeViewer().addSelectionChangedListener(new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                AbstractObject object = objectTree.getFirstSelectedObject2();
                if ((object != null) && ((object instanceof AbstractNode) || (object instanceof MobileDevice) || (object instanceof Cluster) || (allowTemplateItems && (object instanceof Template) || (object instanceof Sensor)))) {
                    dciList.setNode(object);
                } else {
                    dciList.setNode(null);
                }
            }
        });
        objectTree.setFocus();
    } else {
        dciList.setNode(((NXCSession) ConsoleSharedData.getSession()).findObjectById(fixedNode));
    }
    return dialogArea;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) AbstractNode(org.netxms.client.objects.AbstractNode) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Cluster(org.netxms.client.objects.Cluster) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FillLayout(org.eclipse.swt.layout.FillLayout) DciList(org.netxms.ui.eclipse.datacollection.widgets.DciList) Template(org.netxms.client.objects.Template) SashForm(org.eclipse.swt.custom.SashForm) MobileDevice(org.netxms.client.objects.MobileDevice) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) ObjectTree(org.netxms.ui.eclipse.objectbrowser.widgets.ObjectTree) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) AbstractObject(org.netxms.client.objects.AbstractObject) Sensor(org.netxms.client.objects.Sensor)

Example 2 with ObjectTree

use of org.netxms.ui.eclipse.objectbrowser.widgets.ObjectTree 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 3 with ObjectTree

use of org.netxms.ui.eclipse.objectbrowser.widgets.ObjectTree in project netxms by netxms.

the class ObjectSelectionDialog method createDialogArea.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets
	 * .Composite)
	 */
@Override
protected Control createDialogArea(Composite parent) {
    IDialogSettings settings = Activator.getDefault().getDialogSettings();
    Composite dialogArea = (Composite) super.createDialogArea(parent);
    dialogArea.setLayout(new FormLayout());
    objectTree = new ObjectTree(dialogArea, SWT.NONE, multiSelection ? ObjectTree.MULTI : 0, rootObjects, classFilter, showFilterToolTip, showFilterCloseButton);
    // $NON-NLS-1$
    String text = settings.get("SelectObject.Filter");
    if (text != null)
        objectTree.setFilter(text);
    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);
    return dialogArea;
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Composite(org.eclipse.swt.widgets.Composite) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) ObjectTree(org.netxms.ui.eclipse.objectbrowser.widgets.ObjectTree) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 4 with ObjectTree

use of org.netxms.ui.eclipse.objectbrowser.widgets.ObjectTree in project netxms by netxms.

the class DashboardNavigator method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    session = (NXCSession) ConsoleSharedData.getSession();
    final Set<Integer> classFilter = new HashSet<Integer>(2);
    classFilter.add(AbstractObject.OBJECT_DASHBOARDGROUP);
    classFilter.add(AbstractObject.OBJECT_DASHBOARD);
    objectTree = new ObjectTree(parent, SWT.NONE, ObjectTree.NONE, getRootObjects(classFilter), classFilter, false, true);
    objectTree.enableFilter(false);
    objectTree.getTreeViewer().expandToLevel(2);
    createActions();
    contributeToActionBars();
    createPopupMenu();
    getSite().setSelectionProvider(objectTree.getTreeViewer());
    sessionListener = new SessionListener() {

        @Override
        public void notificationHandler(SessionNotification n) {
            if ((n.getCode() == SessionNotification.OBJECT_CHANGED) && (n.getObject() instanceof DashboardRoot)) {
                objectTree.getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        refresh();
                    }
                });
            }
        }
    };
    session.addListener(sessionListener);
}
Also used : ObjectTree(org.netxms.ui.eclipse.objectbrowser.widgets.ObjectTree) DashboardRoot(org.netxms.client.objects.DashboardRoot) SessionListener(org.netxms.client.SessionListener) SessionNotification(org.netxms.client.SessionNotification) HashSet(java.util.HashSet)

Example 5 with ObjectTree

use of org.netxms.ui.eclipse.objectbrowser.widgets.ObjectTree in project netxms by netxms.

the class SelectInstallTargetDialog method createDialogArea.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite dialogArea = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
    layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
    layout.verticalSpacing = WidgetHelper.DIALOG_SPACING;
    dialogArea.setLayout(layout);
    final SelectionListener listener = new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            objectTree.setEnabled(radioInstallOnSelected.getSelection());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    };
    radioInstallOnCurrent = new Button(dialogArea, SWT.RADIO);
    radioInstallOnCurrent.setText(Messages.get().SelectInstallTargetDialog_InstallOnAlreadyInstalled);
    radioInstallOnCurrent.setSelection(installMode == INSTALL_ON_CURRENT);
    radioInstallOnCurrent.addSelectionListener(listener);
    radioInstallOnSelected = new Button(dialogArea, SWT.RADIO);
    radioInstallOnSelected.setText(Messages.get().SelectInstallTargetDialog_InstallOnSelected);
    radioInstallOnSelected.setSelection(installMode == INSTALL_ON_SELECTED);
    radioInstallOnSelected.addSelectionListener(listener);
    // 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;
    }
    objectTree = new ObjectTree(dialogArea, SWT.BORDER, ObjectTree.CHECKBOXES, rootObjects, ObjectSelectionDialog.createNodeSelectionFilter(false), true, false);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.heightHint = 300;
    objectTree.setLayoutData(gd);
    objectTree.setEnabled(installMode == INSTALL_ON_SELECTED);
    return dialogArea;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) ObjectTree(org.netxms.ui.eclipse.objectbrowser.widgets.ObjectTree) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) AbstractObject(org.netxms.client.objects.AbstractObject) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

ObjectTree (org.netxms.ui.eclipse.objectbrowser.widgets.ObjectTree)5 Composite (org.eclipse.swt.widgets.Composite)3 AbstractObject (org.netxms.client.objects.AbstractObject)3 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 FormAttachment (org.eclipse.swt.layout.FormAttachment)2 FormData (org.eclipse.swt.layout.FormData)2 FormLayout (org.eclipse.swt.layout.FormLayout)2 HashSet (java.util.HashSet)1 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 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 ICellEditorListener (org.eclipse.jface.viewers.ICellEditorListener)1 ICellModifier (org.eclipse.jface.viewers.ICellModifier)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1