mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +02:00
Add API to select a template. Also some progress monitor cleanup.
Change-Id: Ic1070fff49ee352c1ab0ccd11fa12cab36e602e3
This commit is contained in:
parent
b6038873b1
commit
8b8a9babc5
4 changed files with 43 additions and 5 deletions
|
@ -16,6 +16,7 @@ import org.eclipse.core.resources.IWorkspace;
|
|||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.SubMonitor;
|
||||
|
||||
public abstract class FMProjectGenerator extends FMGenerator {
|
||||
|
||||
|
@ -65,6 +66,7 @@ public abstract class FMProjectGenerator extends FMGenerator {
|
|||
}
|
||||
|
||||
protected IProject createProject(IProgressMonitor monitor) throws CoreException {
|
||||
SubMonitor sub = SubMonitor.convert(monitor, "Creating project", 1);
|
||||
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
||||
|
||||
project = workspace.getRoot().getProject(projectName);
|
||||
|
@ -75,13 +77,14 @@ public abstract class FMProjectGenerator extends FMGenerator {
|
|||
description.setReferencedProjects(referencedProjects);
|
||||
}
|
||||
initProjectDescription(description);
|
||||
project.create(description, monitor);
|
||||
project.open(monitor);
|
||||
project.create(description, sub);
|
||||
project.open(sub);
|
||||
} else {
|
||||
// TODO make sure it's got all our settings or is this an error
|
||||
// condition?
|
||||
}
|
||||
|
||||
sub.worked(1);
|
||||
return project;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ public class NewWizard extends Wizard implements INewWizard {
|
|||
protected NewWizard(String... tags) {
|
||||
this.tags = tags;
|
||||
setForcePreviousAndNextButtons(true);
|
||||
setNeedsProgressMonitor(true);
|
||||
}
|
||||
|
||||
protected void setTemplateSelectionPageTitle(String title) {
|
||||
|
@ -61,6 +62,12 @@ public class NewWizard extends Wizard implements INewWizard {
|
|||
nextWizard.init(workbench, selection);
|
||||
}
|
||||
|
||||
public void selectTemplate(String id) {
|
||||
if (templateSelectionPage != null) {
|
||||
templateSelectionPage.selectTemplate(id);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFinish() {
|
||||
// Need to check with the template wizard
|
||||
|
|
|
@ -100,6 +100,17 @@ public class TemplateSelectionPage extends WizardPage {
|
|||
tags.addAll(template.getTags());
|
||||
}
|
||||
|
||||
if (requestedTags.length == 1) {
|
||||
// Implies that the requested tag is actually the same as All.
|
||||
// We can safely remove it.
|
||||
for (Tag tag : tags) {
|
||||
if (tag.getId().equals(requestedTags[0])) {
|
||||
tags.remove(tag);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
templateTable.setTemplates(templates);
|
||||
tagList.setInput(tags);
|
||||
tagList.getList().select(0); // All
|
||||
|
@ -107,6 +118,18 @@ public class TemplateSelectionPage extends WizardPage {
|
|||
form.setWeights(new int[] { 20, 80 });
|
||||
}
|
||||
|
||||
public void selectTemplate(String id) {
|
||||
if (templateTable != null) {
|
||||
for (Template template : templates) {
|
||||
if (template.getId().equals(id)) {
|
||||
templateTable.selectTemplate(template);
|
||||
updateButtons();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateButtons() {
|
||||
setPageComplete(templateTable.getSelectedTemplate() != null);
|
||||
getContainer().updateButtons();
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.eclipse.core.resources.IFile;
|
|||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.SubMonitor;
|
||||
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
||||
import org.eclipse.tools.templates.core.IGenerator;
|
||||
import org.eclipse.tools.templates.ui.internal.Activator;
|
||||
|
@ -30,6 +31,10 @@ import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
|
|||
*/
|
||||
public abstract class TemplateWizard extends BasicNewResourceWizard {
|
||||
|
||||
public TemplateWizard() {
|
||||
setNeedsProgressMonitor(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* The generator to be called when the wizard is finished.
|
||||
*
|
||||
|
@ -78,15 +83,15 @@ public abstract class TemplateWizard extends BasicNewResourceWizard {
|
|||
@Override
|
||||
protected void execute(IProgressMonitor monitor)
|
||||
throws CoreException, InvocationTargetException, InterruptedException {
|
||||
monitor.beginTask("Generating project", 1); //$NON-NLS-1$
|
||||
generator.generate(model, monitor);
|
||||
SubMonitor sub = SubMonitor.convert(monitor, "Generating", 1);
|
||||
generator.generate(model, sub);
|
||||
getWorkbench().getDisplay().asyncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
postProcess(generator);
|
||||
}
|
||||
});
|
||||
monitor.done();
|
||||
sub.done();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Reference in a new issue