package org.simantics.sysdyn.ui.properties;\r
\r
+import java.util.List;\r
+\r
import org.eclipse.jface.layout.GridDataFactory;\r
import org.eclipse.jface.layout.GridLayoutFactory;\r
import org.eclipse.jface.viewers.ISelection;\r
import org.eclipse.swt.events.SelectionListener;\r
import org.eclipse.swt.widgets.Composite;\r
import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.swt.widgets.Event;\r
+import org.eclipse.swt.widgets.Listener;\r
import org.eclipse.swt.widgets.Tree;\r
+import org.eclipse.swt.widgets.TreeItem;\r
import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.browsing.ui.NodeContext;\r
import org.simantics.browsing.ui.swt.PropertyTabContributorImpl;\r
import org.simantics.browsing.ui.swt.SingleSelectionInputSource;\r
import org.simantics.browsing.ui.swt.widgets.Button;\r
import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.databoard.Bindings;\r
import org.simantics.db.Builtins;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.common.utils.OrderedSetUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.management.ISessionContext;\r
+import org.simantics.db.request.Read;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.manager.SysdynModel;\r
+import org.simantics.sysdyn.manager.SysdynModelManager;\r
+import org.simantics.sysdyn.ui.properties.widgets.arrays.EnumerationIndexNode;\r
import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNamePropertyModifier;\r
import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNameValidator;\r
import org.simantics.ui.SimanticsUI;\r
public class EnumerationTab extends PropertyTabContributorImpl {\r
\r
GraphExplorerComposite indexExplorer;\r
+ \r
+ Button showAll;\r
\r
\r
Table table;\r
\r
Composite container = new Composite(body, SWT.None);\r
GridDataFactory.fillDefaults().grab(true, true).applyTo(container);\r
- GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(container);\r
+ GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(3).applyTo(container);\r
\r
TrackedText nameText = new TrackedText(container, support, SWT.BORDER);\r
nameText.setTextFactory(new StringPropertyFactory(Builtins.URIs.HasName));\r
nameText.addModifyListener(new VariableNamePropertyModifier(context, Builtins.URIs.HasName));\r
nameText.setInputValidator(new VariableNameValidator(support));\r
- GridDataFactory.fillDefaults().grab(true, false).span(2,1).applyTo(nameText.getWidget());\r
+ GridDataFactory.fillDefaults().grab(true, false).span(3,1).applyTo(nameText.getWidget());\r
\r
\r
\r
\r
indexExplorer = new GraphExplorerComposite(ArrayMap.keys(\r
- "displaySelectors", "displayFilter").values(false, false), site, container, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI);\r
+ "displaySelectors", "displayFilter").values(false, false), site, container, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI | SWT.CHECK);\r
\r
indexExplorer\r
.setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/EnumerationIndexes");\r
indexExplorer.setInputSource(new SingleSelectionInputSource(\r
Resource.class));\r
+ ((Tree)indexExplorer.getExplorerControl()).addListener(SWT.Selection, new Listener () {\r
+ \r
+ @Override\r
+ public void handleEvent (Event event) {\r
+ if(event.detail == SWT.CHECK) {\r
+ final TreeItem item = (TreeItem)event.item;\r
+ final boolean checked = item.getChecked();\r
+ NodeContext context = (NodeContext)item.getData();\r
+ final EnumerationIndexNode node = (EnumerationIndexNode) context.getAdapter(EnumerationIndexNode.class);\r
+ node.setShowInChartsSelected(checked);\r
+ \r
+ SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+ @Override\r
+ public void run(ReadGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ Resource enumeration = (Resource)indexExplorer.getExplorer().getRoot().getAdapter(Resource.class);\r
+ Resource configuration = graph.getSingleObject(enumeration, l0.PartOf);\r
+ SysdynModel model = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration);\r
+ // update results in graphs\r
+ model.resultChanged();\r
+ }\r
+ });\r
+ }\r
+ }\r
+ });\r
+ \r
\r
indexExplorer.finish();\r
\r
- GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(\r
+ GridDataFactory.fillDefaults().grab(true, true).span(3, 1).applyTo(\r
indexExplorer);\r
\r
Control c = indexExplorer.getExplorerControl();\r
if (c instanceof Tree)\r
((Tree) c).setLinesVisible(true);\r
- \r
- \r
- /*\r
- \r
- \r
- table = new Table(container, support, SWT.BORDER);\r
- table.setItemFactory(new ReadFactoryImpl<Object, List<Pair<String,Object>>>() {\r
\r
- @Override\r
- public List<Pair<String, Object>> perform(ReadGraph graph,\r
- Object input) throws DatabaseException {\r
- Resource enumeration = (Resource)input;\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- Resource list = graph.getSingleObject(enumeration, sr.HasEnumerationIndexes);\r
- List<Resource> resourceList = OrderedSetUtils.toList(graph, list);\r
-\r
- List<Pair<String, Object>> result = new ArrayList<Pair<String, Object>>();\r
- for(Resource r : resourceList) {\r
- result.add(new Pair<String, Object>( \r
- (String)graph.getRelatedValue(r, Layer0.getInstance(graph).HasName, Bindings.STRING)\r
- , r));\r
- }\r
- return result;\r
- }\r
- });\r
- table.setSelectionFactory(new ReadFactoryImpl<Resource, String>() {\r
-\r
- @Override\r
- public String perform(ReadGraph graph, final Resource input) throws DatabaseException {\r
- return graph.getRelatedValue(input, Layer0.getInstance(graph).HasName);\r
- }\r
- });\r
- GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(table.getWidget());\r
- \r
-\r
- final TableEditor editor = new TableEditor(table.getWidget());\r
- // The editor must have the same size as the cell and must\r
- // not be any smaller than 50 pixels.\r
- editor.horizontalAlignment = SWT.LEFT;\r
- editor.grabHorizontal = true;\r
- editor.minimumWidth = 50;\r
- // editing the second column\r
- final int EDITABLECOLUMN = 0;\r
-\r
- table.addSelectionListener(new SelectionAdapter() {\r
- public void widgetSelected(SelectionEvent e) {\r
- // Clean up any previous editor control\r
- Control oldEditor = editor.getEditor();\r
- if (oldEditor != null)\r
- oldEditor.dispose();\r
-\r
- // Identify the selected row\r
- final TableItem item = (TableItem) e.item;\r
- if (item == null)\r
- return;\r
-\r
- // The control that will be the editor must be a child of the\r
- // Table\r
- Text newEditor = new Text(item.getParent(), SWT.NONE);\r
- final String originalText = item.getText(EDITABLECOLUMN);\r
- final Resource resource = (Resource) item.getData();\r
- newEditor.setText(originalText);\r
- newEditor.addModifyListener(new ModifyListener() {\r
- public void modifyText(ModifyEvent me) {\r
- Text text = (Text) editor.getEditor();\r
- if(!text.isDisposed()) {\r
- TableItem item = editor.getItem();\r
- if(!item.isDisposed())\r
- item.setText(EDITABLECOLUMN, text.getText());\r
- }\r
- }\r
- });\r
- newEditor.addFocusListener(new FocusAdapter() {\r
- @Override\r
- public void focusLost(FocusEvent e) {\r
- final Text text = (Text) editor.getEditor();\r
- if(!text.getText().equals(originalText)) {\r
- final String newText = text.getText();\r
- try {\r
- context.getSession().syncRequest(new WriteRequest() {\r
-\r
- @Override\r
- public void perform(WriteGraph graph) throws DatabaseException {\r
- graph.claimLiteral(\r
- resource, \r
- Layer0.getInstance(graph).HasName, \r
- newText);\r
- }\r
- });\r
- } catch (DatabaseException e1) {\r
- e1.printStackTrace();\r
- }\r
- }\r
- }\r
- });\r
- newEditor.selectAll();\r
- newEditor.setFocus();\r
- editor.setEditor(newEditor, item, EDITABLECOLUMN);\r
- }\r
- });\r
-\r
- \r
- \r
- \r
- */\r
- \r
\r
Button add = new Button(container, support, SWT.None);\r
- add.setText("Add index");\r
+ add.setText("Add");\r
add.addSelectionListener(new addEnumerationIndexListener(support));\r
\r
Button remove = new Button(container, support, SWT.None);\r
remove.setText("Remove");\r
remove.addSelectionListener(new removeEnumerationIndexListener(support));\r
+ \r
+ showAll = new Button(container, support, SWT.CHECK);\r
+ showAll.setText("Show all in charts");\r
+ showAll.addSelectionListener(new ShowAllIndexesListener(support));\r
}\r
\r
private class addEnumerationIndexListener implements SelectionListener, Widget {\r
}\r
\r
}\r
+ \r
+ private class ShowAllIndexesListener implements SelectionListener, Widget {\r
+\r
+ Resource enumerationIndexes;\r
+\r
+ public ShowAllIndexesListener(WidgetSupport support) {\r
+ support.register(this);\r
+ }\r
+\r
+ @Override\r
+ public void setInput(ISessionContext context, Object input) {\r
+ final Resource enumeration = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class);\r
+ \r
+ context.getSession().asyncRequest(new Read<Boolean>() {\r
+\r
+ @Override\r
+ public Boolean perform(ReadGraph graph)\r
+ throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ enumerationIndexes = graph.getSingleObject(enumeration, sr.HasEnumerationIndexes);\r
+ List<Resource> indexes = OrderedSetUtils.toList(graph, enumerationIndexes);\r
+ for(Resource index : indexes) {\r
+ Boolean show = graph.getPossibleRelatedValue(index, sr.ShowEnumerationIndexInCharts, Bindings.BOOLEAN);\r
+ if(!Boolean.TRUE.equals(show))\r
+ return false;\r
+ }\r
+ return true;\r
+ }\r
+ \r
+ }, new org.simantics.db.procedure.Listener<Boolean>() {\r
+\r
+ @Override\r
+ public void execute(final Boolean result) {\r
+ showAll.getWidget().getDisplay().asyncExec(new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+ showAll.getWidget().setSelection(result.booleanValue());\r
+ }\r
+ });\r
+ }\r
+ \r
+\r
+ @Override\r
+ public void exception(Throwable t) {\r
+ t.printStackTrace();\r
+ }\r
+\r
+ @Override\r
+ public boolean isDisposed() {\r
+ if(showAll == null)\r
+ return true;\r
+ return showAll.getWidget().isDisposed();\r
+ }\r
+ });\r
+ \r
+ }\r
+\r
+ @Override\r
+ public void widgetSelected(SelectionEvent e) {\r
+ final boolean selected = showAll.getWidget().getSelection();\r
+ try {\r
+ SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ List<Resource> indexes = OrderedSetUtils.toList(graph, enumerationIndexes);\r
+ for(Resource index : indexes) {\r
+ Boolean show = graph.getPossibleRelatedValue(index, sr.ShowEnumerationIndexInCharts, Bindings.BOOLEAN);\r
+ if(selected && !Boolean.TRUE.equals(show)) {\r
+ graph.claimLiteral(index, sr.ShowEnumerationIndexInCharts, true, Bindings.BOOLEAN);\r
+ } else if(!selected && !Boolean.FALSE.equals(show)) {\r
+ graph.claimLiteral(index, sr.ShowEnumerationIndexInCharts, false, Bindings.BOOLEAN);\r
+ }\r
+ }\r
+ \r
+ Resource enumeration = graph.getSingleObject(enumerationIndexes, sr.HasEnumerationIndexes_Inverse);\r
+ Resource configuration = graph.getSingleObject(enumeration, Layer0.getInstance(graph).PartOf);\r
+ SysdynModel model = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration);\r
+ // update results in graphs\r
+ model.resultChanged();\r
+\r
+ }\r
+ });\r
+ } catch (DatabaseException e1) {\r
+ e1.printStackTrace();\r
+ }\r
+ \r
+\r
+ }\r
+\r
+ @Override\r
+ public void widgetDefaultSelected(SelectionEvent e) {\r
+\r
+ }\r
+\r
+ }\r
}\r
import org.eclipse.jface.viewers.IStructuredSelection;\r
import org.eclipse.ui.ISelectionListener;\r
import org.eclipse.ui.IWorkbenchPart;\r
+import org.simantics.databoard.Bindings;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.Session;\r
import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.SelectionHints;\r
+import org.simantics.db.layer0.variable.RepresentsProperty;\r
import org.simantics.db.layer0.variable.Variable;\r
import org.simantics.db.layer0.variable.Variables;\r
import org.simantics.diagram.stubs.DiagramResource;\r
+import org.simantics.layer0.Layer0;\r
import org.simantics.modeling.ModelingUtils;\r
import org.simantics.simulation.ontology.SimulationResource;\r
import org.simantics.sysdyn.SysdynResource;\r
\r
protected Collection<SysdynDataSet> loadAllActive(ReadGraph g, Variable variable) throws DatabaseException {\r
ArrayList<SysdynDataSet> dataSets = new ArrayList<SysdynDataSet>();\r
-\r
+ HashMap<String, String> rvis = new HashMap<String, String>();\r
+ \r
String rvi = Variables.getRVI(g, variable);\r
if (rvi == null) \r
return dataSets;\r
rvi = rvi.length() > 0 ? rvi.substring(1) : rvi;\r
rvi = rvi.replace("/", ".");\r
\r
+ RepresentsProperty rp = (RepresentsProperty)variable.getProperty(g, Variables.REPRESENTS);\r
+ Resource r = rp.getValue(g);\r
+ \r
+ SysdynResource sr = SysdynResource.getInstance(g);\r
+ Resource arrayIndexes = g.getPossibleObject(r, sr.HasArrayIndexes);\r
+ if(arrayIndexes == null) {\r
+ rvis.put(rvi, rvi);\r
+ } else {\r
+ traverseIndexes(g, rvi, rvis, OrderedSetUtils.toList(g, arrayIndexes));\r
+ }\r
+ \r
Resource modelResource = Variables.getModel(g, variable);\r
SysdynModel model = getSysdynModel(g, modelResource);\r
\r
\r
Collection<SysdynResult> activeResults = model.getActiveResults(g);\r
for(SysdynResult sysdynResult : activeResults) {\r
- SysdynDataSet sds = sysdynResult.getDataSet(rvi);\r
- if(sds != null)\r
- dataSets.add(sds);\r
+ for(String currvi : rvis.keySet()) {\r
+ SysdynDataSet sds = sysdynResult.getDataSet(currvi);\r
+ if(sds != null) {\r
+ sds.name = rvis.get(currvi);\r
+ dataSets.add(sds);\r
+ }\r
+ }\r
}\r
return dataSets;\r
\r
}\r
\r
+ private void traverseIndexes(ReadGraph g, String rvi, HashMap<String, String> rvis, List<Resource> arrayIndexes) throws DatabaseException {\r
+ traverseIndexes(g, rvi, rvis, arrayIndexes, arrayIndexes.get(0), "", "");\r
+ }\r
+ \r
+ private void traverseIndexes(ReadGraph g, String rvi, HashMap<String, String> rvis, List<Resource> arrayIndexes, Resource currentEnumeration, String indexesSoFar, String indexNamesSoFar) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(g);\r
+ Resource enumerationIndexes = g.getPossibleObject(currentEnumeration, sr.HasEnumerationIndexes);\r
+ if(enumerationIndexes == null)\r
+ return;\r
+ List<Resource> indexes = OrderedSetUtils.toList(g, enumerationIndexes);\r
+ for(int i = 0; i < indexes.size(); i++) {\r
+ Boolean b = g.getPossibleRelatedValue(indexes.get(i), sr.ShowEnumerationIndexInCharts, Bindings.BOOLEAN);\r
+ if(Boolean.TRUE.equals(b)) {\r
+ int arrayIndex = arrayIndexes.indexOf(currentEnumeration);\r
+ String name = g.getRelatedValue(indexes.get(i), Layer0.getInstance(g).HasName);\r
+ if(arrayIndex < arrayIndexes.size() - 1)\r
+ traverseIndexes(g, rvi, rvis, arrayIndexes, arrayIndexes.get(arrayIndex + 1), \r
+ indexesSoFar + (i + 1) +",", indexNamesSoFar + (name) +",");\r
+ else {\r
+ rvis.put(\r
+ rvi + "[" + indexesSoFar + (i + 1) + "]", \r
+ rvi + "[" + indexNamesSoFar + (name) + "]");\r
+ }\r
+ }\r
+ }\r
+ }\r
+ \r
private Variable getVariable(ReadGraph g, Resource element, Resource runtime) throws DatabaseException {\r
SysdynResource sr = SysdynResource.getInstance(g);\r
DiagramResource dr = DiagramResource.getInstance(g);\r