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
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.ArrayList;
\r
14 import java.util.Collection;
\r
15 import java.util.List;
\r
17 import org.simantics.db.Graph;
\r
18 import org.simantics.db.Resource;
\r
19 import org.simantics.layer0.utils.EntityFactory;
\r
20 import org.simantics.layer0.utils.IEntity;
\r
21 import org.simantics.layer0.utils.ResourceDebugUtils;
\r
22 import org.simantics.processeditor.common.PathUtils;
\r
26 public class ResourcePathPropertyProvider implements MonitorTextProvider {
\r
28 private Resource instance;
\r
29 private List<Resource> properties = new ArrayList<Resource>();
\r
30 private List<String> names = new ArrayList<String>();
\r
31 private List<String> units = new ArrayList<String>();
\r
34 private MonitorTextProvider provider = new ObjectPropertyProvider();
\r
36 public void setSource(IEntity instance) {
\r
37 this.instance = instance.getResource();
\r
41 List<List<Resource>> paths = PathContainer.getInstance().getPaths(instance);
\r
42 if (paths != null) {
\r
43 for (List<Resource> path : paths) {
\r
44 IEntity source = PathUtils.findSimilar(path, instance);
\r
46 properties.add(source.getResource());
\r
49 Collection<IEntity> types = instance.getTypes();
\r
50 name = ResourceDebugUtils.getReadableNameForEntity(types.iterator().next());
\r
51 for (Resource p : properties) {
\r
52 names.add(ResourceDebugUtils.getReadableNameForEntity(EntityFactory.create(instance.getGraph(),p)));
\r
53 // if (p.isInstanceOf(Builtins.Double)) {
\r
54 // typeResources = p.getRelatedResources(Builtins.InstanceOf);
\r
55 // String name = PropertyUtils.getScalarStringProperty(typeResources[0],Builtins.HasName);
\r
56 // Property property = new Property(p);
\r
57 // String abbr = property.getUnitAbbreviation();
\r
59 // if (abbr != null)
\r
63 // //titles.add(name + " " + PropertyUtils.getDoubleValue(p)[0] + " " + abbr);
\r
66 provider.setSource(instance);
\r
69 public ArrayList<String> getTexts(Graph graph) {
\r
70 if (properties.size() == 0)
\r
71 return provider.getTexts(graph);
\r
72 ArrayList<String> titles = new ArrayList<String>();
\r
73 if (instance == null)
\r
77 for (int i = 0; i < properties.size(); i++) {
\r
78 //titles.add(names.get(i) + " " + Double.toString(PropertyUtils.getDoubleValue(properties.get(i))[0]) + " " + units.get(i));
\r
79 // FIXME : check value
\r
80 titles.add(names.get(i) + " " + EntityFactory.create(graph,properties.get(i)).toProperty().getValue());
\r