]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.ui/src/org/simantics/ui/workbench/action/DefaultActions.java
Minor cleanup for performing default actions
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / workbench / action / DefaultActions.java
1 package org.simantics.ui.workbench.action;
2
3 import org.eclipse.swt.widgets.Control;
4 import org.eclipse.swt.widgets.Shell;
5 import org.eclipse.ui.IWorkbenchWindow;
6 import org.eclipse.ui.PlatformUI;
7 import org.simantics.db.Session;
8 import org.simantics.utils.ui.SWTUtils;
9 import org.simantics.utils.ui.workbench.WorkbenchUtils;
10
11 /**
12  * @author Tuukka Lehtonen
13  */
14 public final class DefaultActions {
15
16     /**
17      * Perform a default workbench action on the specified input object using
18      * {@link ChooseActionRequest} from any thread asynchronously.
19      * 
20      * @param session
21      * @param input
22      * @param rememberAction
23      * @param alwaysAsk
24      * @param neverPromptForAction true to never prompt/run an action if the
25      *        action selection is ambiguous
26      */
27     public static void asyncPerformDefaultAction(
28             final Session session,
29             final Object input,
30             final boolean rememberAction,
31             final boolean alwaysAsk,
32             final boolean neverPromptForAction)
33     {
34         SWTUtils.asyncExec(PlatformUI.getWorkbench().getDisplay(), new Runnable() {
35             @Override
36             public void run() {
37                 performDefaultAction(session, input, rememberAction, alwaysAsk, neverPromptForAction);
38             }
39         });
40     }
41
42     /**
43      * Perform a default workbench action on the specified input object using
44      * {@link ChooseActionRequest} from the current thread. The current thread
45      * must be the SWT UI thread.
46      * 
47      * @param session
48      * @param input
49      * @param rememberAction
50      * @param alwaysAsk
51      * @param neverPromptForAction true to never prompt/run an action if the
52      *        action selection is ambiguous
53      */
54     public static void performDefaultAction(
55             final Session session,
56             final Object input,
57             boolean rememberAction,
58             boolean alwaysAsk,
59             boolean neverPromptForAction)
60     {
61         IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
62         Shell shell = window != null ? window.getShell() : null;
63         session.asyncRequest(new ChooseActionRequest(shell, null, input, WorkbenchUtils.getCurrentPerspectiveId(), rememberAction, alwaysAsk, neverPromptForAction));
64     }
65
66     /**
67      * Perform a default workbench action on the specified input object using
68      * {@link ChooseActionRequest} from the current thread. The current thread
69      * must be the SWT UI thread.
70      * 
71      * @param control the control contained
72      */
73     public static void performDefaultAction(Control control, Object input) {
74         new PerformDefaultAction("Perform Default Action", control, input).run();
75     }
76
77 }