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