{
}
public void actionPerformed(final ActionEvent e)
{
final ReportDocumentContext activeContext = getActiveContext();
if (activeContext == null)
{
return;
}
final RelationalGroup newGroup = new RelationalGroup();
final EditGroupUndoEntry groupUndoEntry = EditGroupAction.performEditGroup(getReportDesignerContext(), newGroup, true);
if (groupUndoEntry == null)
{
return;
}
// apply the data from the EditGroupAction ..
newGroup.setName(groupUndoEntry.getNewName());
newGroup.setFieldsArray(groupUndoEntry.getNewFields());
try
{
Object selectedElement = activeContext.getReportDefinition();
if (getSelectionModel().getSelectionCount() > 0)
{
selectedElement = getSelectionModel().getSelectedElement(0);
}
if (selectedElement == activeContext.getReportDefinition() )
{
// execution order is important here.
// first unlink the old root-group by setting a new one ...
final AbstractReportDefinition report = (AbstractReportDefinition) selectedElement;
final Group rootGroup = report.getRootGroup();
final SubGroupBody body = new SubGroupBody();
newGroup.setBody(body);
report.setRootGroup(newGroup);
// *then* you can set the old-root to the newly inserted group ..
body.setGroup(rootGroup);
activeContext.getUndo().addChange(ActionMessages.getString("InsertGroupAction.UndoName"),
new InsertGroupOnReportUndoEntry(rootGroup, newGroup));
return;
}
if (selectedElement instanceof RelationalGroup == false)
{
return;
}
final RelationalGroup selectedGroup = (RelationalGroup) selectedElement;
final GroupBody bodyElement = selectedGroup.getBody();
if (bodyElement instanceof SubGroupBody)
{
final SubGroupBody subGroupBodyReportElement = (SubGroupBody) bodyElement;
final Group oldBodyContent = subGroupBodyReportElement.getGroup();
final SubGroupBody body = new SubGroupBody();
newGroup.setBody(body);
subGroupBodyReportElement.setGroup(newGroup);
body.setGroup(oldBodyContent);
activeContext.getUndo().addChange(ActionMessages.getString("InsertGroupAction.UndoName"),
new InsertGroupOnGroupUndoEntry(selectedGroup.getObjectID(), oldBodyContent, newGroup));
}
else if (bodyElement instanceof GroupDataBody)
{
final GroupDataBody oldBody = (GroupDataBody) bodyElement;
selectedGroup.setBody(new SubGroupBody(newGroup));
newGroup.setBody(oldBody);
activeContext.getUndo().addChange(ActionMessages.getString("InsertGroupAction.UndoName"),
new InsertGroupOnDetailsUndoEntry(selectedGroup.getObjectID(), newGroup));
}
}
catch (Exception ex)
{