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