Source Code Cross Referenced for UserTemplatesDialog.java in  » Report » iReport-2.0.5 » it » businesslogic » ireport » gui » wizard » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Report » iReport 2.0.5 » it.businesslogic.ireport.gui.wizard 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:         * UserTemplatesDialog.java
028:         *
029:         * Created on 22 aprile 2005, 18.05
030:         *
031:         */
032:
033:        package it.businesslogic.ireport.gui.wizard;
034:
035:        import it.businesslogic.ireport.Report;
036:        import it.businesslogic.ireport.gui.*;
037:        import it.businesslogic.ireport.util.I18nOptionPane;
038:        import it.businesslogic.ireport.util.Misc;
039:        import it.businesslogic.ireport.util.ReportGenerator;
040:        import java.awt.event.MouseAdapter;
041:        import java.awt.event.MouseEvent;
042:        import java.io.File;
043:        import javax.swing.DefaultListModel;
044:        import java.util.*;
045:        import javax.swing.JCheckBox;
046:        import it.businesslogic.ireport.util.I18n;
047:        import javax.swing.JFileChooser;
048:        import javax.swing.JOptionPane;
049:
050:        /**
051:         *
052:         * @author  Administrator
053:         */
054:        public class UserTemplatesDialog extends javax.swing.JDialog {
055:
056:            private int dialogResult = javax.swing.JOptionPane.CANCEL_OPTION;
057:            private boolean modifiedList = false;
058:
059:            /** Creates new form ClassPathDialog */
060:            public UserTemplatesDialog(java.awt.Frame parent, boolean modal) {
061:                super (parent, modal);
062:                initComponents();
063:                applyI18n();
064:                jList1.setModel(new DefaultListModel());
065:                it.businesslogic.ireport.util.Misc.centerFrame(this );
066:
067:                javax.swing.KeyStroke escape = javax.swing.KeyStroke
068:                        .getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0,
069:                                false);
070:                javax.swing.Action escapeAction = new javax.swing.AbstractAction() {
071:                    public void actionPerformed(java.awt.event.ActionEvent e) {
072:                        jButtonCancelActionPerformed(e);
073:                    }
074:                };
075:
076:                getRootPane().getInputMap(
077:                        javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(
078:                        escape, "ESCAPE");
079:                getRootPane().getActionMap().put("ESCAPE", escapeAction);
080:
081:                DefaultListModel dlm = new DefaultListModel();
082:                jList1.setModel(dlm);
083:
084:                java.util.List list = MainFrame.getMainInstance()
085:                        .getUserChoicesWizardTemplates();
086:
087:                for (int i = 0; i < list.size(); ++i) {
088:                    dlm.addElement(list.get(i));
089:                }
090:
091:                if (list.size() > 0) {
092:                    jList1.setSelectedIndex(0);
093:                }
094:
095:                jList1.updateUI();
096:
097:                //to make the default button ...
098:                this .getRootPane().setDefaultButton(this .jButtonSave);
099:            }
100:
101:            /** This method is called from within the constructor to
102:             * initialize the form.
103:             * WARNING: Do NOT modify this code. The content of this method is
104:             * always regenerated by the Form Editor.
105:             */
106:            // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
107:            private void initComponents() {
108:                java.awt.GridBagConstraints gridBagConstraints;
109:
110:                jScrollPane2 = new javax.swing.JScrollPane();
111:                jList1 = new javax.swing.JList();
112:                jPanel1 = new javax.swing.JPanel();
113:                jButtonCreateReports = new javax.swing.JButton();
114:                jButtonDeleteTemplate = new javax.swing.JButton();
115:                jButtonSave = new javax.swing.JButton();
116:                jButtonCancel = new javax.swing.JButton();
117:
118:                getContentPane().setLayout(new java.awt.GridBagLayout());
119:
120:                setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
121:                setTitle("Classpath");
122:                addWindowListener(new java.awt.event.WindowAdapter() {
123:                    public void windowClosed(java.awt.event.WindowEvent evt) {
124:                        formWindowClosed(evt);
125:                    }
126:
127:                    public void windowClosing(java.awt.event.WindowEvent evt) {
128:                        formWindowClosing(evt);
129:                    }
130:                });
131:
132:                jScrollPane2.setPreferredSize(new java.awt.Dimension(258, 300));
133:                jList1
134:                        .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
135:                            public void valueChanged(
136:                                    javax.swing.event.ListSelectionEvent evt) {
137:                                jList1ValueChanged(evt);
138:                            }
139:                        });
140:
141:                jScrollPane2.setViewportView(jList1);
142:
143:                gridBagConstraints = new java.awt.GridBagConstraints();
144:                gridBagConstraints.gridx = 0;
145:                gridBagConstraints.gridy = 1;
146:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
147:                gridBagConstraints.weightx = 1.0;
148:                gridBagConstraints.weighty = 1.0;
149:                gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
150:                getContentPane().add(jScrollPane2, gridBagConstraints);
151:
152:                jPanel1.setLayout(new java.awt.GridBagLayout());
153:
154:                jPanel1.setMinimumSize(new java.awt.Dimension(120, 10));
155:                jPanel1.setPreferredSize(new java.awt.Dimension(120, 10));
156:                jButtonCreateReports.setText("Create report(s)");
157:                jButtonCreateReports
158:                        .setToolTipText("Create report from selected template");
159:                jButtonCreateReports.setEnabled(false);
160:                jButtonCreateReports
161:                        .addActionListener(new java.awt.event.ActionListener() {
162:                            public void actionPerformed(
163:                                    java.awt.event.ActionEvent evt) {
164:                                jButtonDeselectAllActionPerformed1(evt);
165:                            }
166:                        });
167:
168:                gridBagConstraints = new java.awt.GridBagConstraints();
169:                gridBagConstraints.gridx = 0;
170:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
171:                gridBagConstraints.weightx = 1.0;
172:                gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0);
173:                jPanel1.add(jButtonCreateReports, gridBagConstraints);
174:
175:                jButtonDeleteTemplate.setText("Delete temlplate");
176:                jButtonDeleteTemplate.setToolTipText("");
177:                jButtonDeleteTemplate.setEnabled(false);
178:                jButtonDeleteTemplate
179:                        .addActionListener(new java.awt.event.ActionListener() {
180:                            public void actionPerformed(
181:                                    java.awt.event.ActionEvent evt) {
182:                                jButtonCreateReportsjButtonDeselectAllActionPerformed1(evt);
183:                            }
184:                        });
185:
186:                gridBagConstraints = new java.awt.GridBagConstraints();
187:                gridBagConstraints.gridx = 0;
188:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
189:                gridBagConstraints.weightx = 1.0;
190:                gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0);
191:                jPanel1.add(jButtonDeleteTemplate, gridBagConstraints);
192:
193:                jButtonSave.setText("Save");
194:                jButtonSave
195:                        .addActionListener(new java.awt.event.ActionListener() {
196:                            public void actionPerformed(
197:                                    java.awt.event.ActionEvent evt) {
198:                                jButtonSaveActionPerformed(evt);
199:                            }
200:                        });
201:
202:                gridBagConstraints = new java.awt.GridBagConstraints();
203:                gridBagConstraints.gridx = 0;
204:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
205:                gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
206:                gridBagConstraints.weightx = 1.0;
207:                gridBagConstraints.weighty = 1.0;
208:                gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0);
209:                jPanel1.add(jButtonSave, gridBagConstraints);
210:
211:                jButtonCancel.setText("Cancel");
212:                jButtonCancel
213:                        .addActionListener(new java.awt.event.ActionListener() {
214:                            public void actionPerformed(
215:                                    java.awt.event.ActionEvent evt) {
216:                                jButtonCancelActionPerformed(evt);
217:                            }
218:                        });
219:
220:                gridBagConstraints = new java.awt.GridBagConstraints();
221:                gridBagConstraints.gridx = 0;
222:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
223:                gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
224:                gridBagConstraints.weightx = 1.0;
225:                jPanel1.add(jButtonCancel, gridBagConstraints);
226:
227:                gridBagConstraints = new java.awt.GridBagConstraints();
228:                gridBagConstraints.gridx = 1;
229:                gridBagConstraints.gridy = 1;
230:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
231:                gridBagConstraints.weighty = 1.0;
232:                gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
233:                getContentPane().add(jPanel1, gridBagConstraints);
234:
235:                pack();
236:            }// </editor-fold>//GEN-END:initComponents
237:
238:            private void jList1ValueChanged(
239:                    javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged
240:
241:                if (jList1.getSelectedIndex() >= 0) {
242:                    jButtonCreateReports.setEnabled(true);
243:                    jButtonDeleteTemplate.setEnabled(true);
244:                } else {
245:                    jButtonCreateReports.setEnabled(false);
246:                    jButtonDeleteTemplate.setEnabled(false);
247:                }
248:
249:            }//GEN-LAST:event_jList1ValueChanged
250:
251:            private void jButtonSaveActionPerformed(
252:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveActionPerformed
253:
254:                List list = MainFrame.getMainInstance()
255:                        .getUserChoicesWizardTemplates();
256:                list.clear();
257:                DefaultListModel dlm = (DefaultListModel) jList1.getModel();
258:                for (int i = 0; i < dlm.getSize(); ++i) {
259:                    list.add(dlm.getElementAt(i));
260:                }
261:
262:                UserChoicesWizardTemplate.storeWizardTemplates(list);
263:
264:                setDialogResult(javax.swing.JOptionPane.OK_OPTION);
265:                setVisible(false);
266:            }//GEN-LAST:event_jButtonSaveActionPerformed
267:
268:            private void jButtonCreateReportsjButtonDeselectAllActionPerformed1(
269:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCreateReportsjButtonDeselectAllActionPerformed1
270:
271:                DefaultListModel dlm = (DefaultListModel) jList1.getModel();
272:                int[] indexes = jList1.getSelectedIndices();
273:                for (int i = indexes.length - 1; i >= 0; --i) {
274:                    dlm.remove(indexes[i]);
275:                    modifiedList = true;
276:                }
277:
278:            }//GEN-LAST:event_jButtonCreateReportsjButtonDeselectAllActionPerformed1
279:
280:            private void jButtonDeselectAllActionPerformed1(
281:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDeselectAllActionPerformed1
282:
283:                Object[] templates = jList1.getSelectedValues();
284:                if (templates.length == 0)
285:                    return;
286:
287:                int filesCreated = 0;
288:
289:                // Ask for destination directory...
290:
291:                javax.swing.JFileChooser jfc = new javax.swing.JFileChooser(
292:                        MainFrame.getMainInstance().getCurrentDirectory());
293:
294:                jfc.setDialogTitle("Select output directory");
295:                jfc.setDialogTitle(it.businesslogic.ireport.util.I18n
296:                        .getString("selectOutputDirectory",
297:                                "Select output directory"));//I18N
298:
299:                jfc.setAcceptAllFileFilterUsed(true);
300:                jfc.setFileSelectionMode(jfc.DIRECTORIES_ONLY);
301:                /*jfc.addChoosableFileFilter( new javax.swing.filechooser.FileFilter() {
302:                    public boolean accept(java.io.File file) {
303:                        String filename = file.getName();
304:                        return (filename.toLowerCase().endsWith(".jar") || file.isDirectory() ||
305:                                filename.toLowerCase().endsWith(".zip")
306:                                ) ;
307:                    }
308:                    public String getDescription() {
309:                        return "*.jar, *.zip";
310:                    }
311:                });
312:                 */
313:
314:                jfc.setMultiSelectionEnabled(false);
315:
316:                jfc.setDialogType(javax.swing.JFileChooser.OPEN_DIALOG);
317:                if (jfc.showOpenDialog(this ) == javax.swing.JOptionPane.OK_OPTION) {
318:                    java.io.File directory = jfc.getSelectedFile();
319:
320:                    MainFrame.getMainInstance().setCurrentDirectory(directory,
321:                            true);
322:
323:                    for (int i = templates.length - 1; i >= 0; --i) {
324:                        UserChoicesWizardTemplate template = (UserChoicesWizardTemplate) templates[i];
325:                        File file = new File(directory, Misc.string_replace(
326:                                "_", " ", template.getName())
327:                                + ".jrxml");
328:
329:                        if (file.exists()) {
330:                            //is different file to save?
331:                            //confirm overwrite
332:                            int ret = JOptionPane
333:                                    .showConfirmDialog(
334:                                            this ,
335:                                            I18n
336:                                                    .getFormattedString(
337:                                                            "userTemplatesDialog.message.overwrite",
338:                                                            "The file {0} already exists.\nDo you want overwrite it?",
339:                                                            new Object[] { ""
340:                                                                    + file }),
341:                                            "",
342:                                            JOptionPane.YES_NO_CANCEL_OPTION,
343:                                            JOptionPane.WARNING_MESSAGE);
344:
345:                            if (ret == JOptionPane.CANCEL_OPTION)
346:                                break;
347:                            if (ret == JOptionPane.NO_OPTION) {
348:                                // Select a new File...
349:                                jfc = new javax.swing.JFileChooser(MainFrame
350:                                        .getMainInstance()
351:                                        .getCurrentDirectory());
352:                                jfc
353:                                        .setDialogTitle("Save report as XML jasperreports file...");
354:
355:                                // Handling the new File, that gets saved for the first time
356:                                // Propose a new file name based on the report name
357:
358:                                jfc.setSelectedFile(file);
359:
360:                                jfc
361:                                        .setFileFilter(new javax.swing.filechooser.FileFilter() {
362:                                            public boolean accept(
363:                                                    java.io.File file) {
364:                                                String filename = file
365:                                                        .getName();
366:                                                return (filename.toLowerCase()
367:                                                        .endsWith(".xml")
368:                                                        || file.isDirectory() || filename
369:                                                        .toLowerCase()
370:                                                        .endsWith(".jrxml"));
371:                                            }
372:
373:                                            public String getDescription() {
374:                                                return "JasperReports XML *.xml, *.jrxml";
375:                                            }
376:                                        });
377:                                jfc.setMultiSelectionEnabled(false);
378:                                jfc
379:                                        .setDialogType(javax.swing.JFileChooser.SAVE_DIALOG);
380:
381:                                // Show the dialog:
382:                                if (jfc.showSaveDialog(this ) != javax.swing.JOptionPane.OK_OPTION) {
383:                                    return;
384:                                }
385:
386:                                file = jfc.getSelectedFile();
387:                            }
388:                        }
389:
390:                        try {
391:                            Report report = ReportGenerator
392:                                    .createReport(template);
393:                            report.saveXMLFile("" + file);
394:                            filesCreated++;
395:                        } catch (Exception ex) {
396:                            JOptionPane.showMessageDialog(this ,
397:                                    ex.getMessage(), I18n.getString(
398:                                            "message.title.exception",
399:                                            "Exception"),
400:                                    JOptionPane.ERROR_MESSAGE);
401:                            break;
402:                        }
403:                    }
404:
405:                    JOptionPane
406:                            .showMessageDialog(
407:                                    this ,
408:                                    I18n
409:                                            .getFormattedString(
410:                                                    "userTemplatesDialog.message.createdReports",
411:                                                    "{0} report(s) created successful.",
412:                                                    new Object[] { new Integer(
413:                                                            filesCreated) }),
414:                                    "", JOptionPane.INFORMATION_MESSAGE);
415:                }
416:
417:            }//GEN-LAST:event_jButtonDeselectAllActionPerformed1
418:
419:            private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
420:
421:            }//GEN-LAST:event_formWindowClosed
422:
423:            private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
424:
425:                // Save all...
426:                if (modifiedList) {
427:                    int ret = javax.swing.JOptionPane.showConfirmDialog(this ,
428:                            it.businesslogic.ireport.util.I18n.getString(
429:                                    "userTemplatesDialog.saveTemplatesList",
430:                                    "Do you want save the changes ?"));
431:
432:                    if (ret == javax.swing.JOptionPane.CANCEL_OPTION) {
433:                        return;
434:                    }
435:
436:                    jButtonSaveActionPerformed(null);
437:                } else {
438:                    setVisible(false);
439:                }
440:            }//GEN-LAST:event_formWindowClosing
441:
442:            private void jButtonCancelActionPerformed(
443:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
444:                setVisible(false);
445:            }//GEN-LAST:event_jButtonCancelActionPerformed
446:
447:            /**
448:             * @param args the command line arguments
449:             */
450:            public static void main(String args[]) {
451:                java.awt.EventQueue.invokeLater(new Runnable() {
452:                    public void run() {
453:                        new ClassPathDialog(new javax.swing.JFrame(), true)
454:                                .setVisible(true);
455:                    }
456:                });
457:            }
458:
459:            public int getDialogResult() {
460:                return dialogResult;
461:            }
462:
463:            public void setDialogResult(int dialogResult) {
464:                this .dialogResult = dialogResult;
465:            }
466:
467:            // Variables declaration - do not modify//GEN-BEGIN:variables
468:            private javax.swing.JButton jButtonCancel;
469:            private javax.swing.JButton jButtonCreateReports;
470:            private javax.swing.JButton jButtonDeleteTemplate;
471:            private javax.swing.JButton jButtonSave;
472:            private javax.swing.JList jList1;
473:            private javax.swing.JPanel jPanel1;
474:            private javax.swing.JScrollPane jScrollPane2;
475:
476:            // End of variables declaration//GEN-END:variables
477:
478:            public void applyI18n() {
479:                // Start autogenerated code ----------------------
480:                jButtonCancel.setText(I18n.getString(
481:                        "jRFieldDialog.buttonCancel", "Cancel"));
482:                jButtonCreateReports.setText(I18n.getString(
483:                        "userTemplatesDialog.buttonGenerateReport",
484:                        "Generate report(s)"));
485:                jButtonDeleteTemplate.setText(I18n.getString(
486:                        "userTemplatesDialog.buttonRemoveTemplate",
487:                        "Remove template"));
488:                jButtonSave.setText(I18n.getString(
489:                        "userTemplatesDialog.buttonSave", "Save changes"));
490:
491:                this .setTitle(I18n.getString("userTemplatesDialog.title",
492:                        "User choices templates"));
493:                // End autogenerated code ----------------------
494:            }
495:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.