]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.proconf.processeditor/src/org/simantics/processeditor/monitors/PathContainer.java
Set copyright texts for java files in the latest development branches.
[simantics/3d.git] / org.simantics.proconf.processeditor / src / org / simantics / processeditor / monitors / PathContainer.java
index b0205f521aa800d115c38fe7ac2b88c2f9b0b3fc..7a7998047abfa174b456a2e757df827b4f74b6b7 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.\r
+ * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
  * All rights reserved. This program and the accompanying materials\r
  * are made available under the terms of the Eclipse Public License v1.0\r
  * which accompanies this distribution, and is available at\r
@@ -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