]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser2/image/SubscriptionImageRule.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / modelBrowser2 / image / SubscriptionImageRule.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.image;
13
14 import java.util.Map;
15
16 import org.eclipse.jface.resource.ImageDescriptor;
17 import org.simantics.browsing.ui.common.ColumnKeys;
18 import org.simantics.browsing.ui.model.images.ImageRule;
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.modeling.ui.Activator;
25 import org.simantics.utils.datastructures.ArrayMap;
26
27 /**
28  * @author Tuukka Lehtonen
29  */
30 public enum SubscriptionImageRule implements ImageRule {
31
32     INSTANCE;
33
34     public static SubscriptionImageRule get() {
35         return INSTANCE;
36     }
37
38     @Override
39     public boolean isCompatible(Class<?> contentType) {
40         return contentType.equals(Resource.class);
41     }
42
43     @Override
44     public Map<String, ImageDescriptor> getImage(ReadGraph graph, Object content) throws DatabaseException {
45         Resource subscription = (Resource) content;
46
47         ModelingResources MOD = ModelingResources.getInstance(graph);
48         Boolean enabled = graph.getPossibleRelatedValue(subscription, MOD.Subscription_Enabled, Bindings.BOOLEAN);
49         ImageDescriptor img = ImageDescriptor.getMissingImageDescriptor();
50         if (enabled != null)
51             img = enabled ? Activator.SUBSCRIPTION_ICON : Activator.SUBSCRIPTION_DISABLED_ICON ;
52
53         return ArrayMap.make(ColumnKeys.KEYS_SINGLE, img);
54     }
55
56 }