]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.proconf.processeditor/src/fi/vtt/simantics/processeditor/monitors/PathContainer.java
4c2aab7e42de89dc3fbdc20d8fcd79c95dab9dd8
[simantics/3d.git] / org.simantics.proconf.processeditor / src / fi / vtt / simantics / processeditor / monitors / PathContainer.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.\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 fi.vtt.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  * \r
27  * \r
28  * @author Marko Luukkainen\r
29  *\r
30  */\r
31 public class PathContainer {\r
32         \r
33         private static PathContainer instance = new PathContainer();\r
34         \r
35         MapList<Resource, List<Resource>> paths;\r
36         \r
37         private PathContainer() {\r
38                 paths = new MapList<Resource, List<Resource>>();\r
39         }\r
40         \r
41         public List<List<Resource>> getPaths(IEntity instance) {\r
42                 Collection<IEntity> types = instance.getTypes();\r
43                 if (types.size() != 1)\r
44                         throw new UnsupportedOperationException("Multi-instances not supported!");\r
45                 Resource type = types.iterator().next().getResource();\r
46                 return paths.getValues(type);\r
47         }\r
48         \r
49         public void addPath(Resource type, List<Resource> path) {\r
50                 paths.add(type, path);\r
51         }\r
52         \r
53         public void clearPaths(Resource type) {\r
54                 paths.remove(type);\r
55         }\r
56         \r
57         public static PathContainer getInstance() {\r
58                 return instance;\r
59         }\r
60 \r
61 }\r