diff --git a/bundles/org.eclipse.tools.templates.core/META-INF/MANIFEST.MF b/bundles/org.eclipse.tools.templates.core/META-INF/MANIFEST.MF index f8c30c945e6..7f278de091f 100644 --- a/bundles/org.eclipse.tools.templates.core/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.tools.templates.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Templates Core Bundle-SymbolicName: org.eclipse.tools.templates.core -Bundle-Version: 1.0.0.qualifier +Bundle-Version: 1.1.0.qualifier Bundle-Activator: org.eclipse.tools.templates.core.internal.Activator Bundle-Vendor: Eclipse CDT Require-Bundle: org.eclipse.core.runtime, diff --git a/bundles/org.eclipse.tools.templates.core/src/org/eclipse/tools/templates/core/IGenerator.java b/bundles/org.eclipse.tools.templates.core/src/org/eclipse/tools/templates/core/IGenerator.java index 9a904fc4bf4..d9fbce34013 100644 --- a/bundles/org.eclipse.tools.templates.core/src/org/eclipse/tools/templates/core/IGenerator.java +++ b/bundles/org.eclipse.tools.templates.core/src/org/eclipse/tools/templates/core/IGenerator.java @@ -13,10 +13,43 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +/** + * Interface used by the Template Wizard to call on the generator to generate. Also provides other + * utility methods as necessary, but that should be limited. + */ public interface IGenerator { - void generate(Map model, IProgressMonitor monitor) throws CoreException; + /** + * Generate. + * + * @param model + * @param monitor + * @throws CoreException + * @deprecated The generator should manage it's own model. + */ + @Deprecated + default void generate(Map model, IProgressMonitor monitor) throws CoreException { + if (model.isEmpty()) { + generate(monitor); + } + } - IFile[] getFilesToOpen(); + /** + * Generate. + * + * @param monitor + * @throws CoreException + */ + default void generate(IProgressMonitor monitor) throws CoreException { + }; + + /** + * Return which files should be opened in the workbench when the generation is complete. + * + * @return files to open + */ + default IFile[] getFilesToOpen() { + return new IFile[0]; + } } diff --git a/bundles/org.eclipse.tools.templates.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.tools.templates.ui/META-INF/MANIFEST.MF index d489defeb40..1ba9b50e5bc 100644 --- a/bundles/org.eclipse.tools.templates.ui/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.tools.templates.ui/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Ui Bundle-SymbolicName: org.eclipse.tools.templates.ui;singleton:=true -Bundle-Version: 1.0.0.qualifier +Bundle-Version: 1.1.0.qualifier Bundle-Activator: org.eclipse.tools.templates.ui.internal.Activator Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, 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 a7d73182f07..d972de4c60f 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 @@ -24,17 +24,52 @@ import org.eclipse.ui.actions.WorkspaceModifyOperation; import org.eclipse.ui.ide.IDE; import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard; +/** + * The wizard component of a template. Takes over when the template is selected in the from the + * Template Selection Page in the parent wizard. + */ public abstract class TemplateWizard extends BasicNewResourceWizard { + /** + * The generator to be called when the wizard is finished. + * + * @return generator + */ protected abstract IGenerator getGenerator(); + /** + * Populate the model. + * + * @param model + * @deprecated The subclass should initialize the generator with information in the + * getGenerator() method. + */ + @Deprecated protected void populateModel(Map model) { // nothing by default } - + + /** + * Perform additional UI actions after the generation is complete. + * + * @param generator + */ + protected void postProcess(IGenerator generator) { + try { + IWorkbenchPage activePage = getWorkbench().getActiveWorkbenchWindow().getActivePage(); + for (IFile file : generator.getFilesToOpen()) { + IDE.openEditor(activePage, file); + } + } catch (PartInitException e) { + Activator.log(e); + } + } + @Override public boolean performFinish() { IGenerator generator = getGenerator(); + // TODO remove the model in 2.0. The getGenerator method should have + // initialized this. Map model = new HashMap<>(); populateModel(model); @@ -45,20 +80,13 @@ public abstract class TemplateWizard extends BasicNewResourceWizard { throws CoreException, InvocationTargetException, InterruptedException { monitor.beginTask("Generating project", 1); //$NON-NLS-1$ generator.generate(model, monitor); - monitor.done(); getWorkbench().getDisplay().asyncExec(new Runnable() { @Override public void run() { - try { - IWorkbenchPage activePage = getWorkbench().getActiveWorkbenchWindow().getActivePage(); - for (IFile file : generator.getFilesToOpen()) { - IDE.openEditor(activePage, file); - } - } catch (PartInitException e) { - Activator.log(e); - } + postProcess(generator); } }); + monitor.done(); } @Override