]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Enumeration definition to multiple variables at the same time (fixes #2921)
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 21 Nov 2012 09:05:54 +0000 (09:05 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 21 Nov 2012 09:05:54 +0000 (09:05 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26380 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayIndexesTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/AvailableEnumerations.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ConflictingEnumerationLabeler.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ConflictingEnumerationNode.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/UsedEnumerations.java

index 5fe8735b05942c317128b94fb0c0192272ca1414..ba2cf75452e34b4a8b06a621aca26829f7737b14 100644 (file)
                class="org.simantics.sysdyn.ui.properties.widgets.arrays.EnumerationLabeler"\r
                preference="2.0">\r
          </implementation>\r
+         <implementation\r
+               class="org.simantics.sysdyn.ui.properties.widgets.arrays.ConflictingEnumerationLabeler"\r
+               preference="2.0">\r
+         </implementation>\r
       </binding>\r
       <binding\r
             browseContext="http://www.simantics.org/Sysdyn-0.0/EnumerationIndexes">\r
index 004b8c1df44d9b4ce452eeae269975ae6d2f9145..964a141722f2ee11692a952692a56a38278ae67c 100644 (file)
@@ -1,45 +1,61 @@
 package org.simantics.sysdyn.ui.properties;\r
 \r
 import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.Collections;\r
+import java.util.HashSet;\r
 import java.util.List;\r
+import java.util.Set;\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.jface.viewers.StructuredSelection;\r
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Control;\r
 import org.eclipse.swt.widgets.Label;\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.swt.AdaptableHintContext;\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.impl.ReadFactoryImpl;\r
 import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;\r
 import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl;\r
+import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.ResourceArray;\r
+import org.simantics.db.common.utils.NameUtils;\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.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys;\r
+import org.simantics.utils.RunnableWithObject;\r
 import org.simantics.utils.datastructures.ArrayMap;\r
 \r
 public class ArrayIndexesTab extends LabelPropertyTabContributor implements Widget{\r
 \r
        GraphExplorerComposite availableEnumerationsExplorer;\r
        GraphExplorerComposite usedEnumerationsExplorer;\r
+       private WidgetSupportImpl buttonSupport;\r
+       private org.simantics.browsing.ui.swt.widgets.Label usedEnumerationsLabel;\r
        \r
        @Override\r
        public void createControls(Composite body, IWorkbenchSite site,\r
                        ISessionContext context, WidgetSupport support) {\r
                support.register(this);\r
                \r
+               buttonSupport = new WidgetSupportImpl();\r
+               \r
                GridLayoutFactory.fillDefaults().numColumns(4).applyTo(body);\r
                \r
                \r
@@ -55,7 +71,7 @@ public class ArrayIndexesTab extends LabelPropertyTabContributor implements Widg
                .setBrowseContexts(SysdynResource.URIs.AvailableVariableIndexes);\r
                availableEnumerationsExplorer.setColumns(ColumnKeys.ENUMERATION_TABLE_COLUMNS);\r
                availableEnumerationsExplorer.setInputSource(new SingleSelectionInputSource(\r
-                               Resource.class));\r
+                               ResourceArray.class));\r
 \r
                availableEnumerationsExplorer.finish();\r
 \r
@@ -67,10 +83,10 @@ public class ArrayIndexesTab extends LabelPropertyTabContributor implements Widg
                        ((Tree) c).setLinesVisible(true);\r
                \r
                \r
-               Button add = new Button(body, support, SWT.NONE);\r
+               Button add = new Button(body, buttonSupport, SWT.NONE);\r
                add.setText(" -> ");\r
                \r
-               add.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+               add.addSelectionListener(new SelectionListenerImpl<ResourceArray>(context) {\r
 \r
             List<Resource> enumerationResources;\r
 \r
@@ -80,32 +96,56 @@ public class ArrayIndexesTab extends LabelPropertyTabContributor implements Widg
             }\r
 \r
                        @Override\r
-                       public void apply(WriteGraph graph, Resource input)\r
+                       public void apply(WriteGraph graph, ResourceArray input)\r
                                        throws DatabaseException {\r
                                SysdynResource sr = SysdynResource.getInstance(graph);\r
-                               Resource arrayIndexes = graph.getPossibleObject(input, sr.Variable_arrayIndexes);\r
-                               if(arrayIndexes == null) {\r
-                                       arrayIndexes = OrderedSetUtils.create(graph, sr.ArrayIndexes);\r
-                                       graph.claim(input, sr.Variable_arrayIndexes, arrayIndexes);\r
+                               for(Resource r : input.resources) {\r
+                                   Resource arrayIndexes = graph.getPossibleObject(r, sr.Variable_arrayIndexes);\r
+                                   if(arrayIndexes == null) {\r
+                                       arrayIndexes = OrderedSetUtils.create(graph, sr.ArrayIndexes);\r
+                                       graph.claim(r, sr.Variable_arrayIndexes, arrayIndexes);\r
+                                   }\r
+                                   OrderedSetUtils.addAll(graph, arrayIndexes, enumerationResources);\r
                                }\r
-                               OrderedSetUtils.addAll(graph, arrayIndexes, enumerationResources);\r
                        }\r
                });\r
                \r
                Composite used = new Composite(body, SWT.NONE);\r
                GridLayoutFactory.fillDefaults().applyTo(used);\r
                GridDataFactory.fillDefaults().grab(true, true).applyTo(used);\r
-               label = new Label(used, SWT.None);\r
-               label.setText("Used Enumerations");\r
+               usedEnumerationsLabel = new org.simantics.browsing.ui.swt.widgets.Label(used, buttonSupport, SWT.None);\r
+               usedEnumerationsLabel.setTextFactory(new ReadFactoryImpl<ResourceArray, String>() {\r
+\r
+            @Override\r
+            public String perform(ReadGraph graph, ResourceArray input) throws DatabaseException {\r
+                if(input.size() < 2)\r
+                    return "Used Enumerations";\r
+                else {\r
+                    StringBuilder sb = new StringBuilder();\r
+                    sb.append("Enumerations in: ");\r
+                    boolean first = true;\r
+                    for(Resource r : input) {\r
+                        if(!first)\r
+                            sb.append(", ");\r
+                        first = false;\r
+                        \r
+                        String name = NameUtils.getSafeName(graph, r);\r
+                        sb.append(name);\r
+                    }\r
+                    return sb.toString();\r
+                }\r
+            }\r
+\r
+        });\r
                \r
                usedEnumerationsExplorer = new GraphExplorerComposite(ArrayMap.keys(\r
-                               "displaySelectors", "displayFilter").values(false, false), site, used, SWT.FULL_SELECTION | SWT.BORDER);\r
+                               "displaySelectors", "displayFilter").values(false, false), site, used, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI);\r
                \r
                usedEnumerationsExplorer\r
                .setBrowseContexts(SysdynResource.URIs.UsedVariableIndexes);\r
                usedEnumerationsExplorer.setColumns(ColumnKeys.ENUMERATION_TABLE_COLUMNS);\r
                usedEnumerationsExplorer.setInputSource(new SingleSelectionInputSource(\r
-                               Resource.class));\r
+                               ResourceArray.class));\r
 \r
                usedEnumerationsExplorer.finish();\r
 \r
