1 package org.simantics.modeling.ui.componentTypeEditor;
3 import org.eclipse.core.runtime.IAdaptable;
4 import org.eclipse.jface.viewers.IStructuredSelection;
5 import org.eclipse.ui.IWorkbenchPage;
6 import org.eclipse.ui.PartInitException;
7 import org.eclipse.ui.PlatformUI;
8 import org.simantics.Simantics;
9 import org.simantics.db.ReadGraph;
10 import org.simantics.db.Resource;
11 import org.simantics.db.common.request.ReadRequest;
12 import org.simantics.db.exception.DatabaseException;
13 import org.simantics.layer0.Layer0;
14 import org.simantics.scl.ui.editor2.StandardSCLModuleEditorInput;
15 import org.simantics.ui.workbench.editor.AbstractResourceEditorAdapter;
16 import org.simantics.ui.workbench.editor.EditorAdapter;
17 import org.simantics.utils.ui.workbench.WorkbenchUtils;
19 public class SCLModuleEditorAdapter extends AbstractResourceEditorAdapter
20 implements EditorAdapter {
22 public SCLModuleEditorAdapter() {
23 super("SCL Module Editor", null, 20);
27 public boolean canHandle(ReadGraph g, Object input)
28 throws DatabaseException {
29 if(input instanceof IStructuredSelection)
30 input = ((IStructuredSelection)input).getFirstElement();
31 if(!(input instanceof Resource)) {
32 if(input instanceof IAdaptable) {
33 input = ((IAdaptable)input).getAdapter(Resource.class);
40 Resource resource = (Resource)input;
41 Layer0 L0 = Layer0.getInstance(g);
42 return g.isInstanceOf(resource, L0.SCLModule);
45 protected void openEditor(Resource input) throws Exception {
46 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
49 Simantics.getSession().asyncRequest(new ReadRequest() {
51 public void run(ReadGraph graph) throws DatabaseException {
52 String uri = graph.getURI(input);
53 PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
57 WorkbenchUtils.openEditor("org.simantics.scl.ui.editor2",
58 new StandardSCLModuleEditorInput(uri));
59 } catch (PartInitException e) {