Search in sources :

Example 11 with ChartDciConfig

use of org.netxms.client.datacollection.ChartDciConfig 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 12 with ChartDciConfig

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

the class HistoricalGraphView 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);
    refreshController = new ViewRefreshController(this, -1, new Runnable() {

        @Override
        public void run() {
            if (((Widget) chart).isDisposed())
                return;
            updateChart();
        }
    });
    session = (NXCSession) ConsoleSharedData.getSession();
    settings.setTimeFrom(new Date(System.currentTimeMillis() - settings.getTimeRangeMillis()));
    settings.setTimeTo(new Date(System.currentTimeMillis()));
    // Extract DCI ids from view id
    // (first field will be unique view id, so we skip it)
    String id = site.getSecondaryId();
    // $NON-NLS-1$
    String[] fields = id.split("&");
    if (!fields[0].equals(PREDEFINED_GRAPH_SUBID)) {
        List<ChartDciConfig> items = new ArrayList<ChartDciConfig>();
        for (int i = 1; i < fields.length; i++) {
            // $NON-NLS-1$
            String[] subfields = fields[i].split("\\@");
            if (subfields.length == 0)
                continue;
            if (Integer.parseInt(subfields[0]) == ChartDciConfig.ITEM) {
                try {
                    ChartDciConfig dci = new ChartDciConfig();
                    dci.type = Integer.parseInt(subfields[0]);
                    dci.nodeId = Long.parseLong(subfields[1], 10);
                    dci.dciId = Long.parseLong(subfields[2], 10);
                    // $NON-NLS-1$
                    dci.name = URLDecoder.decode(subfields[3], "UTF-8");
                    // $NON-NLS-1$
                    dci.dciDescription = URLDecoder.decode(subfields[3], "UTF-8");
                    // $NON-NLS-1$
                    dci.dciName = URLDecoder.decode(subfields[4], "UTF-8");
                    // Extra fields
                    if (subfields.length >= 6)
                        dci.invertValues = (Integer.parseInt(subfields[5]) & GraphItemStyle.INVERTED) > 0 ? true : false;
                    if (subfields.length >= 7)
                        dci.area = Integer.parseInt(subfields[6]) == GraphItemStyle.AREA ? true : false;
                    if (subfields.length >= 8)
                        dci.color = "0x" + Integer.toHexString(Integer.parseInt(subfields[7]));
                    items.add(dci);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            } else if (Integer.parseInt(subfields[0]) == ChartDciConfig.TABLE) {
                try {
                    ChartDciConfig dci = new ChartDciConfig();
                    dci.type = Integer.parseInt(subfields[0]);
                    dci.nodeId = Long.parseLong(subfields[1], 10);
                    dci.dciId = Long.parseLong(subfields[2], 10);
                    // $NON-NLS-1$
                    dci.name = URLDecoder.decode(subfields[3], "UTF-8");
                    // $NON-NLS-1$
                    dci.dciName = URLDecoder.decode(subfields[3], "UTF-8");
                    // $NON-NLS-1$
                    dci.instance = URLDecoder.decode(subfields[4], "UTF-8");
                    // $NON-NLS-1$
                    dci.column = URLDecoder.decode(subfields[5], "UTF-8");
                    items.add(dci);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }
        }
        // Set view title to "host name: dci description" if we have only one DCI
        if (items.size() == 1) {
            ChartDciConfig item = items.get(0);
            AbstractObject object = session.findObjectById(item.nodeId);
            if (object != null) {
                // $NON-NLS-1$
                setPartName(object.getObjectName() + ": " + item.name);
            }
        } else if (items.size() > 1) {
            long nodeId = items.get(0).nodeId;
            for (ChartDciConfig item : items) if (item.nodeId != nodeId) {
                nodeId = -1;
                break;
            }
            if (nodeId != -1) {
                // All DCIs from same node, set title to "host name"
                AbstractObject object = session.findObjectById(nodeId);
                if (object != null) {
                    setPartName(String.format(Messages.get().HistoricalGraphView_PartName, object.getObjectName()));
                }
            }
        }
        settings.setTitle(getPartName());
        settings.setDciList(items.toArray(new ChartDciConfig[items.size()]));
    }
}
Also used : ChartDciConfig(org.netxms.client.datacollection.ChartDciConfig) Widget(org.eclipse.swt.widgets.Widget) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Date(java.util.Date) AbstractObject(org.netxms.client.objects.AbstractObject) ViewRefreshController(org.netxms.ui.eclipse.tools.ViewRefreshController)

Example 13 with ChartDciConfig

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

the class HistoricalGraphView method getDataFromServer.

/**
 * Get DCI data from server
 */
private void getDataFromServer() {
    final ChartDciConfig[] dciList = settings.getDciList();
    // Request data from server
    ConsoleJob job = new ConsoleJob(Messages.get().HistoricalGraphView_JobName, this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

        private ChartDciConfig currentItem;

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            monitor.beginTask(getName(), dciList.length);
            final DciData[] data = new DciData[dciList.length];
            final Threshold[][] thresholds = new Threshold[dciList.length][];
            for (int i = 0; i < dciList.length; i++) {
                currentItem = dciList[i];
                if (currentItem.type == ChartDciConfig.ITEM) {
                    data[i] = session.getCollectedData(currentItem.nodeId, currentItem.dciId, settings.getTimeFrom(), settings.getTimeTo(), 0, false);
                    thresholds[i] = session.getThresholds(currentItem.nodeId, currentItem.dciId);
                } else {
                    data[i] = session.getCollectedTableData(currentItem.nodeId, currentItem.dciId, currentItem.instance, currentItem.column, settings.getTimeFrom(), settings.getTimeTo(), 0);
                    thresholds[i] = null;
                }
                monitor.worked(1);
            }
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    if (!((Widget) chart).isDisposed()) {
                        chart.setTimeRange(settings.getTimeFrom(), settings.getTimeTo());
                        setChartData(data);
                        chart.clearErrors();
                    }
                    updateInProgress = false;
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return String.format(Messages.get().HistoricalGraphView_JobError, session.getObjectName(currentItem.nodeId), currentItem.name);
        }

        @Override
        protected void jobFailureHandler() {
            updateInProgress = false;
            super.jobFailureHandler();
        }

        @Override
        protected IStatus createFailureStatus(final Exception e) {
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    chart.addError(getErrorMessage() + " (" + e.getLocalizedMessage() + ")");
                }
            });
            return Status.OK_STATUS;
        }
    };
    job.setUser(false);
    job.start();
}
Also used : ChartDciConfig(org.netxms.client.datacollection.ChartDciConfig) Widget(org.eclipse.swt.widgets.Widget) DciData(org.netxms.client.datacollection.DciData) PartInitException(org.eclipse.ui.PartInitException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NXCException(org.netxms.client.NXCException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) Threshold(org.netxms.client.datacollection.Threshold)

Example 14 with ChartDciConfig

use of org.netxms.client.datacollection.ChartDciConfig 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)

