DCI Summary Tables 'Use multipliers' treat string objects as numbers fixes ##1246
authorEriks Jenkevics <eriks@netxms.org>
Tue, 30 Aug 2016 08:36:48 +0000 (11:36 +0300)
committerEriks Jenkevics <eriks@netxms.org>
Tue, 30 Aug 2016 08:39:04 +0000 (11:39 +0300)
ChangeLog
src/java/netxms-eclipse/DataCollection/src/org/netxms/ui/eclipse/datacollection/widgets/SummaryTableWidget.java
src/java/netxms-eclipse/DataCollection/src/org/netxms/ui/eclipse/datacollection/widgets/internal/TableLabelProvider.java
webui/webapp/DataCollection/src/org/netxms/ui/eclipse/datacollection/widgets/SummaryTableWidget.java
webui/webapp/DataCollection/src/org/netxms/ui/eclipse/datacollection/widgets/internal/TableLabelProvider.java

index 553041c..b3897be 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -27,7 +27,7 @@
        - New editors for Agent Config Policy and Log Parser Policy. 
        - DCI summary tables with empty menu path not shown in object context menu
        - Fixed glitches in table value view
-- Fixed issues: #92, #568, #851, #906, #909, #942, #959, #987, #992, #999, #1006, #1051, #1096, #1100, #1159, #1187, #1191, #1230, #1237, #1245, #1254, #1261, #1263, #1273, #1275, #1277, #1278
+- Fixed issues: #92, #568, #851, #906, #909, #942, #959, #987, #992, #999, #1006, #1051, #1096, #1100, #1159, #1187, #1191, #1230, #1237, #1245, #1246, #1254, #1261, #1263, #1273, #1275, #1277, #1278
 
 
 *
index b41ae89..babb16c 100644 (file)
@@ -317,6 +317,7 @@ public class SummaryTableWidget extends Composite
          });
          viewer.setComparator(new TableItemComparator(table.getColumnDataTypes()));
       }
+      labelProvider.setColumnDataTypes(table.getColumnDataTypes());
       viewer.setInput(table);
    }
 
index 1d16705..ddb0f3a 100644 (file)
@@ -27,8 +27,9 @@ import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.widgets.Display;
 import org.netxms.client.TableCell;
 import org.netxms.client.TableRow;
+import org.netxms.client.datacollection.DataCollectionItem;
+import org.netxms.client.datacollection.DataCollectionObject;
 import org.netxms.ui.eclipse.console.resources.StatusDisplayInfo;
-import org.netxms.ui.eclipse.datacollection.Messages;
 
 /**
  * Label provider for NetXMS table
@@ -41,6 +42,7 @@ public class TableLabelProvider extends LabelProvider implements ITableLabelProv
       { null, FOREGROUND_COLOR_DARK, FOREGROUND_COLOR_DARK, FOREGROUND_COLOR_LIGHT, FOREGROUND_COLOR_LIGHT };
    
    private boolean useMultipliers = false;
+   private int[] columnDataTypes = null;
 
    /* (non-Javadoc)
         * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
@@ -62,65 +64,107 @@ public class TableLabelProvider extends LabelProvider implements ITableLabelProv
                if (columnIndex >= row.size())
                        return null;
                
-               return useMultipliers ? getValue(row.get(columnIndex).getValue()) : row.get(columnIndex).getValue();
+               return getValue(row, columnIndex);
+       }
+       
+       public void setColumnDataTypes(int[] ColumnDataTypes)
+       {
+          this.columnDataTypes = ColumnDataTypes;
        }
        
    /**
     * @param value
     * @return
     */
