Search in sources :

Example 1 with GraphSettings

use of org.netxms.client.datacollection.GraphSettings in project netxms by netxms.

the class PredefinedGraphTree method editPredefinedGraph.

/**
 * Edit predefined graph
 */
private void editPredefinedGraph() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() != 1)
        return;
    GraphSettings settings = (GraphSettings) selection.getFirstElement();
    PropertyDialog dlg = PropertyDialog.createDialogOn(getSite().getShell(), null, settings);
    if (dlg != null) {
        if (dlg.open() == Window.OK) {
            final GraphSettings newSettings = settings;
            try {
                new ConsoleJob(Messages.get().PredefinedGraphTree_UpdateJobName, null, Activator.PLUGIN_ID, null) {

                    @Override
                    protected void runInternal(IProgressMonitor monitor) throws Exception {
                        session.saveGraph(newSettings, true);
                        runInUIThread(new Runnable() {

                            @Override
                            public void run() {
                                viewer.update(newSettings, null);
                            }
                        });
                    }

                    @Override
                    protected String getErrorMessage() {
                        return Messages.get().PredefinedGraphTree_UpdateJobError;
                    }
                }.start();
            } catch (Exception e) {
                // $NON-NLS-1$ //$NON-NLS-2$
                MessageDialogHelper.openError(getSite().getShell(), "Internal Error", String.format("Unexpected exception: %s", e.getLocalizedMessage()));
            }
        }
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GraphSettings(org.netxms.client.datacollection.GraphSettings) PropertyDialog(org.eclipse.ui.internal.dialogs.PropertyDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with GraphSettings

use of org.netxms.client.datacollection.GraphSettings in project netxms by netxms.

the class PredefinedGraphTree method onFilterModify.

/**
 * Handler for filter modification
 */
private void onFilterModify() {
    final String text = filterText.getText();
    filter.setFilterString(text);
    viewer.refresh(false);
    GraphSettings s = filter.getLastMatch();
    if (s != null) {
        viewer.expandToLevel(s, 1);
        viewer.setSelection(new StructuredSelection(s), true);
    }
}
Also used : GraphSettings(org.netxms.client.datacollection.GraphSettings) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 3 with GraphSettings

use of org.netxms.client.datacollection.GraphSettings in project netxms by netxms.

the class PredefinedGraphTree method createActions.

/**
 * Create actions
 */
private void createActions() {
    final IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
    actionRefresh = new RefreshAction(this) {

        @Override
        public void run() {
            reloadGraphList();
        }
    };
    actionDelete = new Action(Messages.get().PredefinedGraphTree_Delete, SharedIcons.DELETE_OBJECT) {

        @Override
        public void run() {
            deletePredefinedGraph();
        }
    };
    actionOpen = new Action() {

        @SuppressWarnings("rawtypes")
        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            Iterator it = selection.iterator();
            while (it.hasNext()) {
                Object o = it.next();
                if (o instanceof GraphSettings) {
                    showPredefinedGraph((GraphSettings) o);
                }
            }
        }
    };
    actionOpen.setText(Messages.get().PredefinedGraphTree_Open);
    actionProperties = new Action(Messages.get().PredefinedGraphTree_Properties) {

        @Override
        public void run() {
            editPredefinedGraph();
        }
    };
    actionShowFilter = new Action(Messages.get().PredefinedGraphTree_ShowFilter, Action.AS_CHECK_BOX) {

        @Override
        public void run() {
            enableFilter(!initShowFilter);
            actionShowFilter.setChecked(initShowFilter);
        }
    };
    // $NON-NLS-1$
    actionShowFilter.setId("org.netxms.ui.eclipse.perfview.actions.showFilter");
    actionShowFilter.setChecked(initShowFilter);
    // $NON-NLS-1$
    actionShowFilter.setActionDefinitionId("org.netxms.ui.eclipse.perfview.commands.show_graph_filter");
    final ActionHandler showFilterHandler = new ActionHandler(actionShowFilter);
    handlerService.activateHandler(actionShowFilter.getActionDefinitionId(), showFilterHandler);
}
Also used : 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) GraphSettings(org.netxms.client.datacollection.GraphSettings) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ActionHandler(org.eclipse.jface.commands.ActionHandler)

Example 4 with GraphSettings

use of org.netxms.client.datacollection.GraphSettings in project netxms by netxms.

