]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.selectionview/src/org/simantics/selectionview/VariableColoringDecorationRule.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.selectionview / src / org / simantics / selectionview / VariableColoringDecorationRule.java
1 package org.simantics.selectionview;\r
2 \r
3 import org.eclipse.jface.resource.ColorDescriptor;\r
4 import org.eclipse.swt.graphics.RGB;\r
5 import org.simantics.browsing.ui.common.ColumnKeys;\r
6 import org.simantics.browsing.ui.content.LabelDecorator;\r
7 import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule;\r
8 import org.simantics.db.ReadGraph;\r
9 import org.simantics.db.exception.DatabaseException;\r
10 import org.simantics.db.layer0.variable.Variable;\r
11 import org.simantics.db.layer0.variable.Variables;\r
12 \r
13 /**\r
14  * @author Tuukka Lehtonen\r
15  */\r
16 public class VariableColoringDecorationRule implements LabelDecorationRule {\r
17 \r
18         private final static ColorDescriptor READONLY_GRAY = ColorDescriptor.createFrom(new RGB(240, 240, 240));\r
19 \r
20         @Override\r
21         public boolean isCompatible(Class<?> contentType) {\r
22                 return contentType.equals(Variable.class);\r
23         }\r
24 \r
25         @Override\r
26         public LabelDecorator getLabelDecorator(ReadGraph graph, Object content)\r
27                         throws DatabaseException {\r
28                 Variable variable = (Variable)content;\r
29                 Object o = variable.getPossiblePropertyValue(graph, Variables.READONLY);\r
30                 if (!Boolean.TRUE.equals(o))\r
31                         return null;\r
32                 return ReadOnlyDecorator.INSTANCE;\r
33         }\r
34 \r
35         private static class ReadOnlyDecorator extends LabelDecorator.Stub {\r
36                 public static ReadOnlyDecorator INSTANCE = new ReadOnlyDecorator();\r
37                 @SuppressWarnings("unchecked")\r
38                 @Override\r
39                 public <C> C decorateBackground(C color, String column, int itemIndex) {\r
40                         if (ColumnKeys.DISPLAY_VALUE.equals(column) || ColumnKeys.DISPLAY_UNIT.equals(column))\r
41                                 return (C) READONLY_GRAY;\r
42                         return null;\r
43                 }\r
44         }\r
45 \r
46 }\r