Search in sources :

Example 61 with AbstractObject

use of org.netxms.client.objects.AbstractObject 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 62 with AbstractObject

use of org.netxms.client.objects.AbstractObject in project netxms by netxms.

the class ObjectBrowser method registerActionValidators.

/**
 * Register object action validators
 */
private void registerActionValidators() {
    List<ActionValidatorData> list = new ArrayList<ActionValidatorData>();
    // Read all registered extensions and create validators
    final IExtensionRegistry reg = Platform.getExtensionRegistry();
    // $NON-NLS-1$
    IConfigurationElement[] elements = reg.getConfigurationElementsFor("org.netxms.ui.eclipse.objectbrowser.objectActionValidators");
    for (int i = 0; i < elements.length; i++) {
        try {
            final ActionValidatorData v = new ActionValidatorData();
            // $NON-NLS-1$
            v.validator = (ObjectActionValidator) elements[i].createExecutableExtension("class");
            // $NON-NLS-1$
            v.priority = safeParseInt(elements[i].getAttribute("priority"));
            list.add(v);
        } catch (CoreException e) {
            e.printStackTrace();
        }
    }
    // Sort handlers by priority
    Collections.sort(list, new Comparator<ActionValidatorData>() {

        @Override
        public int compare(ActionValidatorData arg0, ActionValidatorData arg1) {
            return arg0.priority - arg1.priority;
        }
    });
    actionValidators = new ObjectActionValidator[list.size() + 1];
    int i = 0;
    for (ActionValidatorData v : list) actionValidators[i++] = v.validator;
    // Default validator
    actionValidators[i] = new ObjectActionValidator() {

        @Override
        public int isValidSelectionForMove(SubtreeType subtree, AbstractObject currentObject, AbstractObject parentObject) {
            switch(subtree) {
                case INFRASTRUCTURE:
                    return ((currentObject instanceof Node) || (currentObject instanceof Cluster) || (currentObject instanceof Subnet) || (currentObject instanceof Condition) || (currentObject instanceof Rack) || (currentObject instanceof MobileDevice) || (currentObject instanceof Container) || (currentObject instanceof Sensor)) && ((parentObject instanceof Container) || (parentObject instanceof ServiceRoot)) ? APPROVE : REJECT;
                case TEMPLATES:
                    return ((currentObject instanceof Template) || (currentObject instanceof TemplateGroup)) && ((parentObject instanceof TemplateGroup) || (parentObject instanceof TemplateRoot)) ? APPROVE : REJECT;
                case BUSINESS_SERVICES:
                    return (currentObject instanceof BusinessService) && ((parentObject instanceof BusinessService) || (parentObject instanceof BusinessServiceRoot)) ? APPROVE : REJECT;
                case MAPS:
                    return ((currentObject instanceof NetworkMap) || (currentObject instanceof NetworkMapGroup)) && ((parentObject instanceof NetworkMapGroup) || (parentObject instanceof NetworkMapRoot)) ? APPROVE : REJECT;
                case DASHBOARDS:
                    return (((currentObject instanceof Dashboard) || (currentObject instanceof DashboardGroup)) && ((parentObject instanceof DashboardRoot) || (parentObject instanceof DashboardGroup) || (parentObject instanceof Dashboard))) ? APPROVE : REJECT;
                case POLICIES:
                    return ((currentObject instanceof AgentPolicy) || (currentObject instanceof PolicyGroup)) && ((parentObject instanceof PolicyGroup) || (parentObject instanceof PolicyRoot)) ? APPROVE : REJECT;
                default:
                    return REJECT;
            }
        }
    };
}
Also used : TemplateRoot(org.netxms.client.objects.TemplateRoot) DashboardGroup(org.netxms.client.objects.DashboardGroup) Node(org.netxms.client.objects.Node) DashboardRoot(org.netxms.client.objects.DashboardRoot) ArrayList(java.util.ArrayList) NetworkMapGroup(org.netxms.client.objects.NetworkMapGroup) Dashboard(org.netxms.client.objects.Dashboard) Template(org.netxms.client.objects.Template) SubtreeType(org.netxms.ui.eclipse.objectbrowser.api.SubtreeType) Rack(org.netxms.client.objects.Rack) Container(org.netxms.client.objects.Container) BusinessServiceRoot(org.netxms.client.objects.BusinessServiceRoot) MobileDevice(org.netxms.client.objects.MobileDevice) TemplateGroup(org.netxms.client.objects.TemplateGroup) PolicyRoot(org.netxms.client.objects.PolicyRoot) ObjectActionValidator(org.netxms.ui.eclipse.objectbrowser.api.ObjectActionValidator) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) Condition(org.netxms.client.objects.Condition) PolicyGroup(org.netxms.client.objects.PolicyGroup) Cluster(org.netxms.client.objects.Cluster) NetworkMapRoot(org.netxms.client.objects.NetworkMapRoot) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) ServiceRoot(org.netxms.client.objects.ServiceRoot) BusinessServiceRoot(org.netxms.client.objects.BusinessServiceRoot) BusinessService(org.netxms.client.objects.BusinessService) AgentPolicy(org.netxms.client.objects.AgentPolicy) CoreException(org.eclipse.core.runtime.CoreException) AbstractObject(org.netxms.client.objects.AbstractObject) Subnet(org.netxms.client.objects.Subnet) NetworkMap(org.netxms.client.objects.NetworkMap) Sensor(org.netxms.client.objects.Sensor)

