]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.ui/src/org/simantics/ui/workbench/action/OpenWithDialogAction.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / workbench / action / OpenWithDialogAction.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.jface.action.Action;\r
15 import org.eclipse.jface.action.IAction;\r
16 import org.eclipse.swt.widgets.Shell;\r
17 import org.simantics.db.Resource;\r
18 import org.simantics.ui.dialogs.ActionChooserDialog;\r
19 import org.simantics.ui.workbench.editor.EditorAdapter;\r
20 import org.simantics.utils.ui.action.IPriorityAction;\r
21 \r
22 \r
23 /**\r
24  * @author Tuukka Lehtonen\r
25  */\r
26 public class OpenWithDialogAction extends Action {\r
27 \r
28     Shell             shell;\r
29     String            description;\r
30     IPriorityAction[] actions;\r
31 \r
32     public OpenWithDialogAction(Shell parent, EditorAdapter[] adapters, Resource r) {\r
33         super("Open With...");\r
34         this.shell = parent;\r
35         this.description = "Open with:";\r
36         this.actions = ResourceEditorAdapterAction.toActions(adapters, r);\r
37     }\r
38 \r
39     @Override\r
40     public void run() {\r
41         ActionChooserDialog dialog = new ActionChooserDialog(shell, actions, "Choose Editor", description);\r
42         dialog.open();\r
43         IAction a = dialog.getChosenAction();\r
44         if (a != null) {\r
45             a.run();\r
46         }\r
47     }\r
48 \r
49 }\r