the class PredefinedGraphTree 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();
    parent.setLayout(new FormLayout());
    // Create filter area
    filterText = new FilterText(parent, SWT.NONE);
    filterText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            onFilterModify();
        }
    });
    filterText.setCloseAction(new Action() {

        @Override
        public void run() {
            enableFilter(false);
        }
    });
    viewer = new TreeViewer(parent, SWT.NONE);
    viewer.setUseHashlookup(true);
    viewer.setContentProvider(new GraphTreeContentProvider());
    viewer.setLabelProvider(new GraphTreeLabelProvider());
    viewer.setComparer(new IElementComparer() {

        @Override
        public int hashCode(Object element) {
            if ((element instanceof GraphSettings)) {
                return (int) ((GraphSettings) element).getId();
            }
            if ((element instanceof GraphFolder)) {
                return ((GraphFolder) element).getName().hashCode();
            }
            return element.hashCode();
        }

        @Override
        public boolean equals(Object a, Object b) {
            if ((a instanceof GraphSettings) && (b instanceof GraphSettings))
                return ((GraphSettings) a).getId() == ((GraphSettings) b).getId();
            if ((a instanceof GraphFolder) && (b instanceof GraphFolder))
                return ((GraphFolder) a).getName().equals(((GraphFolder) b).getName());
            return a.equals(b);
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            actionOpen.run();
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @SuppressWarnings("rawtypes")
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            Iterator it = selection.iterator();
            boolean enabled = false;
            while (it.hasNext()) {
                if (it.next() instanceof GraphSettings) {
                    enabled = true;
                    break;
                }
            }
            actionOpen.setEnabled(enabled);
            actionDelete.setEnabled(enabled);
            actionProperties.setEnabled(enabled);
        }
    });
    filter = new GraphTreeFilter();
    viewer.addFilter(filter);
    // Setup layout
    FormData fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(filterText);
    fd.right = new FormAttachment(100, 0);
    fd.bottom = new FormAttachment(100, 0);
    viewer.getTree().setLayoutData(fd);
    fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(0, 0);
    fd.right = new FormAttachment(100, 0);
    filterText.setLayoutData(fd);
    activateContext();
    createActions();
    contributeToActionBars();
    createPopupMenu();
    reloadGraphList();
    session.addListener(this);
    // Set initial focus to filter input line
    if (initShowFilter)
        filterText.setFocus();
    else
        // Will hide filter area correctly
        enableFilter(false);
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) GraphFolder(org.netxms.ui.eclipse.perfview.views.helpers.GraphFolder) RefreshAction(org.netxms.ui.eclipse.actions.RefreshAction) Action(org.eclipse.jface.action.Action) ModifyListener(org.eclipse.swt.events.ModifyListener) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IElementComparer(org.eclipse.jface.viewers.IElementComparer) GraphTreeContentProvider(org.netxms.ui.eclipse.perfview.views.helpers.GraphTreeContentProvider) GraphTreeLabelProvider(org.netxms.ui.eclipse.perfview.views.helpers.GraphTreeLabelProvider) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GraphSettings(org.netxms.client.datacollection.GraphSettings) GraphTreeFilter(org.netxms.ui.eclipse.perfview.views.helpers.GraphTreeFilter) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) Iterator(java.util.Iterator) FilterText(org.netxms.ui.eclipse.widgets.FilterText) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 5 with GraphSettings

use of org.netxms.client.datacollection.GraphSettings in project netxms by netxms.

the class TemplateGraphView method saveGraph.

/**
 * Save this graph as predefined
 */
private void saveGraph(String graphName, String errorMessage, final boolean canBeOverwritten) {
    SaveGraphDlg dlg = new SaveGraphDlg(getSite().getShell(), graphName, errorMessage, canBeOverwritten);
    int result = dlg.open();
    if (result == Window.CANCEL)
        return;
    final GraphSettings gs = new GraphSettings(0, session.getUserId(), 0, new ArrayList<AccessListElement>(0));
    gs.setName(dlg.getName());
    gs.setFlags(GraphSettings.GRAPH_FLAG_TEMPLATE);
    if (result == SaveGraphDlg.OVERRIDE) {
        new ConsoleJob(Messages.get().HistoricalGraphView_SaveSettings, this, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                session.saveGraph(gs, canBeOverwritten);
            }

            @Override
            protected String getErrorMessage() {
                return Messages.get().HistoricalGraphView_SaveSettingsError;
            }
        }.start();
    } else {
        new ConsoleJob(Messages.get().HistoricalGraphView_SaveSettings, this, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                try {
                    session.saveGraph(gs, canBeOverwritten);
                } catch (NXCException e) {
                    if (e.getErrorCode() == RCC.OBJECT_ALREADY_EXISTS) {
                        runInUIThread(new Runnable() {

                            @Override
                            public void run() {
                                saveGraph(gs.getName(), Messages.get().HistoricalGraphView_NameAlreadyExist, true);
                            }
                        });
                    } else {
                        if (e.getErrorCode() == RCC.ACCESS_DENIED) {
                            runInUIThread(new Runnable() {

                                @Override
                                public void run() {
                                    saveGraph(gs.getName(), Messages.get().HistoricalGraphView_NameAlreadyExistNoOverwrite, false);
                                }
                            });
                        } else {
                            throw e;
                        }
                    }
                }
            }

            @Override
            protected String getErrorMessage() {
                return Messages.get().HistoricalGraphView_SaveError;
            }
        }.start();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GraphSettings(org.netxms.client.datacollection.GraphSettings) SaveGraphDlg(org.netxms.ui.eclipse.perfview.dialogs.SaveGraphDlg) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) AccessListElement(org.netxms.client.AccessListElement) PartInitException(org.eclipse.ui.PartInitException) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException)

Aggregations

GraphSettings (org.netxms.client.datacollection.GraphSettings)18 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)8 NXCSession (org.netxms.client.NXCSession)5 PartInitException (org.eclipse.ui.PartInitException)4 ChartDciConfig (org.netxms.client.datacollection.ChartDciConfig)4 ArrayList (java.util.ArrayList)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 NXCException (org.netxms.client.NXCException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Action (org.eclipse.jface.action.Action)2 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)2 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 PropertyDialog (org.eclipse.ui.internal.dialogs.PropertyDialog)2