Search in sources :

Example 6 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)

Example 7 with GraphSettings

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

the class TemplateGraphView method editTemplateGraph.

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

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

                    @Override
                    protected String getErrorMessage() {
                        return "Cannot update predefined graph";
                    }
                }.start();
            } catch (Exception e) {
                // $NON-NLS-1$ //$NON-NLS-2$
                MessageDialogHelper.openError(getSite().getShell(), "Internal Error", String.format("Unexpected exception: %s", e.getLocalizedMessage()));
            }
        }
        settings.setName(newSettings.getName());
        settings.getAccessList().clear();
        settings.getAccessList().addAll(newSettings.getAccessList());
        viewer.update(settings, null);
    }
}
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) NXCException(org.netxms.client.NXCException)

Example 8 with GraphSettings

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

the class DataSources method createContents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    config = (ChartConfig) getElement().getAdapter(ChartConfig.class);
    if (config instanceof GraphSettings)
        graphIsTemplate = ((GraphSettings) config).isTemplate();
    Composite dialogArea = new Composite(parent, SWT.NONE);
    dciList = new ArrayList<ChartDciConfig>();
    for (ChartDciConfig dci : config.getDciList()) dciList.add(new ChartDciConfig(dci));
    labelProvider = new DciListLabelProvider(dciList);
    labelProvider.resolveDciNames(dciList);
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = 2;
    dialogArea.setLayout(layout);
    final String[] columnNames = { Messages.get().DataSources_ColPosition, Messages.get().DataSources_ColNode, Messages.get().DataSources_ColParameter, Messages.get().DataSources_ColLabel, Messages.get().DataSources_ColColor };
    final int[] columnWidths = { 40, 130, 200, 150, 50 };
    viewer = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(labelProvider);
    viewer.disableSorting();
    viewer.setInput(dciList.toArray());
    GridData gridData = new GridData();
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.heightHint = 0;
    gridData.horizontalSpan = 2;
    viewer.getControl().setLayoutData(gridData);
    /* buttons on left side */
    Composite leftButtons = new Composite(dialogArea, SWT.NONE);
    RowLayout buttonLayout = new RowLayout();
    buttonLayout.type = SWT.HORIZONTAL;
    buttonLayout.pack = false;
    buttonLayout.marginWidth = 0;
    buttonLayout.marginLeft = 0;
    leftButtons.setLayout(buttonLayout);
    gridData = new GridData();
    gridData.horizontalAlignment = SWT.LEFT;
    leftButtons.setLayoutData(gridData);
    upButton = new Button(leftButtons, SWT.PUSH);
    upButton.setText(Messages.get().DataSources_Up);
    RowData rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    upButton.setLayoutData(rd);
    upButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveUp();
        }
    });
    upButton.setEnabled(false);
    downButton = new Button(leftButtons, SWT.PUSH);
    downButton.setText(Messages.get().DataSources_Down);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    downButton.setLayoutData(rd);
    downButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveDown();
        }
    });
    downButton.setEnabled(false);
    /* buttons on right side */
    Composite rightButtons = new Composite(dialogArea, SWT.NONE);
    buttonLayout = new RowLayout();
    buttonLayout.type = SWT.HORIZONTAL;
    buttonLayout.pack = false;
    buttonLayout.marginWidth = 0;
    buttonLayout.marginRight = 0;
    rightButtons.setLayout(buttonLayout);
    gridData = new GridData();
    gridData.horizontalAlignment = SWT.RIGHT;
    rightButtons.setLayoutData(gridData);
    addButton = new Button(rightButtons, SWT.PUSH);
    addButton.setText(Messages.get().DataSources_Add);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    addButton.setLayoutData(rd);
    addButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            addItem();
        }
    });
    editButton = new Button(rightButtons, SWT.PUSH);
    editButton.setText(Messages.get().DataSources_Modify);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    editButton.setLayoutData(rd);
    editButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            editItem();
        }
    });
    editButton.setEnabled(false);
    deleteButton = new Button(rightButtons, SWT.PUSH);
    deleteButton.setText(Messages.get().DataSources_Delete);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    deleteButton.setLayoutData(rd);
    deleteButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            deleteItems();
        }
    });
    deleteButton.setEnabled(false);
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            editButton.notifyListeners(SWT.Selection, new Event());
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            editButton.setEnabled(selection.size() == 1);
            deleteButton.setEnabled(selection.size() > 0);
            upButton.setEnabled(selection.size() == 1);
            downButton.setEnabled(selection.size() == 1);
        }
    });
    return dialogArea;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ChartDciConfig(org.netxms.client.datacollection.ChartDciConfig) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) RowData(org.eclipse.swt.layout.RowData) GraphSettings(org.netxms.client.datacollection.GraphSettings) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DciListLabelProvider(org.netxms.ui.eclipse.perfview.propertypages.helpers.DciListLabelProvider) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 9 with GraphSettings

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