-   private String getValue(String value)
+   private String getValue(TableRow row, int columnIndex)
    {
-      try
-      {
-         long i = Long.parseLong(value);
-         if ((i >= 10000000000000L) || (i <= -10000000000000L))
-         {
-            return Long.toString(i / 1000000000000L) + " T"; //$NON-NLS-1$
-         }
-         if ((i >= 10000000000L) || (i <= -10000000000L))
-         {
-            return Long.toString(i / 1000000000L) + Messages.get().LastValuesLabelProvider_Giga;
-         }
-         if ((i >= 10000000) || (i <= -10000000))
-         {
-            return Long.toString(i / 1000000) + Messages.get().LastValuesLabelProvider_Mega;
-         }
-         if ((i >= 10000) || (i <= -10000))
-         {
-            return Long.toString(i / 1000) + Messages.get().LastValuesLabelProvider_Kilo;
-         }
-      }
-      catch(NumberFormatException e)
-      {
-      }
+      String value;
+      String suffix = null;
       
       try
       {
-         double d = Double.parseDouble(value);
-         NumberFormat nf = NumberFormat.getNumberInstance();
-         nf.setMaximumFractionDigits(2);
-         if ((d >= 10000000000000.0) || (d <= -10000000000000.0))
-         {
-            return nf.format(d / 1000000000000.0) + " T"; //$NON-NLS-1$
-         }
-         if ((d >= 10000000000.0) || (d <= -10000000000.0))
-         {
-            return nf.format(d / 1000000000.0) + Messages.get().LastValuesLabelProvider_Giga;
-         }
-         if ((d >= 10000000) || (d <= -10000000))
+         switch(columnDataTypes[columnIndex])
          {
-            return nf.format(d / 1000000) + Messages.get().LastValuesLabelProvider_Mega;
+            case DataCollectionObject.DT_INT:
+            case DataCollectionObject.DT_UINT:
+            case DataCollectionItem.DT_INT64:
+            case DataCollectionItem.DT_UINT64:               
+               if (useMultipliers)
+               {
+                  long i = Long.parseLong(row.get(columnIndex).getValue());
+                  if ((i >= 10000000000000L) || (i <= -10000000000000L))
+                  {
+                     i = i / 1000000000000L;
+                     suffix = "T";
+                  }
+                  if ((i >= 10000000000L) || (i <= -10000000000L))
+                  {
+                     i = i / 1000000000L;
+                     suffix = "G";
+                  }
+                  if ((i >= 10000000) || (i <= -10000000))
+                  {
+                     i = i / 1000000;
+                     suffix = "M";
+                  }
+                  if ((i >= 10000) || (i <= -10000))
+                  {
+                     i = i / 1000;
+                     suffix = "K";
+                  }
+                  value = Long.toString(i);
+               }
+               else
+               {
+                  value = row.get(columnIndex).getValue();
+                  suffix = " ";
+               }
+               break;
+            case DataCollectionObject.DT_FLOAT:
+               if (useMultipliers)
+               {
+                  double d = Double.parseDouble(row.get(columnIndex).getValue());
+                  NumberFormat nf = NumberFormat.getNumberInstance();
+                  nf.setMaximumFractionDigits(2);
+                  if ((d >= 10000000000000.0) || (d <= -10000000000000.0))
+                  {
+                     d = d / 1000000000000.0;
+                     suffix = "T";
+                  }
+                  if ((d >= 10000000000.0) || (d <= -10000000000.0))
+                  {
+                     d = d / 1000000000.0;
+                     suffix = "G";
+                  }
+                  if ((d >= 10000000) || (d <= -10000000))
+                  {
+                     d = d / 1000000;
+                     suffix = "M";
+                  }
+                  if ((d >= 10000) || (d <= -10000))
+                  {
+                     d = d / 1000;
+                     suffix = "K";
+                  }
+                  value = Double.toString(d);
+               }
+               else
+               {
+                  value = row.get(columnIndex).getValue();
+               }
+               break;
+            default:
+               value = row.get(columnIndex).getValue();
+               break;
          }
-         if ((d >= 10000) || (d <= -10000))
-         {
-            return nf.format(d / 1000) + Messages.get().LastValuesLabelProvider_Kilo;
-         }
-      }
+      }     
       catch(NumberFormatException e)
       {
+         value = row.get(columnIndex).getValue();
       }
       
+      if (suffix != null)
+         return value + " " + suffix;
       return value;
    }
 
index b41ae89..babb16c 100644 (file)
@@ -317,6 +317,7 @@ public class SummaryTableWidget extends Composite
          });
          viewer.setComparator(new TableItemComparator(table.getColumnDataTypes()));
       }
+      labelProvider.setColumnDataTypes(table.getColumnDataTypes());
       viewer.setInput(table);
    }
 
index 3bed3a2..8f72739 100644 (file)
@@ -27,8 +27,9 @@ import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.widgets.Display;
 import org.netxms.client.TableCell;
 import org.netxms.client.TableRow;
+import org.netxms.client.datacollection.DataCollectionItem;
+import org.netxms.client.datacollection.DataCollectionObject;
 import org.netxms.ui.eclipse.console.resources.StatusDisplayInfo;
-import org.netxms.ui.eclipse.datacollection.Messages;
 
 /**
  * Label provider for NetXMS table
@@ -41,6 +42,7 @@ public class TableLabelProvider extends LabelProvider implements ITableLabelProv
       { null, FOREGROUND_COLOR_DARK, FOREGROUND_COLOR_DARK, FOREGROUND_COLOR_LIGHT, FOREGROUND_COLOR_LIGHT };
 
    private boolean useMultipliers = false;
+   private int[] columnDataTypes = null;
 
    /* (non-Javadoc)
         * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
@@ -62,67 +64,109 @@ public class TableLabelProvider extends LabelProvider implements ITableLabelProv
                if (columnIndex >= row.size())
                        return null;
                
-               return useMultipliers ? getValue(row.get(columnIndex).getValue()) : row.get(columnIndex).getValue();
+               return getValue(row, columnIndex);
+       }
+       
+       public void setColumnDataTypes(int[] ColumnDataTypes)
+       {
+          this.columnDataTypes = ColumnDataTypes;
        }
        
    /**
     * @param value
     * @return
     */
