diff --git a/tools.templates/org.eclipse.tools.templates.ui/META-INF/MANIFEST.MF b/tools.templates/org.eclipse.tools.templates.ui/META-INF/MANIFEST.MF index 6de00f12d22..2d4a520074a 100644 --- a/tools.templates/org.eclipse.tools.templates.ui/META-INF/MANIFEST.MF +++ b/tools.templates/org.eclipse.tools.templates.ui/META-INF/MANIFEST.MF @@ -1,8 +1,9 @@ Manifest-Version: 1.0 +Automatic-Module-Name: org.eclipse.tools.templates.ui Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.tools.templates.ui;singleton:=true -Bundle-Version: 1.1.100.qualifier +Bundle-Version: 1.1.200.qualifier Bundle-Activator: org.eclipse.tools.templates.ui.internal.Activator Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, diff --git a/tools.templates/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/TemplateSelectionPage.java b/tools.templates/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/TemplateSelectionPage.java index 0c5db3403ba..c5360f18ed3 100644 --- a/tools.templates/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/TemplateSelectionPage.java +++ b/tools.templates/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/TemplateSelectionPage.java @@ -17,6 +17,7 @@ import java.util.List; import java.util.Set; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Platform; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.wizard.IWizardPage; @@ -149,7 +150,7 @@ public class TemplateSelectionPage extends WizardPage { nextWizard.addPages(); return nextWizard.getPages()[0]; } catch (CoreException e) { - Activator.log(e); + Platform.getLog(getClass()).log(e.getStatus()); } } return super.getNextPage(); diff --git a/tools.templates/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/TemplateWizard.java b/tools.templates/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/TemplateWizard.java index a96f150af3e..4b9dcf727be 100644 --- a/tools.templates/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/TemplateWizard.java +++ b/tools.templates/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/TemplateWizard.java @@ -17,16 +17,21 @@ import java.util.Map; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.ILog; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.core.runtime.jobs.ISchedulingRule; +import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.tools.templates.core.IGenerator; -import org.eclipse.tools.templates.ui.internal.Activator; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PartInitException; import org.eclipse.ui.actions.WorkspaceModifyOperation; import org.eclipse.ui.ide.IDE; import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard; +import org.osgi.framework.FrameworkUtil; /** * The wizard component of a template. Takes over when the template is selected in the from the @@ -69,7 +74,7 @@ public abstract class TemplateWizard extends BasicNewResourceWizard { IDE.openEditor(activePage, file); } } catch (PartInitException e) { - Activator.log(e); + log("Failed to open editor", e); } } @@ -103,12 +108,28 @@ public abstract class TemplateWizard extends BasicNewResourceWizard { } }); } catch (InterruptedException e) { - Activator.errorDialog(getShell(), "Error Creating Project", "Project cannot be created", e, true); + handle(e); } catch (InvocationTargetException e) { - Activator.errorDialog(getShell(), "Error Creating Project", "Project cannot be created", - e.getTargetException(), true); + handle(e.getTargetException()); } return true; } + private void handle(Throwable target) { + String message = "Project cannot be created"; + log(message, target); + IStatus status; + if (target instanceof CoreException) { + status = ((CoreException) target).getStatus(); + } else { + status = new Status(IStatus.ERROR, FrameworkUtil.getBundle(getClass()).getSymbolicName(), + "Internal Error: ", target); + } + ErrorDialog.openError(getShell(), "Error Creating Project", message, status); + } + + private void log(String message, Throwable e) { + ILog log = Platform.getLog(getClass()); + log.log(new Status(IStatus.ERROR, log.getBundle().getSymbolicName(), message, e)); + } } diff --git a/tools.templates/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/internal/Activator.java b/tools.templates/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/internal/Activator.java index 170d5207b13..47ac3111dbf 100644 --- a/tools.templates/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/internal/Activator.java +++ b/tools.templates/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/internal/Activator.java @@ -10,18 +10,13 @@ *******************************************************************************/ 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.BundleActivator; import org.osgi.framework.BundleContext; /** * The activator class controls the plug-in life cycle */ -public class Activator extends AbstractUIPlugin { +public class Activator implements BundleActivator { public static final String PLUGIN_ID = "org.eclipse.tools.templates.ui"; //$NON-NLS-1$ private static Activator plugin; @@ -30,85 +25,17 @@ public class Activator extends AbstractUIPlugin { @Override public void start(BundleContext context) throws Exception { - super.start(context); plugin = this; - templateExtension = new TemplateExtension(); } @Override public void stop(BundleContext context) throws Exception { plugin = null; - super.stop(context); - } - - public static String getId() { - return plugin.getBundle().getSymbolicName(); } public static TemplateExtension getTemplateExtension() { return plugin.templateExtension; } - public static void log(Exception e) { - if (e instanceof CoreException) { - plugin.getLog().log(((CoreException) e).getStatus()); - } else { - plugin.getLog().log(new Status(IStatus.ERROR, getId(), e.getLocalizedMessage(), e)); - } - } - - /** - * 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); - } - } diff --git a/tools.templates/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/internal/TemplateExtension.java b/tools.templates/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/internal/TemplateExtension.java index e2c17c7f460..e30692706ea 100644 --- a/tools.templates/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/internal/TemplateExtension.java +++ b/tools.templates/org.eclipse.tools.templates.ui/src/org/eclipse/tools/templates/ui/internal/TemplateExtension.java @@ -18,7 +18,9 @@ import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.Platform; +import org.osgi.framework.FrameworkUtil; +//FIXME: AF: reimplement as a service public class TemplateExtension { private Map templates; @@ -32,7 +34,8 @@ public class TemplateExtension { tags = new HashMap<>(); IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint point = registry.getExtensionPoint(Activator.getId(), "templates"); //$NON-NLS-1$ + IExtensionPoint point = registry.getExtensionPoint(FrameworkUtil.getBundle(getClass()).getSymbolicName(), + "templates"); //$NON-NLS-1$ // tags Tag allTag = new Tag(Tag.ALL_ID, "All");