/******************************************************************************* * 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 fi.vtt.simantics.processeditor.monitors; import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.simantics.db.Graph; import org.simantics.db.Resource; import org.simantics.layer0.utils.EntityFactory; import org.simantics.layer0.utils.IEntity; import org.simantics.layer0.utils.ResourceDebugUtils; import fi.vtt.simantics.processeditor.common.PathUtils; public class ResourcePathPropertyProvider implements MonitorTextProvider { private Resource instance; private List properties = new ArrayList(); private List names = new ArrayList(); private List units = new ArrayList(); String name; private MonitorTextProvider provider = new ObjectPropertyProvider(); public void setSource(IEntity instance) { this.instance = instance.getResource(); properties.clear(); names.clear(); //units.clear(); List> paths = PathContainer.getInstance().getPaths(instance); if (paths != null) { for (List path : paths) { IEntity source = PathUtils.findSimilar(path, instance); if (source != null) properties.add(source.getResource()); } } Collection types = instance.getTypes(); name = ResourceDebugUtils.getReadableNameForEntity(types.iterator().next()); for (Resource p : properties) { names.add(ResourceDebugUtils.getReadableNameForEntity(EntityFactory.create(instance.getGraph(),p))); // if (p.isInstanceOf(Builtins.Double)) { // typeResources = p.getRelatedResources(Builtins.InstanceOf); // String name = PropertyUtils.getScalarStringProperty(typeResources[0],Builtins.HasName); // Property property = new Property(p); // String abbr = property.getUnitAbbreviation(); // names.add(name); // if (abbr != null) // units.add(abbr); // else // units.add(""); // //titles.add(name + " " + PropertyUtils.getDoubleValue(p)[0] + " " + abbr); // } } provider.setSource(instance); } public ArrayList getTexts(Graph graph) { if (properties.size() == 0) return provider.getTexts(graph); ArrayList titles = new ArrayList(); if (instance == null) return titles; titles.add(name); for (int i = 0; i < properties.size(); i++) { //titles.add(names.get(i) + " " + Double.toString(PropertyUtils.getDoubleValue(properties.get(i))[0]) + " " + units.get(i)); // FIXME : check value titles.add(names.get(i) + " " + EntityFactory.create(graph,properties.get(i)).toProperty().getValue()); } return titles; } }