@@ -119,90 +159,179 @@ public class ArrayIndexesTab extends LabelPropertyTabContributor implements Widg
                Composite buttons = new Composite(body, SWT.None);\r
                GridLayoutFactory.fillDefaults().applyTo(buttons);\r
                \r
-               Button up = new Button(buttons, support, SWT.NONE);\r
+               Button up = new Button(buttons, buttonSupport, SWT.NONE);\r
                up.setText("Up");\r
-               up.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+               up.addSelectionListener(new SelectionListenerImpl<ResourceArray>(context) {\r
 \r
-                   List<Resource> enumerationResources;\r
+            List<Integer> selectedIndexes;\r
 \r
                    @Override\r
                    public void beforeApply() {\r
-                       enumerationResources = getSelectedResources(usedEnumerationsExplorer);\r
+                selectedIndexes = getSelectedIndexes(usedEnumerationsExplorer);\r
                    }\r
 \r
                    @Override\r
-                   public void apply(WriteGraph graph, Resource input)\r
+                   public void apply(WriteGraph graph, ResourceArray input)\r
                            throws DatabaseException {\r
-                       if(enumerationResources != null && enumerationResources.size() == 1) {\r
-                           SysdynResource sr = SysdynResource.getInstance(graph);\r
-                           Resource arrayIndexes = graph.getPossibleObject(input, sr.Variable_arrayIndexes);\r
-                           if(arrayIndexes == null)\r
-                               return;\r
-\r
-                           Resource enumeration = enumerationResources.get(0);\r
-                           Resource prev = OrderedSetUtils.prev(graph, arrayIndexes, enumeration);\r
-                           if(prev.equals(arrayIndexes))\r
-                               return;\r
-\r
-                           OrderedSetUtils.remove(graph, arrayIndexes, enumeration);\r
-                           OrderedSetUtils.addBefore(graph, arrayIndexes, prev, enumeration);\r
-                       }\r
+                       \r
+                       \r
+                       SysdynResource sr = SysdynResource.getInstance(graph);\r
+\r
+                for(Resource variable : input) {\r
+                    Resource arrayIndexes = graph.getPossibleObject(variable, sr.Variable_arrayIndexes);\r
+                    if(arrayIndexes != null) {\r
+                        List<Resource> enumerations = OrderedSetUtils.toList(graph, arrayIndexes);\r
+                        List<Resource> toBeMoved = new ArrayList<Resource>();\r
+                        for(Integer index : selectedIndexes) {\r
+                            if(index < enumerations.size()) {\r
+                                Resource enumeration = enumerations.get(index);\r
+                                toBeMoved.add(enumeration);\r
+                            }\r
+\r
+                        }\r
+\r
+                        for(Resource enumeration : toBeMoved) {\r
+                            Resource prev = OrderedSetUtils.prev(graph, arrayIndexes, enumeration);\r
+                            if(!prev.equals(arrayIndexes) && !toBeMoved.contains(prev)) {\r
+                                OrderedSetUtils.remove(graph, arrayIndexes, enumeration);\r
+                                OrderedSetUtils.addBefore(graph, arrayIndexes, prev, enumeration);\r
+                            }\r
+                        }\r
+                    }\r
+                }\r
+                \r
+                // Move selection\r
+                usedEnumerationsExplorer.getDisplay().asyncExec(new RunnableWithObject(usedEnumerationsExplorer, selectedIndexes) {\r
+                    @Override\r
+                    public void run() {\r
+                        Control c = ((GraphExplorerComposite)object).getExplorerControl();\r
+                        if(c != null && c instanceof Tree && object2 instanceof List<?>) {\r
+                            Tree tree = (Tree) c;\r
+                            tree.deselectAll();\r
+                            \r
+                            @SuppressWarnings("unchecked")\r
+                            List<Integer> list = (List<Integer>) object2;\r
+                            Set<TreeItem> selection = new HashSet<TreeItem>();\r
+                            for(Integer i : list) {\r
+                                TreeItem item = null;\r
+                                if(i - 1 >= 0)\r
+                                    item = tree.getItem(i - 1);\r
+                                if(item == null || selection.contains(item))\r
+                                    item = tree.getItem(i);\r
+                                if(item != null && !selection.contains(item))\r
+                                    selection.add(item);\r
+                            }\r
+                            tree.setSelection(selection.toArray(new TreeItem[selection.size()]));\r
+                        }\r
+                    }\r
+                });\r
                    }\r
                });\r
 \r
