1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.annotation.ui.modelBrowser2.model;
16 import org.simantics.browsing.ui.common.ColumnKeys;
17 import org.simantics.browsing.ui.model.labels.LabelRule;
18 import org.simantics.databoard.Bindings;
19 import org.simantics.db.ReadGraph;
20 import org.simantics.db.Resource;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.layer0.Layer0;
23 import org.simantics.utils.datastructures.ArrayMap;
26 * @author Antti Villberg
28 public enum AnnotationTypeLabelRule implements LabelRule {
32 public static AnnotationTypeLabelRule get() {
37 public boolean isCompatible(Class<?> contentType) {
38 return contentType.equals(Resource.class);
42 public Map<String, String> getLabel(ReadGraph graph, Object content) throws DatabaseException {
43 Resource type = (Resource) content;
45 Layer0 L0 = Layer0.getInstance(graph);
46 Resource property = graph.getPossibleObject(type, L0.HasRange_Inverse);
48 if (property != null) {
49 String pname = graph.getPossibleRelatedValue(property, L0.HasName, Bindings.STRING);
54 return ArrayMap.make(ColumnKeys.KEYS_SINGLE, new String[] { name });