KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > gui > queryexecuters > QueryExecutersDialog


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  * QueryExecutersDialog.java
28  *
29  * Created on 7 maggio 2003, 23.43
30  *
31  */

32
33 package it.businesslogic.ireport.gui.queryexecuters;
34
35 import it.businesslogic.ireport.*;
36 import it.businesslogic.ireport.SubDataset;
37 import it.businesslogic.ireport.gui.MainFrame;
38
39 import javax.swing.table.*;
40 import javax.swing.*;
41 import javax.swing.event.*;
42 import it.businesslogic.ireport.*;
43 import it.businesslogic.ireport.util.*;
44
45 import java.util.*;
46 /**
47  *
48  * @author Administrator
49  */

50 public class QueryExecutersDialog extends javax.swing.JDialog JavaDoc {
51     
52     /** Creates new form ValuesDialog */
53     public QueryExecutersDialog(java.awt.Dialog JavaDoc parent, boolean modal) {
54         super(parent, modal);
55         initAll();
56     }
57     public QueryExecutersDialog(java.awt.Frame JavaDoc parent, boolean modal) {
58         super(parent, modal);
59         initAll();
60     }
61     
62     public void initAll()
63     {
64         initComponents();
65         this.setSize(420, 250);
66         DefaultTableColumnModel dtcm = (DefaultTableColumnModel)jTableProperties.getColumnModel();
67         
68         dtcm.getColumn(0).setWidth(150);
69         dtcm.getColumn(0).setPreferredWidth(150);
70         
71         DefaultListSelectionModel dlsm = (DefaultListSelectionModel)this.jTableProperties.getSelectionModel();
72         dlsm.addListSelectionListener(new javax.swing.event.ListSelectionListener JavaDoc() {
73             public void valueChanged(ListSelectionEvent e) {
74                 jTablePropertiesListSelectionValueChanged(e);
75             }
76         });
77             
78     applyI18n();
79         // Open in center...
80
it.businesslogic.ireport.util.Misc.centerFrame(this);
81         
82         
83         javax.swing.KeyStroke JavaDoc escape = javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0, false);
84         javax.swing.Action JavaDoc escapeAction = new javax.swing.AbstractAction JavaDoc() {
85             public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
86                 jButtonSaveActionPerformed(e);
87             }
88         };
89        
90         getRootPane().getInputMap(javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE");
91         getRootPane().getActionMap().put("ESCAPE", escapeAction);
92
93
94         //to make the default button ...
95
this.getRootPane().setDefaultButton(this.jButtonSave);
96         
97         this.updateQueryExecuters();
98         
99     }
100     
101     
102     public void jTablePropertiesListSelectionValueChanged(javax.swing.event.ListSelectionEvent JavaDoc e)
103     {
104          if (this.jTableProperties.getSelectedRowCount() > 0) {
105             this.jButtonModifyProperty.setEnabled(true);
106             this.jButtonDeleteProperty.setEnabled(true);
107             this.jButtonMoveUp.setEnabled(true);
108             this.jButtonMoveDown.setEnabled(true);
109         }
110         else {
111             this.jButtonModifyProperty.setEnabled(false);
112             this.jButtonDeleteProperty.setEnabled(false);
113             this.jButtonMoveUp.setEnabled(false);
114             this.jButtonMoveDown.setEnabled(false);
115         }
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 JavaDoc gridBagConstraints;
126
127         jPanelFields = new javax.swing.JPanel JavaDoc();
128         jScrollPane3 = new javax.swing.JScrollPane JavaDoc();
129         jTableProperties = new it.businesslogic.ireport.gui.JDragTable();
130         jPanelButtons2 = new javax.swing.JPanel JavaDoc();
131         jButtonNewProperty = new javax.swing.JButton JavaDoc();
132         jButtonModifyProperty = new javax.swing.JButton JavaDoc();
133         jButtonDeleteProperty = new javax.swing.JButton JavaDoc();
134         jButtonSave = new javax.swing.JButton JavaDoc();
135         jButtonMoveUp = new javax.swing.JButton JavaDoc();
136         jButtonMoveDown = new javax.swing.JButton JavaDoc();
137         jPanel1 = new javax.swing.JPanel JavaDoc();
138
139         setTitle("Values");
140         addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
141             public void windowClosing(java.awt.event.WindowEvent JavaDoc evt) {
142                 closeDialog(evt);
143             }
144         });
145
146         jPanelFields.setLayout(new java.awt.GridBagLayout JavaDoc());
147
148         jScrollPane3.setBackground(new java.awt.Color JavaDoc(255, 255, 255));
149         jScrollPane3.addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
150             public void mouseClicked(java.awt.event.MouseEvent JavaDoc evt) {
151                 jScrollPane3MouseClicked(evt);
152             }
153         });
154
155         jTableProperties.setModel(new javax.swing.table.DefaultTableModel JavaDoc(
156             new Object JavaDoc [][] {
157
158             },
159             new String JavaDoc [] {
160                 "Language", "Factory class", "Fields Provider"
161             }
162         ) {
163             Class JavaDoc[] types = new Class JavaDoc [] {
164                 java.lang.Object JavaDoc.class, java.lang.String JavaDoc.class, java.lang.String JavaDoc.class
165             };
166             boolean[] canEdit = new boolean [] {
167                 false, false, false
168             };
169
170             public Class JavaDoc getColumnClass(int columnIndex) {
171                 return types [columnIndex];
172             }
173
174             public boolean isCellEditable(int rowIndex, int columnIndex) {
175                 return canEdit [columnIndex];
176             }
177         });
178         jTableProperties.addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
179             public void mouseClicked(java.awt.event.MouseEvent JavaDoc evt) {
180                 jTablePropertiesMouseClicked(evt);
181             }
182         });
183
184         jScrollPane3.setViewportView(jTableProperties);
185
186         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
187         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
188         gridBagConstraints.weightx = 1.0;
189         gridBagConstraints.weighty = 1.0;
190         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 4, 4, 0);
191         jPanelFields.add(jScrollPane3, gridBagConstraints);
192
193         jPanelButtons2.setLayout(new java.awt.GridBagLayout JavaDoc());
194
195         jPanelButtons2.setMinimumSize(new java.awt.Dimension JavaDoc(100, 10));
196         jPanelButtons2.setPreferredSize(new java.awt.Dimension JavaDoc(130, 100));
197         jButtonNewProperty.setText("New");
198         jButtonNewProperty.addActionListener(new java.awt.event.ActionListener JavaDoc() {
199             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
200                 jButtonNewPropertyActionPerformed(evt);
201             }
202         });
203
204         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
205         gridBagConstraints.gridx = 0;
206         gridBagConstraints.gridy = 0;
207         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
208         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
209         gridBagConstraints.weightx = 1.0;
210         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 4, 0, 4);
211         jPanelButtons2.add(jButtonNewProperty, gridBagConstraints);
212
213         jButtonModifyProperty.setText("Modify");
214         jButtonModifyProperty.setEnabled(false);
215         jButtonModifyProperty.addActionListener(new java.awt.event.ActionListener JavaDoc() {
216             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
217                 jButtonModifyPropertyActionPerformed(evt);
218             }
219         });
220
221         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
222         gridBagConstraints.gridx = 0;
223         gridBagConstraints.gridy = 1;
224         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
225         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
226         gridBagConstraints.weightx = 1.0;
227         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 4, 0, 4);
228         jPanelButtons2.add(jButtonModifyProperty, gridBagConstraints);
229
230         jButtonDeleteProperty.setText("Delete");
231         jButtonDeleteProperty.setEnabled(false);
232         jButtonDeleteProperty.addActionListener(new java.awt.event.ActionListener JavaDoc() {
233             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
234                 jButtonDeletePropertyActionPerformed(evt);
235             }
236         });
237
238         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
239         gridBagConstraints.gridx = 0;
240         gridBagConstraints.gridy = 2;
241         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
242         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
243         gridBagConstraints.weightx = 1.0;
244         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 4, 4, 4);
245         jPanelButtons2.add(jButtonDeleteProperty, gridBagConstraints);
246
247         jButtonSave.setMnemonic('c');
248         jButtonSave.setText("Close");
249         jButtonSave.addActionListener(new java.awt.event.ActionListener JavaDoc() {
250             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
251                 jButtonSaveActionPerformed(evt);
252             }
253         });
254
255         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
256         gridBagConstraints.gridx = 0;
257         gridBagConstraints.gridy = 20;
258         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
259         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
260         gridBagConstraints.weightx = 1.0;
261         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 4, 0, 4);
262         jPanelButtons2.add(jButtonSave, gridBagConstraints);
263
264         jButtonMoveUp.setText("Move up");
265         jButtonMoveUp.setEnabled(false);
266         jButtonMoveUp.addActionListener(new java.awt.event.ActionListener JavaDoc() {
267             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
268                 jButtonDeletePropertyActionPerformed1(evt);
269             }
270         });
271
272         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
273         gridBagConstraints.gridx = 0;
274         gridBagConstraints.gridy = 3;
275         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
276         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
277         gridBagConstraints.weightx = 1.0;
278         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 4, 4, 4);
279         jPanelButtons2.add(jButtonMoveUp, gridBagConstraints);
280
281         jButtonMoveDown.setText("Move down");
282         jButtonMoveDown.setEnabled(false);
283         jButtonMoveDown.addActionListener(new java.awt.event.ActionListener JavaDoc() {
284             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
285                 jButtonDeletePropertyActionPerformed2(evt);
286             }
287         });
288
289         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
290         gridBagConstraints.gridx = 0;
291         gridBagConstraints.gridy = 4;
292         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
293         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
294         gridBagConstraints.weightx = 1.0;
295         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 4, 4, 4);
296         jPanelButtons2.add(jButtonMoveDown, gridBagConstraints);
297
298         jPanel1.setLayout(new java.awt.BorderLayout JavaDoc());
299
300         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
301         gridBagConstraints.gridx = 0;
302         gridBagConstraints.gridy = 10;
303         gridBagConstraints.weighty = 1.0;
304         jPanelButtons2.add(jPanel1, gridBagConstraints);
305
306         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
307         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
308         gridBagConstraints.weightx = 0.1;
309         gridBagConstraints.weighty = 1.0;
310         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 0, 4, 4);
311         jPanelFields.add(jPanelButtons2, gridBagConstraints);
312
313         getContentPane().add(jPanelFields, java.awt.BorderLayout.CENTER);
314
315         pack();
316     }// </editor-fold>//GEN-END:initComponents
317

