]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Enumeration tab updated to use graph explorer
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 14 Dec 2010 13:04:22 +0000 (13:04 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 14 Dec 2010 13:04:22 +0000 (13:04 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@19150 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexLabeler.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexNode.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexes.java [new file with mode: 0644]

index c911739908aeac56f548acd47f20c10ddb8793df..af4921f503881bee15dd3b51a6ecfeea8a0dd677 100644 (file)
             id="org.simantics.sysdyn.ui.category"\r
             name="System Dynamics">\r
       </category>\r
-      <view\r
-            category="org.simantics.sysdyn.ui.category"\r
-            class="org.simantics.sysdyn.ui.equation.EquationView"\r
-            id="org.simantics.sysdyn.ui.equation.view"\r
-            name="Equation View"\r
-            restorable="true">\r
-      </view>\r
       <view\r
             allowMultiple="true"\r
             category="org.simantics.sysdyn.ui.category"\r
                preference="2.0">\r
          </implementation>\r
       </binding>\r
+      <binding\r
+            browseContext="http://www.simantics.org/Sysdyn-1.0/EnumerationIndexes">\r
+         <implementation\r
+               class="org.simantics.sysdyn.ui.properties.widgets.arrays.EnumerationIndexes"\r
+               preference="2.0">\r
+         </implementation>\r
+      </binding>\r
    </extension>\r
    <extension\r
          point="org.simantics.browsing.ui.common.labelerBinding">\r
                preference="2.0">\r
          </implementation>\r
       </binding>\r
+      <binding\r
+            browseContext="http://www.simantics.org/Sysdyn-1.0/EnumerationIndexes">\r
+         <implementation\r
+               class="org.simantics.sysdyn.ui.properties.widgets.arrays.EnumerationIndexLabeler"\r
+               preference="2.0">\r
+         </implementation>\r
+      </binding>\r
    </extension>\r
    <extension\r
          point="org.simantics.browsing.ui.common.imagerBinding">\r
index 0e43aba7758fcbc7f866d32dd7ced149b7040a57..d006e9c265b8b6fb9b728770e8c9f9b4cea17919 100644 (file)
@@ -1,34 +1,26 @@
 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
@@ -44,11 +36,15 @@ import org.simantics.sysdyn.SysdynResource;
 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
@@ -65,6 +61,29 @@ public class EnumerationTab extends PropertyTabContributorImpl {
         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
@@ -161,6 +180,11 @@ public class EnumerationTab extends PropertyTabContributorImpl {
                        }\r
                });\r
 \r
+               \r
+               \r
+               \r
+               */\r
+               \r
 \r
                Button add = new Button(container, support, SWT.None);\r
                add.setText("Add index");\r
@@ -251,24 +275,26 @@ public class EnumerationTab extends PropertyTabContributorImpl {
 \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
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexLabeler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexLabeler.java
new file mode 100644 (file)
index 0000000..a740831
--- /dev/null
@@ -0,0 +1,20 @@
+package org.simantics.sysdyn.ui.properties.widgets.arrays;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+\r
+public class EnumerationIndexLabeler  extends LabelerContributor<EnumerationIndexNode>{\r
+\r
+    @Override\r
+    public String getLabel(ReadGraph graph, EnumerationIndexNode index) throws DatabaseException {\r
+       Resource r = index.data;\r
+       if(r == null) return "Null resource";\r
+       String name = graph.getPossibleRelatedValue(r, Layer0.getInstance(graph).HasName);\r
+        return name == null ? "No name" : name;\r
+    }\r
+\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexNode.java
new file mode 100644 (file)
index 0000000..94909cd
--- /dev/null
@@ -0,0 +1,72 @@
+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
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexes.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexes.java
new file mode 100644 (file)
index 0000000..fcf13e9
--- /dev/null
@@ -0,0 +1,40 @@
+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