From d8e577d154d31c1f25851736d35ba0f26d337898 Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Wed, 13 Nov 2019 12:58:43 -0500 Subject: [PATCH] Bug 552481: Expose error when wizard fails An example of a failure that used to be buried in the log is a project that failed to be created due to different case resource exception. Change-Id: I513f0dbd36bbb116a5c7de296f7459d200d65af5 --- .../tools/templates/ui/TemplateWizard.java | 6 +- .../templates/ui/internal/Activator.java | 56 +++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/bundles/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/TemplateWizard.java b/bundles/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/TemplateWizard.java index 2cc25636141..4c38068a1da 100644 --- a/bundles/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/TemplateWizard.java +++ b/bundles/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/TemplateWizard.java @@ -99,8 +99,10 @@ public abstract class TemplateWizard extends BasicNewResourceWizard { return ResourcesPlugin.getWorkspace().getRoot(); } }); - } catch (InterruptedException | InvocationTargetException e) { - throw new RuntimeException(e); + } catch (InterruptedException e) { + Activator.errorDialog(getShell(), "Error Creating Project", "Project cannot be created", e, true); + } catch (InvocationTargetException e) { + Activator.errorDialog(getShell(), "Error Creating Project", "Project cannot be created", e.getTargetException(), true); } return true; } diff --git a/bundles/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/internal/Activator.java b/bundles/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/internal/Activator.java index f93228edacd..fe9fb6a8616 100644 --- a/bundles/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/internal/Activator.java +++ b/bundles/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/internal/Activator.java @@ -10,6 +10,8 @@ package org.eclipse.tools.templates.ui.internal; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; @@ -17,6 +19,7 @@ import org.osgi.framework.BundleContext; * The activator class controls the plug-in life cycle */ public class Activator extends AbstractUIPlugin { + public static final String PLUGIN_ID = "org.eclipse.tools.templates.ui"; //$NON-NLS-1$ private static Activator plugin; @@ -52,4 +55,57 @@ public class Activator extends AbstractUIPlugin { } } + /** + * Creates an error status. + * + * @noreference This method is not intended to be referenced by clients. + */ + public static Status createErrorStatus(String message) { + return createErrorStatus(message, null); + } + + /** + * Creates an error status. + * + * @noreference This method is not intended to be referenced by clients. + */ + public static Status createErrorStatus(String message, Throwable e) { + return new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, e); + } + + /** + * @noreference This method is not intended to be referenced by clients. + */ + public static void log(IStatus status) { + plugin.getLog().log(status); + } + + /** + * @noreference This method is not intended to be referenced by clients. + */ + public static void log(String message, Throwable e) { + log(createErrorStatus(message, e)); + } + + /** + * Utility method with conventions + */ + public static void errorDialog(Shell shell, String title, String message, Throwable t, boolean logError) { + if (logError) + log(message, t); + + IStatus status; + if (t instanceof CoreException) { + status = ((CoreException) t).getStatus(); + // if the 'message' resource string and the IStatus' message are the same, + // don't show both in the dialog + if (status != null && message.equals(status.getMessage())) { + message = null; + } + } else { + status = new Status(IStatus.ERROR, PLUGIN_ID, -1, "Internal Error: ", t); //$NON-NLS-1$ + } + ErrorDialog.openError(shell, title, message, status); + } + }