--- /dev/null
+/*******************************************************************************\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