KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > undo > InsertElementOperation


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * InsertElementOperation.java
28  *
29  * Created on 19 giugno 2003, 23.23
30  *
31  */

32
33 package it.businesslogic.ireport.undo;
34 import it.businesslogic.ireport.gui.event.*;
35 import it.businesslogic.ireport.*;
36 import it.businesslogic.ireport.gui.*;
37 import it.businesslogic.ireport.util.*;
38
39 import java.util.*;
40
41 /**
42  * This class handle the Insert operation.
43  * As all operations, the costructor take the JReportFrame (owner of the element)
44  * The ReportElement is not cloned, this can be a problem if not all undo operations
45  * are correctly logged and handled.
46  * @author Giulio Toffoli
47  */

48 public class InsertElementOperation implements it.businesslogic.ireport.UndoOperation {
49     
50     /*
51      * The report element that was inserted.
52      */

53     private ReportElement element = null;
54     
55     private JReportFrame jrf = null;
56     private CrosstabReportElement crosstabReportElement = null;
57     
58     /** Creates a new instance of InsertElementOperation */
59     public InsertElementOperation(JReportFrame jrf, CrosstabReportElement crosstabReportElement, ReportElement element) {
60         this.crosstabReportElement = crosstabReportElement;
61         this.element = element;
62         this.jrf = jrf;
63     }
64     
65     /** Creates a new instance of InsertElementOperation */
66     public InsertElementOperation(JReportFrame jrf, ReportElement element) {
67         this(jrf, null, element);
68     }
69     
70     public void undo()
71     {
72         // We must remove our element...
73
if (jrf == null && crosstabReportElement == null) return;
74         if (crosstabReportElement != null)
75         {
76             crosstabReportElement.getElements().remove( element );
77             jrf.getCrosstabEditor(crosstabReportElement).getPanelEditor().getSelectedElements().remove( element );
78             jrf.getCrosstabEditor(crosstabReportElement).getPanelEditor().repaint();
79         }
80         else
81         {
82             jrf.getReport().getElements().remove( element );
83             jrf.getSelectedElements().remove( element );
84             if (element instanceof CrosstabReportElement)
85             {
86                 jrf.removeCrosstabEditor((CrosstabReportElement)element);
87             }
88             jrf.getReportPanel().repaint();
89         }
90         jrf.fireReportListenerReportElementsChanged(new ReportElementChangedEvent(jrf, crosstabReportElement, element , ReportElementChangedEvent.REMOVED));
91         
92     }
93     
94     public void redo()
95     {
96         if (jrf == null && crosstabReportElement == null) return;
97         if (crosstabReportElement != null)
98         {
99             crosstabReportElement.getElements().addElement( element );
100             jrf.getCrosstabEditor(crosstabReportElement).getPanelEditor().setSelectedElement( element );
101             jrf.getCrosstabEditor(crosstabReportElement).getPanelEditor().repaint();
102         }
103         else
104         {
105             jrf.getReport().getElements().addElement( element );
106             if (element instanceof CrosstabReportElement)
107             {
108                 jrf.addCrosstabEditor((CrosstabReportElement)element);
109             }
110             jrf.setSelectedElement(element);
111             jrf.getReportPanel().repaint();
112         }
113         jrf.fireReportListenerReportElementsChanged(new ReportElementChangedEvent(jrf, crosstabReportElement, element , ReportElementChangedEvent.ADDED));
114     }
115     
116     public String JavaDoc toString()
117     {
118         return "insert element";
119     }
120
121     public CrosstabReportElement getCrosstabReportElement() {
122         return crosstabReportElement;
123     }
124
125     public void setCrosstabReportElement(CrosstabReportElement crosstabReportElement) {
126         this.crosstabReportElement = crosstabReportElement;
127     }
128 }
129
130
Popular Tags