@Override
public IWizardPage getNextPage(IWizardPage page) {
// Templates are downloaded only when a user clicks "Next"
if (page == getWizard().getMainPage()) {
final Template template = getWizard().getModel().selectedTemplate.getValue();
// First, clear the cached first template page, as to not show the
// wrong page
firstTemplatePage = null;
if (template == null) {
// no need to log an error that a template was not
// selected, template validation occurs in the template
// selection part
// itself.
return null;
}
else if (template instanceof SimpleProject && !((SimpleProject) template).hasWizardPages()) {
// Handle the special case simple projects with no pages
return null;
}
else {
// Download the template contents for templates that contribute
// additional UI pages, as the
// content will determine the UI controls of the additional
// pages.
if (!TemplateUtils.hasBeenDownloaded(template)) {
final IStatus[] errors = new IStatus[1];
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
public void run() {
try {
getWizard().getContainer().run(true, true,
new TemplateDataUIJob(template, getWizard().getShell()));
}
catch (InvocationTargetException ce) {
String errorMessage = ErrorUtils.getErrorMessage(ce);
errors[0] = new Status(IStatus.ERROR, WizardPlugin.PLUGIN_ID, errorMessage, ce);
}
catch (InterruptedException ie) {
errors[0] = new Status(IStatus.ERROR, WizardPlugin.PLUGIN_ID,
"Interrupt exception while downloading data for " + template.getName());
}
}
});
if (errors[0] != null && !errors[0].isOK()) {
handleError(errors[0]);
return null;
}
// Let the UI know that the template was downloaded. This is
// Only needed as long as the content manager does not fire
// a more accurate event indicating which template changed.
// Once the content manager is updated with that change,
// this
// call back is no longer needed
getWizard().getMainPage().refreshTemplateInUI();
}
WizardUIInfo info = getUIInfo(template);
if (info == null || !hasTemplateWizardPages()) {
// Update the buttons so that the "Next" button is disabled.
// This is done
// indirectly by the wizard which calls hasNext() once
// again to determine the button states based on data
// already downloaded.
getWizard().getContainer().updateButtons();
return null;
}
ITemplateWizardPage previousPage = null;
ITemplateWizardPage templatePage = null;
ITemplateWizardPage firstPage = null;
try {
for (int i = 0; i < info.getPageCount(); i++) {
List<WizardUIInfoElement> pageElements = info.getElementsForPage(i);
if (pageElements == null || pageElements.isEmpty()) {
continue;
}
templatePage = new NewTemplateWizardPage(info.getPage(i).getDescription(), template,
new TemplateInputCollector(pageElements));
templatePage.setWizard(getWizard());
// Always set a new first template page, as the template
// selection may have changed and may
// have a different associated template page
if (firstPage == null) {
firstPage = templatePage;
}
if (previousPage != null) {
previousPage.setNextPage(templatePage);
}
previousPage = templatePage;
}
}
catch (Exception e) {
String error = ErrorUtils.getErrorMessage("Failed to load wizard page for project template for "
+ template.getName(), e);
handleError(new Status(Status.ERROR, WizardPlugin.PLUGIN_ID, error, e));
}
// Regardless of whether wizard pages where successfully
// resolved for the given template, update