1 /*******************************************************************************
\r
2 * Copyright (c) 2012 Association for Decentralized Information Management in
\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.modeling.ui.modelBrowser2.label;
\r
14 import java.util.Collections;
\r
15 import java.util.Map;
\r
17 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
\r
18 import org.eclipse.core.runtime.preferences.InstanceScope;
\r
19 import org.simantics.browsing.ui.common.ColumnKeys;
\r
20 import org.simantics.browsing.ui.model.labels.LabelRule;
\r
21 import org.simantics.db.ReadGraph;
\r
22 import org.simantics.db.Resource;
\r
23 import org.simantics.db.exception.DatabaseException;
\r
24 import org.simantics.modeling.subscription.SubscriptionItemLabel;
\r
25 import org.simantics.utils.format.ValueFormat;
\r
28 * @author Tuukka Lehtonen
\r
30 public class SubscriptionItemLabelRule implements LabelRule {
\r
32 public static final SubscriptionItemLabelRule INSTANCE = new SubscriptionItemLabelRule();
\r
34 ValueFormat valueFormat;
\r
36 public SubscriptionItemLabelRule() {
\r
37 IEclipsePreferences chartPreferenceNode = InstanceScope.INSTANCE.getNode( "org.simantics.charts" );
\r
38 String s = chartPreferenceNode.get("chart.valueformat", ValueFormat.Default.name());
\r
39 valueFormat = ValueFormat.valueOf( s );
\r
43 public boolean isCompatible(Class<?> contentType) {
\r
44 return contentType.equals(Resource.class);
\r
48 public Map<String, String> getLabel(ReadGraph graph, Object content) throws DatabaseException {
\r
49 boolean oldSync = graph.setSynchronous(true);
\r
51 Resource item = (Resource) content;
\r
52 String label = SubscriptionItemLabel.resolveLabel(graph, item, valueFormat, true);
\r
53 return Collections.singletonMap(ColumnKeys.SINGLE, label);
\r
55 graph.setSynchronous(oldSync);
\r