]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyGraphQueryProcessor.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.browsing.ui.graph.impl / src / org / simantics / browsing / ui / graph / impl / LazyGraphQueryProcessor.java
diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyGraphQueryProcessor.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyGraphQueryProcessor.java
new file mode 100644 (file)
index 0000000..00277d4
--- /dev/null
@@ -0,0 +1,67 @@
+/*******************************************************************************\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;\r
+\r
+import org.simantics.browsing.ui.NodeContext;\r
+import org.simantics.browsing.ui.PrimitiveQueryUpdater;\r
+import org.simantics.browsing.ui.NodeContext.PrimitiveQueryKey;\r
+import org.simantics.browsing.ui.common.processors.AbstractPrimitiveQueryProcessor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.utils.Container;\r
+\r
+public abstract class LazyGraphQueryProcessor<Result> extends AbstractPrimitiveQueryProcessor<Container<Result>> {\r
+\r
+    /**\r
+     * Returns the value to be returned as the initial query result, before the\r
+     * real result has been calculated.\r
+     * \r
+     * @return the initial result value stored in the returned {@link Container}\r
+     */\r
+    protected abstract Result initial();\r
+\r
+    /**\r
+     * \r
+     * @param graph\r
+     * @param context\r
+     * @return\r
+     */\r
+    protected abstract Result compute(ReadGraph graph, NodeContext context, PrimitiveQueryKey<Container<Result>> key) throws DatabaseException;\r
+\r
+    final Result init = initial();\r
+\r
+    @Override\r
+    public Container<Result> query(PrimitiveQueryUpdater updater, NodeContext context,\r
+            final PrimitiveQueryKey<Container<Result>> key) {\r
+        assert(updater != null);\r
+        assert(context != null);\r
+        assert(key != null);\r
+\r
+        return new LazyResourceQueryContainer<Result>(updater, context, init) {\r
+            @Override\r
+            protected PrimitiveQueryKey<Container<Result>> getKey() {\r
+                return key;\r
+            }\r
+\r
+            @Override\r
+            protected Result compute(ReadGraph graph) throws DatabaseException {\r
+                return LazyGraphQueryProcessor.this.compute(graph, context, key);\r
+            }\r
+        };\r
+    }\r
+\r
+    @Override\r
+    public String toString() {\r
+        return "abstract LazyGraphQueryProcessor2";\r
+    }\r
+\r
+}\r