1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\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 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.browsing.ui.graph.impl;
\r
14 import org.simantics.browsing.ui.NodeContext;
\r
15 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
\r
16 import org.simantics.browsing.ui.NodeContext.PrimitiveQueryKey;
\r
17 import org.simantics.browsing.ui.common.processors.AbstractPrimitiveQueryProcessor;
\r
18 import org.simantics.db.ReadGraph;
\r
19 import org.simantics.db.exception.DatabaseException;
\r
20 import org.simantics.utils.Container;
\r
22 public abstract class LazyGraphQueryProcessor<Result> extends AbstractPrimitiveQueryProcessor<Container<Result>> {
\r
25 * Returns the value to be returned as the initial query result, before the
\r
26 * real result has been calculated.
\r
28 * @return the initial result value stored in the returned {@link Container}
\r
30 protected abstract Result initial();
\r
38 protected abstract Result compute(ReadGraph graph, NodeContext context, PrimitiveQueryKey<Container<Result>> key) throws DatabaseException;
\r
40 final Result init = initial();
\r
43 public Container<Result> query(PrimitiveQueryUpdater updater, NodeContext context,
\r
44 final PrimitiveQueryKey<Container<Result>> key) {
\r
45 assert(updater != null);
\r
46 assert(context != null);
\r
47 assert(key != null);
\r
49 return new LazyResourceQueryContainer<Result>(updater, context, init) {
\r
51 protected PrimitiveQueryKey<Container<Result>> getKey() {
\r
56 protected Result compute(ReadGraph graph) throws DatabaseException {
\r
57 return LazyGraphQueryProcessor.this.compute(graph, context, key);
\r
63 public String toString() {
\r
64 return "abstract LazyGraphQueryProcessor2";
\r