]> gerrit.simantics Code Review - simantics/3d.git/blob
b15e5a9f2e9cb2dea0c87e79f4dfb195bd419e29
[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.ProcessResource;\r
23 \r
24 \r
25 \r
26 \r
27 public class ObjectPropertyProvider implements MonitorTextProvider {\r
28         \r
29         private Resource instance;\r
30         private Resource properties[];\r
31         String name;\r
32         \r
33         public void setSource(IEntity instance) {\r
34                 this.instance = instance.getResource();\r
35                 Collection<IEntity> props = instance.getRelatedObjects(ProcessResource.builtins.HasProperty);\r
36                 List<Resource> res = new ArrayList<Resource>();\r
37                 for (IEntity t : props)\r
38                         res.add(t.getResource());\r
39                 properties = new Resource[res.size()];\r
40                 properties = res.toArray(properties);\r
41                 name = ResourceDebugUtils.getReadableNameForEntity(instance);\r
42         }\r
43         \r
44         public ArrayList<String> getTexts(Graph graph) {\r
45                 ArrayList<String> titles = new ArrayList<String>();\r
46                 if (instance == null)\r
47                         return titles;\r
48                 IEntity thing = EntityFactory.create(graph,instance);\r
49                 name = ResourceDebugUtils.getReadableNameForEntity(thing);\r
50                 titles.add(name);\r
51 \r
52                 for (Resource p : properties) {\r
53                         thing = EntityFactory.create(graph,p);\r
54                         //if (p.isInstanceOf(Builtins.Double)) {\r
55                                 //typeResources = p.getRelatedResources(Builtins.InstanceOf);\r
56                                 //name = PropertyUtils.getScalarStringProperty(typeResources[0],Builtins.HasName);\r
57                                 name = ResourceDebugUtils.getReadableNameForEntity(thing);\r
58                                 titles.add(name);\r
59                         //}\r
60                 }\r
61                 return titles;\r
62         }\r
63 \r
64 }\r