-/*******************************************************************************\r
- * Copyright (c) 2013 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Semantum Oy - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.browsing.ui.swt;\r
-\r
-import org.eclipse.jface.resource.ColorDescriptor;\r
-import org.eclipse.swt.graphics.RGB;\r
-import org.simantics.browsing.ui.BuiltinKeys;\r
-import org.simantics.browsing.ui.BuiltinKeys.LabelDecoratorKey;\r
-import org.simantics.browsing.ui.NodeContext;\r
-import org.simantics.browsing.ui.PrimitiveQueryUpdater;\r
-import org.simantics.browsing.ui.common.ColumnKeys;\r
-import org.simantics.browsing.ui.common.property.IArrayProperty;\r
-import org.simantics.browsing.ui.common.property.IProperty;\r
-import org.simantics.browsing.ui.content.LabelDecorator;\r
-import org.simantics.browsing.ui.content.LabelDecoratorFactory;\r
-import org.simantics.browsing.ui.graph.impl.contribution.LabelDecoratorContributionImpl;\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.layer0.Layer0;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class PropertyLabelDecoratorFactory implements LabelDecoratorFactory {\r
-\r
- private final static ColorDescriptor READONLY_GRAY = ColorDescriptor.createFrom(new RGB(240, 240, 240));\r
-\r
- @Override\r
- public LabelDecorator create(PrimitiveQueryUpdater manager, NodeContext context, LabelDecoratorKey key) {\r
- Object o = context.getConstant(BuiltinKeys.INPUT);\r
- if (o instanceof IProperty) {\r
- IProperty prop = (IProperty) o;\r
- if (o instanceof IArrayProperty) {\r
- IArrayProperty array = (IArrayProperty) o;\r
- if (array.isSlice())\r
- // Prevent the decorator from overworking on each and every sliced table row.\r
- return null;\r
- }\r
-\r
- final Resource[] data = prop.getData(Resource[].class);\r
- if (data == null)\r
- return null;\r
- if (data.length != 3)\r
- return null;\r
-\r
- return new PropertyReadOnlyLabelDecorator(manager, context, key);\r
- }\r
- return null;\r
- }\r
-\r
- static class PropertyReadOnlyLabelDecorator extends LabelDecoratorContributionImpl {\r
-\r
- public PropertyReadOnlyLabelDecorator(PrimitiveQueryUpdater manager, NodeContext context, LabelDecoratorKey key) {\r
- super(manager, context, key);\r
- }\r
-\r
- @Override\r
- public LabelDecorator getDecorator(ReadGraph graph, NodeContext context) throws DatabaseException {\r
- IProperty prop = (IProperty) context.getConstant(BuiltinKeys.INPUT);\r
- final Resource[] data = prop.getData(Resource[].class);\r
- Layer0 L0 = Layer0.getInstance(graph);\r
- Object o = graph.getPossibleRelatedValue2(data[1], L0.readOnly, Bindings.BOOLEAN);\r
- if (!Boolean.TRUE.equals(o))\r
- return null;\r
-\r
- return new LabelDecorator.Stub() {\r
- @Override\r
- public <C> C decorateForeground(C color, String column, int itemIndex) {\r
- return null;\r
- }\r
- @SuppressWarnings("unchecked")\r
- @Override\r
- public <C> C decorateBackground(C color, String column, int itemIndex) {\r
- if (ColumnKeys.VALUE.equals(column))\r
- return (C) READONLY_GRAY;\r
- return null;\r
- }\r
- };\r
- }\r
-\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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> C decorateForeground(C color, String column, int itemIndex) {
+ return null;
+ }
+ @SuppressWarnings("unchecked")
+ @Override
+ public <C> C decorateBackground(C color, String column, int itemIndex) {
+ if (ColumnKeys.VALUE.equals(column))
+ return (C) READONLY_GRAY;
+ return null;
+ }
+ };
+ }
+
+ }
+
+}