001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * InsertElementOperation.java
028: *
029: * Created on 19 giugno 2003, 23.23
030: *
031: */
032:
033: package it.businesslogic.ireport.undo;
034:
035: import it.businesslogic.ireport.gui.event.*;
036: import it.businesslogic.ireport.*;
037: import it.businesslogic.ireport.gui.*;
038: import it.businesslogic.ireport.util.*;
039:
040: import java.util.*;
041:
042: /**
043: * This class handle the Insert operation.
044: * As all operations, the costructor take the JReportFrame (owner of the element)
045: * The ReportElement is not cloned, this can be a problem if not all undo operations
046: * are correctly logged and handled.
047: * @author Giulio Toffoli
048: */
049: public class InsertElementOperation implements
050: it.businesslogic.ireport.UndoOperation {
051:
052: /*
053: * The report element that was inserted.
054: */
055: private ReportElement element = null;
056:
057: private JReportFrame jrf = null;
058: private CrosstabReportElement crosstabReportElement = null;
059:
060: /** Creates a new instance of InsertElementOperation */
061: public InsertElementOperation(JReportFrame jrf,
062: CrosstabReportElement crosstabReportElement,
063: ReportElement element) {
064: this .crosstabReportElement = crosstabReportElement;
065: this .element = element;
066: this .jrf = jrf;
067: }
068:
069: /** Creates a new instance of InsertElementOperation */
070: public InsertElementOperation(JReportFrame jrf,
071: ReportElement element) {
072: this (jrf, null, element);
073: }
074:
075: public void undo() {
076: // We must remove our element...
077: if (jrf == null && crosstabReportElement == null)
078: return;
079: if (crosstabReportElement != null) {
080: crosstabReportElement.getElements().remove(element);
081: jrf.getCrosstabEditor(crosstabReportElement)
082: .getPanelEditor().getSelectedElements().remove(
083: element);
084: jrf.getCrosstabEditor(crosstabReportElement)
085: .getPanelEditor().repaint();
086: } else {
087: jrf.getReport().getElements().remove(element);
088: jrf.getSelectedElements().remove(element);
089: if (element instanceof CrosstabReportElement) {
090: jrf
091: .removeCrosstabEditor((CrosstabReportElement) element);
092: }
093: jrf.getReportPanel().repaint();
094: }
095: jrf
096: .fireReportListenerReportElementsChanged(new ReportElementChangedEvent(
097: jrf, crosstabReportElement, element,
098: ReportElementChangedEvent.REMOVED));
099:
100: }
101:
102: public void redo() {
103: if (jrf == null && crosstabReportElement == null)
104: return;
105: if (crosstabReportElement != null) {
106: crosstabReportElement.getElements().addElement(element);
107: jrf.getCrosstabEditor(crosstabReportElement)
108: .getPanelEditor().setSelectedElement(element);
109: jrf.getCrosstabEditor(crosstabReportElement)
110: .getPanelEditor().repaint();
111: } else {
112: jrf.getReport().getElements().addElement(element);
113: if (element instanceof CrosstabReportElement) {
114: jrf.addCrosstabEditor((CrosstabReportElement) element);
115: }
116: jrf.setSelectedElement(element);
117: jrf.getReportPanel().repaint();
118: }
119: jrf
120: .fireReportListenerReportElementsChanged(new ReportElementChangedEvent(
121: jrf, crosstabReportElement, element,
122: ReportElementChangedEvent.ADDED));
123: }
124:
125: public String toString() {
126: return "insert element";
127: }
128:
129: public CrosstabReportElement getCrosstabReportElement() {
130: return crosstabReportElement;
131: }
132:
133: public void setCrosstabReportElement(
134: CrosstabReportElement crosstabReportElement) {
135: this.crosstabReportElement = crosstabReportElement;
136: }
137: }
|