1 package org.simantics.selectionview;
\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
14 * @author Tuukka Lehtonen
\r
16 public class VariableColoringDecorationRule implements LabelDecorationRule {
\r
18 private final static ColorDescriptor READONLY_GRAY = ColorDescriptor.createFrom(new RGB(240, 240, 240));
\r
21 public boolean isCompatible(Class<?> contentType) {
\r
22 return contentType.equals(Variable.class);
\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
32 return ReadOnlyDecorator.INSTANCE;
\r
35 private static class ReadOnlyDecorator extends LabelDecorator.Stub {
\r
36 public static ReadOnlyDecorator INSTANCE = new ReadOnlyDecorator();
\r
37 @SuppressWarnings("unchecked")
\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