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