a7f2ae4811b6a38d836e34afa5f4d6c7bc8b1f7d
[public/netxms.git] / src / java / netxms-eclipse / PerfView / src / org / netxms / ui / eclipse / perfview / PerfTabGraphSettings.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;
20
21 import java.io.StringWriter;
22 import java.io.Writer;
23 import org.netxms.client.datacollection.GraphItemStyle;
24 import org.netxms.client.datacollection.GraphSettings;
25 import org.netxms.client.datacollection.PerfTabDci;
26 import org.simpleframework.xml.Element;
27 import org.simpleframework.xml.Root;
28 import org.simpleframework.xml.Serializer;
29 import org.simpleframework.xml.core.Persister;
30
31 /**
32 * Settings for performance tab graph
33 */
34 @Root(name="config", strict=false)
35 public class PerfTabGraphSettings
36 {
37 @Element(required=false)
38 private boolean enabled = false;
39
40 @Element(required = false)
41 private boolean autoScale = true;
42
43 @Element(required = false)
44 private boolean logScaleEnabled = false;
45
46 @Element(required = false)
47 private boolean stacked = false;
48
49 @Element(required = false)
50 private int minYScaleValue = 1;
51
52 @Element(required = false)
53 private int maxYScaleValue = 100;
54
55 @Element(required = false)
56 private int timeRange = 1;
57
58 @Element(required = false)
59 private int timeUnits = 1;
60
61 @Element(required=false)
62 private int type = GraphItemStyle.LINE;
63
64 @Element(required=false)
65 private String color = "0x00C000"; //$NON-NLS-1$
66
67 @Element(required=false)
68 private String title = ""; //$NON-NLS-1$
69
70 @Element(required=false)
71 private String name = ""; //$NON-NLS-1$
72
73 @Element(required=false)
74 private boolean showThresholds = false;
75
76 @Element(required=false)
77 private String groupName = null;
78
79 @Element(required=false)
80 private int order = 100;
81
82 @Element(required=false)
83 private long parentDciId = 0;
84
85 private PerfTabDci runtimeDciInfo = null;
86
87 /**
88 * Create performance tab graph settings object from XML document
89 *
90 * @param xml XML document
91 * @return deserialized object
92 * @throws Exception if the object cannot be fully deserialized
93 */
94 public static PerfTabGraphSettings createFromXml(final String xml) throws Exception
95 {
96 Serializer serializer = new Persister();
97 return serializer.read(PerfTabGraphSettings.class, xml);
98 }
99
100 /**
101 * Create XML document from object
102 *
103 * @return XML document
104 * @throws Exception if the schema for the object is not valid
105 */
106 public String createXml() throws Exception
107 {
108 Serializer serializer = new Persister();
109 Writer writer = new StringWriter();
110 serializer.write(this, writer);
111 return writer.toString();
112 }
113
114 /**
115 * @return the enabled
116 */
117 public boolean isEnabled()
118 {
119 return enabled;
120 }
121
122 /**
123 * @return the type
124 */
125 public int getType()
126 {
127 return type;
128 }
129
130 /**
131 * @return the color
132 */
133 public String getColor()
134 {
135 return color;
136 }
137
138 /**
139 * @return the color
140 */
141 public int getColorAsInt()
142 {
143 try
144 {
145 if (color.startsWith("0x")) //$NON-NLS-1$
146 return Integer.parseInt(color.substring(2), 16);
147 return Integer.parseInt(color, 10);
148 }
149 catch(NumberFormatException e)
150 {
151 return 0; // black color in case of error
152 }
153 }
154
155 /**
156 * Get configured title
157 *
158 * @return the title
159 */
160 public String getTitle()
161 {
162 return title;
163 }
164
165 /**
166 * Get actual title to be shown in runtime
167 *
168 * @return
169 */
170 public String getRuntimeTitle()
171 {
172 String t = ((title == null) || title.isEmpty()) ? ((runtimeDciInfo != null) ? runtimeDciInfo.getDescription() : "") : title; //$NON-NLS-1$
173 return t.replace("{instance}", (runtimeDciInfo != null) ? runtimeDciInfo.getInstance() : ""); //$NON-NLS-1$ //$NON-NLS-2$
174 }
175
176 /**
177 * @param enabled the enabled to set
178 */
179 public void setEnabled(boolean enabled)
180 {
181 this.enabled = enabled;
182 }
183
184 /**
185 * @param type the type to set
186 */
187 public void setType(int type)
188 {
189 this.type = type;
190 }
191
192 /**
193 * @param color the color to set
194 */
195 public void setColor(final String color)
196 {
197 this.color = color;
198 }
199
200 /**
201 * @param color the color to set
202 */
203 public void setColor(final int color)
204 {
205 this.color = Integer.toString(color);
206 }
207
208 /**
209 * @param title the title to set
210 */
211 public void setTitle(String title)
212 {
213 this.title = title;
214 }
215
216 /**
217 * @return the showThresholds
218 */
219 public boolean isShowThresholds()
220 {
221 return showThresholds;
222 }
223
224 /**
225 * @param showThresholds the showThresholds to set
226 */
227 public void setShowThresholds(boolean showThresholds)
228 {
229 this.showThresholds = showThresholds;
230 }
231
232 /**
233 * @return the groupName
234 */
235 public String getGroupName()
236 {
237 if (groupName != null)
238 return runtimeDciInfo != null ? groupName.replace("{instance}", runtimeDciInfo.getInstance()) : groupName;
239 return parentDciId != 0 ? "##" + Long.toString(parentDciId) : "";
240 }
241
242 /**
243 * @param groupName the groupName to set
244 */
245 public void setGroupName(String groupName)
246 {
247 this.groupName = groupName;
248 }
249
250 /**
251 * @return the runtimeDciInfo
252 */
253 public final PerfTabDci getRuntimeDciInfo()
254 {
255 return runtimeDciInfo;
256 }
257
258 /**
259 * @param runtimeDciInfo the runtimeDciInfo to set
260 */
261 public final void setRuntimeDciInfo(PerfTabDci runtimeDciInfo)
262 {
263 this.runtimeDciInfo = runtimeDciInfo;
264 }
265
266 /**
267 * Get configured name for chart legend
268 *
269 * @return the name
270 */
271 public final String getName()
272 {
273 return name;
274 }
275
276 /**
277 * @param name the name to set
278 */
279 public final void setName(String name)
280 {
281 this.name = name;
282 }
283
284 /**
285 * Get runtime name for chart legend
286 *
287 * @return the name
288 */
289 public String getRuntimeName()
290 {
291 String n = ((name == null) || name.isEmpty()) ? ((runtimeDciInfo != null) ? runtimeDciInfo.getDescription() : "") : name; //$NON-NLS-1$
292 return n.replace("{instance}", (runtimeDciInfo != null) ? runtimeDciInfo.getInstance() : ""); //$NON-NLS-1$ //$NON-NLS-2$
293 }
294
295 /**
296 * @return the order
297 */
298 public final int getOrder()
299 {
300 return order;
301 }
302
303 /**
304 * @param order the order to set
305 */
306 public final void setOrder(int order)
307 {
308 this.order = order;
309 }
310
311 /**
312 * @return
313 */
314 public boolean isAutoScale()
315 {
316 return autoScale;
317 }
318
319 /**
320 * @param autoScale
321 */
322 public void setAutoScale(boolean autoScale)
323 {
324 this.autoScale = autoScale;
325 }
326
327 /**
328 * @return the stacked
329 */
330 public boolean isStacked()
331 {
332 return stacked;
333 }
334
335 /**
336 * @param stacked the stacked to set
337 */
338 public void setStacked(boolean stacked)
339 {
340 this.stacked = stacked;
341 }
342
343 /**
344 * @return
345 */
346 public int getMinYScaleValue()
347 {
348 return minYScaleValue;
349 }
350
351 /**
352 * @param minYScaleValue
353 */
354 public void setMinYScaleValue(int minYScaleValue)
355 {
356 this.minYScaleValue = minYScaleValue;
357 }
358
359 /**
360 * @return
361 */
362 public int getMaxYScaleValue()
363 {
364 return maxYScaleValue;
365 }
366
367 /**
368 * @param maxYScaleValue
369 */
370 public void setMaxYScaleValue(int maxYScaleValue)
371 {
372 this.maxYScaleValue = maxYScaleValue;
373 }
374
375 /**
376 * @return the timeInterval
377 */
378 public int getTimeRange()
379 {
380 return timeRange;
381 }
382
383 /**
384 * Get time range covered by graph in milliseconds
385 *
386 * @return
387 */
388 public long getTimeRangeMillis()
389 {
390 switch(timeUnits)
391 {
392 case GraphSettings.TIME_UNIT_MINUTE:
393 return (long)timeRange * 60L * 1000L;
394 case GraphSettings.TIME_UNIT_HOUR:
395 return (long)timeRange * 60L * 60L * 1000L;
396 case GraphSettings.TIME_UNIT_DAY:
397 return (long)timeRange * 24L * 60L * 60L * 1000L;
398 }
399 return 0;
400 }
401
402 /**
403 * @param timeInterval the timeInterval to set
404 */
405 public void setTimeRange(int timeInterval)
406 {
407 this.timeRange = timeInterval;
408 }
409
410 /**
411 * @return the timeUnits
412 */
413 public int getTimeUnits()
414 {
415 return timeUnits;
416 }
417
418 /**
419 * @param timeUnits the timeUnits to set
420 */
421 public void setTimeUnits(int timeUnits)
422 {
423 this.timeUnits = timeUnits;
424 }
425
426 /**
427 * @return the logScaleEnabled
428 */
429 public boolean isLogScaleEnabled()
430 {
431 return logScaleEnabled;
432 }
433
434 /**
435 * @param logScaleEnabled the logScaleEnabled to set
436 */
437 public void setLogScaleEnabled(boolean logScaleEnabled)
438 {
439 this.logScaleEnabled = logScaleEnabled;
440 }
441 }