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.action;
14 import org.eclipse.core.runtime.SafeRunner;
15 import org.eclipse.jface.util.SafeRunnable;
16 import org.simantics.db.Resource;
17 import org.simantics.ui.workbench.editor.EditorAdapter;
18 import org.simantics.utils.ui.action.IPriorityAction;
19 import org.simantics.utils.ui.action.PriorityAction;
22 * @author Tuukka Lehtonen
24 public class ResourceEditorAdapterAction extends PriorityAction {
26 private static final boolean DEBUG = false;
28 protected EditorAdapter adapter;
30 protected Object resource;
32 public ResourceEditorAdapterAction(EditorAdapter adapter, Object r) {
33 super(makeName(adapter), adapter.getIcon());
34 this.adapter = adapter;
38 public static String makeName(EditorAdapter adapter) {
40 return adapter.getName() + " (" + adapter.getClass().getName() + ")[" + adapter.getPriority() + "]";
42 return adapter.getName();
46 public final void run() {
47 SafeRunner.run(new SafeRunnable() {
49 public void run() throws Exception {
55 protected void safeRun() throws Exception {
56 adapter.openEditor(resource);
59 public EditorAdapter getAdapter() {
63 public Object getResource() {
68 public int getPriority() {
69 return adapter.getPriority();
72 public static IPriorityAction[] toActions(EditorAdapter[] adapters, Resource forResource) {
73 IPriorityAction[] actions = new IPriorityAction[adapters.length];
74 for (int i = 0; i < adapters.length; ++i) {
75 actions[i] = new ResourceEditorAdapterAction(adapters[i], forResource);