Example 63 with AbstractObject

use of org.netxms.client.objects.AbstractObject 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 64 with AbstractObject

use of org.netxms.client.objects.AbstractObject in project netxms by netxms.

the class IPAddressSelector method setNode.

/**
 * Set node for which list of IP addresses will be displayed.
 *
 * @param nodeId node ID
 */
public void setNode(long nodeId) {
    AbstractObject object = session.findObjectById(nodeId);
    if (object instanceof AbstractNode) {
        node = (AbstractNode) object;
        address = node.getPrimaryIP().getAddress();
        setText((address != null) ? address.getHostAddress() : "");
    } else {
        node = null;
        setText(Messages.get().IPAddressSelector_None);
    }
}
Also used : AbstractNode(org.netxms.client.objects.AbstractNode) AbstractObject(org.netxms.client.objects.AbstractObject)

Example 65 with AbstractObject

use of org.netxms.client.objects.AbstractObject in project netxms by netxms.

the class ObjectStatusIndicator method paintControl.

/* (non-Javadoc)
	 * @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent)
	 */
@Override
public void paintControl(PaintEvent e) {
    if (objectTree == null)
        return;
    final GC gc = e.gc;
    gc.setAntialias(SWT.ON);
    final int width = getClientArea().width;
    TreeItem item = objectTree.getTree().getTopItem();
    if (item != null) {
        int y = 0;
        final int limit = objectTree.getTree().getClientArea().height;
        final int height = objectTree.getTree().getItemHeight();
        ViewerRow row = objectTree.getTreeViewerRow(item);
        while ((row != null) && (y < limit)) {
            AbstractObject object = (AbstractObject) row.getItem().getData();
            drawObject(gc, object, y, width, height);
            y += height;
            row = row.getNeighbor(ViewerRow.BELOW, false);
            if (row == null) {
                // in that case we try to find next item from position
                for (int i = 16; i < 192; i += 16) {
                    item = objectTree.getTree().getItem(new Point(y, y + height / 2));
                    if (item != null) {
                        row = objectTree.getTreeViewerRow(item);
                        break;
                    }
                }
            }
        }
    }
    gc.setForeground(SharedColors.getColor(SharedColors.BORDER, getDisplay()));
    gc.drawLine(width - 1, 0, width - 1, getClientArea().height);
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) AbstractObject(org.netxms.client.objects.AbstractObject) ViewerRow(org.eclipse.jface.viewers.ViewerRow) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point)

Aggregations

AbstractObject (org.netxms.client.objects.AbstractObject)216 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)55 NXCSession (org.netxms.client.NXCSession)51 AbstractNode (org.netxms.client.objects.AbstractNode)31 PartInitException (org.eclipse.ui.PartInitException)27 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)26 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)25 Cluster (org.netxms.client.objects.Cluster)22 ObjectSelectionDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog)22 ArrayList (java.util.ArrayList)20 Node (org.netxms.client.objects.Node)20 GridData (org.eclipse.swt.layout.GridData)18 Composite (org.eclipse.swt.widgets.Composite)18 NetworkMapObject (org.netxms.client.maps.elements.NetworkMapObject)18 GridLayout (org.eclipse.swt.layout.GridLayout)15 Container (org.netxms.client.objects.Container)15 Interface (org.netxms.client.objects.Interface)12 Template (org.netxms.client.objects.Template)12 SelectionEvent (org.eclipse.swt.events.SelectionEvent)11 Point (org.eclipse.swt.graphics.Point)11