1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.browsing.ui.graph.impl;
14 import org.simantics.browsing.ui.NodeContext;
15 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
16 import org.simantics.browsing.ui.NodeContext.PrimitiveQueryKey;
17 import org.simantics.browsing.ui.common.processors.AbstractPrimitiveQueryProcessor;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.utils.Container;
22 public abstract class LazyGraphQueryProcessor<Result> extends AbstractPrimitiveQueryProcessor<Container<Result>> {
25 * Returns the value to be returned as the initial query result, before the
26 * real result has been calculated.
28 * @return the initial result value stored in the returned {@link Container}
30 protected abstract Result initial();
38 protected abstract Result compute(ReadGraph graph, NodeContext context, PrimitiveQueryKey<Container<Result>> key) throws DatabaseException;
40 final Result init = initial();
43 public Container<Result> query(PrimitiveQueryUpdater updater, NodeContext context,
44 final PrimitiveQueryKey<Container<Result>> key) {
45 assert(updater != null);
46 assert(context != null);
49 return new LazyResourceQueryContainer<Result>(updater, context, init) {
51 protected PrimitiveQueryKey<Container<Result>> getKey() {
56 protected Result compute(ReadGraph graph) throws DatabaseException {
57 return LazyGraphQueryProcessor.this.compute(graph, context, key);
63 public String toString() {
64 return "abstract LazyGraphQueryProcessor2";