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
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.processeditor.monitors;
\r
13 import java.util.Collection;
\r
14 import java.util.List;
\r
16 import org.simantics.db.Resource;
\r
17 import org.simantics.layer0.utils.IEntity;
\r
18 import org.simantics.utils.datastructures.MapList;
\r
22 * Container for Paths
\r
24 * TODO : removing paths
\r
25 * TODO : prevent adding same path multiple times
\r
26 * TODO : how to handle multi-instances?
\r
29 * @author Marko Luukkainen
\r
32 public class PathContainer {
\r
34 private static PathContainer instance = new PathContainer();
\r
36 MapList<Resource, List<Resource>> paths;
\r
37 //List<Pair<List<Resource>,List<Resource>>> multiInstancePaths;
\r
39 private PathContainer() {
\r
40 paths = new MapList<Resource, List<Resource>>();
\r
41 //multiInstancePaths = new ArrayList<Pair<List<Resource>,List<Resource>>>();
\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
57 Resource type = types.iterator().next().getResource();
\r
58 return paths.getValues(type);
\r
62 public void addPath(Resource type, List<Resource> path) {
\r
63 paths.add(type, path);
\r
66 public void clearPaths(Resource type) {
\r
70 public static PathContainer getInstance() {
\r