318     private void jButtonDeletePropertyActionPerformed2(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonDeletePropertyActionPerformed2
319

320         
321         if (jTableProperties.getSelectedRowCount() > 0)
322         {
323             DefaultTableModel dtm = (DefaultTableModel)jTableProperties.getModel();
324             int[] indices = jTableProperties.getSelectedRows();
325             for (int i=indices.length-1; i>=0; --i)
326             {
327                 if (indices[i] >= jTableProperties.getRowCount() -1 ) continue;
328                 Object JavaDoc val = jTableProperties.getValueAt( indices[i], 0);
329                 dtm.removeRow( indices[i]);
330                 dtm.insertRow( indices[i]+1, new Object JavaDoc[]{val, ((QueryExecuterDef)val).getClassName(),((QueryExecuterDef)val).getFieldsProvider() });
331                 indices[i]++;
332             }
333             for (int i=0; i<indices.length; ++i)
334             {
335                 jTableProperties.addRowSelectionInterval(indices[i], indices[i]);
336             }
337             
338             saveAll();
339         }
340         
341     }//GEN-LAST:event_jButtonDeletePropertyActionPerformed2
342

343     private void jButtonDeletePropertyActionPerformed1(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonDeletePropertyActionPerformed1
344

345         
346         if (jTableProperties.getSelectedRowCount() > 0)
347         {
348             DefaultTableModel dtm = (DefaultTableModel)jTableProperties.getModel();
349             int[] indices = jTableProperties.getSelectedRows();
350             for (int i=0; i<indices.length; ++i)
351             {
352                 if (indices[i] == 0) continue;
353                 Object JavaDoc val = jTableProperties.getValueAt( indices[i], 0);
354                 dtm.removeRow( indices[i]);
355                 dtm.insertRow( indices[i]-1, new Object JavaDoc[]{val, ((QueryExecuterDef)val).getClassName(),((QueryExecuterDef)val).getFieldsProvider()});
356                 indices[i]--;
357             }
358             for (int i=0; i<indices.length; ++i)
359             {
360                 jTableProperties.addRowSelectionInterval(indices[i], indices[i]);
361             }
362             
363             saveAll();
364         }
365         
366     }//GEN-LAST:event_jButtonDeletePropertyActionPerformed1
367

