Search in sources :

Example 6 with ObjectToolDetails

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

the class ObjectToolsEditor method createActions.

/**
 * Create actions
 */
private void createActions() {
    final IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
    actionShowFilter = new Action("Show filter", Action.AS_CHECK_BOX) {

        @Override
        public void run() {
            enableFilter(!initShowFilter);
            actionShowFilter.setChecked(initShowFilter);
        }
    };
    actionShowFilter.setChecked(initShowFilter);
    // $NON-NLS-1$
    actionShowFilter.setActionDefinitionId("org.netxms.ui.eclipse.objecttools.commands.showFilter");
    handlerService.activateHandler(actionShowFilter.getActionDefinitionId(), new ActionHandler(actionShowFilter));
    actionRefresh = new RefreshAction() {

        @Override
        public void run() {
            refreshToolList();
        }
    };
    actionNew = new Action(Messages.get().ObjectToolsEditor_New) {

        @Override
        public void run() {
            createTool();
        }
    };
    actionNew.setImageDescriptor(SharedIcons.ADD_OBJECT);
    actionEdit = new PropertyDialogAction(getSite(), viewer) {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            if (selection.size() != 1)
                return;
            final long toolId = ((ObjectTool) selection.getFirstElement()).getId();
            // If there will be error, adapter factory will show error message to user
            if (Platform.getAdapterManager().getAdapter(selection.getFirstElement(), ObjectToolDetails.class) == null)
                return;
            super.run();
            ObjectToolDetails details = ObjectToolsAdapterFactory.getDetailsFromCache(toolId);
            if ((details != null) && details.isModified()) {
                saveObjectTool(details);
            }
        }
    };
    actionEdit.setImageDescriptor(SharedIcons.EDIT);
    actionDelete = new Action(Messages.get().ObjectToolsEditor_Delete) {

        @Override
        public void run() {
            deleteTools();
        }
    };
    actionDelete.setImageDescriptor(SharedIcons.DELETE_OBJECT);
    actionDisable = new Action(Messages.get().ObjectToolsEditor_Disable) {

        @Override
        public void run() {
            setSelectedDisabled();
        }
    };
    actionEnable = new Action(Messages.get().ObjectToolsEditor_Enable) {

        @Override
        public void run() {
            setSelectedEnabled();
        }
    };
    actionClone = new Action(Messages.get().ObjectToolsEditor_Clone) {

        @Override
        public void run() {
            cloneTool();
        }
    };
}
Also used : PropertyDialogAction(org.eclipse.ui.dialogs.PropertyDialogAction) RefreshAction(org.netxms.ui.eclipse.actions.RefreshAction) Action(org.eclipse.jface.action.Action) IHandlerService(org.eclipse.ui.handlers.IHandlerService) RefreshAction(org.netxms.ui.eclipse.actions.RefreshAction) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ActionHandler(org.eclipse.jface.commands.ActionHandler) ObjectToolDetails(org.netxms.client.objecttools.ObjectToolDetails) PropertyDialogAction(org.eclipse.ui.dialogs.PropertyDialogAction)

Example 7 with ObjectToolDetails

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

the class ObjectToolsEditor method createTool.

/**
 * Create new tool
 */
private void createTool() {
    final CreateNewToolDialog dlg = new CreateNewToolDialog(getSite().getShell());
    if (dlg.open() == Window.OK) {
        new ConsoleJob(Messages.get().ObjectToolsEditor_JobNewId, this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                final long toolId = session.generateObjectToolId();
                final ObjectToolDetails details = new ObjectToolDetails(toolId, dlg.getType(), dlg.getName());
                session.modifyObjectTool(details);
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        PropertyDialog dlg = PropertyDialog.createDialogOn(getSite().getShell(), null, details);
                        dlg.open();
                        if (details.isModified())
                            saveObjectTool(details);
                    }
                });
            }

            @Override
            protected String getErrorMessage() {
                return Messages.get(getDisplay()).ObjectToolsEditor_JobNewIdError;
            }
        }.start();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PropertyDialog(org.eclipse.ui.internal.dialogs.PropertyDialog) CreateNewToolDialog(org.netxms.ui.eclipse.objecttools.dialogs.CreateNewToolDialog) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) ObjectToolDetails(org.netxms.client.objecttools.ObjectToolDetails) PartInitException(org.eclipse.ui.PartInitException)

Example 8 with ObjectToolDetails

use of org.netxms.client.objecttools.ObjectToolDetails 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

ObjectToolDetails (org.netxms.client.objecttools.ObjectToolDetails)8 ObjectTool (org.netxms.client.objecttools.ObjectTool)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 PartInitException (org.eclipse.ui.PartInitException)2 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Action (org.eclipse.jface.action.Action)1 ActionHandler (org.eclipse.jface.commands.ActionHandler)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Text (org.eclipse.swt.widgets.Text)1 PropertyDialogAction (org.eclipse.ui.dialogs.PropertyDialogAction)1 IHandlerService (org.eclipse.ui.handlers.IHandlerService)1 PropertyDialog (org.eclipse.ui.internal.dialogs.PropertyDialog)1 IWorkbenchAdapter (org.eclipse.ui.model.IWorkbenchAdapter)1