final Window window = SwingUtil.getWindowAncestor(carrierPanel);
final Object selectedItem = expressionEditor.getSelectedItem();
if (selectedItem instanceof FormulaExpression)
{
final FormulaExpression fe = (FormulaExpression) selectedItem;
final FormulaEditorDialog dialog = GUIUtils.createFormulaEditorDialog(getReportDesignerContext(), carrierPanel);
final String formula = dialog.editFormula(fe.getFormula(), getFields());
if (formula == null)
{
// cancel pressed ... do nothing ...
return;
}
final FormulaExpression derived = (FormulaExpression) fe.getInstance();
derived.setFormula(formula);
expressionEditor.setSelectedItem(derived);
fireEditingStopped();
}
else if (selectedItem instanceof Expression)
{
final ExpressionPropertiesDialog optionPane;
if (window instanceof JFrame)
{
optionPane = new ExpressionPropertiesDialog((JFrame) window);
}
else if (window instanceof JDialog)
{
optionPane = new ExpressionPropertiesDialog((JDialog) window);
}
else
{
optionPane = new ExpressionPropertiesDialog();
}
final Expression expression = optionPane.editExpression((Expression) selectedItem);
if (expression != selectedItem)
{
expressionEditor.setSelectedItem(expression);
fireEditingStopped();
}
}
else if (selectedItem instanceof ExpressionMetaData)
{
try
{
final ExpressionMetaData emd = (ExpressionMetaData) selectedItem;
final Expression expression = (Expression) emd.getExpressionType().newInstance();
final ExpressionPropertiesDialog optionPane;
if (window instanceof JFrame)
{
optionPane = new ExpressionPropertiesDialog((JFrame) window);
}
else if (window instanceof JDialog)
{
optionPane = new ExpressionPropertiesDialog((JDialog) window);
}
else
{
optionPane = new ExpressionPropertiesDialog();
}
final Expression resultexpression = optionPane.editExpression(expression);
if (resultexpression != expression)
{
expressionEditor.setSelectedItem(resultexpression);
fireEditingStopped();
}
}
catch (Throwable e1)
{
UncaughtExceptionsModel.getInstance().addException(e1);
}
}
else
{
// assume that we want to edit a formula ..
final FormulaEditorDialog dialog = GUIUtils.createFormulaEditorDialog(getReportDesignerContext(), carrierPanel);
final String formula = dialog.editFormula(null, getFields());
if (formula == null)
{
// cancel pressed ... do nothing ...
return;
}