KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > crosstab > gui > GroupByFieldPanel


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  * GroupByFieldPanel.java
28  *
29  * Created on January 27, 2006, 3:33 PM
30  *
31  */

32
33 package it.businesslogic.ireport.crosstab.gui;
34
35 import it.businesslogic.ireport.SubDataset;
36 import it.businesslogic.ireport.util.Misc;
37 import java.awt.event.ActionEvent JavaDoc;
38 import java.util.Vector JavaDoc;
39 import javax.swing.border.TitledBorder JavaDoc;
40 import it.businesslogic.ireport.util.I18n;
41
42 /**
43  *
44  * @author gtoffoli
45  */

46 public class GroupByFieldPanel extends javax.swing.JPanel JavaDoc {
47     
48     private Vector JavaDoc objects = new Vector JavaDoc();
49     
50     /** Creates new form GroupByFieldPanel */
51     public GroupByFieldPanel() {
52         initComponents();
53         applyI18n();
54     }
55     
56     public void addVoidItem()
57     {
58         if (jComboBoxColumnGroup1.getItemCount() == 0 ||
59             jComboBoxColumnGroup1.getSelectedItem() instanceof WizardFieldObject)
60         {
61             jComboBoxColumnGroup1.insertItemAt("",0);
62         }
63         jComboBoxColumnGroup1.setSelectedIndex(0);
64     }
65     
66     public void setTitle(String JavaDoc title)
67     {
68         ((TitledBorder JavaDoc)this.getBorder()).setTitle(title);
69     }
70     
71     public void addObject(Object JavaDoc obj)
72     {
73         if (obj == null) return;
74         
75         WizardFieldObject wo = new WizardFieldObject(obj);
76         jComboBoxColumnGroup1.addItem(wo);
77        
78         //jComboBoxColumnGroup1ActionPerformed(null);
79

80     }
81     
82     /**
83      * Return the name used as Group name...
84      */

85     public String JavaDoc getFieldName()
86     {
87         if (jComboBoxColumnGroup1.getSelectedItem() != null && jComboBoxColumnGroup1.getSelectedItem() instanceof WizardFieldObject)
88         {
89            return ((WizardFieldObject)jComboBoxColumnGroup1.getSelectedItem()).getName();
90         }
91         
92         return null;
93     }
94     
95     public String JavaDoc getExpression()
96     {
97         if (jComboBoxColumnGroup1.getSelectedItem() != null && jComboBoxColumnGroup1.getSelectedItem() instanceof WizardFieldObject)
98         {
99            return ((WizardFieldObject)jComboBoxColumnGroup1.getSelectedItem()).getExpression(jComboBoxColumnGroupBy1.getSelectedItem()+"");
100         }
101         
102         return "";
103     }
104     
105     public String JavaDoc getExpressionClass()
106     {
107         if (jComboBoxColumnGroup1.getSelectedItem() != null && jComboBoxColumnGroup1.getSelectedItem() instanceof WizardFieldObject)
108         {
109            return ((WizardFieldObject)jComboBoxColumnGroup1.getSelectedItem()).getExpressionClass(jComboBoxColumnGroupBy1.getSelectedItem()+"");
110         }
111         
112         return "java.lang.String";
113     }
114     
115     /** This method is called from within the constructor to
116      * initialize the form.
117      * WARNING: Do NOT modify this code. The content of this method is
118      * always regenerated by the Form Editor.
119      */

120     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
121
private void initComponents() {
122         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
123
124         jLabelColumnGroup1 = new javax.swing.JLabel JavaDoc();
125         jComboBoxColumnGroup1 = new javax.swing.JComboBox JavaDoc();
126         jComboBoxColumnGroupBy1 = new javax.swing.JComboBox JavaDoc();
127         jLabelColumnGroupBy1 = new javax.swing.JLabel JavaDoc();
128
129         setLayout(new java.awt.GridBagLayout JavaDoc());
130
131         setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font JavaDoc("Dialog", 0, 11)));
132         jLabelColumnGroup1.setText("Group");
133         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
134         gridBagConstraints.gridx = 0;
135         gridBagConstraints.gridy = 0;
136         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
137         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 4, 0, 0);
138         add(jLabelColumnGroup1, gridBagConstraints);
139
140         jComboBoxColumnGroup1.setPreferredSize(new java.awt.Dimension JavaDoc(55, 20));
141         jComboBoxColumnGroup1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
142             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
143                 jComboBoxColumnGroup1ActionPerformed(evt);
144             }
145         });
146
147         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
148         gridBagConstraints.gridx = 1;
149         gridBagConstraints.gridy = 0;
150         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
151         gridBagConstraints.weightx = 1.0;
152         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 4, 0, 4);
153         add(jComboBoxColumnGroup1, gridBagConstraints);
154
155         jComboBoxColumnGroupBy1.setEnabled(false);
156         jComboBoxColumnGroupBy1.setPreferredSize(new java.awt.Dimension JavaDoc(55, 20));
157         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
158         gridBagConstraints.gridx = 1;
159         gridBagConstraints.gridy = 1;
160         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
161         gridBagConstraints.weightx = 1.0;
162         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 4, 4, 4);
163         add(jComboBoxColumnGroupBy1, gridBagConstraints);
164
165         jLabelColumnGroupBy1.setText("Group by");
166         jLabelColumnGroupBy1.setEnabled(false);
167         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
168         gridBagConstraints.gridx = 0;
169         gridBagConstraints.gridy = 1;
170         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
171         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 4, 4, 0);
172         add(jLabelColumnGroupBy1, gridBagConstraints);
173
174     }// </editor-fold>//GEN-END:initComponents
175

