/******************************************************************************* * Copyright (c) 2007 VTT Technical Research Centre of Finland and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.processeditor.monitors; import java.util.Collection; import java.util.List; import org.simantics.db.Resource; import org.simantics.layer0.utils.IEntity; import org.simantics.utils.datastructures.MapList; /** * Container for Paths * FIXME : singleton * TODO : removing paths * TODO : prevent adding same path multiple times * TODO : how to handle multi-instances? * * * @author Marko Luukkainen * */ public class PathContainer { private static PathContainer instance = new PathContainer(); MapList> paths; //List,List>> multiInstancePaths; private PathContainer() { paths = new MapList>(); //multiInstancePaths = new ArrayList,List>>(); } public List> getPaths(IEntity instance) { Collection types = instance.getTypes(); if (types.size() != 1) { // for multi-instances we check if any of the types have paths // no we return paths for a single type (it is possible to combine paths for all types) for (IEntity type : types) { Resource r = type.getResource(); List> path = paths.getValues(r); if (path != null) return path; } return null; } else { Resource type = types.iterator().next().getResource(); return paths.getValues(type); } } public void addPath(Resource type, List path) { paths.add(type, path); } public void clearPaths(Resource type) { paths.remove(type); } public static PathContainer getInstance() { return instance; } }