1 package org.simantics.db.layer0.util;
3 import java.util.Arrays;
6 import org.simantics.db.ReadGraph;
7 import org.simantics.db.RequestProcessor;
8 import org.simantics.db.Resource;
9 import org.simantics.db.common.request.UniqueRead;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.layer0.util.SimanticsClipboard.Representation;
12 import org.simantics.graph.db.TransferableGraphs;
13 import org.simantics.graph.representation.TransferableGraph1;
14 import org.simantics.utils.datastructures.hints.IHintContext.Key;
16 public class TGRepresentation implements Representation {
18 protected boolean ignoreVirtualResources = false;
19 protected Resource[] resources;
20 private TransferableGraph1 value = null;
21 private TransferableGraphConfiguration2 configuration;
23 public TGRepresentation(Resource ... resources) {
24 this.resources = resources;
27 public TGRepresentation(boolean ignoreVirtualResources, Resource ... resources) {
28 this.ignoreVirtualResources = ignoreVirtualResources;
29 this.resources = resources;
32 public TGRepresentation(TransferableGraphConfiguration2 configuration) {
33 this.configuration = configuration;
36 public TGRepresentation(TransferableGraph1 value) {
42 return SimanticsKeys.KEY_TRANSFERABLE_GRAPH;
45 public TransferableGraph1 compute(ReadGraph graph, Map<String,Object> hints) throws DatabaseException {
47 if(configuration == null) {
48 configuration = new TransferableGraphConfiguration2(graph, Arrays.asList(resources), ignoreVirtualResources, false);
49 configuration.exclusionFunction = TGRepresentationUtils.computeExclusionFunction(graph, resources, hints);
52 ModelTransferableGraphSource source = graph.syncRequest(new ModelTransferableGraphSourceRequest(configuration));
53 return TransferableGraphs.create(graph, source);
57 @SuppressWarnings("unchecked")
59 public <T> T getValue(RequestProcessor processor, Map<String,Object> hints) throws DatabaseException {
63 value = processor.syncRequest(new UniqueRead<TransferableGraph1>() {
66 public TransferableGraph1 perform(ReadGraph graph) throws DatabaseException {
67 return compute(graph, hints);