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