X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.ui%2Fsrc%2Forg%2Fsimantics%2Fui%2Fworkbench%2Faction%2FDefaultActions.java;fp=bundles%2Forg.simantics.ui%2Fsrc%2Forg%2Fsimantics%2Fui%2Fworkbench%2Faction%2FDefaultActions.java;h=e715055dedca7435fcb91a24328f9a9abd3b475d;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/action/DefaultActions.java b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/action/DefaultActions.java new file mode 100644 index 000000000..e715055de --- /dev/null +++ b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/action/DefaultActions.java @@ -0,0 +1,65 @@ +package org.simantics.ui.workbench.action; + +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.simantics.db.Session; +import org.simantics.utils.ui.SWTUtils; +import org.simantics.utils.ui.workbench.WorkbenchUtils; + +/** + * @author Tuukka Lehtonen + */ +public final class DefaultActions { + + /** + * Perform a default workbench action on the specified input object using + * {@link ChooseActionRequest} from any thread asynchronously. + * + * @param session + * @param input + * @param rememberAction + * @param alwaysAsk + * @param neverPromptForAction true to never prompt/run an action if the + * action selection is ambiguous + */ + public static void asyncPerformDefaultAction( + final Session session, + final Object input, + final boolean rememberAction, + final boolean alwaysAsk, + final boolean neverPromptForAction) + { + SWTUtils.asyncExec(PlatformUI.getWorkbench().getDisplay(), new Runnable() { + @Override + public void run() { + performDefaultAction(session, input, rememberAction, alwaysAsk, neverPromptForAction); + } + }); + } + + /** + * Perform a default workbench action on the specified input object using + * {@link ChooseActionRequest} from the current thread. The current thread + * must be the SWT UI thread. + * + * @param session + * @param input + * @param rememberAction + * @param alwaysAsk + * @param neverPromptForAction true to never prompt/run an action if the + * action selection is ambiguous + */ + public static void performDefaultAction( + final Session session, + final Object input, + boolean rememberAction, + boolean alwaysAsk, + boolean neverPromptForAction) + { + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + Shell shell = window != null ? window.getShell() : null; + session.asyncRequest(new ChooseActionRequest(shell, null, input, WorkbenchUtils.getCurrentPerspectiveId(), rememberAction, alwaysAsk, neverPromptForAction)); + } + +}