mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-12 11:35:21 +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.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.SubMonitor;
|
||||||
|
|
||||||
public abstract class FMProjectGenerator extends FMGenerator {
|
public abstract class FMProjectGenerator extends FMGenerator {
|
||||||
|
|
||||||
|
@ -65,6 +66,7 @@ public abstract class FMProjectGenerator extends FMGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IProject createProject(IProgressMonitor monitor) throws CoreException {
|
protected IProject createProject(IProgressMonitor monitor) throws CoreException {
|
||||||
|
SubMonitor sub = SubMonitor.convert(monitor, "Creating project", 1);
|
||||||
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
||||||
|
|
||||||
project = workspace.getRoot().getProject(projectName);
|
project = workspace.getRoot().getProject(projectName);
|
||||||
|
@ -75,13 +77,14 @@ public abstract class FMProjectGenerator extends FMGenerator {
|
||||||
description.setReferencedProjects(referencedProjects);
|
description.setReferencedProjects(referencedProjects);
|
||||||
}
|
}
|
||||||
initProjectDescription(description);
|
initProjectDescription(description);
|
||||||
project.create(description, monitor);
|
project.create(description, sub);
|
||||||
project.open(monitor);
|
project.open(sub);
|
||||||
} else {
|
} else {
|
||||||
// TODO make sure it's got all our settings or is this an error
|
// TODO make sure it's got all our settings or is this an error
|
||||||
// condition?
|
// condition?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub.worked(1);
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ public class NewWizard extends Wizard implements INewWizard {
|
||||||
protected NewWizard(String... tags) {
|
protected NewWizard(String... tags) {
|
||||||
this.tags = tags;
|
this.tags = tags;
|
||||||
setForcePreviousAndNextButtons(true);
|
setForcePreviousAndNextButtons(true);
|
||||||
|
setNeedsProgressMonitor(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setTemplateSelectionPageTitle(String title) {
|
protected void setTemplateSelectionPageTitle(String title) {
|
||||||
|
@ -61,6 +62,12 @@ public class NewWizard extends Wizard implements INewWizard {
|
||||||
nextWizard.init(workbench, selection);
|
nextWizard.init(workbench, selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void selectTemplate(String id) {
|
||||||
|
if (templateSelectionPage != null) {
|
||||||
|
templateSelectionPage.selectTemplate(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canFinish() {
|
public boolean canFinish() {
|
||||||
// Need to check with the template wizard
|
// Need to check with the template wizard
|
||||||
|
|
|
@ -100,6 +100,17 @@ public class TemplateSelectionPage extends WizardPage {
|
||||||
tags.addAll(template.getTags());
|
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);
|
templateTable.setTemplates(templates);
|
||||||
tagList.setInput(tags);
|
tagList.setInput(tags);
|
||||||
tagList.getList().select(0); // All
|
tagList.getList().select(0); // All
|
||||||
|
@ -107,6 +118,18 @@ public class TemplateSelectionPage extends WizardPage {
|
||||||
form.setWeights(new int[] { 20, 80 });
|
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() {
|
private void updateButtons() {
|
||||||
setPageComplete(templateTable.getSelectedTemplate() != null);
|
setPageComplete(templateTable.getSelectedTemplate() != null);
|
||||||
getContainer().updateButtons();
|
getContainer().updateButtons();
|
||||||
|
|
|
@ -15,6 +15,7 @@ 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.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.SubMonitor;
|
||||||
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
||||||
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.tools.templates.ui.internal.Activator;
|
||||||
|
@ -30,6 +31,10 @@ import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
|
||||||
*/
|
*/
|
||||||
public abstract class TemplateWizard extends BasicNewResourceWizard {
|
public abstract class TemplateWizard extends BasicNewResourceWizard {
|
||||||
|
|
||||||
|
public TemplateWizard() {
|
||||||
|
setNeedsProgressMonitor(true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The generator to be called when the wizard is finished.
|
* The generator to be called when the wizard is finished.
|
||||||
*
|
*
|
||||||
|
@ -78,15 +83,15 @@ public abstract class TemplateWizard extends BasicNewResourceWizard {
|
||||||
@Override
|
@Override
|
||||||
protected void execute(IProgressMonitor monitor)
|
protected void execute(IProgressMonitor monitor)
|
||||||
throws CoreException, InvocationTargetException, InterruptedException {
|
throws CoreException, InvocationTargetException, InterruptedException {
|
||||||
monitor.beginTask("Generating project", 1); //$NON-NLS-1$
|
SubMonitor sub = SubMonitor.convert(monitor, "Generating", 1);
|
||||||
generator.generate(model, monitor);
|
generator.generate(model, sub);
|
||||||
getWorkbench().getDisplay().asyncExec(new Runnable() {
|
getWorkbench().getDisplay().asyncExec(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
postProcess(generator);
|
postProcess(generator);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
monitor.done();
|
sub.done();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Reference in a new issue