Search in sources :

Example 16 with ObjectTool

use of org.netxms.client.objecttools.ObjectTool in project netxms by netxms.

the class ObjectToolsAdapterFactory method getAdapter.

/* (non-Javadoc)
	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
	 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
    if (adaptableObject.getClass() != ObjectTool.class)
        return null;
    // Adapt to tool details
    if (adapterType == ObjectToolDetails.class) {
        final long toolId = ((ObjectTool) adaptableObject).getId();
        ObjectToolDetails details = cache.get(toolId);
        if (details == null) {
            ToolDetailLoader job = new ToolDetailLoader(toolId, PlatformUI.getWorkbench().getDisplay());
            IProgressService service = PlatformUI.getWorkbench().getProgressService();
            try {
                service.busyCursorWhile(job);
                details = job.getResult();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return details;
    }
    // Adapt to IWorkbenchAdapter
    if (adapterType == IWorkbenchAdapter.class) {
        return new IWorkbenchAdapter() {

            @Override
            public Object getParent(Object o) {
                return null;
            }

            @Override
            public String getLabel(Object o) {
                return ((ObjectTool) o).getDisplayName();
            }

            @Override
            public ImageDescriptor getImageDescriptor(Object object) {
                return null;
            }

            @Override
            public Object[] getChildren(Object o) {
                return null;
            }
        };
    }
    return null;
}
Also used : IProgressService(org.eclipse.ui.progress.IProgressService) IWorkbenchAdapter(org.eclipse.ui.model.IWorkbenchAdapter) ObjectToolDetails(org.netxms.client.objecttools.ObjectToolDetails) InvocationTargetException(java.lang.reflect.InvocationTargetException) ObjectTool(org.netxms.client.objecttools.ObjectTool)

Example 17 with ObjectTool

use of org.netxms.client.objecttools.ObjectTool in project netxms by netxms.

the class ObjectToolsEditor method setSelectedDisabled.

private void setSelectedDisabled() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.isEmpty())
        return;
    if (!MessageDialogHelper.openConfirm(getSite().getShell(), Messages.get().ObjectToolsEditor_Confirmation, Messages.get().ObjectToolsEditor_AckToDisableObjectTool))
        return;
    final Object[] objects = selection.toArray();
    new ConsoleJob(Messages.get(viewer.getControl().getDisplay()).ObjectToolsEditor_DisableObjTool, this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

        @Override
        protected String getErrorMessage() {
            return Messages.get(getDisplay()).ObjectToolsEditor_ErrorDisablingObjectTools;
        }

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            for (int i = 0; i < objects.length; i++) {
                if ((((ObjectTool) objects[i]).getFlags() & ObjectTool.DISABLED) == 0)
                    session.changeObjecToolDisableStatuss(((ObjectTool) objects[i]).getId(), false);
            }
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) ObjectTool(org.netxms.client.objecttools.ObjectTool)

Example 18 with ObjectTool

use of org.netxms.client.objecttools.ObjectTool in project netxms by netxms.

the class ObjectToolsEditor method refreshToolList.

/**
 * Refresh tool list
 */
private void refreshToolList() {
    new ConsoleJob(Messages.get(viewer.getControl().getDisplay()).ObjectToolsEditor_JobGetConfig, this, Activator.PLUGIN_ID, Activator.PLUGIN_ID, viewer.getControl().getDisplay()) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final List<ObjectTool> tl = session.getObjectTools();
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    tools.clear();
                    for (ObjectTool t : tl) tools.put(t.getId(), t);
                    viewer.setInput(tools.values().toArray());
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get(getDisplay()).ObjectToolsEditor_JobGetConfigError;
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) ObjectTool(org.netxms.client.objecttools.ObjectTool)

Example 19 with ObjectTool

use of org.netxms.client.objecttools.ObjectTool in project netxms by netxms.

the class ObjectToolsEditor method cloneTool.

/**
 * Clone object tool
 */
private void cloneTool() {
    final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.isEmpty())
        return;
    final CreateObjectDialog dlg = new CreateObjectDialog(getSite().getShell(), "Object tool");
    if (dlg.open() == Window.OK) {
        new ConsoleJob("Clone object tool", this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                final long toolId = session.generateObjectToolId();
                ObjectTool objTool = (ObjectTool) selection.toArray()[0];
                ObjectToolDetails details = session.getObjectToolDetails(objTool.getId());
                details.setId(toolId);
                details.setName(dlg.getObjectName());
                session.modifyObjectTool(details);
            }

            @Override
            protected String getErrorMessage() {
                return "Cannot clone object tool";
            }
        }.start();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CreateObjectDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.CreateObjectDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) ObjectToolDetails(org.netxms.client.objecttools.ObjectToolDetails) PartInitException(org.eclipse.ui.PartInitException) ObjectTool(org.netxms.client.objecttools.ObjectTool)

Aggregations

ObjectTool (org.netxms.client.objecttools.ObjectTool)19 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 PartInitException (org.eclipse.ui.PartInitException)5 ObjectToolDetails (org.netxms.client.objecttools.ObjectToolDetails)3 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 GeoLocation (org.netxms.base.GeoLocation)2 Node (org.netxms.client.objects.Node)2 AlertDialog (android.app.AlertDialog)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 DialogInterface (android.content.DialogInterface)1 OnClickListener (android.content.DialogInterface.OnClickListener)1 Intent (android.content.Intent)1 SubMenu (android.view.SubMenu)1 AdapterView (android.widget.AdapterView)1