]> gerrit.simantics Code Review - simantics/3d.git/blob
b5b6be5300b16020d9d4b10ed0f6105532eb2651
[simantics/3d.git] /
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
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.processeditor.monitors;\r
12 \r
13 import java.util.ArrayList;\r
14 import java.util.Collection;\r
15 import java.util.List;\r
16 \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
23 \r
24 \r
25 \r
26 public class ResourcePathPropertyProvider implements MonitorTextProvider {\r
27         \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
32         String name;\r
33         \r
34         private MonitorTextProvider provider = new ObjectPropertyProvider();\r
35         \r
36         public void setSource(IEntity instance) {\r
37                 this.instance = instance.getResource();\r
38                 properties.clear();\r
39                 names.clear();\r
40                 //units.clear();\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
45                                 if (source != null)\r
46                                         properties.add(source.getResource());\r
47                         }\r
48                 }\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
58 //                              names.add(name);\r
59 //                              if (abbr != null)\r
60 //                                      units.add(abbr);\r
61 //                              else\r
62 //                                      units.add("");\r
63 //                              //titles.add(name + " " + PropertyUtils.getDoubleValue(p)[0] + " " + abbr);\r
64 //                      }\r
65                 }\r
66                 provider.setSource(instance);\r
67         }\r
68         \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
74                         return titles;\r
75                 \r
76                 titles.add(name);\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
81                 }\r
82 \r
83                 return titles;\r
84         }\r
85         \r
86 \r
87 }\r