-               Button down = new Button(buttons, support, SWT.NONE);\r
+               Button down = new Button(buttons, buttonSupport, SWT.NONE);\r
                down.setText("Down");\r
-               down.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+               down.addSelectionListener(new SelectionListenerImpl<ResourceArray>(context) {\r
 \r
-                   List<Resource> enumerationResources;\r
+                   List<Integer> selectedIndexes;\r
 \r
                    @Override\r
                    public void beforeApply() {\r
-                       enumerationResources = getSelectedResources(usedEnumerationsExplorer);\r
+                       selectedIndexes = getSelectedIndexes(usedEnumerationsExplorer);\r
                    }\r
 \r
 \r
                    @Override\r
-                   public void apply(WriteGraph graph, Resource input)\r
+                   public void apply(WriteGraph graph, ResourceArray input)\r
                            throws DatabaseException {\r
-                       if(enumerationResources != null && enumerationResources.size() == 1) {\r
-                           SysdynResource sr = SysdynResource.getInstance(graph);\r
-                           Resource arrayIndexes = graph.getPossibleObject(input, sr.Variable_arrayIndexes);\r
-                           if(arrayIndexes == null)\r
-                               return;\r
-                           Resource enumeration = enumerationResources.get(0);\r
-                           Resource next = OrderedSetUtils.next(graph, arrayIndexes, enumeration);\r
-                           if(next.equals(arrayIndexes))\r
-                               return;\r
-                           OrderedSetUtils.remove(graph, arrayIndexes, enumeration);\r
-                           OrderedSetUtils.addAfter(graph, arrayIndexes, next, enumeration);\r
+\r
+\r
+                       SysdynResource sr = SysdynResource.getInstance(graph);\r
+\r
+                       for(Resource variable : input) {\r
+                           Resource arrayIndexes = graph.getPossibleObject(variable, sr.Variable_arrayIndexes);\r
+                           if(arrayIndexes != null) {\r
+                               List<Resource> enumerations = OrderedSetUtils.toList(graph, arrayIndexes);\r
+                               List<Resource> toBeMoved = new ArrayList<Resource>();\r
+                               for(Integer index : selectedIndexes) {\r
+                                   if(index < enumerations.size()) {\r
+                                       Resource enumeration = enumerations.get(index);\r
+                                       toBeMoved.add(0, enumeration); // Make an inverted list. \r
+                                   }\r
+\r
+                               }\r
+\r
+                               for(Resource enumeration : toBeMoved) {\r
+                                   Resource next = OrderedSetUtils.next(graph, arrayIndexes, enumeration);\r
+                                   if(!next.equals(arrayIndexes) && !toBeMoved.contains(next)) {\r
+                                       OrderedSetUtils.remove(graph, arrayIndexes, enumeration);\r
+                                       OrderedSetUtils.addAfter(graph, arrayIndexes, next, enumeration);\r
+                                   }\r
+                               }\r
+                           }\r
                        }\r
+                       \r
+                       // Move selection\r
+                       usedEnumerationsExplorer.getDisplay().asyncExec(new RunnableWithObject(usedEnumerationsExplorer, selectedIndexes) {\r
+                    @Override\r
+                           public void run() {\r
+                               Control c = ((GraphExplorerComposite)object).getExplorerControl();\r
+                               if(c != null && c instanceof Tree && object2 instanceof List<?>) {\r
+                                   Tree tree = (Tree) c;\r
+                                   tree.deselectAll();\r
+                                   \r
+                                   @SuppressWarnings("unchecked")\r
+                            List<Integer> list = (List<Integer>) object2;\r
+                                   Set<TreeItem> selection = new HashSet<TreeItem>();\r
+                                   Collections.reverse(list);\r
+                            for(Integer i : list) {\r
+                                TreeItem item = null;\r
+                                if(i + 1 < tree.getItemCount())\r
+                                    item = tree.getItem(i + 1);\r
+                                if(item == null || selection.contains(item))\r
+                                    item = tree.getItem(i);\r
+                                if(item != null && !selection.contains(item))\r
+                                    selection.add(item);\r
+                            }\r
+                                   tree.setSelection(selection.toArray(new TreeItem[selection.size()]));\r
+                               }\r
+                           }\r
+                       });\r
                    }\r
                });\r
 \r
                \r
-               Button remove = new Button(buttons, support, SWT.NONE);\r
+               Button remove = new Button(buttons, buttonSupport, SWT.NONE);\r
                remove.setText("Remove");\r
-               remove.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+               remove.addSelectionListener(new SelectionListenerImpl<ResourceArray>(context) {\r
                    \r
-                   List<Resource> enumerationResources;\r
+                   List<Integer> selectedIndexes;\r
 \r
                    @Override\r
                    public void beforeApply() {\r
-                       enumerationResources = getSelectedResources(usedEnumerationsExplorer);\r
+                       selectedIndexes = getSelectedIndexes(usedEnumerationsExplorer);\r
                    }\r
 \r
                    @Override\r
-                   public void apply(WriteGraph graph, Resource input)\r
+                   public void apply(WriteGraph graph, ResourceArray input)\r
                            throws DatabaseException {\r
-                       if(enumerationResources != null && enumerationResources.size() == 1) {\r
-                           SysdynResource sr = SysdynResource.getInstance(graph);\r
-                           Resource arrayIndexes = graph.getPossibleObject(input, sr.Variable_arrayIndexes);\r
-                           if(arrayIndexes == null)\r
-                               return;\r
-\r
-                           Resource enumeration = enumerationResources.get(0);\r
-                           OrderedSetUtils.remove(graph, arrayIndexes, enumeration);\r
+                       SysdynResource sr = SysdynResource.getInstance(graph);\r
+\r
+                       for(Resource variable : input) {\r
+                           Resource arrayIndexes = graph.getPossibleObject(variable, sr.Variable_arrayIndexes);\r
+                           if(arrayIndexes != null) {\r
+                               List<Resource> enumerations = OrderedSetUtils.toList(graph, arrayIndexes);\r
+                               List<Resource> toBeRemoved = new ArrayList<Resource>();\r
+                               for(Integer index : selectedIndexes) {\r
+                               if(index < enumerations.size()) {\r
+                                   Resource enumeration = enumerations.get(index);\r
+                                   toBeRemoved.add(enumeration);\r
+                               }\r
+\r
+                               }\r
+                               \r
+                               for(Resource enumeration : toBeRemoved)\r
+                                   OrderedSetUtils.remove(graph, arrayIndexes, enumeration);\r
+                           }\r
                        }\r
                    }\r
                });\r
@@ -225,12 +354,50 @@ public class ArrayIndexesTab extends LabelPropertyTabContributor implements Widg
                }\r
                return result;\r
        }\r
