]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
git-svn-id: https://www.simantics.org/svn/simantics/3d/branches/dev@8819 ac1ea38d...
authorluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 22 Jan 2009 16:12:03 +0000 (16:12 +0000)
committerluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 22 Jan 2009 16:12:03 +0000 (16:12 +0000)
org.simantics.proconf.processeditor/src/org/simantics/processeditor/monitors/PathContainer.java

index b0205f521aa800d115c38fe7ac2b88c2f9b0b3fc..f41b4b1f498c81bb5562f7ca6cd410e6c5d3372e 100644 (file)
@@ -23,6 +23,7 @@ import org.simantics.utils.datastructures.MapList;
  * FIXME : singleton\r
  * TODO : removing paths\r
  * TODO : prevent adding same path multiple times\r
+ * TODO : how to handle multi-instances?\r
  * \r
  * \r
  * @author Marko Luukkainen\r
@@ -33,17 +34,29 @@ public class PathContainer {
        private static PathContainer instance = new PathContainer();\r
        \r
        MapList<Resource, List<Resource>> paths;\r
+       //List<Pair<List<Resource>,List<Resource>>> multiInstancePaths;\r
        \r
        private PathContainer() {\r
                paths = new MapList<Resource, List<Resource>>();\r
+               //multiInstancePaths = new ArrayList<Pair<List<Resource>,List<Resource>>>();\r
        }\r
        \r
        public List<List<Resource>> getPaths(IEntity instance) {\r
                Collection<IEntity> types = instance.getTypes();\r
-               if (types.size() != 1)\r
-                       throw new UnsupportedOperationException("Multi-instances not supported!");\r
-               Resource type = types.iterator().next().getResource();\r
-               return paths.getValues(type);\r
+               if (types.size() != 1) {\r
+                       // for multi-instances we check if any of the types have paths\r
+                       // no we return paths for a single type (it is possible to combine paths for all types)\r
+                       for (IEntity type : types) {\r
+                               Resource r = type.getResource();\r
+                               List<List<Resource>> path = paths.getValues(r);\r
+                               if (path != null)\r
+                                       return path;\r
+                       }\r
+                       return null;\r
+               } else {\r
+                       Resource type = types.iterator().next().getResource();\r
+                       return paths.getValues(type);\r
+               }\r
        }\r
        \r
        public void addPath(Resource type, List<Resource> path) {\r