final ReportDocumentContext activeContext,
final Component parent)
{
// Get the current file target
final MasterReport report = activeContext.getContextRoot();
final ResourceKey definitionSource = report.getDefinitionSource();
File target = SaveReportUtilities.getCurrentFile(definitionSource);
// If there is no target, this file has not been save before ... prompt for a filename
if (target == null)
{
target = SaveReportUtilities.promptReportFilename(parent, null);
}
else
{
target = SaveReportUtilities.validateFileExtension(target, parent);
}
if (target == null)
{
return false;
}
// if no name has been set for the report, default to the name of the file
try
{
report.setAttribute(ReportDesignerBoot.DESIGNER_NAMESPACE, "report-save-path", target.getCanonicalPath()); // NON-NLS
}
catch (IOException ioe)
{
// then let's not set the save path attribute to the *canonical path*
report.setAttribute(ReportDesignerBoot.DESIGNER_NAMESPACE, "report-save-path", target.getAbsolutePath()); // NON-NLS
}
// Write the report to the filename
if (SaveReportUtilities.saveReport(context, activeContext, target))
{
try
{
// Update the definition source to be the location from which the file is saved
final ResourceManager resourceManager = report.getResourceManager();
final Resource bundleResource = resourceManager.createDirectly(target, DocumentBundle.class);
final DocumentBundle bundle = (DocumentBundle) bundleResource.getResource();
final ResourceKey bundleKey = bundle.getBundleKey();
report.setDefinitionSource(bundleKey);
report.setContentBase(bundleKey);
report.setResourceManager(bundle.getResourceManager());
activeContext.resetChangeTracker();
}