the class TemplateDataSources method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected void applyChanges(final boolean isApply) {
    config.setDciList(dciList.toArray(new ChartDciConfig[dciList.size()]));
    if ((config instanceof GraphSettings) && isApply) {
        setValid(false);
        final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
        new ConsoleJob(Messages.get().DataSources_JobName, null, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                session.saveGraph((GraphSettings) config, true);
            }

            @Override
            protected void jobFinalize() {
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        TemplateDataSources.this.setValid(true);
                    }
                });
            }

            @Override
            protected String getErrorMessage() {
                return Messages.get().DataSources_JobError;
            }
        }.start();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) GraphSettings(org.netxms.client.datacollection.GraphSettings) ChartDciConfig(org.netxms.client.datacollection.ChartDciConfig) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 10 with GraphSettings

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

the class GraphTemplateCache method execute.

public static void execute(final AbstractNode node, final GraphSettings data, final DciValue[] values, final Display disp) throws IOException, NXCException {
    final NXCSession session = ConsoleSharedData.getSession();
    List<String> textsToExpand = new ArrayList<String>();
    textsToExpand.add(data.getTitle());
    String name = session.substitureMacross(new ObjectContext(node, null), textsToExpand, new HashMap<String, String>()).get(0);
    final GraphSettings result = new GraphSettings(data, name);
    ChartDciConfig[] conf = result.getDciList();
    final HashSet<ChartDciConfig> newList = new HashSet<ChartDciConfig>();
    int foundByDescription = -1;
    int foundDCICount = 0;
    // parse config and compare name as regexp and then compare description
    for (int i = 0; i < conf.length; i++) {
        Pattern namePattern = Pattern.compile(conf[i].dciName);
        Pattern descriptionPattern = Pattern.compile(conf[i].dciDescription);
        int j;
        for (j = 0; j < values.length; j++) {
            if (!conf[i].dciName.isEmpty() && namePattern.matcher(values[j].getName()).find()) {
                newList.add(new ChartDciConfig(values[j]));
                foundDCICount++;
                if (!conf[i].multiMatch)
                    break;
            }
            if (!conf[i].dciDescription.isEmpty() && descriptionPattern.matcher(values[j].getDescription()).find()) {
                foundByDescription = j;
                if (conf[i].multiMatch) {
                    newList.add(new ChartDciConfig(values[j]));
                    foundDCICount++;
                }
            }
        }
        if (!conf[i].multiMatch && j == values.length && foundByDescription >= 0) {
            foundDCICount++;
            newList.add(new ChartDciConfig(values[foundByDescription]));
        }
    }
    if (foundDCICount > 0) {
        disp.syncExec(new Runnable() {

            @Override
            public void run() {
                result.setDciList(newList.toArray(new ChartDciConfig[newList.size()]));
                showPredefinedGraph(result, node.getObjectId());
            }
        });
    } else {
        disp.syncExec(new Runnable() {

            @Override
            public void run() {
                MessageDialogHelper.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Graph creation from template error", "None of template graphs DCI were found on a node.");
            }
        });
    }
}
Also used : Pattern(java.util.regex.Pattern) NXCSession(org.netxms.client.NXCSession) HashMap(java.util.HashMap) ChartDciConfig(org.netxms.client.datacollection.ChartDciConfig) ArrayList(java.util.ArrayList) GraphSettings(org.netxms.client.datacollection.GraphSettings) ObjectContext(org.netxms.ui.eclipse.objects.ObjectContext) HashSet(java.util.HashSet)

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