]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Replaced awkward Pair construct with ChartVariable class.
authorluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 17 Jan 2013 16:14:59 +0000 (16:14 +0000)
committerluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 17 Jan 2013 16:14:59 +0000 (16:14 +0000)
refs #3988

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

12 files changed:
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/AllVariablesOfModel.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/ChartVariable.java [new file with mode: 0644]
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/IAllVariablesOfModel.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/IdLabelProposalProvider.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableExistsValidator.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableModifier.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableProposalProvider.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarSeriesPropertyComposite2.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarSeriesTab2.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieSeriesPropertyComposite2.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieSeriesTab2.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/AllVariablesOfModel.java

index c3c1f76ec7d41bacdd1de86df2962d195e7956ca..90ac3d694bb5cd4054df73ee75253bcd824be17f 100644 (file)
@@ -1,12 +1,13 @@
 package org.simantics.jfreechart.chart.properties;\r
 \r
+import java.util.Collection;\r
+\r
 import org.simantics.db.ReadGraph;\r
 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<Pair<String[],String[]>> {\r
+public class AllVariablesOfModel implements Read<Collection<ChartVariable>> {\r
        \r
        public Resource res;\r
        \r
@@ -15,14 +16,10 @@ public class AllVariablesOfModel implements Read<Pair<String[],String[]>> {
        }\r
        \r
        @Override\r
-       public Pair<String[],String[]> perform(ReadGraph graph) throws DatabaseException {\r
+       public Collection<ChartVariable> perform(ReadGraph graph) throws DatabaseException {\r
                IAllVariablesOfModel query = graph.adapt(res, IAllVariablesOfModel.class);\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
+               return graph.syncRequest(query.getVariablesQuery());\r
+               \r
        }\r
 \r
 }\r
diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/ChartVariable.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/ChartVariable.java
new file mode 100644 (file)
index 0000000..77d6c69
--- /dev/null
@@ -0,0 +1,32 @@
+package org.simantics.jfreechart.chart.properties;\r
+\r
+public class ChartVariable {\r
+       \r
+       private String rvi;\r
+       private String label;\r
+       \r
+       public ChartVariable(String rvi) {\r
+               this.rvi = rvi;\r
+       }\r
+       \r
+       public ChartVariable(String rvi, String label) {\r
+               this.rvi = rvi;\r
+               this.label = label;\r
+       }\r
+       \r
+       public String getRvi() {\r
+               return rvi;\r
+       }\r
+       \r
+       public String getLabel() {\r
+               return label;\r
+       }\r
+       \r
+       @Override\r
+       public String toString() {\r
+               if (label != null)\r
+                       return label;\r
+               return rvi;\r
+       }\r
+\r
+}\r
index 2bc61906a0c422c62ed06b641b391a2748f187cb..9557315160c78b09fa4ab31136f9b71c3bc72fd9 100644 (file)
@@ -1,5 +1,7 @@
 package org.simantics.jfreechart.chart.properties;\r
 \r
+import java.util.Collection;\r
+\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.request.Read;\r
@@ -7,8 +9,9 @@ import org.simantics.db.request.Read;
 public interface IAllVariablesOfModel {\r
        \r
        \r
-       public Read<String[]> getVariablesIdsQuery();\r
+       public Read<Collection<ChartVariable>> getVariablesQuery();\r
        \r
-       public String getVariablesLabel(ReadGraph graph, String variableId) throws DatabaseException;\r
+       public String getVariablesLabel(ReadGraph graph, String rvi) throws DatabaseException;\r
+\r
 \r
 }\r
index 0730fc851879dc31b88f9166ba63a754e549b480..f643e70c48430496147fd5877822dc28a180a30c 100644 (file)
@@ -1,6 +1,8 @@
 package org.simantics.jfreechart.chart.properties;\r
 \r
 import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.Iterator;\r
 \r
 import org.eclipse.jface.fieldassist.ContentProposal;\r
 import org.eclipse.jface.fieldassist.IContentProposal;\r
@@ -12,7 +14,7 @@ public class IdLabelProposalProvider implements IContentProposalProvider{
        /*\r
         * The proposals provided.\r
         */\r
-       private Pair<String[],String[]> proposals;\r
+       private Collection<ChartVariable> proposals;\r
 \r
        /*\r
         * The proposals mapped to IContentProposal. Cached for speed in the case\r
@@ -33,7 +35,7 @@ public class IdLabelProposalProvider implements IContentProposalProvider{
         *            the array of Strings to be returned whenever proposals are\r
         *            requested.\r
         */\r
-       public IdLabelProposalProvider(Pair<String[],String[]> proposals) {\r
+       public IdLabelProposalProvider(Collection<ChartVariable> proposals) {\r
                super();\r
                this.proposals = proposals;\r
        }\r
@@ -50,34 +52,33 @@ public class IdLabelProposalProvider implements IContentProposalProvider{
         * @return the array of Objects that represent valid proposals for the field\r
         *         given its current content.\r
         */\r
+       @SuppressWarnings("unchecked")\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
+                       for (ChartVariable proposal : proposals) {\r
+                               if (proposal.getRvi().length() >= contents.length() && proposal.getRvi().substring(0, contents.length()).equalsIgnoreCase(contents)) {\r
+                                       if (proposal.getLabel() != null)\r
+                                               list.add(new ContentProposal(proposal.getRvi(),proposal.getLabel(), 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
+                                               list.add(new ContentProposal(proposal.getRvi()));\r
+                               } else if (proposal.getLabel() != null && proposal.getLabel().length() >= contents.length() && proposal.getLabel().substring(0, contents.length()).equalsIgnoreCase(contents)) {\r
+                                       list.add(new ContentProposal(proposal.getRvi(),proposal.getLabel(), 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
+                       contentProposals = new IContentProposal[proposals.size()];\r
+                       Iterator<ChartVariable> iter = proposals.iterator();\r
+                       for (int i = 0; i < proposals.size(); i++) {\r
+                               ChartVariable proposal = iter.next();\r
+                               if (proposal.getLabel() != null)\r
+                                       contentProposals[i] = new ContentProposal(proposal.getRvi(),proposal.getLabel(),null);\r
                                else\r
-                                       contentProposals[i] = new ContentProposal(proposals.first[i]);\r
+                                       contentProposals[i] = new ContentProposal(proposal.getRvi());\r
                        }\r
                }\r
                return contentProposals;\r
@@ -89,7 +90,7 @@ public class IdLabelProposalProvider implements IContentProposalProvider{
         * @param items\r
         *            the array of Strings to be used as proposals.\r
         */\r
-       public void setProposals(Pair<String[],String[]> items) {\r
+       public void setProposals(Collection<ChartVariable> items) {\r
                this.proposals = items;\r
                contentProposals = null;\r
        }\r
index c393bae6726bbda7b26a38d7eef6e7e2a6432e98..fcbe2d0300224c4cf1aecf738d04606741885504 100644 (file)
@@ -1,5 +1,8 @@
 package org.simantics.jfreechart.chart.properties;\r
 \r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
 import org.eclipse.jface.dialogs.IInputValidator;\r
 import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
 import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
@@ -24,7 +27,7 @@ import org.simantics.utils.datastructures.Pair;
  */\r
 public class VariableExistsValidator implements IInputValidator, Widget {\r
 \r
-    private String[] names;\r
+    private Collection<ChartVariable> variables;\r
     private TrackedText text;\r
     private boolean allowEmpty;\r
     private boolean useLabels = false;\r
@@ -51,6 +54,7 @@ public class VariableExistsValidator implements IInputValidator, Widget {
      */\r
     public VariableExistsValidator(WidgetSupport support, TrackedText text, boolean allowEmpty) {\r
         support.register(this);\r
+        this.variables = new ArrayList<ChartVariable>();\r
         this.text = text;\r
         this.allowEmpty = allowEmpty;\r
     }\r
@@ -65,6 +69,7 @@ public class VariableExistsValidator implements IInputValidator, Widget {
      */\r
     @Override\r
     public String isValid(String newText) {\r
+       System.out.println(this + " validate " + newText);\r
         if(newText == null || newText.isEmpty()) {\r
             if(allowEmpty)\r
                 return null;\r
@@ -72,9 +77,11 @@ public class VariableExistsValidator implements IInputValidator, Widget {
                 return "Empty name not allowed";\r
         }\r
         \r
-        synchronized (names) {\r
-            for(String s : names) {\r
-                if(newText.equals(s))\r
+        synchronized (variables) {\r
+            for(ChartVariable variable : variables) {\r
+                if(newText.equals(variable.getLabel()))\r
+                    return null;\r
+                if(newText.equals(variable.getRvi()))\r
                     return null;\r
             }\r
         }\r
@@ -87,7 +94,7 @@ public class VariableExistsValidator implements IInputValidator, Widget {
         final Resource resource = AdaptionUtils.adaptToSingle(input, Resource.class);\r
         \r
         if(resource == null) {\r
-            names = new String[0];\r
+            variables = new ArrayList<ChartVariable>();\r
             return;\r
         }\r
         \r
@@ -113,14 +120,11 @@ 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<Pair<String[],String[]>>() {\r
+                , new Listener<Collection<ChartVariable>>() {\r
 \r
                     @Override\r
-                    public void execute(Pair<String[],String[]> result) {\r
-                       if (!useLabels)\r
-                               names = result.first;\r
-                       else\r
-                               names = result.second;\r
+                    public void execute(Collection<ChartVariable> variables) {\r
+                        VariableExistsValidator.this.variables = variables;\r
                     }\r
 \r
                     @Override\r
index 6434a5eabe43adcdb41487fe7adee67c7a1b137c..84de0b05b0cd1d4c2ccdd62e9116642d720f8f36 100644 (file)
@@ -67,7 +67,7 @@ public class VariableModifier extends TextModifyListenerImpl<Resource> {
                    @Override\r
                    public void proposalAccepted(IContentProposal proposal) {\r
                        if(VariableModifier.this.control != null && !VariableModifier.this.control.isDisposed())\r
-                               VariableModifier.this.modifyText(new TrackedModifyEvent(VariableModifier.this.control, proposal.getContent()));\r
+                               VariableModifier.this.modifyText(new TrackedModifyEvent(VariableModifier.this.control, proposal.getLabel()));\r
                    }\r
                });\r
            \r
index 993085c4915dcbfc1a13eca78ca02400e67190dc..2f6f20f44bca4dba8284d6867b9f1856fd25f673 100644 (file)
@@ -11,6 +11,9 @@
  *******************************************************************************/\r
 package org.simantics.jfreechart.chart.properties;\r
 \r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
 import org.eclipse.jface.fieldassist.SimpleContentProposalProvider;\r
 import org.eclipse.swt.widgets.Control;\r
 import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
@@ -38,7 +41,7 @@ public class VariableProposalProvider extends IdLabelProposalProvider implements
      * @param resource A resource that is part of a model\r
      */\r
     public VariableProposalProvider(final Control control, WidgetSupport support) {\r
-        super(new Pair<String[], String[]>(new String[0], null));// super(String [] {});\r
+        super(new ArrayList<ChartVariable>());// super(String [] {});\r
         support.register(this);\r
         this.control = control;\r
     }\r
@@ -56,10 +59,10 @@ public class VariableProposalProvider extends IdLabelProposalProvider implements
         \r
         SimanticsUI.getSession().asyncRequest(\r
                 new AllVariablesOfModel(resource)\r
-        , new Listener<Pair<String[],String[]>>() {\r
+        , new Listener<Collection<ChartVariable>>() {\r
 \r
             @Override\r
-            public void execute(Pair<String[],String[]> result) {\r
+            public void execute(Collection<ChartVariable> result) {\r
                 setProposals(result);\r
             }\r
 \r
index 049f701f9fe91ac297653bad98bd56d8b688f131..a53d122d443b47e0ac61fe6e10b45c1a57daed86 100644 (file)
@@ -11,6 +11,8 @@
  *******************************************************************************/\r
 package org.simantics.jfreechart.chart.properties.bar;\r
 \r
+import java.util.Collection;\r
+\r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
 import org.eclipse.swt.SWT;\r
@@ -21,6 +23,7 @@ import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier;
 import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
 import org.simantics.db.management.ISessionContext;\r
+import org.simantics.jfreechart.chart.properties.ChartVariable;\r
 import org.simantics.jfreechart.chart.properties.DoubleValidator;\r
 import org.simantics.jfreechart.chart.properties.JFreeChartPropertyColorProvider;\r
 import org.simantics.jfreechart.chart.properties.RVIFactory;\r
@@ -45,7 +48,7 @@ public class BarSeriesPropertyComposite2 extends Composite {
     \r
     private TrackedText variable, label, time;\r
     \r
-    public BarSeriesPropertyComposite2(Composite parent, final ISessionContext context, WidgetSupport support, Pair<String[],String[]> variables, int style) {\r
+    public BarSeriesPropertyComposite2(Composite parent, final ISessionContext context, WidgetSupport support, Collection<ChartVariable> variables, int style) {\r
         super(parent, style);\r
         \r
         GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(this);\r
@@ -56,20 +59,16 @@ public class BarSeriesPropertyComposite2 extends Composite {
         GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
 \r
         variable = new TrackedText(this, support, SWT.BORDER);\r
-        if (variables.second == null) {\r
-               variable.setTextFactory(new RVIFactory());\r
-               variable.addModifyListener(new RVIModifier(variable.getWidget(), support));\r
-               variable.setInputValidator(new VariableExistsValidator(support, variable));\r
-        } else {\r
-               // FIXME: using bijectionmap and trackedText looses the variables that have the same label.\r
-               BijectionMap<String , String> map = new BijectionMap<String, String>();\r
-               for (int i = 0; i < variables.first.length; i++) {\r
-                       map.map(variables.first[i], variables.second[i]);\r
-               }\r
-               variable.setTextFactory(new VariableFactory(map));\r
-               variable.addModifyListener(new VariableModifier(variable.getWidget(), support));\r
-               variable.setInputValidator(new VariableExistsValidator(support, variable, false, true));\r
-        }\r
+       \r
+       // FIXME: using bijectionmap and trackedText looses the variables that have the same label.\r
+       BijectionMap<String , String> map = new BijectionMap<String, String>();\r
+       for (ChartVariable variable : variables) {\r
+                       map.map(variable.getRvi(), variable.toString());\r
+               }\r
+       variable.setTextFactory(new VariableFactory(map));\r
+       variable.addModifyListener(new VariableModifier(variable.getWidget(), support));\r
+       variable.setInputValidator(new VariableExistsValidator(support, variable, false, true));\r
+       \r
         variable.setColorProvider(new JFreeChartPropertyColorProvider(this.variable.getResourceManager()));\r
         GridDataFactory.fillDefaults().grab(true, false).applyTo(this.variable.getWidget());\r
 \r
index 829238d3b4a1f64b668f4d0453747ee24ca0e55d..fc555dbc601582f88b3187f4e803a0197bb05abf 100644 (file)
@@ -11,6 +11,8 @@
  *******************************************************************************/\r
 package org.simantics.jfreechart.chart.properties.bar;\r
 \r
+import java.util.Collection;\r
+\r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
 import org.eclipse.jface.viewers.ISelectionProvider;\r
@@ -40,6 +42,7 @@ import org.simantics.db.layer0.util.RemoverUtil;
 import org.simantics.db.management.ISessionContext;\r
 import org.simantics.jfreechart.chart.ChartUtils;\r
 import org.simantics.jfreechart.chart.properties.AllVariablesOfModel;\r
+import org.simantics.jfreechart.chart.properties.ChartVariable;\r
 import org.simantics.jfreechart.chart.properties.LabelPropertyTabContributor;\r
 import org.simantics.jfreechart.chart.properties.xyline.AxisAndVariablesExplorerComposite;\r
 import org.simantics.layer0.Layer0;\r
@@ -129,7 +132,7 @@ public class BarSeriesTab2 extends LabelPropertyTabContributor implements Widget
         }\r
         \r
         try {\r
-               Pair<String[],String[]> variables = context.getSession().syncRequest(new AllVariablesOfModel(resource));\r
+               Collection<ChartVariable> variables = context.getSession().syncRequest(new AllVariablesOfModel(resource));\r
                \r
                spc = new BarSeriesPropertyComposite2(propertyContainer, context, additionalSupport, variables, SWT.NONE);\r
        \r
index 5011332ba34b285afd876a8fb19ec6aafbce76b3..e0c3d891d87e0d735cb2a89c71bffd81232fcc83 100644 (file)
@@ -11,6 +11,8 @@
  *******************************************************************************/\r
 package org.simantics.jfreechart.chart.properties.pie;\r
 \r
+import java.util.Collection;\r
+\r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
 import org.eclipse.swt.SWT;\r
@@ -24,6 +26,7 @@ import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
 import org.simantics.db.management.ISessionContext;\r
 import org.simantics.jfreechart.chart.properties.BooleanPropertyFactory;\r
 import org.simantics.jfreechart.chart.properties.BooleanSelectionListener;\r
+import org.simantics.jfreechart.chart.properties.ChartVariable;\r
 import org.simantics.jfreechart.chart.properties.ColorPicker;\r
 import org.simantics.jfreechart.chart.properties.DoubleValidator;\r
 import org.simantics.jfreechart.chart.properties.JFreeChartPropertyColorProvider;\r
@@ -49,7 +52,7 @@ public class PieSeriesPropertyComposite2 extends Composite {
     \r
     private TrackedText variable, label, time;\r
     \r
-    public PieSeriesPropertyComposite2(Composite parent, ISessionContext context, WidgetSupport support, Pair<String[],String[]> variables,int style) {\r
+    public PieSeriesPropertyComposite2(Composite parent, ISessionContext context, WidgetSupport support, Collection<ChartVariable> variables,int style) {\r
         super(parent, style);\r
         \r
         GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(this);\r
@@ -60,20 +63,14 @@ public class PieSeriesPropertyComposite2 extends Composite {
         GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
 \r
         variable = new TrackedText(this, support, SWT.BORDER);\r
-        if (variables.second == null) {\r
-               variable.setTextFactory(new RVIFactory());\r
-               variable.addModifyListener(new RVIModifier(variable.getWidget(), support));\r
-               variable.setInputValidator(new VariableExistsValidator(support, variable));\r
-        } else {\r
-               // FIXME: using bijectionmap and trackedText looses the variables that have the same label.\r
-               BijectionMap<String , String> map = new BijectionMap<String, String>();\r
-               for (int i = 0; i < variables.first.length; i++) {\r
-                       map.map(variables.first[i], variables.second[i]);\r
-               }\r
-               variable.setTextFactory(new VariableFactory(map));\r
-               variable.addModifyListener(new VariableModifier(variable.getWidget(), support));\r
-               variable.setInputValidator(new VariableExistsValidator(support, variable, false, true));\r
-        }\r
+        BijectionMap<String , String> map = new BijectionMap<String, String>();\r
+        for (ChartVariable variable : variables) {\r
+                       map.map(variable.getRvi(), variable.toString());\r
+               }\r
+       variable.setTextFactory(new VariableFactory(map));\r
+       variable.addModifyListener(new VariableModifier(variable.getWidget(), support));\r
+       variable.setInputValidator(new VariableExistsValidator(support, variable, false, true));\r
+        \r
         variable.setColorProvider(new JFreeChartPropertyColorProvider(this.variable.getResourceManager()));\r
         GridDataFactory.fillDefaults().grab(true, false).applyTo(this.variable.getWidget());\r
 \r
index e0d9d5f2ff62e7019569c6521b561339eab1aaf1..aa83c72c11cf85a9f83562d687a4e10b817fc847 100644 (file)
@@ -11,6 +11,8 @@
  *******************************************************************************/\r
 package org.simantics.jfreechart.chart.properties.pie;\r
 \r
+import java.util.Collection;\r
+\r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
 import org.eclipse.jface.viewers.ISelectionProvider;\r
@@ -40,6 +42,7 @@ import org.simantics.db.layer0.util.RemoverUtil;
 import org.simantics.db.management.ISessionContext;\r
 import org.simantics.jfreechart.chart.ChartUtils;\r
 import org.simantics.jfreechart.chart.properties.AllVariablesOfModel;\r
+import org.simantics.jfreechart.chart.properties.ChartVariable;\r
 import org.simantics.jfreechart.chart.properties.LabelPropertyTabContributor;\r
 import org.simantics.jfreechart.chart.properties.xyline.AxisAndVariablesExplorerComposite;\r
 import org.simantics.layer0.Layer0;\r
@@ -127,7 +130,7 @@ public class PieSeriesTab2 extends LabelPropertyTabContributor implements Widget
         }\r
 \r
         try {\r
-               Pair<String[],String[]> variables = context.getSession().syncRequest(new AllVariablesOfModel(resource));\r
+               Collection<ChartVariable> variables = context.getSession().syncRequest(new AllVariablesOfModel(resource));\r
                PieSeriesPropertyComposite2 spc = new PieSeriesPropertyComposite2(propertyContainer, context, additionalSupport, variables, SWT.NONE);\r
                propertyContainer.setContent(spc);\r
                Point size = spc.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
index 10bc8c155c2c84b9f30a2821908fbab43a906fbf..9b7e8ae6580441c759e55b339f3f5132ada0f3b3 100644 (file)
@@ -11,6 +11,7 @@ import org.simantics.db.common.request.ObjectsWithType;
 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.ChartVariable;\r
 import org.simantics.jfreechart.chart.properties.IAllVariablesOfModel;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.simulation.ontology.SimulationResource;\r
@@ -34,44 +35,45 @@ public class AllVariablesOfModel implements IAllVariablesOfModel{
     }\r
 \r
        @Override\r
-       public Read<String[]> getVariablesIdsQuery() {\r
+       public Read<Collection<ChartVariable>> getVariablesQuery() {\r
                return new VariableQuery();\r
        }   \r
        \r
-       @Override\r
+       \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
+    private class VariableQuery implements Read<Collection<ChartVariable>> {\r
         @Override\r
-           public String[] perform(ReadGraph graph) throws DatabaseException {\r
+           public Collection<ChartVariable> 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
+               List<ChartVariable> result = new ArrayList<ChartVariable>();\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
+                   return result;;\r
                \r
                // Find the models configuration\r
                Resource conf = graph.getSingleObject(model, simu.HasConfiguration);\r
-               List<String> items = new ArrayList<String>();\r
+              \r
                \r
                // Recursively read all configurations and add items\r
-               ReadConfiguration(graph, conf, "", items);\r
+               ReadConfiguration(graph, conf, "", result);\r
                \r
                // Add time to the variable list\r
-               items.add("time");\r
+               result.add(new ChartVariable("time"));\r
                \r
                // Finally sort the results\r
-               Collections.sort(items, AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
-               return items.toArray(new String[items.size()]);\r
+               Collections.sort(result, AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
+               return result;\r
            }\r
     }\r
     \r
@@ -86,7 +88,7 @@ public class AllVariablesOfModel implements IAllVariablesOfModel{
      * @param items Found variables\r
      * @throws DatabaseException\r
      */\r
-    private void ReadConfiguration(ReadGraph graph, Resource configuration, String path, Collection<String> items) throws DatabaseException {\r
+    private void ReadConfiguration(ReadGraph graph, Resource configuration, String path, Collection<ChartVariable> items) throws DatabaseException {\r
         SysdynResource sr = SysdynResource.getInstance(graph);\r
         Layer0 l0 = Layer0.getInstance(graph);\r
         StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
@@ -94,12 +96,12 @@ public class AllVariablesOfModel implements IAllVariablesOfModel{
         String name;\r
         for(Resource resource : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.IndependentVariable))) {\r
             name = path + NameUtils.getSafeName(graph, resource);\r
-            items.add(name);\r
+            items.add(new ChartVariable(name, name));\r
         }\r
         \r
         for(Resource resource : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Input))) {\r
             name = path + NameUtils.getSafeName(graph, resource);\r
-            items.add(name);\r
+            items.add(new ChartVariable(name, name));\r
         }\r
 \r
         for(Resource module : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Module))) {\r