1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.ui.diagramEditor;
14 import org.eclipse.ui.PartInitException;
15 import org.eclipse.ui.PlatformUI;
16 import org.simantics.Simantics;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.common.request.ReadRequest;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.layer0.request.PossibleModel;
22 import org.simantics.db.layer0.variable.RVI;
23 import org.simantics.diagram.stubs.DiagramResource;
24 import org.simantics.modeling.ui.Activator;
25 import org.simantics.ui.workbench.ResourceEditorInput2;
26 import org.simantics.ui.workbench.editor.AbstractResourceEditorAdapter;
27 import org.simantics.utils.ui.ErrorLogger;
28 import org.simantics.utils.ui.workbench.WorkbenchUtils;
31 * @author Tuukka Lehtonen
33 public class OpenDiagramAdapter extends AbstractResourceEditorAdapter {
35 private static final String EDITOR_ID = "org.simantics.modeling.ui.plainDiagramEditor"; //$NON-NLS-1$
37 public OpenDiagramAdapter() {
38 super(Messages.OpenDiagramAdapter_DiagramEditor, Activator.COMPOSITE_ICON);
41 protected String getEditorId() {
46 public boolean canHandle(ReadGraph g, Resource r) throws DatabaseException {
47 return g.isInstanceOf(r, DiagramResource.getInstance(g).Diagram);
51 public void openEditor(final Resource r) throws Exception {
53 Simantics.getSession().asyncRequest(new ReadRequest() {
56 public void run(ReadGraph g) throws DatabaseException {
58 final Resource model = g.sync(new PossibleModel(r));
59 if(model == null) return;
61 PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
65 String editorId = getEditorId();
66 WorkbenchUtils.openEditor(editorId, new ResourceEditorInput2(editorId, r, model, (RVI)null));
67 } catch (PartInitException e) {
68 ErrorLogger.defaultLogError(e);