-   private String getValue(String value)
+   private String getValue(TableRow row, int columnIndex)
    {
-      try
-      {
-         long i = Long.parseLong(value);
-         if ((i >= 10000000000000L) || (i <= -10000000000000L))
-         {
-            return Long.toString(i / 1000000000000L) + " T"; //$NON-NLS-1$
-         }
-         if ((i >= 10000000000L) || (i <= -10000000000L))
-         {
-            return Long.toString(i / 1000000000L) + Messages.get().LastValuesLabelProvider_Giga;
-         }
-         if ((i >= 10000000) || (i <= -10000000))
-         {
-            return Long.toString(i / 1000000) + Messages.get().LastValuesLabelProvider_Mega;
-         }
-         if ((i >= 10000) || (i <= -10000))
-         {
-            return Long.toString(i / 1000) + Messages.get().LastValuesLabelProvider_Kilo;
-         }
-      }
-      catch(NumberFormatException e)
-      {
-      }
+      String value;
+      String suffix = null;
       
       try
       {
-         double d = Double.parseDouble(value);
-         NumberFormat nf = NumberFormat.getNumberInstance();
-         nf.setMaximumFractionDigits(2);
-         if ((d >= 10000000000000.0) || (d <= -10000000000000.0))
+         switch(columnDataTypes[columnIndex])
          {
-            return nf.format(d / 1000000000000.0) + " T"; //$NON-NLS-1$
+            case DataCollectionObject.DT_INT:
+            case DataCollectionObject.DT_UINT:
+            case DataCollectionItem.DT_INT64:
+            case DataCollectionItem.DT_UINT64:               
+               if (useMultipliers)
+               {
+                  long i = Long.parseLong(row.get(columnIndex).getValue());
+                  if ((i >= 10000000000000L) || (i <= -10000000000000L))
+                  {
+                     i = i / 1000000000000L;
+                     suffix = "T";
+                  }
+                  if ((i >= 10000000000L) || (i <= -10000000000L))
+                  {
+                     i = i / 1000000000L;
+                     suffix = "G";
+                  }
+                  if ((i >= 10000000) || (i <= -10000000))
+                  {
+                     i = i / 1000000;
+                     suffix = "M";
+                  }
+                  if ((i >= 10000) || (i <= -10000))
+                  {
+                     i = i / 1000;
+                     suffix = "K";
+                  }
+                  value = Long.toString(i);
+               }
+               else
+               {
+                  value = row.get(columnIndex).getValue();
+                  suffix = " ";
+               }
+               break;
+            case DataCollectionObject.DT_FLOAT:
+               if (useMultipliers)
+               {
+                  double d = Double.parseDouble(row.get(columnIndex).getValue());
+                  NumberFormat nf = NumberFormat.getNumberInstance();
+                  nf.setMaximumFractionDigits(2);
+                  if ((d >= 10000000000000.0) || (d <= -10000000000000.0))
+                  {
+                     d = d / 1000000000000.0;
+                     suffix = "T";
+                  }
+                  if ((d >= 10000000000.0) || (d <= -10000000000.0))
+                  {
+                     d = d / 1000000000.0;
+                     suffix = "G";
+                  }
+                  if ((d >= 10000000) || (d <= -10000000))
+                  {
+                     d = d / 1000000;
+                     suffix = "M";
+                  }
+                  if ((d >= 10000) || (d <= -10000))
+                  {
+                     d = d / 1000;
+                     suffix = "K";
+                  }
+                  value = Double.toString(d);
+               }
+               else
+               {
+                  value = row.get(columnIndex).getValue();
+               }
+               break;
+            default:
+               value = row.get(columnIndex).getValue();
+               break;
          }
-         if ((d >= 10000000000.0) || (d <= -10000000000.0))
-         {
-            return nf.format(d / 1000000000.0) + Messages.get().LastValuesLabelProvider_Giga;
-         }
-         if ((d >= 10000000) || (d <= -10000000))
-         {
-            return nf.format(d / 1000000) + Messages.get().LastValuesLabelProvider_Mega;
-         }
-         if ((d >= 10000) || (d <= -10000))
-         {
-            return nf.format(d / 1000) + Messages.get().LastValuesLabelProvider_Kilo;
-         }
-      }
+      }     
       catch(NumberFormatException e)
       {
+         value = row.get(columnIndex).getValue();
       }
       
+      if (suffix != null)
+         return value + " " + suffix;
       return value;
-       }
+   }
 
    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.ITableColorProvider#getForeground(java.lang.Object, int)