+       \r
+          private List<Integer> getSelectedIndexes(final GraphExplorerComposite explorer) {\r
+               final List<Integer> result = new ArrayList<Integer>();\r
+\r
+               explorer.getDisplay().syncExec(new Runnable() {\r
+\r
+                @Override\r
+                public void run() {\r
+                    Control c = explorer.getExplorerControl();\r
+                    if (c instanceof Tree) {\r
+                        Tree tree = (Tree) c;\r
+                        TreeItem[] selection = tree.getSelection();\r
+                        \r
+                        for(TreeItem item : selection) {\r
+                            result.add(tree.indexOf(item));\r
+                        }\r
+                    }\r
+                }\r
+               });\r
+\r
+               return result;\r
+           }\r
 \r
 \r
        @Override\r
        public void setInput(ISessionContext context, Object input) {\r
-               availableEnumerationsExplorer.setInput(context, input);\r
-               usedEnumerationsExplorer.setInput(context, input);\r
+           \r
+        if(input != null && input instanceof IStructuredSelection) {\r
+            Object first = ((IStructuredSelection)input).getFirstElement();\r
+            ResourceArray resourceArray = null;\r
+            if(first instanceof Resource)\r
+                resourceArray = new ResourceArray((Resource)first);\r
+            else if( first instanceof Collection<?>)\r
+                resourceArray = new ResourceArray(((Collection<?>)first).toArray(new Resource[((Collection<?>)first).size()]));\r
+            \r
+            if(resourceArray != null) {\r
+                StructuredSelection selection = new StructuredSelection(resourceArray);\r
+                availableEnumerationsExplorer.setInput(context, selection);\r
+                usedEnumerationsExplorer.setInput(context, selection);    \r
+                buttonSupport.fireInput(context, selection);\r
+            }\r
+        }\r
+        \r
+\r
        }\r
 \r
 }\r
