public EditQueryAction() {
   putValue(Action.NAME, ActionMessages.getString("EditQueryAction.Text"));
   putValue(Action.DEFAULT, ActionMessages.getString("EditQueryAction.Description"));
   putValue(Action.MNEMONIC_KEY, ActionMessages.getOptionalMnemonic("EditQueryAction.Mnemonic"));
   putValue(
       Action.ACCELERATOR_KEY, ActionMessages.getOptionalKeyStroke("EditQueryAction.Accelerator"));
 }
 public LaunchHelpAction() {
   putValue(Action.NAME, ActionMessages.getString("LaunchHelpAction.Text"));
   putValue(Action.SHORT_DESCRIPTION, ActionMessages.getString("LaunchHelpAction.Description"));
   putValue(Action.MNEMONIC_KEY, ActionMessages.getOptionalMnemonic("LaunchHelpAction.Mnemonic"));
   putValue(
       Action.ACCELERATOR_KEY,
       ActionMessages.getOptionalKeyStroke("LaunchHelpAction.Accelerator"));
 }
 public AlignMiddleAction() {
   putValue(Action.NAME, ActionMessages.getString("AlignMiddleAction.Text"));
   putValue(Action.SHORT_DESCRIPTION, ActionMessages.getString("AlignMiddleAction.Description"));
   putValue(Action.MNEMONIC_KEY, ActionMessages.getOptionalMnemonic("AlignMiddleAction.Mnemonic"));
   putValue(Action.SMALL_ICON, IconLoader.getInstance().getAlignMiddleIcon());
   putValue(
       Action.ACCELERATOR_KEY,
       ActionMessages.getOptionalKeyStroke("AlignMiddleAction.Accelerator"));
 }
 public ItalicsAction() {
   putValue(Action.SELECTED_KEY, Boolean.FALSE);
   putValue(Action.NAME, ActionMessages.getString("ItalicsAction.Text"));
   putValue(Action.SHORT_DESCRIPTION, ActionMessages.getString("ItalicsAction.Description"));
   putValue(Action.MNEMONIC_KEY, ActionMessages.getOptionalMnemonic("ItalicsAction.Mnemonic"));
   putValue(Action.SMALL_ICON, IconLoader.getInstance().getItalicCommand());
   putValue(
       Action.ACCELERATOR_KEY, ActionMessages.getOptionalKeyStroke("ItalicsAction.Accelerator"));
 }
 public ApplyFontFamilyAction(final JComboBox comboBox) {
   this.comboBox = comboBox;
   putValue(Action.NAME, ActionMessages.getString("ApplyFontFamilyAction.Text"));
   putValue(
       Action.SHORT_DESCRIPTION, ActionMessages.getString("ApplyFontFamilyAction.Description"));
   putValue(
       Action.MNEMONIC_KEY, ActionMessages.getOptionalMnemonic("ApplyFontFamilyAction.Mnemonic"));
   putValue(
       Action.ACCELERATOR_KEY,
       ActionMessages.getOptionalKeyStroke("ApplyFontFamilyAction.Accelerator"));
 }
  /** 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 actionPerformed(final ActionEvent e) {
    final ReportSelectionModel selectionModel1 = getSelectionModel();
    if (selectionModel1 == null) {
      return;
    }

    final Element[] visualElements = selectionModel1.getSelectedVisualElements();
    if (visualElements.length == 0) {
      return;
    }

    final EditableStyleSheet styleSheet = EditableStyleSheet.create(visualElements);

    final Map<StyleKey, Expression> styleExpressions;
    if (visualElements.length != 1) {
      styleExpressions = null;
    } else {
      styleExpressions = visualElements[0].getStyleExpressions();
    }

    final Component parent = getReportDesignerContext().getParent();
    final Window window = LibSwingUtil.getWindowAncestor(parent);
    final ElementFormatDialog dialog = createDialog(window);
    final ElementFormatUndoEntry.EditResult result =
        dialog.performEdit(getReportDesignerContext(), styleSheet, styleExpressions);
    if (result == null) {
      return;
    }

    final ElementFormatUndoEntry undoEntry = result.process(visualElements);
    getActiveContext()
        .getUndo()
        .addChange(ActionMessages.getString("ElementFormatAction.UndoName"), undoEntry);
  }
  /** Invoked when an action occurs. */
  public void actionPerformed(final ActionEvent e) {
    final Object o = comboBox.getSelectedItem();
    if (o != null && o instanceof String == false) {
      return;
    }
    final String font = (String) o;
    final ReportRenderContext activeContext = getActiveContext();
    if (activeContext == null) {
      return;
    }

    final ReportSelectionModel selectionModel1 = getSelectionModel();
    if (selectionModel1 == null) {
      return;
    }
    final Element[] visualElements = selectionModel1.getSelectedVisualElements();
    final ArrayList<UndoEntry> undos = new ArrayList<UndoEntry>();
    for (int i = 0; i < visualElements.length; i++) {
      final Element visualElement = visualElements[i];
      undos.add(StyleEditUndoEntry.createConditional(visualElement, TextStyleKeys.FONT, font));
      visualElement.getStyle().setStyleProperty(TextStyleKeys.FONT, font);
      visualElement.notifyNodePropertiesChanged();
    }
    getActiveContext()
        .getUndo()
        .addChange(
            ActionMessages.getString("ApplyFontFamilyAction.UndoName"),
            new CompoundUndoEntry(undos.toArray(new UndoEntry[undos.size()])));
  }
  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);
      }
    }
  }
  /** Invoked when an action occurs. */
  public void actionPerformed(final ActionEvent e) {
    final ReportSelectionModel model = getSelectionModel();
    if (model == null) {
      return;
    }
    final Element[] visualElements = model.getSelectedVisualElements();
    if (visualElements.length <= 1) {
      return;
    }
    final Element[] carrier = new Element[1];
    final Element[] objects = ModelUtility.filterParents(visualElements);
    final MassElementStyleUndoEntryBuilder builder = new MassElementStyleUndoEntryBuilder(objects);

    long minY = Long.MAX_VALUE;
    long maxY = Long.MIN_VALUE;
    for (int j = 0; j < objects.length; j++) {
      final Element object = objects[j];
      final CachedLayoutData data = ModelUtility.getCachedLayoutData(object);
      final long y1 = data.getY();
      final long y2 = y1 + data.getHeight();
      if (y2 > maxY) {
        maxY = y2;
      }
      if (y1 < minY) {
        minY = y1;
      }
    }

    final long centerPoint = minY + (maxY - minY) / 2;

    for (int j = 0; j < objects.length; j++) {
      final Element object = objects[j];
      final CachedLayoutData data = ModelUtility.getCachedLayoutData(object);
      final long elementCenter = data.getY() + data.getHeight() / 2;

      final long delta = centerPoint - elementCenter;
      if (delta == 0) {
        continue;
      }

      carrier[0] = object;
      final MoveDragOperation mop =
          new MoveDragOperation(
              carrier, ORIGIN_POINT, EmptySnapModel.INSTANCE, EmptySnapModel.INSTANCE);
      mop.update(new Point2D.Double(0, StrictGeomUtility.toExternalValue(delta)), 1);
      mop.finish();
    }
    final MassElementStyleUndoEntry massElementStyleUndoEntry = builder.finish();
    getActiveContext()
        .getUndo()
        .addChange(
            ActionMessages.getString("AlignMiddleAction.UndoName"), massElementStyleUndoEntry);
  }
  /** Invoked when an action occurs. */
  public void actionPerformed(final ActionEvent e) {
    final Element[] visualElements = getSelectionModel().getSelectedVisualElements();
    if (visualElements.length == 0) {
      return;
    }

    final MassElementStyleUndoEntryBuilder builder =
        new MassElementStyleUndoEntryBuilder(visualElements);
    final MoveDragOperation mop =
        new MoveDragOperation(
            visualElements, new Point(), EmptySnapModel.INSTANCE, EmptySnapModel.INSTANCE);
    mop.update(new Point(1, 0), 1);
    mop.finish();

    final MassElementStyleUndoEntry massElementStyleUndoEntry = builder.finish();
    getActiveContext()
        .getUndo()
        .addChange(
            ActionMessages.getString("MoveRightOneAction.UndoName"), massElementStyleUndoEntry);
  }
  /** Invoked when an action occurs. */
  public void actionPerformed(final ActionEvent e) {
    final ReportDocumentContext activeContext = getActiveContext();
    if (activeContext == null) {
      return;
    }
    final ReportDesignerContext context = getReportDesignerContext();
    final Component parent = context.getView().getParent();
    final Window window = LibSwingUtil.getWindowAncestor(parent);
    final DocumentMetaDataDialog dialog;
    if (window instanceof JDialog) {
      dialog = new DocumentMetaDataDialog((JDialog) window);
    } else if (window instanceof JFrame) {
      dialog = new DocumentMetaDataDialog((JFrame) window);
    } else {
      dialog = new DocumentMetaDataDialog();
    }

    try {
      final MasterReport report = activeContext.getContextRoot();
      final DocumentBundle bundle = report.getBundle();
      final DocumentMetaData oldMetaData = (DocumentMetaData) bundle.getMetaData().clone();
      final DocumentMetaData result =
          dialog.performEdit(
              oldMetaData, report.getResourceManager(), report.getDefinitionSource());

      if (result == null) {
        return;
      }

      final MetaDataEditUndoEntry undoEntry = new MetaDataEditUndoEntry(oldMetaData, result);
      undoEntry.redo(activeContext);
      activeContext
          .getUndo()
          .addChange(ActionMessages.getString("EditReportPropertiesAction.Text"), undoEntry);
    } catch (CloneNotSupportedException cne) {
      // should not happen
      UncaughtExceptionsModel.getInstance().addException(cne);
    }
  }
  /** Invoked when an action occurs. */
  public void actionPerformed(final ActionEvent e) {
    final ReportSelectionModel selectionModel = getSelectionModel();
    if (selectionModel == null) {
      return;
    }
    final Element[] visualElements = selectionModel.getSelectedVisualElements();
    if (visualElements.length == 0) {
      return;
    }
    final ReportRenderContext activeContext = getActiveContext();
    if (activeContext == null) {
      return;
    }

    Boolean value = Boolean.FALSE;
    final ArrayList<UndoEntry> undos = new ArrayList<UndoEntry>();
    for (int i = 0; i < visualElements.length; i++) {
      final Element element = visualElements[i];
      final ElementStyleSheet styleSheet = element.getStyle();
      if (i == 0) {
        if (styleSheet.getBooleanStyleProperty(TextStyleKeys.ITALIC)) {
          value = Boolean.FALSE;
        } else {
          value = Boolean.TRUE;
        }
      }
      undos.add(StyleEditUndoEntry.createConditional(element, TextStyleKeys.ITALIC, value));
      styleSheet.setStyleProperty(TextStyleKeys.ITALIC, value);
      element.notifyNodePropertiesChanged();
    }
    getActiveContext()
        .getUndo()
        .addChange(
            ActionMessages.getString("ItalicsAction.UndoName"),
            new CompoundUndoEntry(undos.toArray(new UndoEntry[undos.size()])));
  }
  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();
    }
  }