]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.selectionview/src/org/simantics/selectionview/VariableColoringDecorationRule.java b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/VariableColoringDecorationRule.java
new file mode 100644 (file)
index 0000000..d636a7f
--- /dev/null
@@ -0,0 +1,46 @@
+package org.simantics.selectionview;\r
+\r
+import org.eclipse.jface.resource.ColorDescriptor;\r
+import org.eclipse.swt.graphics.RGB;\r
+import org.simantics.browsing.ui.common.ColumnKeys;\r
+import org.simantics.browsing.ui.content.LabelDecorator;\r
+import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.db.layer0.variable.Variables;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class VariableColoringDecorationRule implements LabelDecorationRule {\r
+\r
+       private final static ColorDescriptor READONLY_GRAY = ColorDescriptor.createFrom(new RGB(240, 240, 240));\r
+\r
+       @Override\r
+       public boolean isCompatible(Class<?> contentType) {\r
+               return contentType.equals(Variable.class);\r
+       }\r
+\r
+       @Override\r
+       public LabelDecorator getLabelDecorator(ReadGraph graph, Object content)\r
+                       throws DatabaseException {\r
+               Variable variable = (Variable)content;\r
+               Object o = variable.getPossiblePropertyValue(graph, Variables.READONLY);\r
+               if (!Boolean.TRUE.equals(o))\r
+                       return null;\r
+               return ReadOnlyDecorator.INSTANCE;\r
+       }\r
+\r
+       private static class ReadOnlyDecorator extends LabelDecorator.Stub {\r
+               public static ReadOnlyDecorator INSTANCE = new ReadOnlyDecorator();\r
+               @SuppressWarnings("unchecked")\r
+               @Override\r
+               public <C> C decorateBackground(C color, String column, int itemIndex) {\r
+                       if (ColumnKeys.DISPLAY_VALUE.equals(column) || ColumnKeys.DISPLAY_UNIT.equals(column))\r
+                               return (C) READONLY_GRAY;\r
+                       return null;\r
+               }\r
+       }\r
+\r
+}\r