]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/rules/TestImageRule.java
Enhancements to modelled STS-tests
[simantics/platform.git] / bundles / org.simantics.tests.modelled.ui / src / org / simantics / tests / modelled / ui / rules / TestImageRule.java
1 package org.simantics.tests.modelled.ui.rules;
2
3 import java.util.Collections;
4 import java.util.Map;
5
6 import org.eclipse.jface.resource.ImageDescriptor;
7 import org.simantics.browsing.ui.common.ColumnKeys;
8 import org.simantics.browsing.ui.model.images.ImageRule;
9 import org.simantics.databoard.Bindings;
10 import org.simantics.db.ReadGraph;
11 import org.simantics.db.Resource;
12 import org.simantics.db.exception.DatabaseException;
13 import org.simantics.tests.modelled.ontology.TestsResource;
14 import org.simantics.tests.modelled.ui.ontology.TestsUIResource;
15
16 public class TestImageRule implements ImageRule {
17
18     private ImageDescriptor testImage;
19     private ImageDescriptor testIgnoredImage;
20
21     public TestImageRule(ReadGraph graph) throws DatabaseException {
22         TestsUIResource TESTS = TestsUIResource.getInstance(graph);
23         testImage = graph.adapt(TESTS.testImage, ImageDescriptor.class);
24         testIgnoredImage = graph.adapt(TESTS.testIgnoredImage, ImageDescriptor.class);
25     }
26
27     @Override
28     public boolean isCompatible(Class<?> contentType) {
29         return Resource.class.equals(contentType);
30     }
31
32     @Override
33     public Map<String, ImageDescriptor> getImage(ReadGraph graph, Object content) throws DatabaseException {
34         Resource resource = (Resource) content;
35         Boolean ignored = graph.getPossibleRelatedValue2(resource, TestsResource.getInstance(graph).ignore,
36                 Bindings.BOOLEAN);
37         if (ignored != null && ignored)
38             return Collections.singletonMap(ColumnKeys.SINGLE, testIgnoredImage);
39         return Collections.singletonMap(ColumnKeys.SINGLE, testImage);
40     }
41
42 }