]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyGraphQueryProcessor.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 / LazyGraphQueryProcessor.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.browsing.ui.graph.impl;
13
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;
21
22 public abstract class LazyGraphQueryProcessor<Result> extends AbstractPrimitiveQueryProcessor<Container<Result>> {
23
24     /**
25      * Returns the value to be returned as the initial query result, before the
26      * real result has been calculated.
27      * 
28      * @return the initial result value stored in the returned {@link Container}
29      */
30     protected abstract Result initial();
31
32     /**
33      * 
34      * @param graph
35      * @param context
36      * @return
37      */
38     protected abstract Result compute(ReadGraph graph, NodeContext context, PrimitiveQueryKey<Container<Result>> key) throws DatabaseException;
39
40     final Result init = initial();
41
42     @Override
43     public Container<Result> query(PrimitiveQueryUpdater updater, NodeContext context,
44             final PrimitiveQueryKey<Container<Result>> key) {
45         assert(updater != null);
46         assert(context != null);
47         assert(key != null);
48
49         return new LazyResourceQueryContainer<Result>(updater, context, init) {
50             @Override
51             protected PrimitiveQueryKey<Container<Result>> getKey() {
52                 return key;
53             }
54
55             @Override
56             protected Result compute(ReadGraph graph) throws DatabaseException {
57                 return LazyGraphQueryProcessor.this.compute(graph, context, key);
58             }
59         };
60     }
61
62     @Override
63     public String toString() {
64         return "abstract LazyGraphQueryProcessor2";
65     }
66
67 }