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: * GroupByFieldPanel.java
028: *
029: * Created on January 27, 2006, 3:33 PM
030: *
031: */
032:
033: package it.businesslogic.ireport.crosstab.gui;
034:
035: import it.businesslogic.ireport.SubDataset;
036: import it.businesslogic.ireport.util.Misc;
037: import java.awt.event.ActionEvent;
038: import java.util.Vector;
039: import javax.swing.border.TitledBorder;
040: import it.businesslogic.ireport.util.I18n;
041:
042: /**
043: *
044: * @author gtoffoli
045: */
046: public class GroupByFieldPanel extends javax.swing.JPanel {
047:
048: private Vector objects = new Vector();
049:
050: /** Creates new form GroupByFieldPanel */
051: public GroupByFieldPanel() {
052: initComponents();
053: applyI18n();
054: }
055:
056: public void addVoidItem() {
057: if (jComboBoxColumnGroup1.getItemCount() == 0
058: || jComboBoxColumnGroup1.getSelectedItem() instanceof WizardFieldObject) {
059: jComboBoxColumnGroup1.insertItemAt("", 0);
060: }
061: jComboBoxColumnGroup1.setSelectedIndex(0);
062: }
063:
064: public void setTitle(String title) {
065: ((TitledBorder) this .getBorder()).setTitle(title);
066: }
067:
068: public void addObject(Object obj) {
069: if (obj == null)
070: return;
071:
072: WizardFieldObject wo = new WizardFieldObject(obj);
073: jComboBoxColumnGroup1.addItem(wo);
074:
075: //jComboBoxColumnGroup1ActionPerformed(null);
076:
077: }
078:
079: /**
080: * Return the name used as Group name...
081: */
082: public String getFieldName() {
083: if (jComboBoxColumnGroup1.getSelectedItem() != null
084: && jComboBoxColumnGroup1.getSelectedItem() instanceof WizardFieldObject) {
085: return ((WizardFieldObject) jComboBoxColumnGroup1
086: .getSelectedItem()).getName();
087: }
088:
089: return null;
090: }
091:
092: public String getExpression() {
093: if (jComboBoxColumnGroup1.getSelectedItem() != null
094: && jComboBoxColumnGroup1.getSelectedItem() instanceof WizardFieldObject) {
095: return ((WizardFieldObject) jComboBoxColumnGroup1
096: .getSelectedItem())
097: .getExpression(jComboBoxColumnGroupBy1
098: .getSelectedItem()
099: + "");
100: }
101:
102: return "";
103: }
104:
105: public String getExpressionClass() {
106: if (jComboBoxColumnGroup1.getSelectedItem() != null
107: && jComboBoxColumnGroup1.getSelectedItem() instanceof WizardFieldObject) {
108: return ((WizardFieldObject) jComboBoxColumnGroup1
109: .getSelectedItem())
110: .getExpressionClass(jComboBoxColumnGroupBy1
111: .getSelectedItem()
112: + "");
113: }
114:
115: return "java.lang.String";
116: }
117:
118: /** This method is called from within the constructor to
119: * initialize the form.
120: * WARNING: Do NOT modify this code. The content of this method is
121: * always regenerated by the Form Editor.
122: */
123: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
124: private void initComponents() {
125: java.awt.GridBagConstraints gridBagConstraints;
126:
127: jLabelColumnGroup1 = new javax.swing.JLabel();
128: jComboBoxColumnGroup1 = new javax.swing.JComboBox();
129: jComboBoxColumnGroupBy1 = new javax.swing.JComboBox();
130: jLabelColumnGroupBy1 = new javax.swing.JLabel();
131:
132: setLayout(new java.awt.GridBagLayout());
133:
134: setBorder(javax.swing.BorderFactory.createTitledBorder(
135: javax.swing.BorderFactory.createEtchedBorder(), "",
136: javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
137: javax.swing.border.TitledBorder.DEFAULT_POSITION,
138: new java.awt.Font("Dialog", 0, 11)));
139: jLabelColumnGroup1.setText("Group");
140: gridBagConstraints = new java.awt.GridBagConstraints();
141: gridBagConstraints.gridx = 0;
142: gridBagConstraints.gridy = 0;
143: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
144: gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 0);
145: add(jLabelColumnGroup1, gridBagConstraints);
146:
147: jComboBoxColumnGroup1.setPreferredSize(new java.awt.Dimension(
148: 55, 20));
149: jComboBoxColumnGroup1
150: .addActionListener(new java.awt.event.ActionListener() {
151: public void actionPerformed(
152: java.awt.event.ActionEvent evt) {
153: jComboBoxColumnGroup1ActionPerformed(evt);
154: }
155: });
156:
157: gridBagConstraints = new java.awt.GridBagConstraints();
158: gridBagConstraints.gridx = 1;
159: gridBagConstraints.gridy = 0;
160: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
161: gridBagConstraints.weightx = 1.0;
162: gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 4);
163: add(jComboBoxColumnGroup1, gridBagConstraints);
164:
165: jComboBoxColumnGroupBy1.setEnabled(false);
166: jComboBoxColumnGroupBy1
167: .setPreferredSize(new java.awt.Dimension(55, 20));
168: gridBagConstraints = new java.awt.GridBagConstraints();
169: gridBagConstraints.gridx = 1;
170: gridBagConstraints.gridy = 1;
171: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
172: gridBagConstraints.weightx = 1.0;
173: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
174: add(jComboBoxColumnGroupBy1, gridBagConstraints);
175:
176: jLabelColumnGroupBy1.setText("Group by");
177: jLabelColumnGroupBy1.setEnabled(false);
178: gridBagConstraints = new java.awt.GridBagConstraints();
179: gridBagConstraints.gridx = 0;
180: gridBagConstraints.gridy = 1;
181: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
182: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 0);
183: add(jLabelColumnGroupBy1, gridBagConstraints);
184:
185: }// </editor-fold>//GEN-END:initComponents
186:
187: public void populateBySubdataset(SubDataset sd) {
188: populateBySubdataset(sd, false);
189: }
190:
191: public void populateBySubdataset(SubDataset sd, boolean addVoidEntry) {
192: jComboBoxColumnGroup1.removeAllItems();
193: if (addVoidEntry)
194: addVoidItem();
195: for (int i = 0; i < sd.getFields().size(); ++i) {
196: addObject(sd.getFields().get(i));
197: }
198: for (int i = 0; i < sd.getVariables().size(); ++i) {
199: addObject(sd.getVariables().get(i));
200: }
201: for (int i = 0; i < sd.getParameters().size(); ++i) {
202: addObject(sd.getParameters().get(i));
203: }
204:
205: if (jComboBoxColumnGroup1.getItemCount() > 0) {
206: jComboBoxColumnGroup1.setSelectedIndex(0);
207: }
208: }
209:
210: private void jComboBoxColumnGroup1ActionPerformed(
211: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxColumnGroup1ActionPerformed
212:
213: jComboBoxColumnGroupBy1.removeAllItems();
214: if (jComboBoxColumnGroup1.getSelectedItem() != null
215: && jComboBoxColumnGroup1.getSelectedItem() instanceof WizardFieldObject) {
216: Vector itemsGroupByValues = ((WizardFieldObject) jComboBoxColumnGroup1
217: .getSelectedItem()).getGroupByValues();
218: Misc.updateComboBox(jComboBoxColumnGroupBy1,
219: itemsGroupByValues, false);
220: }
221:
222: if (jComboBoxColumnGroupBy1.getItemCount() <= 1) {
223: jComboBoxColumnGroupBy1.setEnabled(false);
224: jLabelColumnGroupBy1.setEnabled(false);
225: } else {
226: jComboBoxColumnGroupBy1.setEnabled(true);
227: jLabelColumnGroupBy1.setEnabled(true);
228: }
229:
230: this .fireActionListenerActionPerformed(new ActionEvent(this , 0,
231: ""));
232:
233: }//GEN-LAST:event_jComboBoxColumnGroup1ActionPerformed
234:
235: // Variables declaration - do not modify//GEN-BEGIN:variables
236: private javax.swing.JComboBox jComboBoxColumnGroup1;
237: private javax.swing.JComboBox jComboBoxColumnGroupBy1;
238: private javax.swing.JLabel jLabelColumnGroup1;
239: private javax.swing.JLabel jLabelColumnGroupBy1;
240: // End of variables declaration//GEN-END:variables
241:
242: /**
243: * Utility field used by event firing mechanism.
244: */
245: private javax.swing.event.EventListenerList listenerList = null;
246:
247: /**
248: * Registers ActionListener to receive events.
249: * @param listener The listener to register.
250: */
251: public synchronized void addActionListener(
252: java.awt.event.ActionListener listener) {
253:
254: if (listenerList == null) {
255: listenerList = new javax.swing.event.EventListenerList();
256: }
257: listenerList.add(java.awt.event.ActionListener.class, listener);
258: }
259:
260: /**
261: * Removes ActionListener from the list of listeners.
262: * @param listener The listener to remove.
263: */
264: public synchronized void removeActionListener(
265: java.awt.event.ActionListener listener) {
266:
267: listenerList.remove(java.awt.event.ActionListener.class,
268: listener);
269: }
270:
271: /**
272: * Notifies all registered listeners about the event.
273: *
274: * @param event The event to be fired
275: */
276: private void fireActionListenerActionPerformed(
277: java.awt.event.ActionEvent event) {
278:
279: if (listenerList == null)
280: return;
281: Object[] listeners = listenerList.getListenerList();
282: for (int i = listeners.length - 2; i >= 0; i -= 2) {
283: if (listeners[i] == java.awt.event.ActionListener.class) {
284: ((java.awt.event.ActionListener) listeners[i + 1])
285: .actionPerformed(event);
286: }
287: }
288: }
289:
290: public void applyI18n() {
291: // Start autogenerated code ----------------------
292: jLabelColumnGroup1.setText(I18n.getString(
293: "groupByFieldPanel.labelColumnGroup1", "Group"));
294: jLabelColumnGroupBy1.setText(I18n.getString(
295: "groupByFieldPanel.labelColumnGroupBy1", "Group by"));
296: // End autogenerated code ----------------------
297: }
298: }
|