1 package org.simantics.document.ui.graphfile;
5 import org.eclipse.swt.widgets.Display;
6 import org.eclipse.ui.PartInitException;
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.Resource;
9 import org.simantics.db.common.request.ReadRequest;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.document.DocumentResource;
12 import org.simantics.document.ui.Activator;
13 import org.simantics.editors.Editors;
14 import org.simantics.graphfile.ontology.GraphFileResource;
15 import org.simantics.graphfile.util.GraphFileUtil;
16 import org.simantics.ui.SimanticsUI;
17 import org.simantics.ui.workbench.editor.AbstractResourceEditorAdapter;
18 import org.simantics.ui.workbench.editor.EditorAdapter;
19 import org.simantics.utils.ui.ExceptionUtils;
21 public class ExternalEditorAdapter extends AbstractResourceEditorAdapter implements EditorAdapter {
23 public ExternalEditorAdapter() {
24 super("External Editor",Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/page.png"));
29 public boolean canHandle(ReadGraph g, Resource r) throws DatabaseException {
30 GraphFileResource gf = GraphFileResource.getInstance(g);
31 DocumentResource doc = DocumentResource.getInstance(g);
32 if (!g.isInstanceOf(r, doc.FileDocument))
34 String filename = g.getPossibleRelatedValue(r, gf.HasResourceName);
35 return filename != null;
39 protected void openEditor(final Resource input) throws Exception {
40 SimanticsUI.getSession().asyncRequest(new ReadRequest() {
43 public void run(ReadGraph graph) throws DatabaseException {
44 final File file = GraphFileUtil.toTempFile(graph, input);
46 Display.getDefault().asyncExec(new Runnable() {
51 if (file.exists() && file.canRead()) {
53 Editors.openExternalEditor(file);
54 } catch (PartInitException e) {
55 ExceptionUtils.logAndShowError(e);