Example 15 with ChartDciConfig

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

the class DataSources method drawColorCell.

/**
 * @param event
 */
private void drawColorCell(Event event) {
    TableItem item = (TableItem) event.item;
    ChartDciConfig dci = (ChartDciConfig) item.getData();
    if (dci.color.equalsIgnoreCase(ChartDciConfig.UNSET_COLOR))
        return;
    int width = viewer.getTable().getColumn(COLUMN_COLOR).getWidth();
    Color color = ColorConverter.colorFromInt(dci.getColorAsInt(), colorCache);
    event.gc.setForeground(colorCache.create(0, 0, 0));
    event.gc.setBackground(color);
    event.gc.setLineWidth(1);
    event.gc.fillRectangle(event.x + 3, event.y + 2, width - 7, event.height - 5);
    event.gc.drawRectangle(event.x + 3, event.y + 2, width - 7, event.height - 5);
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) ChartDciConfig(org.netxms.client.datacollection.ChartDciConfig) Color(org.eclipse.swt.graphics.Color)

Aggregations

ChartDciConfig (org.netxms.client.datacollection.ChartDciConfig)21 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 ArrayList (java.util.ArrayList)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)4 GraphSettings (org.netxms.client.datacollection.GraphSettings)4 DataSourceEditDlg (org.netxms.ui.eclipse.datacollection.dialogs.DataSourceEditDlg)4 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)4 Date (java.util.Date)3 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)3 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)3 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)3 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 SelectionListener (org.eclipse.swt.events.SelectionListener)3 Color (org.eclipse.swt.graphics.Color)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 RowData (org.eclipse.swt.layout.RowData)3