index ad10dd617ed84aa6b2faeda2a2f2b9c4211db94e..31e0c5bd70d015bdf997bb1d914517550f1d028c 100644 (file)
@@ -49,7 +49,7 @@ import org.simantics.sysdyn.ui.trend.chart.properties.xyline.XYLineAxisAndVariab
 import org.simantics.sysdyn.ui.trend.chart.properties.xyline.XYLineGeneralPropertiesTab;\r
 import org.simantics.ui.selection.AnyVariable;\r
 import org.simantics.ui.selection.WorkbenchSelectionElement;\r
-import org.simantics.ui.utils.AdaptionUtils;\r
+import org.simantics.utils.ui.AdaptionUtils;\r
 import org.simantics.utils.ui.ISelectionUtils;\r
 \r
 /**\r
@@ -78,22 +78,26 @@ public class ResourceSelectionProcessor implements SelectionProcessor<Object, Re
         try {\r
             // Many elements \r
             if (selection instanceof ArrayList<?> && ((ArrayList<?>) selection).size() > 1) {\r
-                List<Resource> independentVariables = new ArrayList<Resource>();\r
+                List<Resource> variables = new ArrayList<Resource>();\r
                 Resource model = null;\r
                 for(Object o : (ArrayList<?>)selection) {\r
                     Resource r = AdaptionUtils.adaptToSingle(o, Resource.class);\r
-                    if(r != null && backend.isInstanceOf(r, sr.IndependentVariable)) {\r
+                    Resource component = backend.getPossibleObject(r, mr.ElementToComponent);\r
+                    if (component != null) {\r
+                        r = component;\r
+                    } \r
+                    if(r != null && backend.isInstanceOf(r, sr.Variable)) {\r
                         if(model == null)\r
                             model = backend.getSingleObject(r, Layer0.getInstance(backend).PartOf);\r
                         if(model.equals( backend.getSingleObject(r, Layer0.getInstance(backend).PartOf)))\r
-                            independentVariables.add(r);\r
+                            variables.add(r);\r
                     }\r
                 }\r
 \r
                 tabs.add(new ComparableTabContributor(\r
                         new ArrayIndexesTab(),\r
                         1,\r
-                        independentVariables,\r
+                        variables,\r
                         "Indexes"));\r
 \r
                 return tabs;\r
index 9b2c37e23f9eea29208ea5af0df802c112ae1df9..ea785c0a189caf2a48f895b31347019db59a2a65 100644 (file)
@@ -2,24 +2,38 @@ package org.simantics.sysdyn.ui.properties.widgets.arrays;
 \r
 import java.util.ArrayList;\r
 import java.util.Collection;\r
+import java.util.Collections;\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.ResourceArray;\r
 import org.simantics.db.common.request.ObjectsWithType;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
 \r
-public class AvailableEnumerations extends ViewpointContributorImpl<Resource> {\r
+public class AvailableEnumerations extends ViewpointContributorImpl<ResourceArray> {\r
 \r
        @Override\r
-       public Collection<?> getContribution(ReadGraph graph, Resource input)\r
+       public Collection<?> getContribution(ReadGraph graph, ResourceArray input)\r
                        throws DatabaseException {\r
-               if(input == null) return null;\r
+               Resource[] selection = input.resources;\r
+               if(selection.length < 1)\r
+                   return Collections.emptyList();\r
                Layer0 l0 = Layer0.getInstance(graph);\r
-               Resource configuration = graph.getPossibleObject(input, l0.PartOf);\r
+               Resource configuration = null;\r
+               \r
+               // Variables need to be from the same configuration\r
+               for(Resource r : selection) {\r
+                   Resource conf = graph.getPossibleObject(r, l0.PartOf);\r
+                   if(configuration == null || conf.equals(configuration))\r
+                       configuration = conf;\r
+                   else\r
+                       return Collections.emptyList();\r
+               }\r
+               \r
         ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
         SysdynResource sr = SysdynResource.getInstance(graph);\r
         if(configuration == null) \r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ConflictingEnumerationLabeler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ConflictingEnumerationLabeler.java
new file mode 100644 (file)
index 0000000..4fa7ef9
--- /dev/null
@@ -0,0 +1,41 @@
+package org.simantics.sysdyn.ui.properties.widgets.arrays;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.simantics.browsing.ui.graph.impl.contributor.labeler.ColumnLabelerContributorImpl;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys;\r
+\r
+public class ConflictingEnumerationLabeler extends ColumnLabelerContributorImpl<ConflictingEnumerationNode>{\r
+\r
+    @Override\r
+    public Map<String, String> getLabel(ReadGraph graph, ConflictingEnumerationNode input)\r
+            throws DatabaseException {\r
+        HashMap<String, String> map = new HashMap<String, String>();\r
+\r
+        boolean first = true;\r
+        StringBuilder names = new StringBuilder();\r
+        for(Resource r : (Resource[])input.data) {\r
+            if(!first)\r
+                names.append(", ");\r
+            first = false;\r
+\r
+            String name = "empty";\r
+            if(r != null)\r
+                name =  NameUtils.getSafeName(graph, r);\r
+            names.append(name);\r
+        }\r
+        map.put(ColumnKeys.ENUMERATION, names.toString());\r
+\r
+        map.put(ColumnKeys.INDEXES, "Conflicting enumerations");\r
+        \r
+        return map;\r
+    }\r
+\r
+\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ConflictingEnumerationNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ConflictingEnumerationNode.java
new file mode 100644 (file)
index 0000000..b93f849
--- /dev/null
@@ -0,0 +1,11 @@
+package org.simantics.sysdyn.ui.properties.widgets.arrays;\r
+\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+\r
+public class ConflictingEnumerationNode extends AbstractNode<Object> {\r
+\r
+    public ConflictingEnumerationNode(Object resources) {\r
+        super(resources);\r
+    }\r
+\r
+}\r
index 7d67aa436a8dd648716b6682932d640c2a79266a..681b9ef2a6327e00b27a29e8dd80fd19ef562f6b 100644 (file)
@@ -2,31 +2,109 @@ package org.simantics.sysdyn.ui.properties.widgets.arrays;
 \r
 import java.util.ArrayList;\r
 import java.util.Collection;\r
+import java.util.Collections;\r
+import java.util.List;\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.ResourceArray;\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 UsedEnumerations extends ViewpointContributorImpl<Resource> {\r
+public class UsedEnumerations extends ViewpointContributorImpl<ResourceArray> {\r
 \r
                @Override\r
-               public Collection<?> getContribution(ReadGraph graph, Resource input)\r
+               public Collection<?> getContribution(ReadGraph graph, ResourceArray input)\r
                                throws DatabaseException {\r
                SysdynResource sr = SysdynResource.getInstance(graph);\r
                \r
-               ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
+               Resource[] selection = input.resources;\r
+               if(selection.length < 1)\r
+                   return Collections.emptyList();\r
                \r
-               Resource arrayIndexes = graph.getPossibleObject(input, sr.Variable_arrayIndexes);\r
-               if(arrayIndexes == null) {\r
-                       return result;\r
+               /* Collect enumerations for all variables\r
+                * var1\r
+                *     - enum1\r
+                *     - enum2\r
+                * var2\r
+                *     - enum1\r
+                *     - enum2\r
+                *     - enum3\r
+                */\r
+               ArrayList<List<Resource>> variableEnumerations = new ArrayList<List<Resource>>();\r
+               for(Resource variable : selection) {\r
+                   Resource arrayIndexes = graph.getPossibleObject(variable, sr.Variable_arrayIndexes);\r
+                   if(arrayIndexes != null) {\r
+                       variableEnumerations.add(OrderedSetUtils.toList(graph, arrayIndexes));\r
+                   } else {\r
+                       variableEnumerations.add(new ArrayList<Resource>());\r
+                   }\r
                }\r
