]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.ui/src/org/simantics/ui/workbench/action/PerformDefaultAction.java
22164e5042dd714aa3f42d3a35a89d7e6d853637
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / workbench / action / PerformDefaultAction.java
1 /*******************************************************************************
2  * Copyright (c) 2012 Association for Decentralized Information Management in
3  * Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.ui.workbench.action;
13
14 import org.eclipse.jface.action.Action;
15 import org.eclipse.swt.widgets.Control;
16 import org.eclipse.swt.widgets.Shell;
17 import org.eclipse.ui.IWorkbench;
18 import org.eclipse.ui.IWorkbenchWindow;
19 import org.eclipse.ui.PlatformUI;
20 import org.simantics.db.Resource;
21 import org.simantics.ui.SimanticsUI;
22 import org.simantics.utils.ui.workbench.WorkbenchUtils;
23
24 /**
25  * @author Tuukka Lehtonen
26  */
27 public class PerformDefaultAction extends Action {
28
29     private Control  control;
30     private Resource component;
31
32     public PerformDefaultAction(String name, Control control, Resource component) {
33         super(name);
34         this.control = control;
35         this.component = component;
36     }
37
38     @Override
39     public void run() {
40         final String perspectiveId = WorkbenchUtils.getCurrentPerspectiveId();
41         Shell shell = null;
42         if (control != null) {
43             shell = control.getShell();
44         } else {
45             IWorkbench wb = PlatformUI.getWorkbench();
46             IWorkbenchWindow window = wb.getActiveWorkbenchWindow();
47             if (window != null)
48                 shell = window.getShell();
49         }
50         SimanticsUI.getSession().asyncRequest(new ChooseActionRequest(shell, control, component, perspectiveId));
51     }
52
53 }