threshold color displayed correctly on text gauge
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 30 Nov 2017 07:05:01 +0000 (09:05 +0200)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 30 Nov 2017 07:05:01 +0000 (09:05 +0200)
src/java/netxms-eclipse/Charts/src/org/netxms/ui/eclipse/charts/widgets/GaugeWidget.java
src/java/netxms-eclipse/Charts/src/org/netxms/ui/eclipse/charts/widgets/internal/DataComparisonElement.java
src/java/netxms-eclipse/Dashboard/src/org/netxms/ui/eclipse/dashboard/widgets/ComparisonChartElement.java
src/java/netxms-eclipse/Dashboard/src/org/netxms/ui/eclipse/dashboard/widgets/GaugeElement.java
webui/webapp/Charts/src/org/netxms/ui/eclipse/charts/widgets/GaugeWidget.java
webui/webapp/Charts/src/org/netxms/ui/eclipse/charts/widgets/internal/DataComparisonElement.java
webui/webapp/Dashboard/src/org/netxms/ui/eclipse/dashboard/widgets/ComparisonChartElement.java
webui/webapp/Dashboard/src/org/netxms/ui/eclipse/dashboard/widgets/GaugeElement.java

index 87ffaf2..28dab46 100644 (file)
@@ -256,6 +256,14 @@ public abstract class GaugeWidget extends GenericChart implements Gauge, PaintLi
    @Override
    public void updateParameterThresholds(int index, Threshold[] thresholds)
    {
+      try
+      {
+         DataComparisonElement p = parameters.get(index);
+         p.setThresholds(thresholds);
+      }
+      catch(IndexOutOfBoundsException e)
+      {
+      }
    }
 
        /* (non-Javadoc)
index 667b1bc..6dbbdd4 100644 (file)
@@ -18,6 +18,7 @@
  */
 package org.netxms.ui.eclipse.charts.widgets.internal;
 
+import java.util.Arrays;
 import org.eclipse.birt.chart.model.component.Series;
 import org.netxms.client.constants.Severity;
 import org.netxms.client.datacollection.GraphItem;
@@ -212,4 +213,14 @@ public class DataComparisonElement
        {
           return dci.getDisplayFormat();
        }
+
+   /* (non-Javadoc)
+    * @see java.lang.Object#toString()
+    */
+   @Override
+   public String toString()
+   {
+      return "DataComparisonElement [dci=" + dci + ", thresholds=" + Arrays.toString(thresholds) + ", value=" + value
+            + ", rawValue=" + rawValue + ", series=" + series + "]";
+   }
 }
index 373035a..8f531c6 100644 (file)
@@ -34,6 +34,7 @@ import org.netxms.client.dashboards.DashboardElement;
 import org.netxms.client.datacollection.ChartDciConfig;
 import org.netxms.client.datacollection.DciData;
 import org.netxms.client.datacollection.DciDataRow;
+import org.netxms.client.datacollection.Threshold;
 import org.netxms.ui.eclipse.charts.api.DataComparisonChart;
 import org.netxms.ui.eclipse.dashboard.Activator;
 import org.netxms.ui.eclipse.dashboard.Messages;
@@ -49,6 +50,7 @@ public abstract class ComparisonChartElement extends ElementWidget
        protected DataComparisonChart chart;
        protected NXCSession session;
        protected int refreshInterval = 30;
+       protected boolean updateThresholds = false;
        
        private ViewRefreshController refreshController;
        private boolean updateInProgress = false;
@@ -114,6 +116,21 @@ public abstract class ComparisonChartElement extends ElementWidget
                                        else
                                                data[i] = session.getCollectedTableData(dciList[i].nodeId, dciList[i].dciId, dciList[i].instance, dciList[i].column, null, null, 1);
                                }