-               for(Resource r : OrderedSetUtils.toList(graph, arrayIndexes)) {\r
-                       result.add(new EnumerationNode(r));\r
+\r
+\r
+               /* Construct a list of enumerations\r
+                * FirstEnumeration\r
+                *     - var1.first\r
+                *     - var2.first\r
+                *     - var3.first\r
+                * SecondEnumeration\r
+                *     - var1.second\r
+                *     - ...\r
+                */\r
+               ArrayList<List<Resource>> enumerations = new ArrayList<List<Resource>>();\r
+\r
+               int index = 0;\r
+               while(true) {\r
+\r
+                   // Break loop if enumerations for all variables have been recorded\r
+                   boolean b = true;\r
+                   for(List<Resource> varEnums : variableEnumerations) {\r
+                       if(index < varEnums.size()) {\r
+                           b = false;\r
+                           break;\r
+                       }\r
+                   }\r
+                   \r
+                   if(b) break;\r
+                   \r
+                   for(List<Resource> current : variableEnumerations) {\r
+                       if(index == enumerations.size())\r
+                           enumerations.add(index, new ArrayList<Resource>());\r
+                       Resource enumeration =  index < current.size()? current.get(index) : null;\r
+                       enumerations.get(index).add(enumeration);\r
+                   }\r
+                   \r
+                   index++;\r
                }\r
+               \r
+               // Build nodes\r
+               ArrayList<AbstractNode<?>> result = new ArrayList<AbstractNode<?>>();\r
+\r
+               if(enumerations.size() == 1 && (enumerations.get(0).size() == 0 || (enumerations.get(0).size() == 1 && enumerations.get(0).get(0) == null)))\r
+                   return result;\r
+               \r
+               for(List<Resource> enumeration : enumerations) {\r
+                   boolean same = true;\r
+                   for(int i = 0; i < enumeration.size() - 1; i++) {\r
+                       if(enumeration.get(i) == null || enumeration.get(i + 1) == null ||\r
+                               !enumeration.get(i).equals(enumeration.get(i + 1))) {\r
+                           same = false;\r
+                           break;\r
+                       }\r
+                   }\r
+                   \r
+                   if(!same) {\r
+                       result.add(new ConflictingEnumerationNode(enumeration.toArray(new Resource[enumeration.size()])));\r
+                   } else {\r
+                       result.add(new EnumerationNode(enumeration.get(0)));\r
+                   }\r
+               }\r
+               \r
+\r
+               \r
                return result;\r
                }\r
 \r