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