-/*******************************************************************************\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
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.processeditor.monitors;\r
-\r
-import java.util.Collection;\r
-import java.util.List;\r
-\r
-import org.simantics.db.Resource;\r
-import org.simantics.layer0.utils.IEntity;\r
-import org.simantics.utils.datastructures.MapList;\r
-\r
-\r
-/**\r
- * Container for Paths\r
- * 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
- *\r
- */\r
-public class PathContainer {\r
- \r
- 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
- // 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
- paths.add(type, path);\r
- }\r
- \r
- public void clearPaths(Resource type) {\r
- paths.remove(type);\r
- }\r
- \r
- public static PathContainer getInstance() {\r
- return instance;\r
- }\r
-\r
-}\r