e8794eb3b4dce1819ba45383ee81b210a6b0d5a0
2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2013 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
.perfview
.widgets
.helpers
;
21 import java
.text
.NumberFormat
;
22 import org
.eclipse
.jface
.resource
.JFaceResources
;
23 import org
.eclipse
.jface
.viewers
.ITableFontProvider
;
24 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
25 import org
.eclipse
.jface
.viewers
.LabelProvider
;
26 import org
.eclipse
.swt
.SWT
;
27 import org
.eclipse
.swt
.graphics
.Font
;
28 import org
.eclipse
.swt
.graphics
.FontData
;
29 import org
.eclipse
.swt
.graphics
.Image
;
30 import org
.eclipse
.swt
.widgets
.Display
;
31 import org
.netxms
.client
.TableColumnDefinition
;
32 import org
.netxms
.client
.TableRow
;
33 import org
.netxms
.client
.datacollection
.DataCollectionItem
;
34 import org
.netxms
.client
.datacollection
.DataCollectionObject
;
37 * Label provider for NetXMS table
39 public class TableLabelProvider
extends LabelProvider
implements ITableLabelProvider
, ITableFontProvider
41 private TableColumnDefinition
[] columns
= null;
43 private Font keyColumnFont
;
44 private boolean useMultipliers
= true;
49 public TableLabelProvider()
51 FontData fd
= JFaceResources
.getDefaultFont().getFontData()[0];
52 fd
.setStyle(SWT
.BOLD
);
53 keyColumnFont
= new Font(Display
.getCurrent(), fd
);
57 * @see org.eclipse.jface.viewers.BaseLabelProvider#dispose()
62 keyColumnFont
.dispose();
67 * @param tableColumnDefinitions the columns to set
69 public void setColumns(TableColumnDefinition
[] columns
)
71 this.columns
= columns
;
75 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
78 public Image
getColumnImage(Object element
, int columnIndex
)
84 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
87 public String
getColumnText(Object element
, int columnIndex
)
89 row
= (TableRow
)element
;
91 if (columnIndex
>= row
.size())
94 return getValueForFormat(columnIndex
);
95 return row
.get(columnIndex
).getValue();
99 * @see org.eclipse.jface.viewers.ITableFontProvider#getFont(java.lang.Object, int)
102 public Font
getFont(Object element
, int columnIndex
)
104 if ((columns
== null) || (columnIndex
>= columns
.length
))
106 if (columns
[columnIndex
].isInstanceColumn())
107 return keyColumnFont
;
112 * @param useMultipliers
114 public void setUseMultipliers(boolean useMultipliers
)
116 this.useMultipliers
= useMultipliers
;
122 public boolean areMultipliersUsed()
124 return useMultipliers
;
129 * @return value converted to multiplier form
131 private String
getValueForFormat(int columnIndex
)
134 String suffix
= null;
138 switch(columns
[columnIndex
].getDataType())
140 case DataCollectionObject
.DT_INT
:
141 case DataCollectionObject
.DT_UINT
:
142 case DataCollectionItem
.DT_INT64
:
143 case DataCollectionItem
.DT_UINT64
:
146 long i
= Long
.parseLong(row
.get(columnIndex
).getValue());
147 if ((i
>= 10000000000000L) || (i
<= -10000000000000L))
149 i
= i
/ 1000000000000L;
152 if ((i
>= 10000000000L) || (i
<= -10000000000L))
157 if ((i
>= 10000000) || (i
<= -10000000))
162 if ((i
>= 10000) || (i
<= -10000))
167 value
= Long
.toString(i
);
171 value
= row
.get(columnIndex
).getValue();
175 case DataCollectionObject
.DT_FLOAT
:
178 double d
= Double
.parseDouble(row
.get(columnIndex
).getValue());
179 NumberFormat nf
= NumberFormat
.getNumberInstance();
180 nf
.setMaximumFractionDigits(2);
181 if ((d
>= 10000000000000.0) || (d
<= -10000000000000.0))
183 d
= d
/ 1000000000000.0;
186 if ((d
>= 10000000000.0) || (d
<= -10000000000.0))
188 d
= d
/ 1000000000.0;
191 if ((d
>= 10000000) || (d
<= -10000000))
196 if ((d
>= 10000) || (d
<= -10000))
201 value
= Double
.toString(d
);
205 value
= row
.get(columnIndex
).getValue();
209 value
= row
.get(columnIndex
).getValue();
213 catch(NumberFormatException e
)
215 value
= row
.get(columnIndex
).getValue();
219 return value
+ " " + suffix
;