package org.simantics.sysdyn.ui.properties;\r
\r
-import java.util.ArrayList;\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.jface.viewers.ISelectionProvider;\r
+import org.eclipse.jface.viewers.IStructuredSelection;\r
import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.custom.TableEditor;\r
-import org.eclipse.swt.events.FocusAdapter;\r
-import org.eclipse.swt.events.FocusEvent;\r
-import org.eclipse.swt.events.ModifyEvent;\r
-import org.eclipse.swt.events.ModifyListener;\r
-import org.eclipse.swt.events.SelectionAdapter;\r
import org.eclipse.swt.events.SelectionEvent;\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.TableItem;\r
-import org.eclipse.swt.widgets.Text;\r
+import org.eclipse.swt.widgets.Tree;\r
import org.eclipse.ui.IWorkbenchSite;\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.GraphExplorerComposite;\r
import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
import org.simantics.browsing.ui.swt.widgets.Table;\r
import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
-import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\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.sysdyn.ui.properties.widgets.factories.VariableNamePropertyModifier;\r
import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNameValidator;\r
import org.simantics.ui.SimanticsUI;\r
-import org.simantics.utils.datastructures.Pair;\r
+import org.simantics.ui.utils.AdaptionUtils;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
import org.simantics.utils.ui.ISelectionUtils;\r
\r
public class EnumerationTab extends PropertyTabContributorImpl {\r
\r
+ GraphExplorerComposite indexExplorer;\r
+\r
+ \r
Table table;\r
@Override\r
public void createControls(Composite body, IWorkbenchSite site,\r
GridDataFactory.fillDefaults().grab(true, false).span(2,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
+ \r
+ indexExplorer\r
+ .setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/EnumerationIndexes");\r
+ indexExplorer.setInputSource(new SingleSelectionInputSource(\r
+ Resource.class));\r
+\r
+ indexExplorer.finish();\r
+\r
+ GridDataFactory.fillDefaults().grab(true, true).span(2, 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
}\r
});\r
\r
+ \r
+ \r
+ \r
+ */\r
+ \r
\r
Button add = new Button(container, support, SWT.None);\r
add.setText("Add index");\r
\r
@Override\r
public void widgetSelected(SelectionEvent e) {\r
- TableItem[] items = table.getWidget().getSelection();\r
- final ArrayList<Resource> resources = new ArrayList<Resource>();\r
- for(int i = 0; i < items.length; i++) {\r
- if(items[i].getData() instanceof Resource)\r
- resources.add((Resource)items[i].getData());\r
- }\r
+ ISelectionProvider selectionProvider = (ISelectionProvider)indexExplorer.getAdapter(ISelectionProvider.class);\r
+ final IStructuredSelection selection = (IStructuredSelection)selectionProvider.getSelection();\r
+\r
try {\r
SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
\r
@Override\r
public void perform(WriteGraph graph) throws DatabaseException {\r
- for(Resource r : resources)\r
+ for(Object o : selection.toList()) {\r
+ Resource r = AdaptionUtils.adaptToSingle(o, Resource.class);\r
+ if(r == null)\r
+ continue;\r
OrderedSetUtils.remove(graph, enumerationIndexes, r);\r
+ }\r
}\r
});\r
} catch (DatabaseException e1) {\r
e1.printStackTrace();\r
}\r
+ \r
\r
}\r
\r
--- /dev/null
+package org.simantics.sysdyn.ui.properties.widgets.arrays;\r
+\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.common.node.IModifiableNode;\r
+import org.simantics.browsing.ui.content.Labeler.Modifier;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.ui.utils.VariableNameUtils;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+public class EnumerationIndexNode extends AbstractNode<Resource> implements IModifiableNode {\r
+\r
+ public EnumerationIndexNode(Resource resource) {\r
+ super(resource);\r
+ }\r
+ \r
+ @Override\r
+ public Modifier getModifier(String columnId) {\r
+ Modifier modifier = new Modifier() {\r
+\r
+ @Override\r
+ public String getValue() {\r
+ Read<String> request =\r
+ new Read<String>() {\r
+\r
+ @Override\r
+ public String perform(ReadGraph graph) throws DatabaseException {\r
+ String name = graph.getPossibleRelatedValue(data, Layer0.getInstance(graph).HasName);\r
+ return name != null ? name : "";\r
+ }\r
+\r
+ };\r
+ try {\r
+ return SimanticsUI.getSession().syncRequest(request);\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ return "";\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public String isValid(String label) {\r
+ if(!VariableNameUtils.isValid(label))\r
+ return "Not valid";\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public void modify(final String label) {\r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ graph.claimLiteral(data, Layer0.getInstance(graph).HasName, label);\r
+ }\r
+ });\r
+ }\r
+\r
+ };\r
+ \r
+ return modifier;\r
+ \r
+ \r
+ \r
+ \r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.properties.widgets.arrays;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.graph.impl.contributor.viewpoint.ViewpointContributorImpl;\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.sysdyn.SysdynResource;\r
+\r
+public class EnumerationIndexes extends ViewpointContributorImpl<Resource> {\r
+\r
+ @Override\r
+ public Collection<?> getContribution(ReadGraph graph, Resource input)\r
+ throws DatabaseException {\r
+ if(input == null) \r
+ return null;\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ if(!graph.isInstanceOf(input, sr.Enumeration))\r
+ return null;\r
+ Resource enumerationIndexList = graph.getPossibleObject(input, sr.HasEnumerationIndexes);\r
+ if(enumerationIndexList == null)\r
+ return null;\r
+ ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
+ for(Resource r : OrderedSetUtils.toList(graph, enumerationIndexList)) {\r
+ result.add(new EnumerationIndexNode(r));\r
+ }\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public String getViewpointId() {\r
+ return "Enumeration indexes";\r
+ }\r
+\r
+\r
+}\r