Search in sources :

Example 1 with PerfTabGraph

use of org.netxms.ui.eclipse.perfview.objecttabs.internal.PerfTabGraph in project netxms by netxms.

the class PerformanceTab method update.

/**
 * Update tab with received DCIs
 *
 * @param items Performance tab items
 */
private void update(final PerfTabDci[] items) {
    if (waitingImage != null) {
        waitingImage.dispose();
        waitingImage = null;
    }
    for (PerfTabGraph chart : charts.values()) chart.dispose();
    charts.clear();
    List<PerfTabGraphSettings> settings = new ArrayList<PerfTabGraphSettings>(items.length);
    for (int i = 0; i < items.length; i++) {
        try {
            PerfTabGraphSettings s = PerfTabGraphSettings.createFromXml(items[i].getPerfTabSettings());
            if (s.isEnabled()) {
                s.setRuntimeDciInfo(items[i]);
                settings.add(s);
            }
        } catch (Exception e) {
        }
    }
    // Sort DCIs: by group name, then by order number, then alphabetically
    Collections.sort(settings, new Comparator<PerfTabGraphSettings>() {

        @Override
        public int compare(PerfTabGraphSettings o1, PerfTabGraphSettings o2) {
            int result = Integer.signum(o1.getOrder() - o2.getOrder());
            if (result == 0)
                result = o1.getGroupName().compareToIgnoreCase(o2.getGroupName());
            if (result == 0) {
                // Sort top-level DCI's by chart title, and attached DCIs by legend name
                if (o1.getGroupName().isEmpty())
                    result = o1.getRuntimeTitle().compareToIgnoreCase(o2.getRuntimeTitle());
                else
                    result = o1.getRuntimeName().compareToIgnoreCase(o2.getRuntimeName());
            }
            return result;
        }
    });
    for (PerfTabGraphSettings s : settings) {
        String groupName = s.getGroupName();
        PerfTabGraph chart = groupName.isEmpty() ? null : charts.get(groupName);
        if (chart == null) {
            chart = new PerfTabGraph(chartArea, getObject().getObjectId(), s.getRuntimeDciInfo(), s, getViewPart(), new VisibilityValidator() {

                @Override
                public boolean isVisible() {
                    return isActive();
                }
            });
            charts.put(groupName.isEmpty() ? "##" + Long.toString(s.getRuntimeDciInfo().getId()) : groupName, chart);
            final GridData gd = new GridData();
            gd.horizontalAlignment = SWT.FILL;
            gd.grabExcessHorizontalSpace = true;
            gd.heightHint = 320;
            chart.setLayoutData(gd);
        } else {
            chart.addItem(s.getRuntimeDciInfo(), s);
        }
    }
    for (PerfTabGraph chart : charts.values()) chart.start();
    updateChartAreaLayout();
}
Also used : VisibilityValidator(org.netxms.ui.eclipse.tools.VisibilityValidator) PerfTabGraphSettings(org.netxms.ui.eclipse.perfview.PerfTabGraphSettings) ArrayList(java.util.ArrayList) GridData(org.eclipse.swt.layout.GridData) PerfTabGraph(org.netxms.ui.eclipse.perfview.objecttabs.internal.PerfTabGraph) MalformedURLException(java.net.MalformedURLException)

Example 2 with PerfTabGraph

use of org.netxms.ui.eclipse.perfview.objecttabs.internal.PerfTabGraph in project netxms by netxms.

the class PerformanceTab method objectChanged.

/* (non-Javadoc)
	 * @see org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab#objectChanged(org.netxms.client.objects.AbstractObject)
	 */
@Override
public void objectChanged(final AbstractObject object) {
    for (PerfTabGraph chart : charts.values()) chart.dispose();
    charts.clear();
    if (object == null)
        return;
    if (waitingImage != null)
        waitingImage.dispose();
    waitingImage = new AnimatedImage(chartArea, SWT.NONE);
    waitingImage.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true, 2, 1));
    try {
        // $NON-NLS-1$
        waitingImage.setImage(new URL("platform:/plugin/org.netxms.webui.core/icons/progress.gif"));
    } catch (MalformedURLException e) {
    }
    updateChartAreaLayout();
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    Job job = new Job(Messages.get().PerformanceTab_JobName) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                final PerfTabDci[] items = session.getPerfTabItems(object.getObjectId());
                final Display display = PerformanceTab.this.getClientArea().getDisplay();
                new UIJob(display, Messages.get(display).PerformanceTab_JobName) {

                    @Override
                    public IStatus runInUIThread(IProgressMonitor monitor) {
                        if (!getClientArea().isDisposed() && (PerformanceTab.this.getObject() != null) && (PerformanceTab.this.getObject().getObjectId() == object.getObjectId())) {
                            update(items);
                        }
                        return Status.OK_STATUS;
                    }
                }.schedule();
            } catch (Exception e) {
                // $NON-NLS-1$
                Activator.logError("Exception in performance tab loading job", e);
            }
            return Status.OK_STATUS;
        }
    };
    job.setSystem(true);
    job.schedule();
}
Also used : MalformedURLException(java.net.MalformedURLException) IStatus(org.eclipse.core.runtime.IStatus) NXCSession(org.netxms.client.NXCSession) PerfTabGraph(org.netxms.ui.eclipse.perfview.objecttabs.internal.PerfTabGraph) AnimatedImage(org.netxms.ui.eclipse.widgets.AnimatedImage) URL(java.net.URL) PerfTabDci(org.netxms.client.datacollection.PerfTabDci) MalformedURLException(java.net.MalformedURLException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GridData(org.eclipse.swt.layout.GridData) UIJob(org.eclipse.ui.progress.UIJob) Job(org.eclipse.core.runtime.jobs.Job) UIJob(org.eclipse.ui.progress.UIJob) Display(org.eclipse.swt.widgets.Display)

Aggregations

MalformedURLException (java.net.MalformedURLException)2 GridData (org.eclipse.swt.layout.GridData)2 PerfTabGraph (org.netxms.ui.eclipse.perfview.objecttabs.internal.PerfTabGraph)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Job (org.eclipse.core.runtime.jobs.Job)1 Display (org.eclipse.swt.widgets.Display)1 UIJob (org.eclipse.ui.progress.UIJob)1 NXCSession (org.netxms.client.NXCSession)1 PerfTabDci (org.netxms.client.datacollection.PerfTabDci)1 PerfTabGraphSettings (org.netxms.ui.eclipse.perfview.PerfTabGraphSettings)1 VisibilityValidator (org.netxms.ui.eclipse.tools.VisibilityValidator)1 AnimatedImage (org.netxms.ui.eclipse.widgets.AnimatedImage)1