]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalLabelDecoratorContributionImpl.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.graph.impl / src / org / simantics / browsing / ui / graph / impl / contribution / FinalLabelDecoratorContributionImpl.java
index 348e823ba93057c0a0aa5eaace08450b9ad6f11d..3459990009ede231ba7259c4d8535638dd363a5c 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.browsing.ui.graph.impl.contribution;\r
-\r
-import org.simantics.browsing.ui.BuiltinKeys.LabelDecoratorKey;\r
-import org.simantics.browsing.ui.DataSource;\r
-import org.simantics.browsing.ui.NodeContext;\r
-import org.simantics.browsing.ui.PrimitiveQueryUpdater;\r
-import org.simantics.browsing.ui.content.LabelDecorator;\r
-import org.simantics.browsing.ui.graph.impl.request.ResourceQuery;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.procedure.Listener;\r
-import org.simantics.db.procedure.Procedure;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-\r
-public abstract class FinalLabelDecoratorContributionImpl extends LabelDecorator.Stub {\r
-\r
-    final LabelDecorator FRESH = new LabelDecorator.Stub();\r
-    final LabelDecorator PENDING = new LabelDecorator.Stub();\r
-    final LabelDecorator NO_DECORATION = new LabelDecorator.Stub();\r
-\r
-    protected final PrimitiveQueryUpdater       updater;\r
-    private final ResourceQuery<LabelDecorator> labelQuery;\r
-    private final LabelDecoratorKey             key;\r
-\r
-    /**\r
-     * The current decorator result produced for this contribution. The value\r
-     * should never be <code>null</code>, but one of {@link #FRESH},\r
-     * {@link #PENDING}, {@link #NO_DECORATION} instead.\r
-     */\r
-    protected LabelDecorator                      decorator = FRESH;\r
-\r
-    final protected NodeContext                   context;\r
-\r
-    public Object getIdentity(LabelDecoratorKey key) {\r
-        return key;\r
-    }\r
-\r
-    private void request() {\r
-\r
-        final DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);\r
-        assert(source != null);\r
-        \r
-        final Procedure<LabelDecorator> procedure = createProcedure();\r
-\r
-        source.schedule(graph -> {\r
-            if(procedure instanceof Listener<?>)\r
-                graph.asyncRequest(labelQuery, (Listener<LabelDecorator>)procedure);\r
-            else\r
-                graph.asyncRequest(labelQuery, procedure);\r
-        });\r
-\r
-    }\r
-\r
-\r
-\r
-    @Override\r
-    public <Color_> Color_ decorateBackground(Color_ color, String column, int itemIndex) {\r
-        if(FRESH == decorator) {\r
-            decorator = PENDING;\r
-            request();\r
-        }\r
-        return decorator.decorateBackground(color, column, itemIndex);\r
-    }\r
-\r
-    @Override\r
-    public <Font_> Font_ decorateFont(Font_ font, String column, int itemIndex) {\r
-        if(FRESH == decorator) {\r
-            decorator = PENDING;\r
-            request();\r
-        }\r
-        return decorator.decorateFont(font, column, itemIndex);\r
-    }\r
-\r
-    @Override\r
-    public String decorateLabel(String label, String column, int itemIndex) {\r
-        if(FRESH == decorator) {\r
-            decorator = PENDING;\r
-            request();\r
-        }\r
-        return decorator.decorateLabel(label, column, itemIndex);\r
-    }\r
-\r
-    @Override\r
-    public <Color_> Color_ decorateForeground(Color_ color, String column, int itemIndex) {\r
-        if(FRESH == decorator) {\r
-            decorator = PENDING;\r
-            request();\r
-        }\r
-        return decorator.decorateForeground(color, column, itemIndex);\r
-    }\r
-\r
-    public FinalLabelDecoratorContributionImpl(final PrimitiveQueryUpdater updater, final NodeContext context, final LabelDecoratorKey key) {\r
-\r
-        this.updater = updater;\r
-        this.context = context;\r
-        this.key = key;\r
-\r
-        labelQuery = new ResourceQuery<LabelDecorator>(getIdentity(key), context) {\r
-\r
-            @Override\r
-            public LabelDecorator perform(ReadGraph graph) throws DatabaseException {\r
-                try {\r
-                    return getDecorator(graph, context);\r
-                } catch (DatabaseException e) {\r
-                    throw e;\r
-                } catch (Throwable t) {\r
-                    ErrorLogger.defaultLogError("LazyGraphLabeler.labelQuery produced unexpected exception.", t);\r
-                    return null;\r
-                }\r
-            }\r
-\r
-            @Override\r
-            public String toString() {\r
-                return FinalLabelDecoratorContributionImpl.this + " with context " + context;\r
-            }\r
-\r
-        };\r
-\r
-    }\r
-\r
-    protected Procedure<LabelDecorator> createProcedure() {\r
-\r
-        return new Procedure<LabelDecorator>() {\r
-\r
-            @Override\r
-            public void execute(LabelDecorator result) {\r
-                replaceResult(result);\r
-            }\r
-\r
-            @Override\r
-            public void exception(Throwable t) {\r
-                ErrorLogger.defaultLogError("LazyContributionImpl.childQuery failed, see exception for details.", t);\r
-            }\r
-\r
-        };\r
-\r
-    }\r
-\r
-    protected void replaceResult(LabelDecorator result) {\r
-        // Never let decorator become null, use a stub decorator instead.\r
-        if (result == null)\r
-            result = NO_DECORATION;\r
-\r
-        decorator = result;\r
-        updater.scheduleReplace(context, key, this);\r
-    }\r
-\r
-    // OVERRIDE\r
-\r
-    public abstract LabelDecorator getDecorator(ReadGraph graph, NodeContext context) throws DatabaseException;\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 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:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.browsing.ui.graph.impl.contribution;
+
+import org.simantics.browsing.ui.BuiltinKeys.LabelDecoratorKey;
+import org.simantics.browsing.ui.DataSource;
+import org.simantics.browsing.ui.NodeContext;
+import org.simantics.browsing.ui.PrimitiveQueryUpdater;
+import org.simantics.browsing.ui.content.LabelDecorator;
+import org.simantics.browsing.ui.graph.impl.request.ResourceQuery;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.Listener;
+import org.simantics.db.procedure.Procedure;
+import org.simantics.utils.ui.ErrorLogger;
+
+public abstract class FinalLabelDecoratorContributionImpl extends LabelDecorator.Stub {
+
+    final LabelDecorator FRESH = new LabelDecorator.Stub();
+    final LabelDecorator PENDING = new LabelDecorator.Stub();
+    final LabelDecorator NO_DECORATION = new LabelDecorator.Stub();
+
+    protected final PrimitiveQueryUpdater       updater;
+    private final ResourceQuery<LabelDecorator> labelQuery;
+    private final LabelDecoratorKey             key;
+
+    /**
+     * The current decorator result produced for this contribution. The value
+     * should never be <code>null</code>, but one of {@link #FRESH},
+     * {@link #PENDING}, {@link #NO_DECORATION} instead.
+     */
+    protected LabelDecorator                      decorator = FRESH;
+
+    final protected NodeContext                   context;
+
+    public Object getIdentity(LabelDecoratorKey key) {
+        return key;
+    }
+
+    private void request() {
+
+        final DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+        assert(source != null);
+        
+        final Procedure<LabelDecorator> procedure = createProcedure();
+
+        source.schedule(graph -> {
+            if(procedure instanceof Listener<?>)
+                graph.asyncRequest(labelQuery, (Listener<LabelDecorator>)procedure);
+            else
+                graph.asyncRequest(labelQuery, procedure);
+        });
+
+    }
+
+
+
+    @Override
+    public <Color_> Color_ decorateBackground(Color_ color, String column, int itemIndex) {
+        if(FRESH == decorator) {
+            decorator = PENDING;
+            request();
+        }
+        return decorator.decorateBackground(color, column, itemIndex);
+    }
+
+    @Override
+    public <Font_> Font_ decorateFont(Font_ font, String column, int itemIndex) {
+        if(FRESH == decorator) {
+            decorator = PENDING;
+            request();
+        }
+        return decorator.decorateFont(font, column, itemIndex);
+    }
+
+    @Override
+    public String decorateLabel(String label, String column, int itemIndex) {
+        if(FRESH == decorator) {
+            decorator = PENDING;
+            request();
+        }
+        return decorator.decorateLabel(label, column, itemIndex);
+    }
+
+    @Override
+    public <Color_> Color_ decorateForeground(Color_ color, String column, int itemIndex) {
+        if(FRESH == decorator) {
+            decorator = PENDING;
+            request();
+        }
+        return decorator.decorateForeground(color, column, itemIndex);
+    }
+
+    public FinalLabelDecoratorContributionImpl(final PrimitiveQueryUpdater updater, final NodeContext context, final LabelDecoratorKey key) {
+
+        this.updater = updater;
+        this.context = context;
+        this.key = key;
+
+        labelQuery = new ResourceQuery<LabelDecorator>(getIdentity(key), context) {
+
+            @Override
+            public LabelDecorator perform(ReadGraph graph) throws DatabaseException {
+                try {
+                    return getDecorator(graph, context);
+                } catch (DatabaseException e) {
+                    throw e;
+                } catch (Throwable t) {
+                    ErrorLogger.defaultLogError("LazyGraphLabeler.labelQuery produced unexpected exception.", t);
+                    return null;
+                }
+            }
+
+            @Override
+            public String toString() {
+                return FinalLabelDecoratorContributionImpl.this + " with context " + context;
+            }
+
+        };
+
+    }
+
+    protected Procedure<LabelDecorator> createProcedure() {
+
+        return new Procedure<LabelDecorator>() {
+
+            @Override
+            public void execute(LabelDecorator result) {
+                replaceResult(result);
+            }
+
+            @Override
+            public void exception(Throwable t) {
+                ErrorLogger.defaultLogError("LazyContributionImpl.childQuery failed, see exception for details.", t);
+            }
+
+        };
+
+    }
+
+    protected void replaceResult(LabelDecorator result) {
+        // Never let decorator become null, use a stub decorator instead.
+        if (result == null)
+            result = NO_DECORATION;
+
+        decorator = result;
+        updater.scheduleReplace(context, key, this);
+    }
+
+    // OVERRIDE
+
+    public abstract LabelDecorator getDecorator(ReadGraph graph, NodeContext context) throws DatabaseException;
+
+}