]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/EvaluatorViewpoint.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 / EvaluatorViewpoint.java
1 package org.simantics.browsing.ui.graph.impl;
2
3 import java.util.Collection;
4
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;
12
13 public class EvaluatorViewpoint extends LazyViewpoint {
14
15         final BrowseContext browseContext;
16         final boolean useNodeBrowseContexts;
17         final boolean useNodeActionContexts;
18         
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;
25         }
26
27         @Override
28     public Boolean hasChildren(ReadGraph graph) throws DatabaseException {
29         return BrowseContext.get(graph,context,browseContext,useNodeBrowseContexts).hasChildren(graph, context);
30     }
31
32     @Override
33     public NodeContext[] children(ReadGraph graph) throws DatabaseException {
34         boolean oldSynchronous = graph.setSynchronous(false); 
35         try {
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[]>() {
39
40                                 @Override
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()]);
46                                 }
47                         
48                 });
49         } finally {
50                 graph.setSynchronous(oldSynchronous);
51         }
52     }
53     
54     public String toString() {
55         return "EvaluatorViewpoint[" + browseContext + "] " + context;
56     }
57     
58 }