]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.ui/src/org/simantics/ui/workbench/action/PerformDefaultAction.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / workbench / action / PerformDefaultAction.java
1 /*******************************************************************************\r
2  * Copyright (c) 2012 Association for Decentralized Information Management in\r
3  * 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.swt.widgets.Control;\r
16 import org.eclipse.swt.widgets.Shell;\r
17 import org.eclipse.ui.IWorkbench;\r
18 import org.eclipse.ui.IWorkbenchWindow;\r
19 import org.eclipse.ui.PlatformUI;\r
20 import org.simantics.db.Resource;\r
21 import org.simantics.ui.SimanticsUI;\r
22 import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
23 \r
24 /**\r
25  * @author Tuukka Lehtonen\r
26  */\r
27 public class PerformDefaultAction extends Action {\r
28 \r
29     private Control  control;\r
30     private Resource component;\r
31 \r
32     public PerformDefaultAction(String name, Control control, Resource component) {\r
33         super(name);\r
34         this.control = control;\r
35         this.component = component;\r
36     }\r
37 \r
38     @Override\r
39     public void run() {\r
40         final String perspectiveId = WorkbenchUtils.getCurrentPerspectiveId();\r
41         Shell shell = null;\r
42         if (control != null) {\r
43             shell = control.getShell();\r
44         } else {\r
45             IWorkbench wb = PlatformUI.getWorkbench();\r
46             IWorkbenchWindow window = wb.getActiveWorkbenchWindow();\r
47             if (window != null)\r
48                 shell = window.getShell();\r
49         }\r
50         SimanticsUI.getSession().asyncRequest(new ChooseActionRequest(shell, control, component, perspectiveId));\r
51     }\r
52 \r
53 }