import java.util.HashSet;
import java.util.Map;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.common.request.ResourceRead;
import org.simantics.graph.db.TransferableGraphs;
import org.simantics.graph.representation.TransferableGraph1;
import org.simantics.operation.Layer0X;
+import org.slf4j.LoggerFactory;
public class DefaultCopyHandler implements CopyHandler, CopyHandler2 {
+ private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(DefaultCopyHandler.class);
+
protected Collection<Resource> resources;
public DefaultCopyHandler(Resource resource) {
};
}
- protected void fillTG(ReadGraph graph, HashSet<Representation> items, boolean cut) {
-
+ protected void fillTG(ReadGraph graph, HashSet<Representation> items, boolean cut, IProgressMonitor monitor) {
+ SubMonitor subMonitor = SubMonitor.convert(monitor, 10);
+ subMonitor.subTask("Fill tg");
try {
Representation tgRepresentation = createTransferableGraph(graph, resources, cut);
- if(tgRepresentation != null) items.add(tgRepresentation);
+ if (tgRepresentation != null)
+ items.add(tgRepresentation);
+ subMonitor.worked(2);
Representation tgSourceRepresentation = createTransferableGraphSource(graph, resources, cut);
- if(tgSourceRepresentation != null) items.add(tgSourceRepresentation);
-
- if(resources.size() == 1) {
- Collection<Representation> representations = graph.syncRequest(new ResourceRead<Collection<Representation>>(resources.iterator().next()) {
- @Override
- public Collection<Representation> perform(ReadGraph graph) throws DatabaseException {
- ArrayList<Representation> result = new ArrayList<Representation>();
- Layer0X L0X = Layer0X.getInstance(graph);
- for(Resource adapter : graph.getObjects(resource, L0X.HasRepresentation)) {
- result.add(graph.adapt(adapter, Representation.class));
- }
- return result;
- }
- });
+ if (tgSourceRepresentation != null)
+ items.add(tgSourceRepresentation);
+ subMonitor.worked(2);
+
+ if (resources.size() == 1) {
+ SubMonitor splittedChild = subMonitor.split(6);
+ Collection<Representation> representations = graph
+ .syncRequest(new ResourceRead<Collection<Representation>>(resources.iterator().next()) {
+ @Override
+ public Collection<Representation> perform(ReadGraph graph) throws DatabaseException {
+ ArrayList<Representation> result = new ArrayList<Representation>();
+ Layer0X L0X = Layer0X.getInstance(graph);
+ for (Resource adapter : graph.getObjects(resource, L0X.HasRepresentation)) {
+ result.add(graph.adapt(adapter, Representation.class));
+ splittedChild.worked(1);
+ }
+ return result;
+ }
+ });
for (Representation r : representations)
items.add(r);
+ } else {
+ LOGGER.warn("Invalid amount of resources {} for filling tg", resources);
}
} catch (DatabaseException e) {
}
- protected void fillCopyResource(ReadGraph graph, HashSet<Representation> items) {
+ protected void fillCopyResource(ReadGraph graph, HashSet<Representation> items, IProgressMonitor monitor) {
+ SubMonitor subMonitor = SubMonitor.convert(monitor, 1);
+ subMonitor.subTask("Fill copy resources");
items.add(ClipboardUtils.createCopyResources(resources));
+ subMonitor.worked(1);
}
- protected void fillCutResource(ReadGraph graph, HashSet<Representation> items) {
+ protected void fillCutResource(ReadGraph graph, HashSet<Representation> items, IProgressMonitor monitor) {
+ SubMonitor subMonitor = SubMonitor.convert(monitor, 1);
+ subMonitor.subTask("Fill cut resources");
items.add(ClipboardUtils.createCutResources(resources));
+ subMonitor.worked(1);
}
@Override
- public void copyToClipboard(ReadGraph graph, SimanticsClipboardBuilder clipboard) throws DatabaseException {
+ public void copyToClipboard(ReadGraph graph, SimanticsClipboardBuilder clipboard, IProgressMonitor monitor) throws DatabaseException {
+ SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
HashSet<Representation> items = new HashSet<Representation>();
- fillTG(graph, items, false);
- fillCopyResource(graph, items);
- clipboard.addContent(items);
+ fillTG(graph, items, false, subMonitor.split(80));
+ fillCopyResource(graph, items, subMonitor.split(10));
+ clipboard.addContent(items, subMonitor.split(10));
}
@Override
- public void cutToClipboard(ReadGraph graph, SimanticsClipboardBuilder clipboard) throws DatabaseException {
+ public void cutToClipboard(ReadGraph graph, SimanticsClipboardBuilder clipboard, IProgressMonitor monitor) throws DatabaseException {
+ SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
HashSet<Representation> items = new HashSet<Representation>();
- fillTG(graph, items, true);
- fillCutResource(graph, items);
- clipboard.addContent(items);
+ fillTG(graph, items, true, subMonitor.split(80));
+ fillCutResource(graph, items, subMonitor.split(10));
+ clipboard.addContent(items, subMonitor.split(10));
}
}