2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2015 Victor Kirhenshtein
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 package org
.netxms
.ui
.eclipse
.dashboard
.widgets
;
21 import java
.util
.Date
;
22 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
23 import org
.eclipse
.core
.runtime
.IStatus
;
24 import org
.eclipse
.core
.runtime
.Status
;
25 import org
.eclipse
.swt
.SWT
;
26 import org
.eclipse
.swt
.events
.DisposeEvent
;
27 import org
.eclipse
.swt
.events
.DisposeListener
;
28 import org
.eclipse
.swt
.graphics
.Point
;
29 import org
.eclipse
.swt
.layout
.FillLayout
;
30 import org
.eclipse
.swt
.widgets
.Widget
;
31 import org
.eclipse
.ui
.IViewPart
;
32 import org
.netxms
.client
.NXCSession
;
33 import org
.netxms
.client
.dashboards
.DashboardElement
;
34 import org
.netxms
.client
.datacollection
.ChartDciConfig
;
35 import org
.netxms
.client
.datacollection
.DciData
;
36 import org
.netxms
.client
.datacollection
.DciDataRow
;
37 import org
.netxms
.ui
.eclipse
.charts
.api
.DataComparisonChart
;
38 import org
.netxms
.ui
.eclipse
.dashboard
.Activator
;
39 import org
.netxms
.ui
.eclipse
.dashboard
.Messages
;
40 import org
.netxms
.ui
.eclipse
.jobs
.ConsoleJob
;
41 import org
.netxms
.ui
.eclipse
.shared
.ConsoleSharedData
;
42 import org
.netxms
.ui
.eclipse
.tools
.ViewRefreshController
;
45 * Base class for data comparison charts - like bar chart, pie chart, etc.
47 public abstract class ComparisonChartElement
extends ElementWidget
49 protected DataComparisonChart chart
;
50 protected NXCSession session
;
51 protected int refreshInterval
= 30;
53 private ViewRefreshController refreshController
;
54 private boolean updateInProgress
= false
;
60 public ComparisonChartElement(DashboardControl parent
, DashboardElement element
, IViewPart viewPart
)
62 super(parent
, element
, viewPart
);
63 session
= (NXCSession
)ConsoleSharedData
.getSession();
65 setLayout(new FillLayout());
67 addDisposeListener(new DisposeListener() {
69 public void widgetDisposed(DisposeEvent e
)
71 if (refreshController
!= null
)
72 refreshController
.dispose();
80 protected void startRefreshTimer()
82 refreshController
= new ViewRefreshController(viewPart
, refreshInterval
, new Runnable() {
86 if (ComparisonChartElement
.this.isDisposed())
89 refreshData(getDciList());
92 refreshData(getDciList());
96 * Refresh graph's data
98 protected void refreshData(final ChartDciConfig
[] dciList
)
100 if (updateInProgress
)
103 updateInProgress
= true
;
105 ConsoleJob job
= new ConsoleJob(Messages
.get().ComparisonChartElement_JobTitle
, viewPart
, Activator
.PLUGIN_ID
, Activator
.PLUGIN_ID
) {
107 protected void runInternal(IProgressMonitor monitor
) throws Exception
109 final DciData
[] data
= new DciData
[dciList
.length
];
110 for(int i
= 0; i
< dciList
.length
; i
++)
112 if (dciList
[i
].type
== ChartDciConfig
.ITEM
)
113 data
[i
] = session
.getCollectedData(dciList
[i
].nodeId
, dciList
[i
].dciId
, null
, null
, 1);
115 data
[i
] = session
.getCollectedTableData(dciList
[i
].nodeId
, dciList
[i
].dciId
, dciList
[i
].instance
, dciList
[i
].column
, null
, null
, 1);
117 runInUIThread(new Runnable() {
121 if (!((Widget
)chart
).isDisposed())
123 for(int i
= 0; i
< data
.length
; i
++)
125 DciDataRow lastValue
= data
[i
].getLastValue();
126 chart
.updateParameter(i
, (lastValue
!= null
) ? lastValue
: new DciDataRow(new Date(), 0.0), data
[i
].getDataType(), false
);
131 updateInProgress
= false
;
137 protected String
getErrorMessage()
139 return Messages
.get().ComparisonChartElement_JobError
;
143 protected void jobFailureHandler()
145 updateInProgress
= false
;
146 super.jobFailureHandler();
150 protected IStatus
createFailureStatus(final Exception e
)
152 runInUIThread(new Runnable() {
156 chart
.addError(getErrorMessage() + " (" + e
.getLocalizedMessage() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
159 return Status
.OK_STATUS
;
167 * @see org.eclipse.swt.widgets.Composite#computeSize(int, int, boolean)
170 public Point
computeSize(int wHint
, int hHint
, boolean changed
)
172 Point size
= super.computeSize(wHint
, hHint
, changed
);
173 if ((hHint
== SWT
.DEFAULT
) && (size
.y
< 250))
178 protected abstract ChartDciConfig
[] getDciList();