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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.annotation.ui.modelBrowser2.model;
\r
14 import java.util.Map;
\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
26 * @author Antti Villberg
\r
28 public enum AnnotationTypeLabelRule implements LabelRule {
\r
32 public static AnnotationTypeLabelRule get() {
\r
37 public boolean isCompatible(Class<?> contentType) {
\r
38 return contentType.equals(Resource.class);
\r
42 public Map<String, String> getLabel(ReadGraph graph, Object content) throws DatabaseException {
\r
43 Resource type = (Resource) content;
\r
45 Layer0 L0 = Layer0.getInstance(graph);
\r
46 Resource property = graph.getPossibleObject(type, L0.HasRange_Inverse);
\r
48 if (property != null) {
\r
49 String pname = graph.getPossibleRelatedValue(property, L0.HasName, Bindings.STRING);
\r
54 return ArrayMap.make(ColumnKeys.KEYS_SINGLE, new String[] { name });
\r