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
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
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