]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Simplified selections and trend view selection listener
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 14 Jan 2011 13:20:30 +0000 (13:20 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 14 Jan 2011 13:20:30 +0000 (13:20 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@19378 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/BrowserSelection.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/SysdynBrowser.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/PointerInteractor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java

index 4106a4553b8afc42453631c6e737b6ad375df495..60ab9fefe1499f98acb0377566ebcb5a7bc0aefd 100644 (file)
@@ -14,18 +14,22 @@ package org.simantics.sysdyn.ui.browser;
 import org.eclipse.core.runtime.IAdaptable;\r
 import org.simantics.browsing.ui.NodeContext;\r
 import org.simantics.db.Resource;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.sysdyn.ui.browser.nodes.VariableNode;\r
 \r
 public class BrowserSelection implements IAdaptable {\r
        private Resource resource;\r
        private Resource model;\r
        private String URI;\r
        private Object originalInput;\r
+       private Variable variable;\r
 \r
-       public BrowserSelection(Object originalInput, Resource resource, String URI, Resource model) {\r
+       public BrowserSelection(Object originalInput, VariableNode<Resource> vn) {\r
                this.originalInput = originalInput;\r
-               this.resource = resource;\r
-               this.URI = URI;\r
-               this.model = model;\r
+               this.resource = vn.getResource();\r
+               this.URI = vn.getURI();\r
+               this.model = vn.getModel();\r
+               this.variable = vn.getVariable();\r
        }\r
 \r
        @SuppressWarnings("rawtypes")\r
@@ -33,6 +37,8 @@ public class BrowserSelection implements IAdaptable {
        public Object getAdapter(Class adapter) {\r
                if (adapter == Resource.class)\r
                        return resource;\r
+               if (adapter == Variable.class)\r
+                       return variable;\r
                if (NodeContext.class.equals(adapter))\r
             return originalInput;\r
                if (originalInput instanceof IAdaptable) {\r
index dac17e5e20ca416bd4877ed9ca754b725e71a69b..fdd38f713b97720515bc1f958d197e2755bed21c 100644 (file)
@@ -52,9 +52,8 @@ public class SysdynBrowser extends GraphExplorerView {
                                VariableNode<Resource> vn = (VariableNode<Resource>) ctx.getAdapter(VariableNode.class);\r
                    IHintContext context;\r
                    if(vn != null) {\r
-                       Resource resource = vn.getResource() == null ? vn.data : vn.getResource();\r
                        context = new AdaptableHintContext(SelectionHints.KEY_MAIN, SelectionHints.KEY_SELECTION_PROPERTY);\r
-                       context.setHint(SelectionHints.KEY_MAIN, new BrowserSelection(objects[i], resource, vn.getURI(), vn.getModel()));\r
+                       context.setHint(SelectionHints.KEY_MAIN, new BrowserSelection(objects[i], vn));\r
                        context.setHint(SelectionHints.KEY_SELECTION_PROPERTY, vn.getVariable());\r
                    } else {\r
                        context = new AdaptableHintContext(SelectionHints.KEY_MAIN);\r
index 70a998824fc545bed5b7b0acad76f27a7fcab379..dbaa401450d66bd99209839ccd008158dce79bd4 100644 (file)
@@ -122,7 +122,7 @@ public class PointerInteractor extends org.simantics.g2d.diagram.participant.poi
                                 diagram.setHint(DiagramHints.KEY_USE_CONNECTION_FLAGS, true);\r
                                 ISysdynElementClassProvider secp = (ISysdynElementClassProvider)elementClassProvider;\r
                                 secp.put(ElementClasses.CONNECTION, elementClassProvider.get(ConnectionClasses.FLOW));\r
-                                bsi = new SysdynConnectTool(null, me.mouseId, curCanvasPos); // FIXME\r
+                                bsi = new SysdynConnectTool(null, me.mouseId, curCanvasPos);\r
                        }\r
 \r
                        if (bsi != null) {\r
index 12624c3918fd656486402fb2d4ac9a28cd4661cc..3e26d03566a17a40378698f06ccdbd0aec2ca1a6 100644 (file)
@@ -38,7 +38,6 @@ import org.simantics.sysdyn.manager.SysdynDataSet;
 import org.simantics.sysdyn.manager.SysdynModel;\r
 import org.simantics.sysdyn.manager.SysdynModelManager;\r
 import org.simantics.sysdyn.manager.SysdynResult;\r
-import org.simantics.sysdyn.ui.browser.BrowserSelection;\r
 import org.simantics.sysdyn.ui.trend.PinTrend;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.utils.ui.ISelectionUtils;\r
@@ -50,7 +49,7 @@ public abstract class SysdynDatasetSelectionListener implements ISelectionListen
        HashMap<SysdynModel, Runnable> resultListeners = new HashMap<SysdynModel, Runnable>();\r
 \r
        @Override\r
-       public void selectionChanged(IWorkbenchPart part, ISelection selection) {\r
+       public void selectionChanged(IWorkbenchPart part, final ISelection selection) {\r
                if(selection.isEmpty() || Boolean.TRUE.equals(PinTrend.getState()))\r
                        return;\r
                if(selection instanceof IStructuredSelection) {\r
@@ -59,121 +58,88 @@ public abstract class SysdynDatasetSelectionListener implements ISelectionListen
                                        model.removeResultListener(resultListeners.get(model));\r
                                resultListeners.clear();\r
                        }\r
-                       Set<BrowserSelection> bs = ISelectionUtils.filterSetSelection(selection, BrowserSelection.class);\r
-                       if(!bs.isEmpty()) {\r
-                               BrowserSelection[] browserSelections = bs.toArray(new BrowserSelection[bs.size()]);\r
-                               updateDatasets(browserSelections);\r
-                               addResultListeners(browserSelections);\r
-                       } else {\r
-                               Set<Resource> ress = ISelectionUtils.filterSetSelection(selection, Resource.class);\r
-                               List<Resource> runtimes = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_VARIABLE_RESOURCE, Resource.class);\r
-                               if(runtimes.isEmpty())\r
-                                       return;\r
-                               Resource runtime = runtimes.get(0);\r
-                               Resource[] resources = ress.toArray(Resource.NONE);\r
-                               updateDatasets(resources, runtime);\r
-                               addResultListeners(resources, runtime);\r
-                       }\r
-               }\r
-       }\r
-\r
-       private void addResultListeners(final BrowserSelection[] browserSelections) {\r
-               Session session = SimanticsUI.peekSession();\r
-               if (session == null || browserSelections.length < 1)\r
-                       return;\r
-\r
-               session.asyncRequest(new ReadRequest() {\r
-                       @Override\r
-                       public void run(ReadGraph g) throws DatabaseException {\r
-                               HashSet<SysdynModel> models = new HashSet<SysdynModel>(); \r
-                               for(BrowserSelection bs : browserSelections) {\r
-                                       if(bs.getModel() != null) {\r
-                                               models.add(getSysdynModel(g, bs.getModel()));\r
+                       \r
+                       Session session = SimanticsUI.peekSession();\r
+                       if (session == null)\r
+                               return;\r
+\r
+                       session.asyncRequest(new ReadRequest() {\r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       \r
+                                       Collection<Variable> vars = ISelectionUtils.filterSetSelection(selection, Variable.class);\r
+                                       \r
+                                       if(vars.isEmpty()) {\r
+                                               Set<Resource> ress = ISelectionUtils.filterSetSelection(selection, Resource.class);\r
+                                               List<Resource> runtimes = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_VARIABLE_RESOURCE, Resource.class);\r
+                                               if(runtimes.isEmpty())\r
+                                                       return;\r
+                                               Resource runtime = runtimes.get(0);\r
+                                               \r
+                                               for(Resource resource : ress) {\r
+                                                       Variable variable = getVariable(graph, resource, runtime);\r
+                                                       if(variable != null)\r
+                                                               vars.add(variable);\r
+                                               }\r
                                        }\r
+                                       \r
+                                       updateDatasets(graph, vars);\r
+                                       addResultListeners(graph, vars);\r
                                }\r
-                               \r
-                               Runnable listener = new Runnable() {\r
-                                       @Override\r
-                                       public void run() {\r
-                                               updateDatasets(browserSelections);\r
-                                       }\r
-                               };\r
-                               \r
-                               for(SysdynModel model : models) {\r
-                                       model.addResultListener(listener);\r
-                                       resultListeners.put(model, listener);\r
-                               }\r
-                       }\r
-               });\r
+                       });\r
+               }\r
        }\r
-\r
-       private void addResultListeners(final Resource[] resources, final Resource runtime) {\r
-               Session session = SimanticsUI.peekSession();\r
-               if (session == null || resources.length < 1)\r
-                       return;\r
+       \r
+       \r
+       private void addResultListeners(ReadGraph graph, final Collection<Variable> variables) throws DatabaseException {\r
+               if(variables.size() < 1) return;\r
                \r
-               session.asyncRequest(new ReadRequest() {\r
+               HashSet<SysdynModel> models = new HashSet<SysdynModel>(); \r
+               for(Variable variable : variables) {\r
+                       Resource model = Variables.getModel(graph, variable);\r
+                       if(model != null) {\r
+                               models.add(getSysdynModel(graph, model));\r
+                       }\r
+               }\r
+               \r
+               Runnable listener = new Runnable() {\r
                        @Override\r
-                       public void run(ReadGraph g) throws DatabaseException {\r
-                               Variable variable = getVariable(g, resources[0], runtime);\r
-                               if(variable == null) return;\r
-                               SysdynModel model = getSysdynModel(g, Variables.getModel(g, variable));\r
-                               Runnable listener = new Runnable() {\r
+                       public void run() {\r
+                               Session session = SimanticsUI.peekSession();\r
+                               if (session == null)\r
+                                       return;\r
+                               \r
+                               session.asyncRequest(new ReadRequest() {\r
+                                       \r
                                        @Override\r
-                                       public void run() {\r
-                                               updateDatasets(resources, runtime);\r
+                                       public void run(ReadGraph graph) throws DatabaseException {\r
+                                               updateDatasets(graph, variables);\r
                                        }\r
-                               };\r
-                               model.addResultListener(listener);\r
-                               resultListeners.put(model, listener);\r
+                               });\r
                        }\r
-               });\r
-\r
+               };\r
+               \r
+               for(SysdynModel model : models) {\r
+                       model.addResultListener(listener);\r
+                       resultListeners.put(model, listener);\r
+               }\r
        }\r
        \r
-       private void updateDatasets(final Resource[] resources, final Resource runtime) {\r
-               Session session = SimanticsUI.peekSession();\r
-               if (session == null)\r
-                       return;\r
-\r
-               session.asyncRequest(new ReadRequest() {\r
-                       @Override\r
-                       public void run(ReadGraph g) throws DatabaseException {\r
-                               ArrayList<SysdynDataSet> datasets = new ArrayList<SysdynDataSet>();\r
-                               for(Resource resource : resources) {\r
-                                       Variable variable = getVariable(g, resource, runtime);\r
-                                       if(variable == null) continue;\r
-                                       Collection<SysdynDataSet> activeDataSets = loadAllActive(g, Variables.getRVI(g, variable).substring(1), getSysdynModel(g, Variables.getModel(g, variable)));\r
-                                       if(activeDataSets != null && !activeDataSets.isEmpty())\r
-                                               datasets.addAll(activeDataSets);\r
-                               }\r
-                               selectionChanged(datasets);\r
-                       }\r
-               });\r
+       private void updateDatasets(ReadGraph graph, Collection<Variable> variables) throws DatabaseException {\r
+\r
+               ArrayList<SysdynDataSet> datasets = new ArrayList<SysdynDataSet>();\r
+               for(Variable variable : variables) {\r
+                       String rvi = Variables.getRVI(graph, variable);\r
+                       rvi = rvi.length() > 0 ? rvi.substring(1) : rvi;\r
+                       Resource model = Variables.getModel(graph, variable);\r
+                       Collection<SysdynDataSet> activeDataSets = loadAllActive(graph, rvi, getSysdynModel(graph, model));\r
+                       if(activeDataSets != null && !activeDataSets.isEmpty())\r
+                               datasets.addAll(activeDataSets);\r
+               }\r
+               selectionChanged(datasets);\r
 \r
        }\r
 \r
-       private void updateDatasets(final BrowserSelection[] browserSelections) {\r
-               Session session = SimanticsUI.peekSession();\r
-               if (session == null)\r
-                       return;\r
-\r
-               session.asyncRequest(new ReadRequest() {\r
-                       @Override\r
-                       public void run(ReadGraph g) throws DatabaseException {\r
-                               ArrayList<SysdynDataSet> datasets = new ArrayList<SysdynDataSet>();\r
-                               for(BrowserSelection bs : browserSelections) {\r
-                                       if(bs.getURI() != null && bs.getModel() != null) {\r
-                                               Collection<SysdynDataSet> activeDataSets = loadAllActive(g, bs.getURI(), getSysdynModel(g, bs.getModel()));\r
-                                               if(activeDataSets != null && !activeDataSets.isEmpty()) \r
-                                                       datasets.addAll(activeDataSets);\r
-                                       }\r
-\r
-                               }\r
-                               selectionChanged(datasets);\r
-                       }\r
-               });\r
-       }\r
 \r
        protected Collection<SysdynDataSet> loadAllActive(ReadGraph g, String rvi, SysdynModel model) throws DatabaseException {\r
                ArrayList<SysdynDataSet> dataSets = new ArrayList<SysdynDataSet>();\r
index be414d9e6a7403940a86443809634be034f0ac1b..2212b1eb157b0ffbbb3eaf25e0575761765a1b0d 100644 (file)
@@ -53,7 +53,11 @@ public class StockExpression extends Expression {
                range = sb.toString();\r
        }\r
         \r
-        String each = variable.getArrayIndexes().getEnumerations().isEmpty() ? "" : "each";\r
+        String each = "";\r
+        if( variable.getArrayIndexes() == null ||variable.getArrayIndexes().getEnumerations().isEmpty())\r
+               each = "";\r
+        else \r
+               each =  "each";\r
         if (value == null) {\r
             return "    " + variable.getType() + " " + variable.getName() + range + "(" + each + " fixed=false);\n";\r
         } else {\r