]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
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 (file)
index 0000000..e715055
--- /dev/null
@@ -0,0 +1,65 @@
+package org.simantics.ui.workbench.action;\r
+\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.ui.IWorkbenchWindow;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.simantics.db.Session;\r
+import org.simantics.utils.ui.SWTUtils;\r
+import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public final class DefaultActions {\r
+\r
+    /**\r
+     * Perform a default workbench action on the specified input object using\r
+     * {@link ChooseActionRequest} from any thread asynchronously.\r
+     * \r
+     * @param session\r
+     * @param input\r
+     * @param rememberAction\r
+     * @param alwaysAsk\r
+     * @param neverPromptForAction true to never prompt/run an action if the\r
+     *        action selection is ambiguous\r
+     */\r
+    public static void asyncPerformDefaultAction(\r
+            final Session session,\r
+            final Object input,\r
+            final boolean rememberAction,\r
+            final boolean alwaysAsk,\r
+            final boolean neverPromptForAction)\r
+    {\r
+        SWTUtils.asyncExec(PlatformUI.getWorkbench().getDisplay(), new Runnable() {\r
+            @Override\r
+            public void run() {\r
+                performDefaultAction(session, input, rememberAction, alwaysAsk, neverPromptForAction);\r
+            }\r
+        });\r
+    }\r
+\r
+    /**\r
+     * Perform a default workbench action on the specified input object using\r
+     * {@link ChooseActionRequest} from the current thread. The current thread\r
+     * must be the SWT UI thread.\r
+     * \r
+     * @param session\r
+     * @param input\r
+     * @param rememberAction\r
+     * @param alwaysAsk\r
+     * @param neverPromptForAction true to never prompt/run an action if the\r
+     *        action selection is ambiguous\r
+     */\r
+    public static void performDefaultAction(\r
+            final Session session,\r
+            final Object input,\r
+            boolean rememberAction,\r
+            boolean alwaysAsk,\r
+            boolean neverPromptForAction)\r
+    {\r
+        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();\r
+        Shell shell = window != null ? window.getShell() : null;\r
+        session.asyncRequest(new ChooseActionRequest(shell, null, input, WorkbenchUtils.getCurrentPerspectiveId(), rememberAction, alwaysAsk, neverPromptForAction));\r
+    }\r
+\r
+}\r