1 package org.simantics.browsing.ui.graph.impl;
3 import java.util.Collection;
5 import org.simantics.browsing.ui.BuiltinKeys.ViewpointKey;
6 import org.simantics.browsing.ui.NodeContext;
7 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
8 import org.simantics.browsing.ui.model.browsecontexts.BrowseContext;
9 import org.simantics.db.ReadGraph;
10 import org.simantics.db.common.request.UniqueRead;
11 import org.simantics.db.exception.DatabaseException;
13 public class EvaluatorViewpoint extends LazyViewpoint {
15 final BrowseContext browseContext;
16 final boolean useNodeBrowseContexts;
17 final boolean useNodeActionContexts;
19 public EvaluatorViewpoint(PrimitiveQueryUpdater updater, NodeContext context, ViewpointKey key,
20 BrowseContext browseContext, boolean useNodeBrowseContexts, boolean useNodeActionContexts) {
21 super(updater, context, key);
22 this.browseContext = browseContext;
23 this.useNodeActionContexts = useNodeActionContexts;
24 this.useNodeBrowseContexts = useNodeBrowseContexts;
28 public Boolean hasChildren(ReadGraph graph) throws DatabaseException {
29 return BrowseContext.get(graph,context,browseContext,useNodeBrowseContexts).hasChildren(graph, context);
33 public NodeContext[] children(ReadGraph graph) throws DatabaseException {
34 boolean oldSynchronous = graph.setSynchronous(false);
36 // This intermediate query is a work-around for a listening
37 // bug where old dependencies are not correctly pruned for listened entries
38 return graph.syncRequest(new UniqueRead<NodeContext[]>() {
41 public NodeContext[] perform(ReadGraph graph) throws DatabaseException {
42 BrowseContext bc = BrowseContext.get(graph,context,browseContext,useNodeBrowseContexts);
43 Collection<NodeContext> children = bc.getChildren(graph, context);
44 children = BrowseContext.augment(graph, bc, children, useNodeActionContexts);
45 return children.toArray(new NodeContext[children.size()]);
50 graph.setSynchronous(oldSynchronous);
54 public String toString() {
55 return "EvaluatorViewpoint[" + browseContext + "] " + context;