/**
* Invoked when an action occurs.
*/
public void actionPerformed(final ActionEvent e)
{
final ReportDocumentContext activeContext = getActiveContext();
if (activeContext == null)
{
return;
}
final Component parent = getReportDesignerContext().getView().getParent();
final Window window = LibSwingUtil.getWindowAncestor(parent);
final ExpressionChooserDialog dialog;
if (window instanceof JDialog)
{
dialog = new ExpressionChooserDialog((JDialog) window);
}
else if (window instanceof JFrame)
{
dialog = new ExpressionChooserDialog((JFrame) window);
}
else
{
dialog = new ExpressionChooserDialog();
}
final Expression expression = dialog.performSelect();
if (expression == null)
{
return;
}
final AbstractReportDefinition definition = activeContext.getReportDefinition();
// try generate a unique expression name
String possibleName = expression.getClass().getSimpleName() + nameCounter++;
while (definition.getExpressions().get(possibleName) != null)
{
possibleName = expression.getClass().getSimpleName() + nameCounter++;
}
expression.setName(possibleName);
final int position = definition.getExpressions().size();
activeContext.getUndo().addChange(ActionMessages.getString("AddExpressionsAction.Text"),
new ExpressionAddedUndoEntry(position, expression));
definition.addExpression(expression);
}