]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.ui/src/org/simantics/ui/workbench/action/PerformDefaultAction.java
Minor cleanup for performing default actions
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / workbench / action / PerformDefaultAction.java
1 /*******************************************************************************
2  * Copyright (c) 2012, 2017 Association for Decentralized Information Management
3  * in 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.core.runtime.IStatus;
15 import org.eclipse.core.runtime.Status;
16 import org.eclipse.jface.action.Action;
17 import org.eclipse.swt.widgets.Control;
18 import org.eclipse.swt.widgets.Shell;
19 import org.eclipse.ui.IWorkbench;
20 import org.eclipse.ui.IWorkbenchWindow;
21 import org.eclipse.ui.PlatformUI;
22 import org.simantics.db.common.procedure.adapter.ProcedureAdapter;
23 import org.simantics.ui.SimanticsUI;
24 import org.simantics.ui.internal.Activator;
25 import org.simantics.utils.ui.workbench.WorkbenchUtils;
26
27 /**
28  * @author Tuukka Lehtonen
29  */
30 public class PerformDefaultAction extends Action {
31
32     private Control  control;
33     private Object   input;
34
35     public PerformDefaultAction(String name, Control control, Object input) {
36         super(name);
37         this.control = control;
38         this.input = input;
39     }
40
41     @Override
42     public void run() {
43         final String perspectiveId = WorkbenchUtils.getCurrentPerspectiveId();
44         Shell shell = null;
45         if (control != null) {
46             shell = control.getShell();
47         } else {
48             IWorkbench wb = PlatformUI.getWorkbench();
49             IWorkbenchWindow window = wb.getActiveWorkbenchWindow();
50             if (window != null)
51                 shell = window.getShell();
52         }
53         SimanticsUI.getSession().asyncRequest(
54                 new ChooseActionRequest(shell, control, input, perspectiveId),
55                 new ProcedureAdapter<Object>() {
56                     @Override
57                     public void exception(Throwable t) {
58                         Activator.getDefault().getLog().log(
59                                 new Status(IStatus.ERROR, Activator.PLUGIN_ID,
60                                         "Failed to choose action for input " + input + ", see exception for details.", t));
61                     }
62                 });
63     }
64
65 }