368     private void jButtonSaveActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonSaveActionPerformed
369
setVisible(false);
370     }//GEN-LAST:event_jButtonSaveActionPerformed
371

372     private void jScrollPane3MouseClicked(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_jScrollPane3MouseClicked
373
// Add your handling code here:
374
}//GEN-LAST:event_jScrollPane3MouseClicked
375

376     private void jTablePropertiesMouseClicked(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_jTablePropertiesMouseClicked
377
if (evt.getClickCount() == 2 && evt.getButton() == evt.BUTTON1 && jTableProperties.getSelectedRow() >=0 ) {
378             jButtonModifyPropertyActionPerformed(new java.awt.event.ActionEvent JavaDoc( jButtonModifyProperty,0, ""));
379         }
380     }//GEN-LAST:event_jTablePropertiesMouseClicked
381

382     private void jButtonNewPropertyActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonNewPropertyActionPerformed
383
java.awt.Frame JavaDoc parent = Misc.frameFromComponent(this);
384         QueryExecuterDialog jrpd = new QueryExecuterDialog( parent, true);
385         jrpd.setVisible(true);
386         if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {
387             QueryExecuterDef qe = jrpd.getQueryExecuterDef();
388             ((DefaultTableModel)jTableProperties.getModel()).addRow(new Object JavaDoc[]{qe, qe.getClassName(),qe.getFieldsProvider()});
389             saveAll();
390         }
391         
392         
393     }//GEN-LAST:event_jButtonNewPropertyActionPerformed
394

