Search in sources :

Example 91 with AbstractObject

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

the class MultipleObjectAction method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@SuppressWarnings("unchecked")
@Override
public final void run(IAction action) {
    if (selection == null)
        return;
    if (!confirm())
        return;
    Iterator<AbstractObject> it = selection.iterator();
    while (it.hasNext()) {
        final AbstractObject object = it.next();
        final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
        new ConsoleJob(formatJobDescription(object), part, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                runObjectAction(session, object);
            }

            @Override
            protected String getErrorMessage() {
                return formatErrorMessage(object, getDisplay());
            }
        }.start();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) AbstractObject(org.netxms.client.objects.AbstractObject) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 92 with AbstractObject

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

the class RemoveClusterNode method selectionChanged.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
	 */
public void selectionChanged(IAction action, ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        Object obj = ((IStructuredSelection) selection).getFirstElement();
        if (obj instanceof Cluster) {
            action.setEnabled(true);
            clusterId = ((AbstractObject) obj).getObjectId();
        } else {
            action.setEnabled(false);
            clusterId = 0;
        }
    } else {
        action.setEnabled(false);
        clusterId = 0;
    }
}
Also used : Cluster(org.netxms.client.objects.Cluster) AbstractObject(org.netxms.client.objects.AbstractObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 93 with AbstractObject

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

the class SetObjectMaintenanceState method execute.

/* (non-Javadoc)
    * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
    */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    ISelection selection = window.getActivePage().getSelection();
    if ((selection == null) || !(selection instanceof IStructuredSelection) || selection.isEmpty())
        return null;
    final Object[] objects = ((IStructuredSelection) selection).toArray();
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().SetObjectManagementState_JobTitle, null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            for (Object o : objects) {
                if (o instanceof AbstractObject)
                    session.setObjectMaintenance(((AbstractObject) o).getObjectId(), maintained);
                else if (o instanceof ObjectWrapper)
                    session.setObjectMaintenance(((ObjectWrapper) o).getObjectId(), maintained);
            }
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().SetObjectManagementState_JobError;
        }
    }.start();
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) NXCSession(org.netxms.client.NXCSession) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ExecutionException(org.eclipse.core.commands.ExecutionException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AbstractObject(org.netxms.client.objects.AbstractObject) ISelection(org.eclipse.jface.viewers.ISelection) ObjectWrapper(org.netxms.ui.eclipse.objects.ObjectWrapper) AbstractObject(org.netxms.client.objects.AbstractObject) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 94 with AbstractObject

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

the class UnbindObject method selectionChanged.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
	 */
public void selectionChanged(IAction action, ISelection selection) {
    if ((selection instanceof IStructuredSelection) && (((IStructuredSelection) selection).size() == 1)) {
        Object obj = ((IStructuredSelection) selection).getFirstElement();
        if ((obj instanceof ServiceRoot) || (obj instanceof Container)) {
            action.setEnabled(true);
            parentId = ((AbstractObject) obj).getObjectId();
        } else {
            action.setEnabled(false);
            parentId = 0;
        }
    } else {
        action.setEnabled(false);
        parentId = 0;
    }
}
Also used : Container(org.netxms.client.objects.Container) AbstractObject(org.netxms.client.objects.AbstractObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ServiceRoot(org.netxms.client.objects.ServiceRoot)

Example 95 with AbstractObject

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

the class HistoricalDataView method init.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite)
	 */
@Override
public void init(IViewSite site) throws PartInitException {
    super.init(site);
    session = (NXCSession) ConsoleSharedData.getSession();
    // Secondary ID must by in form nodeId&dciId
    // $NON-NLS-1$
    String[] parts = site.getSecondaryId().split("&");
    if (parts.length != 2)
        // $NON-NLS-1$
        throw new PartInitException("Internal error");
    nodeId = Long.parseLong(parts[0]);
    AbstractObject object = session.findObjectById(nodeId);
    if ((object == null) || (!(object instanceof AbstractNode) && !(object instanceof MobileDevice) && !(object instanceof Cluster) && !(object instanceof Sensor)))
        throw new PartInitException(Messages.get().HistoricalDataView_InvalidObjectID);
    nodeName = object.getObjectName();
    if (parts[1].contains("@")) {
        subparts = parts[1].split("@");
        try {
            dciId = Long.parseLong(subparts[0]);
            // $NON-NLS-1$
            tableName = URLDecoder.decode(subparts[1], "UTF-8");
            // $NON-NLS-1$
            instance = URLDecoder.decode(subparts[2], "UTF-8");
            // $NON-NLS-1$
            column = URLDecoder.decode(subparts[3], "UTF-8");
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    } else {
        dciId = Long.parseLong(parts[1]);
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    setPartName(nodeName + ": [" + (tableName == null ? Long.toString(dciId) : tableName) + "]");
}
Also used : MobileDevice(org.netxms.client.objects.MobileDevice) AbstractNode(org.netxms.client.objects.AbstractNode) AbstractObject(org.netxms.client.objects.AbstractObject) Cluster(org.netxms.client.objects.Cluster) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PartInitException(org.eclipse.ui.PartInitException) Sensor(org.netxms.client.objects.Sensor)

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