1 /*******************************************************************************
2 * Copyright (c) 2013 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.browsing.ui.swt;
14 import org.eclipse.jface.resource.ColorDescriptor;
15 import org.eclipse.swt.graphics.RGB;
16 import org.simantics.browsing.ui.BuiltinKeys;
17 import org.simantics.browsing.ui.BuiltinKeys.LabelDecoratorKey;
18 import org.simantics.browsing.ui.NodeContext;
19 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
20 import org.simantics.browsing.ui.common.ColumnKeys;
21 import org.simantics.browsing.ui.common.property.IArrayProperty;
22 import org.simantics.browsing.ui.common.property.IProperty;
23 import org.simantics.browsing.ui.content.LabelDecorator;
24 import org.simantics.browsing.ui.content.LabelDecoratorFactory;
25 import org.simantics.browsing.ui.graph.impl.contribution.LabelDecoratorContributionImpl;
26 import org.simantics.databoard.Bindings;
27 import org.simantics.db.ReadGraph;
28 import org.simantics.db.Resource;
29 import org.simantics.db.exception.DatabaseException;
30 import org.simantics.layer0.Layer0;
33 * @author Tuukka Lehtonen
35 public class PropertyLabelDecoratorFactory implements LabelDecoratorFactory {
37 private final static ColorDescriptor READONLY_GRAY = ColorDescriptor.createFrom(new RGB(240, 240, 240));
40 public LabelDecorator create(PrimitiveQueryUpdater manager, NodeContext context, LabelDecoratorKey key) {
41 Object o = context.getConstant(BuiltinKeys.INPUT);
42 if (o instanceof IProperty) {
43 IProperty prop = (IProperty) o;
44 if (o instanceof IArrayProperty) {
45 IArrayProperty array = (IArrayProperty) o;
47 // Prevent the decorator from overworking on each and every sliced table row.
51 final Resource[] data = prop.getData(Resource[].class);
57 return new PropertyReadOnlyLabelDecorator(manager, context, key);
62 static class PropertyReadOnlyLabelDecorator extends LabelDecoratorContributionImpl {
64 public PropertyReadOnlyLabelDecorator(PrimitiveQueryUpdater manager, NodeContext context, LabelDecoratorKey key) {
65 super(manager, context, key);
69 public LabelDecorator getDecorator(ReadGraph graph, NodeContext context) throws DatabaseException {
70 IProperty prop = (IProperty) context.getConstant(BuiltinKeys.INPUT);
71 final Resource[] data = prop.getData(Resource[].class);
72 Layer0 L0 = Layer0.getInstance(graph);
73 Object o = graph.getPossibleRelatedValue2(data[1], L0.readOnly, Bindings.BOOLEAN);
74 if (!Boolean.TRUE.equals(o))
77 return new LabelDecorator.Stub() {
79 public <C> C decorateForeground(C color, String column, int itemIndex) {
82 @SuppressWarnings("unchecked")
84 public <C> C decorateBackground(C color, String column, int itemIndex) {
85 if (ColumnKeys.VALUE.equals(column))
86 return (C) READONLY_GRAY;