/** 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 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); } } }
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); }