176     public void populateBySubdataset(SubDataset sd)
177     {
178         populateBySubdataset(sd, false);
179     }
180     
181     public void populateBySubdataset(SubDataset sd, boolean addVoidEntry)
182     {
183         jComboBoxColumnGroup1.removeAllItems();
184         if (addVoidEntry) addVoidItem();
185         for (int i=0; i<sd.getFields().size(); ++i)
186         {
187             addObject(sd.getFields().get(i));
188         }
189         for (int i=0; i<sd.getVariables().size(); ++i)
190         {
191             addObject(sd.getVariables().get(i));
192         }
193         for (int i=0; i<sd.getParameters().size(); ++i)
194         {
195             addObject(sd.getParameters().get(i));
196         }
197         
198         if (jComboBoxColumnGroup1.getItemCount() > 0)
199         {
200             jComboBoxColumnGroup1.setSelectedIndex(0);
201         }
202     }
203     
204     private void jComboBoxColumnGroup1ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jComboBoxColumnGroup1ActionPerformed
205

206         
207         jComboBoxColumnGroupBy1.removeAllItems();
208         if (jComboBoxColumnGroup1.getSelectedItem() != null && jComboBoxColumnGroup1.getSelectedItem() instanceof WizardFieldObject)
209         {
210            Vector JavaDoc itemsGroupByValues = ((WizardFieldObject)jComboBoxColumnGroup1.getSelectedItem()).getGroupByValues();
211            Misc.updateComboBox( jComboBoxColumnGroupBy1,itemsGroupByValues,false);
212         }
213         
214         if (jComboBoxColumnGroupBy1.getItemCount() <= 1)
215         {
216             jComboBoxColumnGroupBy1.setEnabled(false);
217             jLabelColumnGroupBy1.setEnabled(false);
218         }
219         else
220         {
221             jComboBoxColumnGroupBy1.setEnabled(true);
222             jLabelColumnGroupBy1.setEnabled(true);
223         }
224         
225         this.fireActionListenerActionPerformed(new ActionEvent JavaDoc(this,0,""));
226         
227     }//GEN-LAST:event_jComboBoxColumnGroup1ActionPerformed
228

229     
230     // Variables declaration - do not modify//GEN-BEGIN:variables
231
private javax.swing.JComboBox JavaDoc jComboBoxColumnGroup1;
232     private javax.swing.JComboBox JavaDoc jComboBoxColumnGroupBy1;
233     private javax.swing.JLabel JavaDoc jLabelColumnGroup1;
234     private javax.swing.JLabel JavaDoc jLabelColumnGroupBy1;
235     // End of variables declaration//GEN-END:variables
236

237     /**
238      * Utility field used by event firing mechanism.
239      */

240     private javax.swing.event.EventListenerList JavaDoc listenerList = null;
241
242     /**
243      * Registers ActionListener to receive events.
244      * @param listener The listener to register.
245      */

246     public synchronized void addActionListener(java.awt.event.ActionListener JavaDoc listener) {
247
248         if (listenerList == null ) {
249             listenerList = new javax.swing.event.EventListenerList JavaDoc();
250         }
251         listenerList.add (java.awt.event.ActionListener JavaDoc.class, listener);
252     }
253
254     /**
255      * Removes ActionListener from the list of listeners.
256      * @param listener The listener to remove.
257      */

258     public synchronized void removeActionListener(java.awt.event.ActionListener JavaDoc listener) {
259
260         listenerList.remove (java.awt.event.ActionListener JavaDoc.class, listener);
261     }
262
263     /**
264      * Notifies all registered listeners about the event.
265      *
266      * @param event The event to be fired
267      */

268     private void fireActionListenerActionPerformed(java.awt.event.ActionEvent JavaDoc event) {
269
270         if (listenerList == null) return;
271         Object JavaDoc[] listeners = listenerList.getListenerList ();
272         for (int i = listeners.length - 2; i >= 0; i -= 2) {
273             if (listeners[i]==java.awt.event.ActionListener JavaDoc.class) {
274                 ((java.awt.event.ActionListener JavaDoc)listeners[i+1]).actionPerformed (event);
275             }
276         }
277     }
278     
279     public void applyI18n(){
280                 // Start autogenerated code ----------------------
281
jLabelColumnGroup1.setText(I18n.getString("groupByFieldPanel.labelColumnGroup1","Group"));
282                 jLabelColumnGroupBy1.setText(I18n.getString("groupByFieldPanel.labelColumnGroupBy1","Group by"));
283                 // End autogenerated code ----------------------
284
}
285 }
286
Popular Tags