89ba2aec22d46ecee4364791bb09523210d7e1df
[public/netxms.git] / src / java / netxms-eclipse / PerfView / src / org / netxms / ui / eclipse / perfview / propertypages / General.java
1 /**
2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2014 Victor Kirhenshtein
4 *
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.
9 *
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.
14 *
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.
18 */
19 package org.netxms.ui.eclipse.perfview.propertypages;
20
21 import org.eclipse.core.runtime.IProgressMonitor;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.events.SelectionEvent;
24 import org.eclipse.swt.events.SelectionListener;
25 import org.eclipse.swt.layout.GridData;
26 import org.eclipse.swt.layout.GridLayout;
27 import org.eclipse.swt.widgets.Button;
28 import org.eclipse.swt.widgets.Combo;
29 import org.eclipse.swt.widgets.Composite;
30 import org.eclipse.swt.widgets.Control;
31 import org.eclipse.swt.widgets.Group;
32 import org.eclipse.swt.widgets.Label;
33 import org.eclipse.swt.widgets.Scale;
34 import org.eclipse.swt.widgets.Spinner;
35 import org.eclipse.ui.dialogs.PropertyPage;
36 import org.netxms.client.NXCSession;
37 import org.netxms.ui.eclipse.jobs.ConsoleJob;
38 import org.netxms.ui.eclipse.perfview.Activator;
39 import org.netxms.ui.eclipse.perfview.ChartConfig;
40 import org.netxms.ui.eclipse.perfview.Messages;
41 import org.netxms.ui.eclipse.perfview.PredefinedChartConfig;
42 import org.netxms.ui.eclipse.perfview.widgets.YAxisRangeEditor;
43 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
44 import org.netxms.ui.eclipse.tools.WidgetHelper;
45 import org.netxms.ui.eclipse.widgets.LabeledText;
46 import org.netxms.ui.eclipse.widgets.TimePeriodSelector;
47
48 /**
49 * "General" property page for chart
50 */
51 public class General extends PropertyPage
52 {
53 private ChartConfig config;
54 private LabeledText title;
55 private Button checkShowGrid;
56 private Button checkShowLegend;
57 private Button checkShowHostNames;
58 private Button checkAutoRefresh;
59 private Button checkLogScale;
60 private Button checkStacked;
61 private Button checkExtendedLegend;
62 private Button checkTranslucent;
63 private Combo legendPleace;
64 private Scale refreshIntervalScale;
65 private Spinner refreshIntervalSpinner;
66 private TimePeriodSelector timeSelector;
67 private YAxisRangeEditor yAxisRange;
68
69 /* (non-Javadoc)
70 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
71 */
72 @Override
73 protected Control createContents(Composite parent)
74 {
75 config = (ChartConfig)getElement().getAdapter(ChartConfig.class);
76
77 Composite dialogArea = new Composite(parent, SWT.NONE);
78
79 GridLayout layout = new GridLayout();
80 layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
81 layout.marginWidth = 0;
82 layout.marginHeight = 0;
83 dialogArea.setLayout(layout);
84
85 title = new LabeledText(dialogArea, SWT.NONE, SWT.BORDER);
86 title.setLabel(Messages.get().General_Title);
87 title.setText(config.getTitle());
88 GridData gd = new GridData();
89 gd.horizontalAlignment = SWT.FILL;
90 gd.grabExcessHorizontalSpace = true;
91 title.setLayoutData(gd);
92
93 Group optionsGroup = new Group(dialogArea, SWT.NONE);
94 optionsGroup.setText(Messages.get().General_Options);
95 layout = new GridLayout();
96 layout.marginWidth = WidgetHelper.OUTER_SPACING;
97 layout.marginHeight = WidgetHelper.OUTER_SPACING;
98 layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
99 layout.makeColumnsEqualWidth = true;
100 layout.numColumns = 2;
101 optionsGroup.setLayout(layout);
102 gd = new GridData();
103 gd.horizontalAlignment = SWT.FILL;
104 gd.grabExcessHorizontalSpace = true;
105 optionsGroup.setLayoutData(gd);
106
107 checkShowGrid = new Button(optionsGroup, SWT.CHECK);
108 checkShowGrid.setText(Messages.get().General_ShowGridLines);
109 checkShowGrid.setSelection(config.isShowGrid());
110
111 checkLogScale = new Button(optionsGroup, SWT.CHECK);
112 checkLogScale.setText(Messages.get().General_LogScale);
113 checkLogScale.setSelection(config.isLogScale());
114
115 checkStacked = new Button(optionsGroup, SWT.CHECK);
116 checkStacked.setText("Stacked");
117 checkStacked.setSelection(config.isStacked());
118
119 checkTranslucent= new Button(optionsGroup, SWT.CHECK);
120 checkTranslucent.setText("Translucent");
121 checkTranslucent.setSelection(config.isTranslucent());
122
123 Composite legendGroup = new Composite(optionsGroup, SWT.NONE);
124 layout = new GridLayout();
125 layout.numColumns = 2;
126 layout.horizontalSpacing = WidgetHelper.OUTER_SPACING;
127 layout.makeColumnsEqualWidth = true;
128 layout.marginHeight = 0;
129 layout.marginWidth = 0;
130 layout.marginTop = WidgetHelper.OUTER_SPACING;
131 legendGroup.setLayout(layout);
132 gd = new GridData();
133 gd.horizontalAlignment = SWT.FILL;
134 gd.grabExcessHorizontalSpace = true;
135 gd.horizontalSpan = 2;
136 legendGroup.setLayoutData(gd);
137
138 checkShowLegend = new Button(legendGroup, SWT.CHECK);
139 checkShowLegend.setText(Messages.get().General_ShowLegend);
140 checkShowLegend.setSelection(config.isShowLegend());
141 checkShowLegend.addSelectionListener(new SelectionListener() {
142 @Override
143 public void widgetSelected(SelectionEvent e)
144 {
145 checkExtendedLegend.setEnabled(checkShowLegend.getSelection());
146 legendPleace.setEnabled(checkShowLegend.getSelection());
147 checkShowHostNames.setEnabled(checkShowLegend.getSelection());
148 }
149
150 @Override
151 public void widgetDefaultSelected(SelectionEvent e)
152 {
153 widgetSelected(e);
154 }
155 });
156 gd = new GridData();
157 gd.horizontalAlignment = SWT.FILL;
158 gd.grabExcessHorizontalSpace = true;
159 gd.horizontalSpan = 2;
160 checkShowLegend.setLayoutData(gd);
161
162
163 checkShowHostNames = new Button(legendGroup, SWT.CHECK);
164 checkShowHostNames.setText(Messages.get().General_ShowHostNames);
165 checkShowHostNames.setSelection(config.isShowHostNames());
166 checkShowHostNames.setEnabled(config.isShowLegend());
167
168 checkExtendedLegend = new Button(legendGroup, SWT.CHECK);
169 checkExtendedLegend.setText("Show extended legend");
170 checkExtendedLegend.setSelection(config.isExtendedLegend());
171 checkExtendedLegend.setEnabled(config.isShowLegend());
172
173 Composite placeGroup = new Composite(optionsGroup, SWT.NONE);
174 layout = new GridLayout();
175 layout.numColumns = 2;
176 layout.horizontalSpacing = WidgetHelper.OUTER_SPACING;
177 layout.marginHeight = 0;
178 layout.marginWidth = 0;
179 layout.marginTop = WidgetHelper.OUTER_SPACING;
180 placeGroup.setLayout(layout);
181 gd = new GridData();
182 gd.horizontalAlignment = SWT.FILL;
183 gd.grabExcessHorizontalSpace = true;
184 gd.horizontalSpan = 2;
185 placeGroup.setLayoutData(gd);
186
187 Label comboLabel = new Label(placeGroup, SWT.NONE);
188 comboLabel.setText("Place on ");
189
190 legendPleace = new Combo(placeGroup, SWT.READ_ONLY);
191 GridData gridData = new GridData();
192 gridData.horizontalAlignment = GridData.FILL;
193 gridData.grabExcessHorizontalSpace = true;
194 legendPleace.setLayoutData(gridData);
195
196 legendPleace.add("left");
197 legendPleace.add("right");
198 legendPleace.add("top");
199 legendPleace.add("bottom");
200 legendPleace.select(31 - Integer.numberOfLeadingZeros(config.getLegendPosition()));
201 legendPleace.setEnabled(config.isShowLegend());
202
203 Composite refreshGroup = new Composite(optionsGroup, SWT.NONE);
204 layout = new GridLayout();
205 layout.horizontalSpacing = WidgetHelper.OUTER_SPACING;
206 layout.marginHeight = 0;
207 layout.marginWidth = 0;
208 layout.marginTop = WidgetHelper.OUTER_SPACING;
209 refreshGroup.setLayout(layout);
210 gd = new GridData();
211 gd.horizontalAlignment = SWT.FILL;
212 gd.grabExcessHorizontalSpace = true;
213 gd.horizontalSpan = 2;
214 refreshGroup.setLayoutData(gd);
215
216 checkAutoRefresh = new Button(refreshGroup, SWT.CHECK);
217 checkAutoRefresh.setText(Messages.get().General_Autorefresh);
218 checkAutoRefresh.setSelection(config.isAutoRefresh());
219 checkAutoRefresh.addSelectionListener(new SelectionListener() {
220 @Override
221 public void widgetSelected(SelectionEvent e)
222 {
223 refreshIntervalSpinner.setEnabled(checkAutoRefresh.getSelection());
224 refreshIntervalScale.setEnabled(checkAutoRefresh.getSelection());
225 }
226
227 @Override
228 public void widgetDefaultSelected(SelectionEvent e)
229 {
230 widgetSelected(e);
231 }
232 });
233
234 Composite refreshIntervalGroup = new Composite(refreshGroup, SWT.NONE);
235 layout = new GridLayout();
236 layout.numColumns = 2;
237 layout.horizontalSpacing = WidgetHelper.OUTER_SPACING;
238 layout.marginHeight = 0;
239 layout.marginWidth = 0;
240 layout.marginTop = WidgetHelper.OUTER_SPACING;
241 refreshIntervalGroup.setLayout(layout);
242 gd = new GridData();
243 gd.horizontalAlignment = SWT.FILL;
244 gd.grabExcessHorizontalSpace = true;
245 gd.horizontalSpan = 2;
246 refreshIntervalGroup.setLayoutData(gd);
247
248 Label label = new Label(refreshIntervalGroup, SWT.NONE);
249 label.setText(Messages.get().General_RefreshInterval);
250 gd = new GridData();
251 gd.horizontalAlignment = SWT.LEFT;
252 gd.horizontalSpan = 2;
253 label.setLayoutData(gd);
254
255 refreshIntervalScale = new Scale(refreshIntervalGroup, SWT.HORIZONTAL);
256 refreshIntervalScale.setMinimum(1);
257 refreshIntervalScale.setMaximum(600);
258 refreshIntervalScale.setSelection(config.getRefreshRate());
259 gd = new GridData();
260 gd.horizontalAlignment = SWT.FILL;
261 gd.grabExcessHorizontalSpace = true;
262 refreshIntervalScale.setLayoutData(gd);
263 refreshIntervalScale.addSelectionListener(new SelectionListener() {
264 @Override
265 public void widgetSelected(SelectionEvent e)
266 {
267 refreshIntervalSpinner.setSelection(refreshIntervalScale.getSelection());
268 }
269
270 @Override
271 public void widgetDefaultSelected(SelectionEvent e)
272 {
273 widgetSelected(e);
274 }
275 });
276 refreshIntervalScale.setEnabled(config.isAutoRefresh());
277
278 refreshIntervalSpinner = new Spinner(refreshIntervalGroup, SWT.BORDER);
279 refreshIntervalSpinner.setMinimum(1);
280 refreshIntervalSpinner.setMaximum(600);
281 refreshIntervalSpinner.setSelection(config.getRefreshRate());
282 refreshIntervalSpinner.addSelectionListener(new SelectionListener() {
283 @Override
284 public void widgetSelected(SelectionEvent e)
285 {
286 refreshIntervalScale.setSelection(refreshIntervalSpinner.getSelection());
287 }
288
289 @Override
290 public void widgetDefaultSelected(SelectionEvent e)
291 {
292 widgetSelected(e);
293 }
294 });
295 refreshIntervalSpinner.setEnabled(config.isAutoRefresh());
296
297 timeSelector = new TimePeriodSelector(dialogArea, SWT.NONE, config.timePeriod());
298 gd = new GridData();
299 gd.horizontalAlignment = SWT.FILL;
300 gd.grabExcessHorizontalSpace = true;
301 timeSelector.setLayoutData(gd);
302
303 yAxisRange = new YAxisRangeEditor(dialogArea, SWT.NONE);
304 gd = new GridData();
305 gd.horizontalAlignment = SWT.FILL;
306 gd.grabExcessHorizontalSpace = true;
307 yAxisRange.setLayoutData(gd);
308 yAxisRange.setSelection(config.isAutoScale(), config.getMinYScaleValue(), config.getMaxYScaleValue());
309
310 return dialogArea;
311 }
312
313 /* (non-Javadoc)
314 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
315 */
316 @Override
317 protected void performDefaults()
318 {
319 super.performDefaults();
320
321 title.setText(""); //$NON-NLS-1$
322 checkShowGrid.setSelection(true);
323 checkShowLegend.setSelection(true);
324 checkShowHostNames.setSelection(false);
325 checkAutoRefresh.setSelection(true);
326 checkLogScale.setSelection(false);
327 checkStacked.setSelection(false);
328 checkExtendedLegend.setSelection(false);
329 legendPleace.select(3);
330
331 yAxisRange.setSelection(true, 0, 100);
332
333 refreshIntervalScale.setSelection(30);
334 refreshIntervalSpinner.setSelection(30);
335
336 timeSelector.setDefaults();
337 }
338
339 /**
340 * Apply changes
341 *
342 * @param isApply true if update operation caused by "Apply" button
343 */
344 protected void applyChanges(final boolean isApply)
345 {
346 config.setTitle(title.getText());
347 config.setShowGrid(checkShowGrid.getSelection());
348 config.setShowLegend(checkShowLegend.getSelection());
349 config.setAutoScale(yAxisRange.isAuto());
350 config.setShowHostNames(checkShowHostNames.getSelection());
351 config.setAutoRefresh(checkAutoRefresh.getSelection());
352 config.setLogScale(checkLogScale.getSelection());
353 config.setRefreshRate(refreshIntervalSpinner.getSelection());
354 config.setStacked(checkStacked.getSelection());
355 config.setExtendedLegend(checkExtendedLegend.getSelection());
356 config.setLegendPosition((int)Math.pow(2,legendPleace.getSelectionIndex()));
357 config.setTranslucent(checkTranslucent.getSelection());
358 config.setTimeFrameType(timeSelector.getTimeFrameType());
359 config.setTimeUnits(timeSelector.getTimeUnitValue());
360 config.setTimeRange(timeSelector.getTimeRangeValue());
361 config.setTimeFrom(timeSelector.getTimeFrom());
362 config.setTimeTo(timeSelector.getTimeTo());
363
364 config.setMinYScaleValue(yAxisRange.getMinY());
365 config.setMaxYScaleValue(yAxisRange.getMaxY());
366
367 if ((config instanceof PredefinedChartConfig) && isApply)
368 {
369 setValid(false);
370 final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
371 new ConsoleJob(Messages.get().General_JobName, null, Activator.PLUGIN_ID, null) {
372 @Override
373 protected void runInternal(IProgressMonitor monitor) throws Exception
374 {
375 session.saveGraph(((PredefinedChartConfig)config).createServerSettings(), true);
376 runInUIThread(new Runnable() {
377 @Override
378 public void run()
379 {
380 General.this.setValid(true);
381 }
382 });
383 }
384
385 @Override
386 protected String getErrorMessage()
387 {
388 return Messages.get().General_JobError;
389 }
390 }.start();
391 }
392 }
393
394 /* (non-Javadoc)
395 * @see org.eclipse.jface.preference.PreferencePage#performApply()
396 */
397 @Override
398 protected void performApply()
399 {
400 applyChanges(true);
401 }
402
403 /* (non-Javadoc)
404 * @see org.eclipse.jface.preference.PreferencePage#performOk()
405 */
406 @Override
407 public boolean performOk()
408 {
409 applyChanges(false);
410 return true;
411 }
412 }