1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-21 21:52:10 +02:00

Bug 561734 - Clean-up Activator for CDT Tools Templates UI

Clean-up Activator class, may be filly removed after TemplateExtension
rework.

Logging code should be less verbose after merging of
https://git.eclipse.org/r/#/c/160386/

Change-Id: I502e14ac40b3ae5d3850b195f9ad9177bfae5536
Signed-off-by: Alexander Fedorov <alexander.fedorov@arsysop.ru>
This commit is contained in:
Alexander Fedorov 2020-04-03 16:33:11 +03:00
parent e730f8b8d3
commit 68bb85e439
5 changed files with 36 additions and 83 deletions

View file

@ -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,

View file

@ -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();

View file

@ -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));
}
}

View file

@ -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);
}
}

View file

@ -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<String, Template> 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");