if (dataFactory == null)
{
throw new NullPointerException();
}
final AbstractReportDefinition report = activeContext.getReportDefinition();
final DataFactory originalDataFactory = report.getDataFactory();
if (originalDataFactory == null)
{
throw new IllegalStateException("A report in design-mode should have its data-factory normalized.");
}
final String queryAttribute = (String) report.getAttribute(AttributeNames.Internal.NAMESPACE, AttributeNames.Internal.QUERY);
if (StringUtils.isEmpty(queryAttribute) && dataFactory.getQueryNames().length > 0)
{
final String queryName = dataFactory.getQueryNames()[0];
report.setAttribute(AttributeNames.Internal.NAMESPACE, AttributeNames.Internal.QUERY, queryName);
activeContext.getUndo().addChange(ActionMessages.getString("AddDataFactoryAction.SetQuery.UndoText"),
new AttributeEditUndoEntry(report.getObjectID(),
AttributeNames.Internal.NAMESPACE, AttributeNames.Internal.QUERY,
queryAttribute, queryName));
}
if (isLegacyDefaultDataFactory(originalDataFactory))
{
final CompoundDataFactory compoundDataFactory = CompoundDataFactory.normalize(dataFactory);
DefaultDataFactoryChangeRecorder.applyChanges(compoundDataFactory, dataFactoryChanges);
report.setDataFactory(compoundDataFactory);
activeContext.getUndo().addChange(ActionMessages.getString("AddDataFactoryAction.UndoText"),
new DataSourceEditUndoEntry(0, null, dataFactory.derive()));
}
else
{
final CompoundDataFactory reportDf = CompoundDataFactory.normalize(originalDataFactory);
DefaultDataFactoryChangeRecorder.applyChanges(reportDf, dataFactoryChanges);
final int position = reportDf.size();
reportDf.add(dataFactory);
activeContext.getUndo().addChange(ActionMessages.getString("AddDataFactoryAction.UndoText"),
new DataSourceEditUndoEntry(position, null, dataFactory.derive()));
report.setDataFactory(reportDf);
}
}