40691a00b76aee9d8a63cecc9cc73a15dde1d799
[public/netxms.git] / webui / webapp / PerfView / src / org / netxms / ui / eclipse / perfview / propertypages / PerfTab.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.jface.preference.ColorSelector;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.layout.GridLayout;
25 import org.eclipse.swt.layout.RowLayout;
26 import org.eclipse.swt.widgets.Button;
27 import org.eclipse.swt.widgets.Combo;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.swt.widgets.Control;
30 import org.eclipse.swt.widgets.Group;
31 import org.eclipse.swt.widgets.Label;
32 import org.eclipse.swt.widgets.Spinner;
33 import org.netxms.client.datacollection.DataCollectionItem;
34 import org.netxms.ui.eclipse.datacollection.propertypages.helpers.DCIPropertyPageDialog;
35 import org.netxms.ui.eclipse.perfview.Messages;
36 import org.netxms.ui.eclipse.perfview.PerfTabGraphSettings;
37 import org.netxms.ui.eclipse.perfview.widgets.YAxisRangeEditor;
38 import org.netxms.ui.eclipse.tools.ColorConverter;
39 import org.netxms.ui.eclipse.tools.WidgetHelper;
40 import org.netxms.ui.eclipse.widgets.LabeledText;
41
42 /**
43 * DCI property page for Performance Tab settings
44 */
45 public class PerfTab extends DCIPropertyPageDialog
46 {
47 private DataCollectionItem dci;
48 private PerfTabGraphSettings settings;
49 private Button checkShow;
50 private Button checkLogScale;
51 private Button checkStacked;
52 private LabeledText title;
53 private LabeledText name;
54 private ColorSelector color;
55 private Combo type;
56 private Spinner orderNumber;
57 private Button checkShowThresholds;
58 private LabeledText groupName;
59 private Spinner timeRange;
60 private Combo timeUnits;
61 private YAxisRangeEditor yAxisRange;
62
63 /* (non-Javadoc)
64 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
65 */
66 @Override
67 protected Control createContents(Composite parent)
68 {
69 Composite dialogArea = (Composite)super.createContents(parent);
70 dci = editor.getObjectAsItem();
71
72 try
73 {
74 settings = PerfTabGraphSettings.createFromXml(dci.getPerfTabSettings());
75 }
76 catch(Exception e)
77 {
78 settings = new PerfTabGraphSettings(); // Create default empty settings
79 }
80
81 GridLayout layout = new GridLayout();
82 layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
83 layout.marginWidth = 0;
84 layout.marginHeight = 0;
85 layout.numColumns = 4;
86 dialogArea.setLayout(layout);
87
88 checkShow = new Button(dialogArea, SWT.CHECK);
89 checkShow.setText(Messages.get().PerfTab_ShowOnPerfTab);
90 checkShow.setSelection(settings.isEnabled());
91 GridData gd = new GridData();
92 gd.horizontalSpan = layout.numColumns;
93 checkShow.setLayoutData(gd);
94
95 title = new LabeledText(dialogArea, SWT.NONE);
96 title.setLabel(Messages.get().PerfTab_Title);
97 title.setText(settings.getTitle());
98 gd = new GridData();
99 gd.grabExcessHorizontalSpace = true;
100 gd.horizontalAlignment = SWT.FILL;
101 title.setLayoutData(gd);
102
103 Composite colors = new Composite(dialogArea, SWT.NONE);
104 colors.setLayout(new RowLayout(SWT.VERTICAL));
105 new Label(colors, SWT.NONE).setText(Messages.get().PerfTab_Color);
106 color = new ColorSelector(colors);
107 color.setColorValue(ColorConverter.rgbFromInt(settings.getColorAsInt()));
108
109 type = WidgetHelper.createLabeledCombo(dialogArea, SWT.READ_ONLY, Messages.get().PerfTab_Type, new GridData(SWT.LEFT, SWT.CENTER, false, false));
110 type.add(Messages.get().PerfTab_Line);
111 type.add(Messages.get().PerfTab_Area);
112 type.select(settings.getType());
113
114 orderNumber = WidgetHelper.createLabeledSpinner(dialogArea, SWT.BORDER, Messages.get().PerfTab_Order, 0, 65535, new GridData(SWT.LEFT, SWT.CENTER, false, false));
115 orderNumber.setSelection(settings.getOrder());
116
117 groupName = new LabeledText(dialogArea, SWT.NONE);
118 groupName.setLabel("Group");
119 groupName.setText(settings.getGroupName());
120 gd = new GridData();
121 gd.horizontalSpan = layout.numColumns;
122 gd.grabExcessHorizontalSpace = true;
123 gd.horizontalAlignment = SWT.FILL;
124 groupName.setLayoutData(gd);
125
126 name = new LabeledText(dialogArea, SWT.NONE);
127 name.setLabel(Messages.get().PerfTab_NameInLegend);
128 name.setText(settings.getName());
129 gd = new GridData();
130 gd.grabExcessHorizontalSpace = true;
131 gd.horizontalAlignment = SWT.FILL;
132 gd.horizontalSpan = layout.numColumns;
133 name.setLayoutData(gd);
134
135 Group timeGroup = new Group(dialogArea, SWT.NONE);
136 timeGroup.setText(Messages.get().PerfTab_TeimePeriod);
137 GridLayout timeGroupLayout = new GridLayout();
138 timeGroupLayout.marginWidth = WidgetHelper.OUTER_SPACING;
139 timeGroupLayout.marginHeight = WidgetHelper.OUTER_SPACING;
140 timeGroupLayout.horizontalSpacing = 16;
141 timeGroupLayout.makeColumnsEqualWidth = true;
142 timeGroupLayout.numColumns = 1;
143 timeGroup.setLayout(timeGroupLayout);
144 gd = new GridData();
145 gd.horizontalAlignment = SWT.FILL;
146 gd.grabExcessHorizontalSpace = true;
147 gd.horizontalSpan = timeGroupLayout.numColumns;
148 timeGroup.setLayoutData(gd);
149
150 Composite timeRangeArea = new Composite(timeGroup, SWT.NONE);
151 timeGroupLayout = new GridLayout();
152 timeGroupLayout.numColumns = 2;
153 timeGroupLayout.marginWidth = 0;
154 timeGroupLayout.marginHeight = 0;
155 timeGroupLayout.horizontalSpacing = WidgetHelper.DIALOG_SPACING;
156 timeRangeArea.setLayout(timeGroupLayout);
157 gd = new GridData();
158 gd.horizontalAlignment = SWT.FILL;
159 gd.grabExcessHorizontalSpace = true;
160 timeRangeArea.setLayoutData(gd);
161
162 timeRange = WidgetHelper.createLabeledSpinner(timeRangeArea, SWT.BORDER, Messages.get().PerfTab_TimeInterval, 1, 10000, WidgetHelper.DEFAULT_LAYOUT_DATA);
163 timeRange.setSelection(settings.getTimeRange());
164
165 timeUnits = WidgetHelper.createLabeledCombo(timeRangeArea, SWT.READ_ONLY, Messages.get().PerfTab_TimeUnits, WidgetHelper.DEFAULT_LAYOUT_DATA);
166 timeUnits.add(Messages.get().PerfTab_Minutes);
167 timeUnits.add(Messages.get().PerfTab_Hours);
168 timeUnits.add(Messages.get().PerfTab_Days);
169 timeUnits.select(settings.getTimeUnits());
170
171 Group optionsGroup = new Group(dialogArea, SWT.NONE);
172 optionsGroup.setText(Messages.get().PerfTab_Options);
173 gd = new GridData();
174 gd.horizontalAlignment = SWT.FILL;
175 gd.grabExcessHorizontalSpace = true;
176 gd.horizontalSpan = 3;
177 gd.verticalSpan = 2;
178 optionsGroup.setLayoutData(gd);
179 GridLayout optionsLayout = new GridLayout();
180 optionsGroup.setLayout(optionsLayout);
181
182 checkShowThresholds = new Button(optionsGroup, SWT.CHECK);
183 checkShowThresholds.setText(Messages.get().PerfTab_ShowThresholds);
184 checkShowThresholds.setSelection(settings.isShowThresholds());
185 gd = new GridData();
186 gd.horizontalSpan = layout.numColumns;
187 checkShowThresholds.setLayoutData(gd);
188
189 checkLogScale = new Button(optionsGroup, SWT.CHECK);
190 checkLogScale.setText(Messages.get().PerfTab_LogarithmicScale);
191 checkLogScale.setSelection(settings.isLogScaleEnabled());
192 gd = new GridData();
193 gd.horizontalSpan = layout.numColumns;
194 checkLogScale.setLayoutData(gd);
195
196 checkStacked = new Button(optionsGroup, SWT.CHECK);
197 checkStacked.setText("&Stacked");
198 checkStacked.setSelection(settings.isStacked());
199 gd = new GridData();
200 gd.horizontalSpan = layout.numColumns;
201 checkStacked.setLayoutData(gd);
202
203 yAxisRange = new YAxisRangeEditor(dialogArea, SWT.NONE);
204 gd = new GridData();
205 gd.horizontalSpan = layout.numColumns;
206 gd.horizontalAlignment = SWT.FILL;
207 gd.grabExcessHorizontalSpace = true;
208 yAxisRange.setLayoutData(gd);
209 yAxisRange.setSelection(settings.isAutoScale(), settings.getMinYScaleValue(), settings.getMaxYScaleValue());
210
211 return dialogArea;
212 }
213
214 /**
215 * Apply changes
216 *
217 * @param isApply true if APPLY button was used
218 */
219 private void applyChanges(final boolean isApply)
220 {
221 settings.setEnabled(checkShow.getSelection());
222 settings.setLogScaleEnabled(checkLogScale.getSelection());
223 settings.setTitle(title.getText());
224 settings.setName(name.getText());
225 settings.setColor(ColorConverter.rgbToInt(color.getColorValue()));
226 settings.setType(type.getSelectionIndex());
227 settings.setOrder(orderNumber.getSelection());
228 settings.setGroupName(groupName.getText().trim());
229 settings.setShowThresholds(checkShowThresholds.getSelection());
230 settings.setStacked(checkStacked.getSelection());
231
232 settings.setAutoScale(yAxisRange.isAuto());
233 settings.setMinYScaleValue(yAxisRange.getMinY());
234 settings.setMaxYScaleValue(yAxisRange.getMaxY());
235
236 settings.setTimeRange(timeRange.getSelection());
237 settings.setTimeUnits(timeUnits.getSelectionIndex());
238
239 try
240 {
241 dci.setPerfTabSettings(settings.createXml());
242 }
243 catch(Exception e)
244 {
245 dci.setPerfTabSettings(null);
246 }
247
248 editor.modify();
249 }
250
251 /* (non-Javadoc)
252 * @see org.eclipse.jface.preference.PreferencePage#performApply()
253 */
254 @Override
255 protected void performApply()
256 {
257 applyChanges(true);
258 }
259
260 /* (non-Javadoc)
261 * @see org.eclipse.jface.preference.PreferencePage#performOk()
262 */
263 @Override
264 public boolean performOk()
265 {
266 applyChanges(false);
267 return true;
268 }
269
270 /* (non-Javadoc)
271 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
272 */
273 @Override
274 protected void performDefaults()
275 {
276 super.performDefaults();
277 PerfTabGraphSettings defaults = new PerfTabGraphSettings();
278 checkShow.setSelection(defaults.isEnabled());
279 title.setText(defaults.getTitle());
280 color.setColorValue(ColorConverter.rgbFromInt(defaults.getColorAsInt()));
281 groupName.setText("");
282 orderNumber.setSelection(100);
283 }
284 }