]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Initial variable rvi / label separation. Work in progress...
authorluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 17 Jan 2013 13:57:47 +0000 (13:57 +0000)
committerluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 17 Jan 2013 13:57:47 +0000 (13:57 +0000)
refs #3988

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26633 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.jfreechart/src/org/simantics/jfreechart/chart/ge/SeriesLabelRule.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/AllVariablesOfModel.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/IAllVariablesOfModel.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/IdLabelProposalProvider.java [new file with mode: 0644]
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/RVIModifier.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableExistsValidator.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableProposalProvider.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/AllVariablesOfModel.java

index f3db811e5861c5770b82c9116903cb1570d17cd7..399c4d0245d0cac82a41f19f46179ea7df8e5238 100644 (file)
@@ -20,6 +20,7 @@ import org.simantics.databoard.Bindings;
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.jfreechart.chart.properties.IAllVariablesOfModel;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.JFreeChartResource;\r
 \r
@@ -48,10 +49,14 @@ public class SeriesLabelRule implements LabelRule {
         Resource resource = (Resource)content;\r
         String label = graph.getPossibleRelatedValue(resource, l0.HasLabel, Bindings.STRING);\r
         if(label == null || label.isEmpty()) {\r
-            label = graph.getPossibleRelatedValue(resource, jfree.variableRVI);\r
-            if(label != null && !label.isEmpty() && label.length() > 1)\r
-                label = label.substring(1).replace('/', '.');\r
-            else\r
+               IAllVariablesOfModel vom = graph.adapt(resource, IAllVariablesOfModel.class);\r
+               \r
+               String rvi = graph.getPossibleRelatedValue(resource, jfree.variableRVI);\r
+               if (rvi != null) {\r
+                       label =vom.getVariablesLabel(graph, rvi);\r
+                       if (label == null)\r
+                               label = rvi;\r
+               } else\r
                 label = "Set variable";\r
         }\r
         return Collections.singletonMap(ColumnKeys.SINGLE, label);\r
index 251bdfe17370d4db72be0b682b91385794ac0107..c3c1f76ec7d41bacdd1de86df2962d195e7956ca 100644 (file)
@@ -4,8 +4,9 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.request.Read;\r
+import org.simantics.utils.datastructures.Pair;\r
 \r
-public class AllVariablesOfModel implements Read<String[]> {\r
+public class AllVariablesOfModel implements Read<Pair<String[],String[]>> {\r
        \r
        public Resource res;\r
        \r
@@ -14,9 +15,14 @@ public class AllVariablesOfModel implements Read<String[]> {
        }\r
        \r
        @Override\r
-       public String[] perform(ReadGraph graph) throws DatabaseException {\r
+       public Pair<String[],String[]> perform(ReadGraph graph) throws DatabaseException {\r
                IAllVariablesOfModel query = graph.adapt(res, IAllVariablesOfModel.class);\r
-               return graph.syncRequest(query);\r
+               String ids[] = graph.syncRequest(query.getVariablesIdsQuery());\r
+               String labels[] = new String[ids.length];\r
+               for (int i = 0; i < ids.length; i++) {\r
+                       labels[i] = query.getVariablesLabel(graph, ids[i]);\r
+               }\r
+               return new Pair<String[], String[]>(ids, labels);\r
        }\r
 \r
 }\r
index c46c4938acacf3c6b1e0bac736145c8fe013b561..2bc61906a0c422c62ed06b641b391a2748f187cb 100644 (file)
@@ -1,7 +1,14 @@
 package org.simantics.jfreechart.chart.properties;\r
 \r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.request.Read;\r
 \r
-public interface IAllVariablesOfModel extends Read<String[]>{\r
+public interface IAllVariablesOfModel {\r
+       \r
+       \r
+       public Read<String[]> getVariablesIdsQuery();\r
+       \r
+       public String getVariablesLabel(ReadGraph graph, String variableId) throws DatabaseException;\r
 \r
 }\r
diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/IdLabelProposalProvider.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/IdLabelProposalProvider.java
new file mode 100644 (file)
index 0000000..0730fc8
--- /dev/null
@@ -0,0 +1,113 @@
+package org.simantics.jfreechart.chart.properties;\r
+\r
+import java.util.ArrayList;\r
+\r
+import org.eclipse.jface.fieldassist.ContentProposal;\r
+import org.eclipse.jface.fieldassist.IContentProposal;\r
+import org.eclipse.jface.fieldassist.IContentProposalProvider;\r
+import org.simantics.utils.datastructures.Pair;\r
+\r
+public class IdLabelProposalProvider implements IContentProposalProvider{\r
+\r
+       /*\r
+        * The proposals provided.\r
+        */\r
+       private Pair<String[],String[]> proposals;\r
+\r
+       /*\r
+        * The proposals mapped to IContentProposal. Cached for speed in the case\r
+        * where filtering is not used.\r
+        */\r
+       private IContentProposal[] contentProposals;\r
+\r
+       /*\r
+        * Boolean that tracks whether filtering is used.\r
+        */\r
+       private boolean filterProposals = false;\r
+\r
+       /**\r
+        * Construct a SimpleContentProposalProvider whose content proposals are\r
+        * always the specified array of Objects.\r
+        * \r
+        * @param proposals\r
+        *            the array of Strings to be returned whenever proposals are\r
+        *            requested.\r
+        */\r
+       public IdLabelProposalProvider(Pair<String[],String[]> proposals) {\r
+               super();\r
+               this.proposals = proposals;\r
+       }\r
+\r
+       /**\r
+        * Return an array of Objects representing the valid content proposals for a\r
+        * field. \r
+        * \r
+        * @param contents\r
+        *            the current contents of the field (only consulted if filtering\r
+        *            is set to <code>true</code>)\r
+        * @param position\r
+        *            the current cursor position within the field (ignored)\r
+        * @return the array of Objects that represent valid proposals for the field\r
+        *         given its current content.\r
+        */\r
+       public IContentProposal[] getProposals(String contents, int position) {\r
+               if (filterProposals) {\r
+                       ArrayList list = new ArrayList();\r
+                       for (int i = 0; i < proposals.first.length; i++) {\r
+                               if (proposals.first[i].length() >= contents.length() && proposals.first[i].substring(0, contents.length()).equalsIgnoreCase(contents)) {\r
+                                       if (proposals.second != null)\r
+                                               list.add(new ContentProposal(proposals.first[i],proposals.second[i], null));\r
+                                       else\r
+                                               list.add(new ContentProposal(proposals.first[i]));\r
+                               }\r
+                       }\r
+                       if (proposals.second != null) {\r
+                               for (int i = 0; i < proposals.second.length; i++) {\r
+                                       if (proposals.second[i].length() >= contents.length() && proposals.second[i].substring(0, contents.length()).equalsIgnoreCase(contents)) {\r
+                                               list.add(new ContentProposal(proposals.first[i],proposals.second[i], null));\r
+                                       }\r
+                               }\r
+                       }\r
+                       return (IContentProposal[]) list.toArray(new IContentProposal[list\r
+                                       .size()]);\r
+               }\r
+               if (contentProposals == null) {\r
+                       contentProposals = new IContentProposal[proposals.first.length];\r
+                       for (int i = 0; i < proposals.first.length; i++) {\r
+                               if (proposals.second != null)\r
+                                       contentProposals[i] = new ContentProposal(proposals.first[i],proposals.second[i],null);\r
+                               else\r
+                                       contentProposals[i] = new ContentProposal(proposals.first[i]);\r
+                       }\r
+               }\r
+               return contentProposals;\r
+       }\r
+\r
+       /**\r
+        * Set the Strings to be used as content proposals.\r
+        * \r
+        * @param items\r
+        *            the array of Strings to be used as proposals.\r
+        */\r
+       public void setProposals(Pair<String[],String[]> items) {\r
+               this.proposals = items;\r
+               contentProposals = null;\r
+       }\r
+\r
+       /**\r
+        * Set the boolean that controls whether proposals are filtered according to\r
+        * the current field content.\r
+        * \r
+        * @param filterProposals\r
+        *            <code>true</code> if the proposals should be filtered to\r
+        *            show only those that match the current contents of the field,\r
+        *            and <code>false</code> if the proposals should remain the\r
+        *            same, ignoring the field content.\r
+        * @since 3.3\r
+        */\r
+       public void setFiltering(boolean filterProposals) {\r
+               this.filterProposals = filterProposals;\r
+               // Clear any cached proposals.\r
+               contentProposals = null;\r
+       }\r
+}\r
index 6a036607899fe80e3895b92e66464271834f2131..b9359e0d2105732d916bf9b3edfc83cdec17c472 100644 (file)
@@ -62,7 +62,8 @@ public class RVIModifier extends TextModifyListenerImpl<Resource> {
             e1.printStackTrace();\r
         }\r
         \r
-        SimpleContentProposalProvider scpp = new VariableProposalProvider(control, support);\r
+        //SimpleContentProposalProvider scpp = new VariableProposalProvider(control, support);\r
+        IdLabelProposalProvider scpp = new VariableProposalProvider(control, support);\r
         scpp.setFiltering(true);\r
 \r
         ContentProposalAdapter adapter = new ContentProposalAdapter(\r
index 08815bc8f91a1ad92d92fd2ebd97d1f7ef59a42d..c393bae6726bbda7b26a38d7eef6e7e2a6432e98 100644 (file)
@@ -14,6 +14,7 @@ import org.simantics.layer0.Layer0;
 import org.simantics.simulation.ontology.SimulationResource;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.ui.utils.AdaptionUtils;\r
+import org.simantics.utils.datastructures.Pair;\r
 \r
 /**\r
  * Variable exists validator for tracked text widgets. \r
@@ -26,6 +27,7 @@ public class VariableExistsValidator implements IInputValidator, Widget {
     private String[] names;\r
     private TrackedText text;\r
     private boolean allowEmpty;\r
+    private boolean useLabels = false;\r
     \r
     /**\r
      * Validate against all variables\r
@@ -38,6 +40,8 @@ public class VariableExistsValidator implements IInputValidator, Widget {
         this(support, text, false);\r
     }\r
     \r
+   \r
+    \r
     /**\r
      * Validate against all variables\r
      * \r
@@ -47,11 +51,15 @@ public class VariableExistsValidator implements IInputValidator, Widget {
      */\r
     public VariableExistsValidator(WidgetSupport support, TrackedText text, boolean allowEmpty) {\r
         support.register(this);\r
-        names = new String[] {"time"};\r
         this.text = text;\r
         this.allowEmpty = allowEmpty;\r
     }\r
     \r
+    public VariableExistsValidator(WidgetSupport support, TrackedText text, boolean allowEmpty, boolean useLabels) {\r
+        this(support, text, allowEmpty);\r
+        this.useLabels = useLabels;\r
+    }\r
+    \r
     /**\r
      * Returns null if there is a variable named newText in the model\r
      */\r
@@ -79,7 +87,7 @@ public class VariableExistsValidator implements IInputValidator, Widget {
         final Resource resource = AdaptionUtils.adaptToSingle(input, Resource.class);\r
         \r
         if(resource == null) {\r
-            names = new String[] {"time"};\r
+            names = new String[0];\r
             return;\r
         }\r
         \r
@@ -105,11 +113,14 @@ public class VariableExistsValidator implements IInputValidator, Widget {
                 // Find all variables and set them as the reference for isValid(String)\r
                 SimanticsUI.getSession().asyncRequest(\r
                         new AllVariablesOfModel(model)\r
-                , new Listener<String[]>() {\r
+                , new Listener<Pair<String[],String[]>>() {\r
 \r
                     @Override\r
-                    public void execute(String[] result) {\r
-                        names = result;\r
+                    public void execute(Pair<String[],String[]> result) {\r
+                       if (!useLabels)\r
+                               names = result.first;\r
+                       else\r
+                               names = result.second;\r
                     }\r
 \r
                     @Override\r
index d6962cfa58c37b1c661a9834b46069322eb4c510..993085c4915dcbfc1a13eca78ca02400e67190dc 100644 (file)
@@ -20,6 +20,7 @@ import org.simantics.db.management.ISessionContext;
 import org.simantics.db.procedure.Listener;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.ui.utils.AdaptionUtils;\r
+import org.simantics.utils.datastructures.Pair;\r
 \r
 /**\r
  * Provides all variables a model contains\r
@@ -27,7 +28,7 @@ import org.simantics.ui.utils.AdaptionUtils;
  * @author Teemu Lempinen\r
  *\r
  */\r
-public class VariableProposalProvider extends SimpleContentProposalProvider implements Widget {\r
+public class VariableProposalProvider extends IdLabelProposalProvider implements Widget {\r
 \r
     /**\r
      * Provides all variables a model contains. Given resource needs to be\r
@@ -37,7 +38,7 @@ public class VariableProposalProvider extends SimpleContentProposalProvider impl
      * @param resource A resource that is part of a model\r
      */\r
     public VariableProposalProvider(final Control control, WidgetSupport support) {\r
-        super(new String [] {});\r
+        super(new Pair<String[], String[]>(new String[0], null));// super(String [] {});\r
         support.register(this);\r
         this.control = control;\r
     }\r
@@ -55,10 +56,10 @@ public class VariableProposalProvider extends SimpleContentProposalProvider impl
         \r
         SimanticsUI.getSession().asyncRequest(\r
                 new AllVariablesOfModel(resource)\r
-        , new Listener<String[]>() {\r
+        , new Listener<Pair<String[],String[]>>() {\r
 \r
             @Override\r
-            public void execute(String[] result) {\r
+            public void execute(Pair<String[],String[]> result) {\r
                 setProposals(result);\r
             }\r
 \r
index 18da4cb9ea3d0a05d9cacb0e0663c5b1ed02adc8..10bc8c155c2c84b9f30a2821908fbab43a906fbf 100644 (file)
@@ -10,6 +10,7 @@ import org.simantics.db.Resource;
 import org.simantics.db.common.request.ObjectsWithType;\r
 import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.request.Read;\r
 import org.simantics.jfreechart.chart.properties.IAllVariablesOfModel;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.simulation.ontology.SimulationResource;\r
@@ -32,35 +33,50 @@ public class AllVariablesOfModel implements IAllVariablesOfModel{
         this.model = model;\r
     }\r
 \r
-    @Override\r
-    public String[] perform(ReadGraph graph) throws DatabaseException {\r
-        Layer0 l0 = Layer0.getInstance(graph);\r
-        SimulationResource simu = SimulationResource.getInstance(graph);\r
-        SysdynResource sr = SysdynResource.getInstance(graph);\r
-        \r
-        // Find the model of this resource\r
-        Resource model = this.model;\r
-        while(model != null && !graph.isInstanceOf(model, sr.SysdynModel))\r
-            model = graph.getPossibleObject(model, l0.PartOf);\r
-        \r
-        if(model == null)\r
-            return new String[0];\r
-        \r
-        // Find the models configuration\r
-        Resource conf = graph.getSingleObject(model, simu.HasConfiguration);\r
-        List<String> items = new ArrayList<String>();\r
-        \r
-        // Recursively read all configurations and add items\r
-        ReadConfiguration(graph, conf, "", items);\r
-        \r
-        // Add time to the variable list\r
-        items.add("time");\r
-        \r
-        // Finally sort the results\r
-        Collections.sort(items, AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
-        return items.toArray(new String[items.size()]);\r
+       @Override\r
+       public Read<String[]> getVariablesIdsQuery() {\r
+               return new VariableQuery();\r
+       }   \r
+       \r
+       @Override\r
+       public String getVariablesLabel(ReadGraph graph, String variableId)\r
+                       throws DatabaseException {\r
+                  return variableId.substring(1).replace('/', '.');\r
+       }\r
+    \r
+    private class VariableQuery implements Read<String[]> {\r
+        @Override\r
+           public String[] perform(ReadGraph graph) throws DatabaseException {\r
+               Layer0 l0 = Layer0.getInstance(graph);\r
+               SimulationResource simu = SimulationResource.getInstance(graph);\r
+               SysdynResource sr = SysdynResource.getInstance(graph);\r
+               \r
+               // Find the model of this resource\r
+               Resource model = AllVariablesOfModel.this.model;\r
+               while(model != null && !graph.isInstanceOf(model, sr.SysdynModel))\r
+                   model = graph.getPossibleObject(model, l0.PartOf);\r
+               \r
+               if(model == null)\r
+                   return new String[0];\r
+               \r
+               // Find the models configuration\r
+               Resource conf = graph.getSingleObject(model, simu.HasConfiguration);\r
+               List<String> items = new ArrayList<String>();\r
+               \r
+               // Recursively read all configurations and add items\r
+               ReadConfiguration(graph, conf, "", items);\r
+               \r
+               // Add time to the variable list\r
+               items.add("time");\r
+               \r
+               // Finally sort the results\r
+               Collections.sort(items, AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
+               return items.toArray(new String[items.size()]);\r
+           }\r
     }\r
     \r
+    \r
+    \r
     /**\r
      * Read components in a configuration and recursively all module configurations\r
      * \r