]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
6302ad0d922fc30f239f7038113119819875d563
[simantics/sysdyn.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2010 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.sysdyn.ui.browser.contributions;\r
13 \r
14 import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor;\r
15 import org.simantics.db.ReadGraph;\r
16 import org.simantics.db.Resource;\r
17 import org.simantics.db.exception.DatabaseException;\r
18 import org.simantics.layer0.Layer0;\r
19 import org.simantics.operation.Layer0X;\r
20 import org.simantics.sysdyn.ui.browser.nodes.VariableNode;\r
21 \r
22 public class VariableLabeler  extends LabelerContributor<VariableNode<Resource>>{\r
23 \r
24         @Override\r
25         public String getLabel(ReadGraph graph, VariableNode<Resource> var) throws DatabaseException {\r
26                 Layer0 l0 = Layer0.getInstance(graph);\r
27                 Layer0X L0X = Layer0X.getInstance(graph);\r
28                 Resource varres = var.data;\r
29                 StringBuilder sb = new StringBuilder();\r
30                 for(Resource r : graph.getObjects(varres, l0.HasName))\r
31                         sb.append(graph.getValue(r));\r
32                 if(graph.isInstanceOf(varres, L0X.Realization)) {\r
33                         varres = graph.getPossibleObject(varres, L0X.Represents);\r
34                         if(varres == null) return sb.toString();\r
35                 }\r
36                 sb.append(" : ");\r
37                 for(Resource t : graph.getObjects(varres, l0.InstanceOf))\r
38                         for(Resource r : graph.getObjects(t, l0.HasName))\r
39                                 sb.append(graph.getValue(r));\r
40                 return sb.toString();\r
41         }\r
42 \r
43 }\r