Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/ProvUI.java')
-rw-r--r--bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/ProvUI.java81
1 files changed, 81 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/ProvUI.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/ProvUI.java
new file mode 100644
index 000000000..a09162da6
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/ProvUI.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.equinox.p2.ui;
+
+import org.eclipse.core.runtime.*;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.statushandlers.StatusManager;
+
+/**
+ * Generic provisioning UI utility methods
+ *
+ * @since 3.4
+ */
+public class ProvUI {
+
+ /**
+ * Make an <code>IAdaptable</code> that adapts to the specified shell,
+ * suitable for passing for passing to any
+ * {@link org.eclipse.core.commands.operations.IUndoableOperation} or
+ * {@link org.eclipse.core.commands.operations.IOperationHistory} method
+ * that requires an {@link org.eclipse.core.runtime.IAdaptable}
+ * <code>uiInfo</code> parameter.
+ *
+ * @param shell
+ * the shell that should be returned by the IAdaptable when asked
+ * to adapt a shell. If this parameter is <code>null</code>,
+ * the returned shell will also be <code>null</code>.
+ *
+ * @return an IAdaptable that will return the specified shell.
+ */
+ public static IAdaptable getUIInfoAdapter(final Shell shell) {
+ return new IAdaptable() {
+ public Object getAdapter(Class clazz) {
+ if (clazz == Shell.class) {
+ return shell;
+ }
+ return null;
+ }
+ };
+ }
+
+ public static Shell getShell(IAdaptable uiInfo) {
+ Shell shell;
+ if (uiInfo != null) {
+ shell = (Shell) uiInfo.getAdapter(Shell.class);
+ if (shell != null) {
+ return shell;
+ }
+ }
+ // Get the default shell
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (window != null) {
+ return window.getShell();
+ }
+ Display display = Display.getCurrent();
+ if (display == null) {
+ display = Display.getDefault();
+ }
+ return display.getActiveShell();
+ }
+
+ public static void handleException(Throwable t, String message) {
+ if (message == null && t != null) {
+ message = t.getMessage();
+ }
+ IStatus status = new Status(IStatus.ERROR, ProvUIActivator.PLUGIN_ID, 0, message, t);
+ StatusManager.getManager().handle(status, StatusManager.SHOW | StatusManager.LOG);
+ }
+}

Back to the top