395     private void jButtonModifyPropertyActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonModifyPropertyActionPerformed
396
QueryExecuterDef qe = (QueryExecuterDef)jTableProperties.getValueAt( jTableProperties.getSelectedRow(), 0);
397         
398         java.awt.Frame JavaDoc parent = Misc.frameFromComponent(this);
399         QueryExecuterDialog jrpd = new QueryExecuterDialog( parent, true);
400         jrpd.setQueryExecuterDef( qe );
401         jrpd.setVisible(true);
402         
403         if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {
404             jTableProperties.setValueAt( jrpd.getQueryExecuterDef(), jTableProperties.getSelectedRow(), 0);
405             jTableProperties.setValueAt( jrpd.getQueryExecuterDef().getClassName(), jTableProperties.getSelectedRow(), 1);
406             jTableProperties.setValueAt( jrpd.getQueryExecuterDef().getFieldsProvider(), jTableProperties.getSelectedRow(), 2);
407             saveAll();
408         }
409     }//GEN-LAST:event_jButtonModifyPropertyActionPerformed
410

411     private void jButtonDeletePropertyActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonDeletePropertyActionPerformed
412
int[] rows= jTableProperties.getSelectedRows();
413         DefaultTableModel dtm = (DefaultTableModel)jTableProperties.getModel();
414         for (int i=rows.length-1; i>=0; --i) {
415             dtm.removeRow(rows[i]);
416         }
417         saveAll();
418     }//GEN-LAST:event_jButtonDeletePropertyActionPerformed
419

