]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser2/label/SubscriptionLabelRule.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / modelBrowser2 / label / SubscriptionLabelRule.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.modeling.ui.modelBrowser2.label;
13
14 import java.util.Map;
15
16 import org.simantics.browsing.ui.common.ColumnKeys;
17 import org.simantics.browsing.ui.graph.impl.LabelerUtil;
18 import org.simantics.browsing.ui.model.labels.LabelRule;
19 import org.simantics.databoard.Bindings;
20 import org.simantics.db.ReadGraph;
21 import org.simantics.db.Resource;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.modeling.ModelingResources;
24 import org.simantics.utils.datastructures.ArrayMap;
25
26 /**
27  * @author Tuukka Lehtonen
28  */
29 public enum SubscriptionLabelRule implements LabelRule {
30
31     INSTANCE;
32
33     public static SubscriptionLabelRule get() {
34         return INSTANCE;
35     }
36
37     @Override
38     public boolean isCompatible(Class<?> contentType) {
39         return contentType.equals(Resource.class);
40     }
41
42     @Override
43     public Map<String, String> getLabel(ReadGraph graph, Object input) throws DatabaseException {
44         Resource subscription = (Resource) input;
45
46         ModelingResources MOD = ModelingResources.getInstance(graph);
47         String rep = LabelerUtil.safeStringRepresentation(graph, subscription);
48         Boolean enabled = graph.getPossibleRelatedValue(subscription, MOD.Subscription_Enabled, Bindings.BOOLEAN);
49         if (!Boolean.TRUE.equals(enabled)) {
50             rep += " (disabled)";
51         }
52
53         return ArrayMap.make(ColumnKeys.KEYS_SINGLE, rep);
54     }
55
56 }