mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +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:
parent
e730f8b8d3
commit
68bb85e439
5 changed files with 36 additions and 83 deletions
|
@ -1,8 +1,9 @@
|
||||||
Manifest-Version: 1.0
|
Manifest-Version: 1.0
|
||||||
|
Automatic-Module-Name: org.eclipse.tools.templates.ui
|
||||||
Bundle-ManifestVersion: 2
|
Bundle-ManifestVersion: 2
|
||||||
Bundle-Name: %pluginName
|
Bundle-Name: %pluginName
|
||||||
Bundle-SymbolicName: org.eclipse.tools.templates.ui;singleton:=true
|
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
|
Bundle-Activator: org.eclipse.tools.templates.ui.internal.Activator
|
||||||
Require-Bundle: org.eclipse.ui,
|
Require-Bundle: org.eclipse.ui,
|
||||||
org.eclipse.core.runtime,
|
org.eclipse.core.runtime,
|
||||||
|
|
|
@ -17,6 +17,7 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||||
import org.eclipse.jface.wizard.IWizardPage;
|
import org.eclipse.jface.wizard.IWizardPage;
|
||||||
|
@ -149,7 +150,7 @@ public class TemplateSelectionPage extends WizardPage {
|
||||||
nextWizard.addPages();
|
nextWizard.addPages();
|
||||||
return nextWizard.getPages()[0];
|
return nextWizard.getPages()[0];
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
Activator.log(e);
|
Platform.getLog(getClass()).log(e.getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.getNextPage();
|
return super.getNextPage();
|
||||||
|
|
|
@ -17,16 +17,21 @@ import java.util.Map;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.ILog;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
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.SubMonitor;
|
||||||
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
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.core.IGenerator;
|
||||||
import org.eclipse.tools.templates.ui.internal.Activator;
|
|
||||||
import org.eclipse.ui.IWorkbenchPage;
|
import org.eclipse.ui.IWorkbenchPage;
|
||||||
import org.eclipse.ui.PartInitException;
|
import org.eclipse.ui.PartInitException;
|
||||||
import org.eclipse.ui.actions.WorkspaceModifyOperation;
|
import org.eclipse.ui.actions.WorkspaceModifyOperation;
|
||||||
import org.eclipse.ui.ide.IDE;
|
import org.eclipse.ui.ide.IDE;
|
||||||
import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
|
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
|
* 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);
|
IDE.openEditor(activePage, file);
|
||||||
}
|
}
|
||||||
} catch (PartInitException e) {
|
} 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) {
|
} catch (InterruptedException e) {
|
||||||
Activator.errorDialog(getShell(), "Error Creating Project", "Project cannot be created", e, true);
|
handle(e);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
Activator.errorDialog(getShell(), "Error Creating Project", "Project cannot be created",
|
handle(e.getTargetException());
|
||||||
e.getTargetException(), true);
|
|
||||||
}
|
}
|
||||||
return true;
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,18 +10,13 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.tools.templates.ui.internal;
|
package org.eclipse.tools.templates.ui.internal;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.osgi.framework.BundleActivator;
|
||||||
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;
|
import org.osgi.framework.BundleContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The activator class controls the plug-in life cycle
|
* 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$
|
public static final String PLUGIN_ID = "org.eclipse.tools.templates.ui"; //$NON-NLS-1$
|
||||||
|
|
||||||
private static Activator plugin;
|
private static Activator plugin;
|
||||||
|
@ -30,85 +25,17 @@ public class Activator extends AbstractUIPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(BundleContext context) throws Exception {
|
public void start(BundleContext context) throws Exception {
|
||||||
super.start(context);
|
|
||||||
plugin = this;
|
plugin = this;
|
||||||
|
|
||||||
templateExtension = new TemplateExtension();
|
templateExtension = new TemplateExtension();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop(BundleContext context) throws Exception {
|
public void stop(BundleContext context) throws Exception {
|
||||||
plugin = null;
|
plugin = null;
|
||||||
super.stop(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getId() {
|
|
||||||
return plugin.getBundle().getSymbolicName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TemplateExtension getTemplateExtension() {
|
public static TemplateExtension getTemplateExtension() {
|
||||||
return plugin.templateExtension;
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,9 @@ import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
import org.eclipse.core.runtime.IExtensionPoint;
|
import org.eclipse.core.runtime.IExtensionPoint;
|
||||||
import org.eclipse.core.runtime.IExtensionRegistry;
|
import org.eclipse.core.runtime.IExtensionRegistry;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
import org.osgi.framework.FrameworkUtil;
|
||||||
|
|
||||||
|
//FIXME: AF: reimplement as a service
|
||||||
public class TemplateExtension {
|
public class TemplateExtension {
|
||||||
|
|
||||||
private Map<String, Template> templates;
|
private Map<String, Template> templates;
|
||||||
|
@ -32,7 +34,8 @@ public class TemplateExtension {
|
||||||
tags = new HashMap<>();
|
tags = new HashMap<>();
|
||||||
|
|
||||||
IExtensionRegistry registry = Platform.getExtensionRegistry();
|
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
|
// tags
|
||||||
Tag allTag = new Tag(Tag.ALL_ID, "All");
|
Tag allTag = new Tag(Tag.ALL_ID, "All");
|
||||||
|
|
Loading…
Add table
Reference in a new issue