420     /** Closes the dialog */
421     private void closeDialog(java.awt.event.WindowEvent JavaDoc evt) {//GEN-FIRST:event_closeDialog
422
setVisible(false);
423     }//GEN-LAST:event_closeDialog
424

425     
426     public void updateQueryExecuters() {
427         
428         DefaultTableModel dtm = (DefaultTableModel)jTableProperties.getModel();
429         dtm.setRowCount(0);
430     
431         Enumeration e = MainFrame.getMainInstance().getQueryExecuters().elements();
432         
433         while (e.hasMoreElements())
434         {
435             QueryExecuterDef qe = (QueryExecuterDef)e.nextElement();
436             Vector row = new Vector();
437             row.addElement( qe );
438             row.addElement( qe.getClassName());
439             row.addElement( qe.getFieldsProvider());
440             
441             dtm.addRow(row);
442         }
443     }
444     public void applyI18n(){
445                 // Start autogenerated code ----------------------
446
// End autogenerated code ----------------------
447
jButtonNewProperty.setText(it.businesslogic.ireport.util.I18n.getString("new","New"));
448         jButtonModifyProperty.setText(it.businesslogic.ireport.util.I18n.getString("modify","Modify"));
449         jButtonDeleteProperty.setText(it.businesslogic.ireport.util.I18n.getString("delete","Delete"));
450         jButtonMoveUp.setText(it.businesslogic.ireport.util.I18n.getString("moveUp","Move up"));
451         jButtonMoveDown.setText(it.businesslogic.ireport.util.I18n.getString("moveDown","Move down"));
452         jButtonSave.setText(it.businesslogic.ireport.util.I18n.getString("close","Close"));
453         
454         jTableProperties.getColumnModel().getColumn(0).setHeaderValue( I18n.getString("queryExecutersDialog.tablecolumn.language","Language") );
455         jTableProperties.getColumnModel().getColumn(1).setHeaderValue( I18n.getString("queryExecutersDialog.tablecolumn.factoryClass","Factory class") );
456         jTableProperties.getColumnModel().getColumn(2).setHeaderValue( I18n.getString("queryExecutersDialog.tablecolumn.fieldsProvider","Fields Provider") );
457                         
458     }
459     public void languageChanged(LanguageChangedEvent evt) {
460             
461         this.applyI18n();
462     }
463        
464     // Variables declaration - do not modify//GEN-BEGIN:variables
465
private javax.swing.JButton JavaDoc jButtonDeleteProperty;
466     private javax.swing.JButton JavaDoc jButtonModifyProperty;
467     private javax.swing.JButton JavaDoc jButtonMoveDown;
468     private javax.swing.JButton JavaDoc jButtonMoveUp;
469     private javax.swing.JButton JavaDoc jButtonNewProperty;
470     private javax.swing.JButton JavaDoc jButtonSave;
471     private javax.swing.JPanel JavaDoc jPanel1;
472     private javax.swing.JPanel JavaDoc jPanelButtons2;
473     private javax.swing.JPanel JavaDoc jPanelFields;
474     private javax.swing.JScrollPane JavaDoc jScrollPane3;
475     private it.businesslogic.ireport.gui.JDragTable jTableProperties;
476     // End of variables declaration//GEN-END:variables
477

478     
479     public void saveAll()
480     {
481         Vector v = MainFrame.getMainInstance().getQueryExecuters();
482         v.clear();
483         
484         for (int i=0; i<jTableProperties.getRowCount(); ++i)
485         {
486             QueryExecuterDef qe = (QueryExecuterDef)jTableProperties.getValueAt(i,0);
487             v.add(qe);
488         }
489         
490         MainFrame.getMainInstance().saveiReportConfiguration();
491     }
492    }
493
Popular Tags