final WizardEditorModel editorModel = getEditorModel();
try
{
if (startFromFile && fileName != null)
{
final AbstractReportDefinition substituteReportDefinition = loadDefinitionFromFile(new File(fileName));
if (substituteReportDefinition == null)
{
return false;
}
substituteReportDefinition.setName(editorModel.getReportDefinition().getName());
substituteReportDefinition.setAttribute("http://reporting.pentaho.org/namespaces/engine/attributes/wizard", "template", fileName);
editorModel.setReportDefinition(substituteReportDefinition, false);
return true;
}
if (editorModel.isEditing())
{
if (selectedTemplateChanged)
{
final AbstractReportDefinition report;
if (selectedTemplate == -1)
{
report = editorModel.getEmptyTemplate();
}
else
{
final File file = templateHash.get(selectedTemplate);
if (file != null)
{
fileName = file.getAbsolutePath();
report = loadDefinitionFromFile(file);
if (report == null)
{
return false;
}
}
else
{
return false;
}
}
final WizardSpecification specification = editorModel.getReportSpec();
final DataFactory dataFactory = editorModel.getReportDefinition().getDataFactory().derive();
final String oldName = editorModel.getReportDefinition().getName();
report.setAttribute("http://reporting.pentaho.org/namespaces/engine/attributes/wizard", "template", fileName);
report.setDataFactory(dataFactory);
report.setName(oldName);
WizardProcessorUtil.applyWizardSpec(report, specification);
editorModel.setReportDefinition(report, true);
return true;
}
return true;
}
if (!startFromFile && selectedTemplate == -1)
{
final AbstractReportDefinition report = editorModel.getEmptyTemplate();
final DefaultWizardSpecification specification = new DefaultWizardSpecification();
WizardProcessorUtil.applyWizardSpec(report, specification);
editorModel.setReportDefinition(report, false);
return true;
}
if (selectedTemplate != -1)
{
final File reportFile = templateHash.get(selectedTemplate);
if (reportFile != null)
{
this.fileName = reportFile.getAbsolutePath();
}
else
{
this.fileName = null;
}
}
if (fileName == null || fileName.length() < 1)
{
return false;
}
final AbstractReportDefinition fileReportDefinition = loadDefinitionFromFile(new File(fileName));
if (fileReportDefinition == null)
{
return false;
}
if (fileReportDefinition instanceof MasterReport)
{
WizardProcessorUtil.resetDocumentMetaData((MasterReport) fileReportDefinition);
}
fileReportDefinition.setAttribute("http://reporting.pentaho.org/namespaces/engine/attributes/wizard", "template", fileName);
editorModel.setReportDefinition(fileReportDefinition);
return true;
}
catch (Exception e)
{