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.TransferableGraphSource;
13 import org.simantics.utils.datastructures.hints.IHintContext.Key;
15 public class TGSourceRepresentation implements Representation {
17 protected Resource[] resources;
18 protected boolean ignoreVirtualResources = false;
19 private TransferableGraphSource value = null;
20 private TransferableGraphConfiguration2 configuration;
22 public TGSourceRepresentation(Resource ... resources) {
23 this.resources = resources;
26 public TGSourceRepresentation(boolean ignoreVirtualResources, Resource ... resources) {
27 this.ignoreVirtualResources = ignoreVirtualResources;
28 this.resources = resources;
31 public TGSourceRepresentation(TransferableGraphConfiguration2 configuration) {
32 this.configuration = configuration;
35 public TGSourceRepresentation(TransferableGraphSource value) {
41 return SimanticsKeys.KEY_TRANSFERABLE_GRAPH_SOURCE;
44 public TransferableGraphSource compute(ReadGraph graph, Map<String,Object> hints) throws DatabaseException {
46 if(configuration == null) {
47 configuration = new TransferableGraphConfiguration2(graph, Arrays.asList(resources), ignoreVirtualResources, false);
48 configuration.exclusionFunction = TGRepresentationUtils.computeExclusionFunction(graph, resources, hints);
51 return graph.syncRequest(new ModelTransferableGraphSourceRequest(configuration));
55 @SuppressWarnings("unchecked")
57 public <T> T getValue(RequestProcessor processor, Map<String,Object> hints) throws DatabaseException {
60 value = processor.syncRequest(new UniqueRead<TransferableGraphSource>() {
63 public TransferableGraphSource perform(ReadGraph graph) throws DatabaseException {
64 return compute(graph, hints);