X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2FPropertyLabelDecoratorFactory.java;h=dd24a05ca73445c6fbfa8421acd4ea232b2016c9;hp=c037687c9be0b0d0df863ea4272f73c457c2de9a;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/PropertyLabelDecoratorFactory.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/PropertyLabelDecoratorFactory.java index c037687c9..dd24a05ca 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/PropertyLabelDecoratorFactory.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/PropertyLabelDecoratorFactory.java @@ -1,94 +1,94 @@ -/******************************************************************************* - * Copyright (c) 2013 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Semantum Oy - initial API and implementation - *******************************************************************************/ -package org.simantics.browsing.ui.swt; - -import org.eclipse.jface.resource.ColorDescriptor; -import org.eclipse.swt.graphics.RGB; -import org.simantics.browsing.ui.BuiltinKeys; -import org.simantics.browsing.ui.BuiltinKeys.LabelDecoratorKey; -import org.simantics.browsing.ui.NodeContext; -import org.simantics.browsing.ui.PrimitiveQueryUpdater; -import org.simantics.browsing.ui.common.ColumnKeys; -import org.simantics.browsing.ui.common.property.IArrayProperty; -import org.simantics.browsing.ui.common.property.IProperty; -import org.simantics.browsing.ui.content.LabelDecorator; -import org.simantics.browsing.ui.content.LabelDecoratorFactory; -import org.simantics.browsing.ui.graph.impl.contribution.LabelDecoratorContributionImpl; -import org.simantics.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; - -/** - * @author Tuukka Lehtonen - */ -public class PropertyLabelDecoratorFactory implements LabelDecoratorFactory { - - private final static ColorDescriptor READONLY_GRAY = ColorDescriptor.createFrom(new RGB(240, 240, 240)); - - @Override - public LabelDecorator create(PrimitiveQueryUpdater manager, NodeContext context, LabelDecoratorKey key) { - Object o = context.getConstant(BuiltinKeys.INPUT); - if (o instanceof IProperty) { - IProperty prop = (IProperty) o; - if (o instanceof IArrayProperty) { - IArrayProperty array = (IArrayProperty) o; - if (array.isSlice()) - // Prevent the decorator from overworking on each and every sliced table row. - return null; - } - - final Resource[] data = prop.getData(Resource[].class); - if (data == null) - return null; - if (data.length != 3) - return null; - - return new PropertyReadOnlyLabelDecorator(manager, context, key); - } - return null; - } - - static class PropertyReadOnlyLabelDecorator extends LabelDecoratorContributionImpl { - - public PropertyReadOnlyLabelDecorator(PrimitiveQueryUpdater manager, NodeContext context, LabelDecoratorKey key) { - super(manager, context, key); - } - - @Override - public LabelDecorator getDecorator(ReadGraph graph, NodeContext context) throws DatabaseException { - IProperty prop = (IProperty) context.getConstant(BuiltinKeys.INPUT); - final Resource[] data = prop.getData(Resource[].class); - Layer0 L0 = Layer0.getInstance(graph); - Object o = graph.getPossibleRelatedValue2(data[1], L0.readOnly, Bindings.BOOLEAN); - if (!Boolean.TRUE.equals(o)) - return null; - - return new LabelDecorator.Stub() { - @Override - public C decorateForeground(C color, String column, int itemIndex) { - return null; - } - @SuppressWarnings("unchecked") - @Override - public C decorateBackground(C color, String column, int itemIndex) { - if (ColumnKeys.VALUE.equals(column)) - return (C) READONLY_GRAY; - return null; - } - }; - } - - } - -} +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.browsing.ui.swt; + +import org.eclipse.jface.resource.ColorDescriptor; +import org.eclipse.swt.graphics.RGB; +import org.simantics.browsing.ui.BuiltinKeys; +import org.simantics.browsing.ui.BuiltinKeys.LabelDecoratorKey; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.PrimitiveQueryUpdater; +import org.simantics.browsing.ui.common.ColumnKeys; +import org.simantics.browsing.ui.common.property.IArrayProperty; +import org.simantics.browsing.ui.common.property.IProperty; +import org.simantics.browsing.ui.content.LabelDecorator; +import org.simantics.browsing.ui.content.LabelDecoratorFactory; +import org.simantics.browsing.ui.graph.impl.contribution.LabelDecoratorContributionImpl; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; + +/** + * @author Tuukka Lehtonen + */ +public class PropertyLabelDecoratorFactory implements LabelDecoratorFactory { + + private final static ColorDescriptor READONLY_GRAY = ColorDescriptor.createFrom(new RGB(240, 240, 240)); + + @Override + public LabelDecorator create(PrimitiveQueryUpdater manager, NodeContext context, LabelDecoratorKey key) { + Object o = context.getConstant(BuiltinKeys.INPUT); + if (o instanceof IProperty) { + IProperty prop = (IProperty) o; + if (o instanceof IArrayProperty) { + IArrayProperty array = (IArrayProperty) o; + if (array.isSlice()) + // Prevent the decorator from overworking on each and every sliced table row. + return null; + } + + final Resource[] data = prop.getData(Resource[].class); + if (data == null) + return null; + if (data.length != 3) + return null; + + return new PropertyReadOnlyLabelDecorator(manager, context, key); + } + return null; + } + + static class PropertyReadOnlyLabelDecorator extends LabelDecoratorContributionImpl { + + public PropertyReadOnlyLabelDecorator(PrimitiveQueryUpdater manager, NodeContext context, LabelDecoratorKey key) { + super(manager, context, key); + } + + @Override + public LabelDecorator getDecorator(ReadGraph graph, NodeContext context) throws DatabaseException { + IProperty prop = (IProperty) context.getConstant(BuiltinKeys.INPUT); + final Resource[] data = prop.getData(Resource[].class); + Layer0 L0 = Layer0.getInstance(graph); + Object o = graph.getPossibleRelatedValue2(data[1], L0.readOnly, Bindings.BOOLEAN); + if (!Boolean.TRUE.equals(o)) + return null; + + return new LabelDecorator.Stub() { + @Override + public C decorateForeground(C color, String column, int itemIndex) { + return null; + } + @SuppressWarnings("unchecked") + @Override + public C decorateBackground(C color, String column, int itemIndex) { + if (ColumnKeys.VALUE.equals(column)) + return (C) READONLY_GRAY; + return null; + } + }; + } + + } + +}