+
+            final Threshold[][] thresholds;
+            if (updateThresholds)
+            {
+               thresholds = new Threshold[dciList.length][];
+               for(int i = 0; i < dciList.length; i++)
+               {
+                  thresholds[i] = session.getThresholds(dciList[i].nodeId, dciList[i].dciId);
+               }
+            }
+            else
+            {
+               thresholds = null;
+            }
+                               
                                runInUIThread(new Runnable() {
                                        @Override
                                        public void run()
@@ -124,6 +141,8 @@ public abstract class ComparisonChartElement extends ElementWidget
                                                        {
                                                                DciDataRow lastValue = data[i].getLastValue();
                                                                chart.updateParameter(i, (lastValue != null) ? lastValue : new DciDataRow(new Date(), 0.0), data[i].getDataType(), false);
+                                                               if (updateThresholds)
+                                                                  chart.updateParameterThresholds(i, thresholds[i]);
                                                        }
                                                        chart.refresh();
                                                        chart.clearErrors();
index 4a01792..7f5c8b2 100644 (file)
@@ -64,6 +64,7 @@ public class GaugeElement extends ComparisonChartElement
             break;
                        case GaugeConfig.TEXT:
                                chart = ChartFactory.createCurrentValueChart(this, SWT.NONE);
+                     updateThresholds = true;
                                break;
                        default:
                                chart = ChartFactory.createDialChart(this, SWT.NONE);
index d7b4536..0c46b1a 100644 (file)
@@ -75,48 +75,48 @@ public abstract class GaugeWidget extends GenericChart implements Gauge, PaintLi
    protected String fontName = "Verdana"; //$NON-NLS-1$
    protected GaugeColorMode colorMode = GaugeColorMode.ZONE;
    protected RGB customColor = new RGB(0, 0, 0);
-       
-       private boolean fontsCreated = false;
-       
-       /**
-        * @param parent
-        * @param style
-        */
-       public GaugeWidget(Composite parent, int style)
-       {
-               super(parent, style | SWT.NO_BACKGROUND);
-               
-               colors = new ColorCache(this);
-               addPaintListener(this);
-               addDisposeListener(this);
-               addControlListener(new ControlListener() {
-                       @Override
-                       public void controlResized(ControlEvent e)
-                       {
-                               if (chartImage != null)
-                               {
-                                       chartImage.dispose();
-                                       chartImage = null;
-                               }
-                               refresh();
-                       }
-                       
-                       @Override
-                       public void controlMoved(ControlEvent e)
-                       {
-                       }
-               });
-       }
-       
-       /**
-        * Create fonts
-        */
-       protected abstract void createFonts();
-       
-       /**
-        * Dispose fonts
-        */
-       protected abstract void disposeFonts();
+
+   private boolean fontsCreated = false;
+
+   /**
+    * @param parent
+    * @param style
+    */
+   public GaugeWidget(Composite parent, int style)
+   {
+      super(parent, style | SWT.NO_BACKGROUND);
+
+      colors = new ColorCache(this);
+      addPaintListener(this);
+      addDisposeListener(this);
+      addControlListener(new ControlListener() {
+         @Override
+         public void controlResized(ControlEvent e)
+         {
+            if (chartImage != null)
+            {
+               chartImage.dispose();
+               chartImage = null;
+            }
+            refresh();
+         }
+
+         @Override
+         public void controlMoved(ControlEvent e)
+         {
+         }
+      });
+   }
+
+   /**
+    * Create fonts
+    */
+   protected abstract void createFonts();
+
+   /**
+    * Dispose fonts
+    */
+   protected abstract void disposeFonts();
 
        /* (non-Javadoc)
     * @see org.netxms.ui.eclipse.charts.api.DataChart#initializationComplete()
@@ -255,6 +255,14 @@ public abstract class GaugeWidget extends GenericChart implements Gauge, PaintLi
    @Override
    public void updateParameterThresholds(int index, Threshold[] thresholds)
    {
+      try
+      {
+         DataComparisonElement p = parameters.get(index);
+         p.setThresholds(thresholds);
+      }
+      catch(IndexOutOfBoundsException e)
+      {
+      }
    }
 
        /* (non-Javadoc)
index 667b1bc..6dbbdd4 100644 (file)
@@ -18,6 +18,7 @@
  */
 package org.netxms.ui.eclipse.charts.widgets.internal;
 
+import java.util.Arrays;
 import org.eclipse.birt.chart.model.component.Series;
 import org.netxms.client.constants.Severity;
 import org.netxms.client.datacollection.GraphItem;
@@ -212,4 +213,14 @@ public class DataComparisonElement
        {
           return dci.getDisplayFormat();
        }
+
+   /* (non-Javadoc)
+    * @see java.lang.Object#toString()
+    */
+   @Override
+   public String toString()
+   {
+      return "DataComparisonElement [dci=" + dci + ", thresholds=" + Arrays.toString(thresholds) + ", value=" + value
+            + ", rawValue=" + rawValue + ", series=" + series + "]";
+   }
 }
index 373035a..8f531c6 100644 (file)
@@ -34,6 +34,7 @@ import org.netxms.client.dashboards.DashboardElement;
 import org.netxms.client.datacollection.ChartDciConfig;
 import org.netxms.client.datacollection.DciData;
 import org.netxms.client.datacollection.DciDataRow;
+import org.netxms.client.datacollection.Threshold;
 import org.netxms.ui.eclipse.charts.api.DataComparisonChart;
 import org.netxms.ui.eclipse.dashboard.Activator;
 import org.netxms.ui.eclipse.dashboard.Messages;
@@ -49,6 +50,7 @@ public abstract class ComparisonChartElement extends ElementWidget
        protected DataComparisonChart chart;
        protected NXCSession session;
        protected int refreshInterval = 30;
+       protected boolean updateThresholds = false;
        
        private ViewRefreshController refreshController;
        private boolean updateInProgress = false;
@@ -114,6 +116,21 @@ public abstract class ComparisonChartElement extends ElementWidget
                                        else
                                                data[i] = session.getCollectedTableData(dciList[i].nodeId, dciList[i].dciId, dciList[i].instance, dciList[i].column, null, null, 1);
                                }
+
+            final Threshold[][] thresholds;
+            if (updateThresholds)
+            {
+               thresholds = new Threshold[dciList.length][];
+               for(int i = 0; i < dciList.length; i++)
+               {
+                  thresholds[i] = session.getThresholds(dciList[i].nodeId, dciList[i].dciId);
+               }
+            }
+            else
+            {
+               thresholds = null;
+            }
+                               
                                runInUIThread(new Runnable() {
                                        @Override
                                        public void run()
@@ -124,6 +141,8 @@ public abstract class ComparisonChartElement extends ElementWidget
                                                        {
                                                                DciDataRow lastValue = data[i].getLastValue();
                                                                chart.updateParameter(i, (lastValue != null) ? lastValue : new DciDataRow(new Date(), 0.0), data[i].getDataType(), false);
+                                                               if (updateThresholds)
+                                                                  chart.updateParameterThresholds(i, thresholds[i]);
                                                        }
                                                        chart.refresh();
                                                        chart.clearErrors();
index 4a01792..7f5c8b2 100644 (file)
@@ -64,6 +64,7 @@ public class GaugeElement extends ComparisonChartElement
             break;
                        case GaugeConfig.TEXT:
                                chart = ChartFactory.createCurrentValueChart(this, SWT.NONE);
+                     updateThresholds = true;
                                break;
                        default:
                                chart = ChartFactory.createDialChart(this, SWT.NONE);