]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.processeditor/src/org/simantics/processeditor/monitors/PathContainer.java
7a7998047abfa174b456a2e757df827b4f74b6b7
[simantics/3d.git] / org.simantics.processeditor / src / org / simantics / processeditor / monitors / PathContainer.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
3  * All rights reserved. This program and the accompanying materials\r
4  * are made available under the terms of the Eclipse Public License v1.0\r
5  * which accompanies this distribution, and is available at\r
6  * http://www.eclipse.org/legal/epl-v10.html\r
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.processeditor.monitors;\r
12 \r
13 import java.util.Collection;\r
14 import java.util.List;\r
15 \r
16 import org.simantics.db.Resource;\r
17 import org.simantics.layer0.utils.IEntity;\r
18 import org.simantics.utils.datastructures.MapList;\r
19 \r
20 \r
21 /**\r
22  * Container for Paths\r
23  * FIXME : singleton\r
24  * TODO : removing paths\r
25  * TODO : prevent adding same path multiple times\r
26  * TODO : how to handle multi-instances?\r
27  * \r
28  * \r
29  * @author Marko Luukkainen\r
30  *\r
31  */\r
32 public class PathContainer {\r
33         \r
34         private static PathContainer instance = new PathContainer();\r
35         \r
36         MapList<Resource, List<Resource>> paths;\r
37         //List<Pair<List<Resource>,List<Resource>>> multiInstancePaths;\r
38         \r
39         private PathContainer() {\r
40                 paths = new MapList<Resource, List<Resource>>();\r
41                 //multiInstancePaths = new ArrayList<Pair<List<Resource>,List<Resource>>>();\r
42         }\r
43         \r
44         public List<List<Resource>> getPaths(IEntity instance) {\r
45                 Collection<IEntity> types = instance.getTypes();\r
46                 if (types.size() != 1) {\r
47                         // for multi-instances we check if any of the types have paths\r
48                         // no we return paths for a single type (it is possible to combine paths for all types)\r
49                         for (IEntity type : types) {\r
50                                 Resource r = type.getResource();\r
51                                 List<List<Resource>> path = paths.getValues(r);\r
52                                 if (path != null)\r
53                                         return path;\r
54                         }\r
55                         return null;\r
56                 } else {\r
57                         Resource type = types.iterator().next().getResource();\r
58                         return paths.getValues(type);\r
59                 }\r
60         }\r
61         \r
62         public void addPath(Resource type, List<Resource> path) {\r
63                 paths.add(type, path);\r
64         }\r
65         \r
66         public void clearPaths(Resource type) {\r
67                 paths.remove(type);\r
68         }\r
69         \r
70         public static PathContainer getInstance() {\r
71                 return instance;\r
72         }\r
73 \r
74 }\r