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.ui.workbench.editor;
14 import org.simantics.db.ReadGraph;
15 import org.simantics.db.exception.DatabaseException;
16 import org.simantics.ui.DoubleClickEvent;
17 import org.simantics.ui.IDoubleClickAction;
18 import org.simantics.ui.workbench.action.IWorkbenchActionHints;
19 import org.simantics.ui.workbench.action.ResourceEditorAdapterAction;
22 * @author Tuukka Lehtonen
24 public class OpenDefaultEditor implements IDoubleClickAction {
27 public void doubleClickEvent(DoubleClickEvent e) {
28 ReadGraph g = e.getGraph();
29 Object r = e.getResource();
31 Boolean remember = e.getHintContext().getHint(IWorkbenchActionHints.KEY_REMEMBER);
32 final boolean rememberChoice = remember != null ? remember : false;
34 Boolean ask = e.getHintContext().getHint(IWorkbenchActionHints.KEY_ALWAYS_ASK);
35 boolean alwaysAsk = ask != null ? ask : false;
37 EditorAdapter primaryAdapter = EditorRegistry.getInstance().getMappings().get(r);
38 if (!alwaysAsk && primaryAdapter != null) {
39 e.add(new ResourceEditorAdapterAction(primaryAdapter, r));
42 EditorAdapter[] editorAdapters = EditorRegistry.getInstance().getAdaptersFor(g, r);
43 for (final EditorAdapter a : editorAdapters) {
44 e.add(new ResourceEditorAdapterAction(a, r) {
46 protected void safeRun() throws Exception {
50 // Make this choice the default for the next time.
51 EditorRegistry.getInstance().getMappings().put(getResource(), getAdapter());
56 } catch (DatabaseException ex) {