]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fixed regression in TrendNode. 85/185/3
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 30 Nov 2016 12:57:40 +0000 (14:57 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 30 Nov 2016 13:08:14 +0000 (15:08 +0200)
The regression was caused by change r32901 and merge r32981. The problem
was that the code tried to keep existing VertRuler nodes alive as much
as possible to keep their (transient) settings in place between chart
configuration reloads. However the code failed to do this correctly and
caused IndexOutOfBoundsExceptions and other corollary failures.

This fix needs to go into platform branches 1.22.2 and 1.22 as well.

refs #6547
[PRIVATE-11736]

Change-Id: Idb7d9d77b1a6b0bf513a5829b4c373cde9747529

bundles/org.simantics.trend/src/org/simantics/trend/impl/TrendNode.java

index 1d19e2f1775c1df298d31fa864a02ac3c1be4242..304b73c43d3fd01ef0ad60214ec709802cbfedcd 100644 (file)
@@ -60,7 +60,6 @@ import org.simantics.utils.format.ValueFormat;
 \r
 import gnu.trove.map.TObjectIntMap;\r
 import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.procedure.TIntProcedure;\r
 import gnu.trove.procedure.TObjectProcedure;\r
 \r
 public class TrendNode extends G2DParentNode implements TrendLayout {\r
@@ -276,7 +275,6 @@ public class TrendNode extends G2DParentNode implements TrendLayout {
 \r
                TObjectIntMap<String> newItemMap = itemIndexMap(newSpec.items);\r
                TObjectIntMap<String> currentItemMap = itemIndexMap(spec.items);\r
-               TObjectIntMap<String> addedItemMap = subtract(newItemMap, currentItemMap);\r
                TObjectIntMap<String> removedItemMap = subtract(currentItemMap, newItemMap);\r
                Map<String, VertRuler> existingRulers = new HashMap<>();\r
                if (this.spec.axisMode == YAxisMode.MultiAxis) {\r
@@ -347,6 +345,9 @@ public class TrendNode extends G2DParentNode implements TrendLayout {
                                for (int i=0; i<analogItems.size(); i++)\r
                                        vertRulers.add( addNode(VertRuler.class) );\r
                        } else {\r
+                               // Remove rulers of the items that were removed\r
+                               // and add new rulers to have enough of them for\r
+                               // each separate analog signal.\r
                                removedItemMap.forEachKey(new TObjectProcedure<String>() {\r
                                        @Override\r
                                        public boolean execute(String id) {\r
@@ -358,13 +359,11 @@ public class TrendNode extends G2DParentNode implements TrendLayout {
                                                return true;\r
                                        }\r
                                });\r
-                               addedItemMap.forEachValue(new TIntProcedure() {\r
-                                       @Override\r
-                                       public boolean execute(int index) {\r
-                                               vertRulers.add( index, addNode(VertRuler.class) );\r
-                                               return true;\r
-                                       }\r
-                               });\r
+                               // Ensure TODO: validate that this works also for keeping ruler settings \r
+                               for (int i = vertRulers.size(); i < analogItems.size(); ++i) {\r
+                                       VertRuler ruler = addNode(VertRuler.class);\r
+                                       vertRulers.add(ruler);\r
+                               }\r
                        }\r
 \r
                        for (int i = 0; i < analogItems.size(); i++) {\r