X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.selectionview%2Fsrc%2Forg%2Fsimantics%2Fselectionview%2FVariableColoringDecorationRule.java;fp=bundles%2Forg.simantics.selectionview%2Fsrc%2Forg%2Fsimantics%2Fselectionview%2FVariableColoringDecorationRule.java;h=d636a7f25a32e235681fc898bec9adeb15ddf97b;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 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 index 000000000..d636a7f25 --- /dev/null +++ b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/VariableColoringDecorationRule.java @@ -0,0 +1,46 @@ +package org.simantics.selectionview; + +import org.eclipse.jface.resource.ColorDescriptor; +import org.eclipse.swt.graphics.RGB; +import org.simantics.browsing.ui.common.ColumnKeys; +import org.simantics.browsing.ui.content.LabelDecorator; +import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; + +/** + * @author Tuukka Lehtonen + */ +public class VariableColoringDecorationRule implements LabelDecorationRule { + + private final static ColorDescriptor READONLY_GRAY = ColorDescriptor.createFrom(new RGB(240, 240, 240)); + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Variable.class); + } + + @Override + public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) + throws DatabaseException { + Variable variable = (Variable)content; + Object o = variable.getPossiblePropertyValue(graph, Variables.READONLY); + if (!Boolean.TRUE.equals(o)) + return null; + return ReadOnlyDecorator.INSTANCE; + } + + private static class ReadOnlyDecorator extends LabelDecorator.Stub { + public static ReadOnlyDecorator INSTANCE = new ReadOnlyDecorator(); + @SuppressWarnings("unchecked") + @Override + public C decorateBackground(C color, String column, int itemIndex) { + if (ColumnKeys.DISPLAY_VALUE.equals(column) || ColumnKeys.DISPLAY_UNIT.equals(column)) + return (C) READONLY_GRAY; + return null; + } + } + +}