]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.annotation.ui/src/org/simantics/annotation/ui/modelBrowser2/model/AnnotationTypeLabelRule.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.annotation.ui / src / org / simantics / annotation / ui / modelBrowser2 / model / AnnotationTypeLabelRule.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in 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.annotation.ui.modelBrowser2.model;\r
13 \r
14 import java.util.Map;\r
15 \r
16 import org.simantics.browsing.ui.common.ColumnKeys;\r
17 import org.simantics.browsing.ui.model.labels.LabelRule;\r
18 import org.simantics.databoard.Bindings;\r
19 import org.simantics.db.ReadGraph;\r
20 import org.simantics.db.Resource;\r
21 import org.simantics.db.exception.DatabaseException;\r
22 import org.simantics.layer0.Layer0;\r
23 import org.simantics.utils.datastructures.ArrayMap;\r
24 \r
25 /**\r
26  * @author Antti Villberg\r
27  */\r
28 public enum AnnotationTypeLabelRule implements LabelRule {\r
29 \r
30     INSTANCE;\r
31 \r
32     public static AnnotationTypeLabelRule get() {\r
33         return INSTANCE;\r
34     }\r
35 \r
36     @Override\r
37     public boolean isCompatible(Class<?> contentType) {\r
38         return contentType.equals(Resource.class);\r
39     }\r
40 \r
41     @Override\r
42     public Map<String, String> getLabel(ReadGraph graph, Object content) throws DatabaseException {\r
43         Resource type = (Resource) content;\r
44 \r
45         Layer0 L0 = Layer0.getInstance(graph);\r
46         Resource property = graph.getPossibleObject(type, L0.HasRange_Inverse);\r
47         String name = "";\r
48         if (property != null) {\r
49             String pname = graph.getPossibleRelatedValue(property, L0.HasName, Bindings.STRING);\r
50             if (pname != null)\r
51                 name = pname;\r
52         }\r
53 \r
54         return ArrayMap.make(ColumnKeys.KEYS_SINGLE, new String[] { name });\r
55     }\r
56 \r
57 }\r