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