1 package org.simantics.modeling.template2d.ui.export;
3 import java.util.Collection;
4 import java.util.Collections;
8 import org.eclipse.core.runtime.IProgressMonitor;
9 import org.osgi.service.prefs.Preferences;
10 import org.simantics.databoard.binding.mutable.Variant;
11 import org.simantics.databoard.type.RecordType;
12 import org.simantics.db.ReadGraph;
13 import org.simantics.db.Resource;
14 import org.simantics.db.exception.DatabaseException;
15 import org.simantics.db.layer0.adapter.CopyHandler;
16 import org.simantics.db.layer0.util.ClipboardUtils;
17 import org.simantics.db.layer0.util.SimanticsClipboard;
18 import org.simantics.db.layer0.util.SimanticsClipboard.Representation;
19 import org.simantics.db.layer0.util.SimanticsClipboardImpl;
20 import org.simantics.db.layer0.util.SimanticsKeys;
21 import org.simantics.db.request.Read;
22 import org.simantics.export.core.ExportContext;
23 import org.simantics.export.core.error.ExportException;
24 import org.simantics.export.core.intf.ExportClass;
25 import org.simantics.export.core.manager.Content;
26 import org.simantics.export.core.manager.TransferableGraphWriter;
27 import org.simantics.export.core.util.ExportQueries;
28 import org.simantics.graph.representation.TransferableGraph1;
29 import org.simantics.utils.datastructures.MapList;
31 public class DrawingTemplateExporter implements ExportClass {
34 public RecordType options(ExportContext context, Collection<String> content) throws ExportException {
35 // TODO Auto-generated method stub
40 public void fillDefaultPrefs(ExportContext ctx, Variant options) throws ExportException {
41 // TODO Auto-generated method stub
45 public void savePref(Variant options, Preferences contentScopeNode, Preferences workbenchScopeNode) throws ExportException {
46 // TODO Auto-generated method stub
50 public void loadPref(Variant options, Preferences contentScopeNode, Preferences workbenchScopeNode) throws ExportException {
51 // TODO Auto-generated method stub
55 public void export(List<Content> contents,
57 ExportContext context,
59 IProgressMonitor monitor,
60 MapList<Content, Content> attachmentMap
61 ) throws ExportException {
63 final TransferableGraphWriter writer = (TransferableGraphWriter) writer_;
66 List<Resource> resources = context.session.syncRequest( ExportQueries.toResources2(contents) );
67 for ( final Resource model : resources ) {
68 // TODO: figure out a way to make the TG go directly into a file
69 // instead of having it all in memory at once.
70 SimanticsClipboard clipboard = context.session.syncRequest(new Read<SimanticsClipboard>() {
72 public SimanticsClipboard perform(ReadGraph graph) throws DatabaseException {
73 CopyHandler ch = graph.adapt( model, CopyHandler.class );
74 SimanticsClipboardImpl clipboard = new SimanticsClipboardImpl();
75 ch.copyToClipboard(graph, clipboard);
79 for (Set<Representation> object : clipboard.getContents()) {
80 TransferableGraph1 tg = ClipboardUtils.accept(object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH);
81 writer.writeFile(TransferableGraph1.BINDING, tg);
85 } catch (DatabaseException e) {
86 throw new ExportException(e);
92 public List<String> validate(String contentUri, ExportContext context, Variant options) {
93 return Collections.emptyList();