]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.ui/src/org/simantics/ui/workbench/action/OpenEditorAction.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / workbench / action / OpenEditorAction.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.ui.workbench.action;\r
13 \r
14 import org.eclipse.core.runtime.SafeRunner;\r
15 import org.eclipse.jface.resource.ImageDescriptor;\r
16 import org.eclipse.jface.util.SafeRunnable;\r
17 import org.simantics.db.Resource;\r
18 import org.simantics.ui.workbench.ResourceEditorInput;\r
19 import org.simantics.utils.ui.action.PriorityAction;\r
20 import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
21 \r
22 /**\r
23  * A convenience implementation of IPriorityAction for opening a specified\r
24  * workbench EditorPart.\r
25  * \r
26  * @author Tuukka Lehtonen\r
27  */\r
28 public class OpenEditorAction extends PriorityAction {\r
29 \r
30     String   editorId;\r
31 \r
32     Resource r;\r
33 \r
34     public OpenEditorAction(int priority, String text, ImageDescriptor imgDesc, String editorId, Resource r) {\r
35         super(priority, text, imgDesc);\r
36         this.editorId = editorId;\r
37         this.r = r;\r
38     }\r
39 \r
40     @Override\r
41     public void run() {\r
42         SafeRunner.run(new SafeRunnable() {\r
43             @Override\r
44             public void run() throws Exception {\r
45                 WorkbenchUtils.openEditor(editorId, new ResourceEditorInput(editorId, r));\r
46             }\r
47         });\r
48     }\r
49 }\r