/** Invoked when an action occurs. */
  public void actionPerformed(final ActionEvent e) {
    final ReportRenderContext activeContext = getActiveContext();
    if (activeContext == null) {
      return;
    }

    final Object[] selectedElements = getSelectionModel().getSelectedElements();
    for (int i = 0; i < selectedElements.length; i++) {
      final Object element = selectedElements[i];
      if (element instanceof ReportQueryNode) {
        final ReportQueryNode queryNode = (ReportQueryNode) element;
        try {
          performEdit(queryNode.getDataFactory(), queryNode.getQueryName());
        } catch (ReportDataFactoryException e1) {
          UncaughtExceptionsModel.getInstance().addException(e1);
        }
        break;
      } else if (element instanceof DataFactory) {
        try {
          final AbstractReportDefinition report = activeContext.getReportDefinition();
          final DataFactory dataFactory = ((DataFactory) element);
          performEdit(dataFactory, report.getQuery());
        } catch (ReportDataFactoryException e1) {
          UncaughtExceptionsModel.getInstance().addException(e1);
        }
        break;
      }
    }
  }
  /** Invoked when an action occurs. */
  public void actionPerformed(final ActionEvent e) {
    final ReportRenderContext activeContext = getActiveContext();
    if (activeContext == null) {
      return;
    }

    final Object[] selectedElements = activeContext.getSelectionModel().getSelectedElements();
    final AbstractReportDefinition report = activeContext.getReportDefinition();

    final ArrayList<UndoEntry> undos = new ArrayList<UndoEntry>();
    if (collectChange(selectedElements, report, undos) == false) {
      // rollback ..
      for (int i = undos.size() - 1; i >= 0; i--) {
        final UndoEntry undoEntry = undos.get(i);
        undoEntry.undo(activeContext);
      }
    } else {
      final UndoEntry[] undoEntries = undos.toArray(new UndoEntry[undos.size()]);
      activeContext
          .getUndo()
          .addChange(
              ActionMessages.getString("AbstractLayerAction.UndoName"),
              new CompoundUndoEntry(undoEntries));
    }
    // re-select the elements (moving them causes them to be unselected)
    activeContext.getSelectionModel().setSelectedElements(selectedElements);
  }
  public void dispose() {
    super.dispose();

    KeyboardFocusManager.getCurrentKeyboardFocusManager()
        .removePropertyChangeListener("permanentFocusOwner", focusHandler); // NON-NLS

    final ReportRenderContext renderContext = getRenderContext();
    renderContext.getReportDefinition().removeReportModelListener(changeHandler);
  }
  public void actionPerformed(final ActionEvent e) {
    final ReportRenderContext activeContext = getActiveContext();
    if (activeContext == null) {
      return;
    }

    final ReportDesignerContext context = getReportDesignerContext();
    final Component parent = context.getParent();
    final Window window = LibSwingUtil.getWindowAncestor(parent);
    final RowBandingDialog dialog;
    if (window instanceof JDialog) {
      dialog = new RowBandingDialog((JDialog) window);
    } else if (window instanceof JFrame) {
      dialog = new RowBandingDialog((JFrame) window);
    } else {
      dialog = new RowBandingDialog();
    }

    final RowBandingFunction function = findRowbandingFunction(activeContext);
    final AbstractReportDefinition report = activeContext.getReportDefinition();
    if (function == null) {
      final RowBandingFunction newFunction = new RowBandingFunction();
      if (dialog.performEdit(newFunction)) {
        report.getExpressions().add(newFunction);
        activeContext
            .getUndo()
            .addChange(
                ActionMessages.getString("EditRowBandingAction.Text"),
                new ExpressionAddedUndoEntry(report.getExpressions().size() - 1, newFunction));
        report.notifyNodeChildAdded(function);
      }
    } else {
      final RowBandingFunction instance = (RowBandingFunction) function.getInstance();
      if (dialog.performEdit(instance)) {
        final ExpressionCollection expressionCollection = report.getExpressions();
        final int idx = expressionCollection.indexOf(function);
        expressionCollection.set(idx, instance);
        activeContext
            .getUndo()
            .addChange(
                ActionMessages.getString("EditRowBandingAction.Text"),
                new ExpressionEditUndoEntry(idx, function, instance));
        report.fireModelLayoutChanged(report, ReportModelEvent.NODE_PROPERTIES_CHANGED, instance);
      }
    }
  }
 private RowBandingFunction findRowbandingFunction(final ReportRenderContext activeContext) {
   final Expression[] expressions =
       activeContext.getReportDefinition().getExpressions().getExpressions();
   for (int i = 0; i < expressions.length; i++) {
     final Expression expression = expressions[i];
     if (expression instanceof RowBandingFunction) {
       return (RowBandingFunction) expression;
     }
   }
   return null;
 }
  /** Invoked when an action occurs. */
  public void actionPerformed(final ActionEvent e) {

    final ReportDesignerContext reportDesignerContext = getReportDesignerContext();
    final ReportRenderContext activeContext = getActiveContext();
    if (activeContext == null) {
      return;
    }

    if (activeContext.isChanged()) {
      // ask the user and maybe save the report..
      final int option =
          JOptionPane.showConfirmDialog(
              reportDesignerContext.getParent(),
              Messages.getInstance()
                  .getString("PublishToServerAction.ReportModifiedWarning.Message"),
              Messages.getInstance().getString("PublishToServerAction.ReportModifiedWarning.Title"),
              JOptionPane.YES_NO_CANCEL_OPTION,
              JOptionPane.WARNING_MESSAGE);
      if (option == JOptionPane.YES_OPTION) {
        if (SaveReportAction.saveReport(
                reportDesignerContext, activeContext, reportDesignerContext.getParent())
            == false) {
          return;
        }
      }
      if (option == JOptionPane.CANCEL_OPTION) {
        return;
      }
    }

    final PublishToServerTask publishToServerTask =
        new PublishToServerTask(reportDesignerContext, reportDesignerContext.getParent());
    final LoginTask loginTask =
        new LoginTask(
            reportDesignerContext, reportDesignerContext.getParent(), publishToServerTask);

    SwingUtilities.invokeLater(loginTask);
  }
  public AlignmentUtilities(
      final ReportRenderContext reportRenderContext, final PageDefinition pageDefinition) {
    context = reportRenderContext;

    final MasterReport masterReport = reportRenderContext.getMasterReportElement();
    currentPageDefinition = masterReport.getPageDefinition();
    originalPageDefinition = pageDefinition;

    final ArrayList<Element> elementArrayList = new ArrayList<Element>();
    collectAlignableElements(masterReport, elementArrayList);
    visualElements = elementArrayList.toArray(new Element[elementArrayList.size()]);

    builder = new MassElementStyleUndoEntryBuilder(visualElements);
  }
  public void performEdit(final DataFactory dataFactory, final String queryName)
      throws ReportDataFactoryException {
    final DataFactoryMetaData metadata = dataFactory.getMetaData();
    if (metadata.isEditable() == false) {
      return;
    }

    final DataSourcePlugin dataSourcePlugin = metadata.createEditor();
    final DataFactory storedFactory = dataFactory.derive();
    if (dataSourcePlugin.canHandle(dataFactory)) {
      final ReportRenderContext activeContext = getActiveContext();
      final AbstractReportDefinition report = activeContext.getReportDefinition();
      final boolean editingActiveQuery = contains(report.getQuery(), dataFactory.getQueryNames());

      final ReportDesignerDesignTimeContext designTimeContext =
          new ReportDesignerDesignTimeContext(getReportDesignerContext());
      editedDataFactory =
          dataSourcePlugin.performEdit(designTimeContext, dataFactory, queryName, null);
      if (editedDataFactory == null) {
        return;
      }

      final Window parentWindow = designTimeContext.getParentWindow();
      parentWindow.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

      final CompoundDataFactory collection = (CompoundDataFactory) report.getDataFactory();
      final int dataFactoryCount = collection.size();
      for (int j = 0; j < dataFactoryCount; j++) {
        final DataFactory originalDataFactory = collection.getReference(j);
        if (originalDataFactory == dataFactory) {
          collection.remove(j);

          final DataFactory editedClone = editedDataFactory.derive();
          collection.add(j, editedDataFactory);
          activeContext
              .getUndo()
              .addChange(
                  ActionMessages.getString("EditQueryAction.Text"),
                  new DataSourceEditUndoEntry(j, storedFactory, editedClone));

          report.notifyNodeChildRemoved(originalDataFactory);
          report.notifyNodeChildAdded(editedDataFactory);

          parentWindow.setCursor(Cursor.getDefaultCursor());
          if (editingActiveQuery == false) {
            // if we are editing a query that is not the one the current report uses, do not mess
            // around with it.
            return;
          }

          final String[] editedQueries = editedDataFactory.getQueryNames();
          if (contains(report.getQuery(), editedQueries) == false) {
            report.setQuery(null);
          }
          return;
        }
      }

      throw new IllegalStateException();
    }
  }
 private void registerChanges() {
   final MassElementStyleUndoEntry massElementStyleUndoEntry = builder.finish();
   context
       .getUndo()
       .addChange(Messages.getString("AlignmentUtilities.Undo"), massElementStyleUndoEntry);
 }
  protected void inspectExpression(
      final ReportDesignerContext designerContext,
      final ReportRenderContext reportRenderContext,
      final InspectionResultListener resultHandler,
      final String[] columnNames,
      final Expression expression,
      final ExpressionMetaData expressionMetaData) {
    if (expressionMetaData == null) {
      return;
    }

    try {
      final BeanUtility utility = new BeanUtility(expression);
      final ExpressionPropertyMetaData[] datas = expressionMetaData.getPropertyDescriptions();
      for (int i = 0; i < datas.length; i++) {
        final ExpressionPropertyMetaData metaData = datas[i];
        if (metaData.isHidden()) {
          continue;
        }
        if (WorkspaceSettings.getInstance().isShowExpertItems() == false && metaData.isExpert()) {
          continue;
        }
        if (WorkspaceSettings.getInstance().isShowDeprecatedItems() == false
            && metaData.isDeprecated()) {
          continue;
        }

        if (!"ElementName".equals(metaData.getPropertyRole())) // NON-NLS
        {
          continue;
        }

        final Object o = utility.getProperty(metaData.getName());
        final String[] elements = metaData.getReferencedElements(expression, o);
        for (int j = 0; j < elements.length; j++) {
          final String element = elements[j];
          final AbstractReportDefinition reportDefinition =
              reportRenderContext.getReportDefinition();
          final ReportElement e =
              FunctionUtilities.findElementByAttribute(
                  reportDefinition,
                  AttributeNames.Core.NAMESPACE,
                  AttributeNames.Core.NAME,
                  element);
          if (e == null) {
            resultHandler.notifyInspectionResult(
                new InspectionResult(
                    this,
                    InspectionResult.Severity.WARNING,
                    Messages.getString(
                        "InvalidElementReferenceInspection.ExpressionReferencesInvalidName",
                        expression.getName(),
                        metaData.getDisplayName(Locale.getDefault())),
                    new PropertyLocationInfo(expression, metaData.getName())));
          }
        }
      }
    } catch (Exception e) {
      resultHandler.notifyInspectionResult(
          new InspectionResult(
              this,
              InspectionResult.Severity.WARNING,
              e.getMessage(),
              new LocationInfo(expression)));
    }
  }