Source Code Cross Referenced for TableExportDialog.java in  » Database-Client » JSqlTool » org » jsqltool » gui » 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 » Database Client » JSqlTool » org.jsqltool.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.jsqltool.gui;
002:
003:        import java.awt.*;
004:        import javax.swing.*;
005:        import javax.swing.event.*;
006:        import java.awt.event.*;
007:        import org.jsqltool.conn.DbConnectionUtil;
008:        import org.jsqltool.model.CustomTableModel;
009:        import java.util.*;
010:        import java.sql.*;
011:        import java.text.SimpleDateFormat;
012:        import java.io.*;
013:        import java.awt.datatransfer.*;
014:        import org.jsqltool.gui.tableplugins.datatable.filter.*;
015:        import org.jsqltool.utils.Options;
016:        import org.jsqltool.utils.ImageLoader;
017:
018:        import org.apache.poi.poifs.filesystem.POIFSFileSystem;
019:        import org.apache.poi.hssf.record.*;
020:        import org.apache.poi.hssf.model.*;
021:        import org.apache.poi.hssf.usermodel.*;
022:        import org.apache.poi.hssf.util.*;
023:
024:        /**
025:         * <p>Title: JSqlTool Project</p>
026:         * <p>Description: Dialog used to export table content.
027:         * Table content can be exported as:
028:         * - SQL insert statements
029:         * - text data, with a custom delimiter (e.g. ",")
030:         * - XLS (Excel) file format
031:         * </p>
032:         * <p>Copyright: Copyright (C) 2006 Mauro Carniel</p>
033:         *
034:         * <p> This file is part of JSqlTool project.
035:         * This library is free software; you can redistribute it and/or
036:         * modify it under the terms of the (LGPL) Lesser General Public
037:         * License as published by the Free Software Foundation;
038:         *
039:         *                GNU LESSER GENERAL PUBLIC LICENSE
040:         *                 Version 2.1, February 1999
041:         *
042:         * This library is distributed in the hope that it will be useful,
043:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
044:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
045:         * Library General Public License for more details.
046:         *
047:         * You should have received a copy of the GNU Library General Public
048:         * License along with this library; if not, write to the Free
049:         * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
050:         *
051:         *       The author may be contacted at:
052:         *           maurocarniel@tin.it</p>
053:         *
054:         * @author Mauro Carniel
055:         * @version 1.0
056:         */
057:        public class TableExportDialog extends JDialog implements 
058:                TableModelListener {
059:
060:            JPanel mainPanel = new JPanel();
061:            BorderLayout borderLayout1 = new BorderLayout();
062:            JPanel headPanel = new JPanel();
063:            JPanel tabPanel = new JPanel();
064:            JTabbedPane tabbedPane = new JTabbedPane();
065:            BorderLayout borderLayout2 = new BorderLayout();
066:            JTextField tableTF = new JTextField();
067:            JButton cancelButton = new JButton();
068:            JButton okButton = new JButton();
069:            GridBagLayout gridBagLayout1 = new GridBagLayout();
070:            JPanel optionsPanel = new JPanel();
071:            JPanel colPanel = new JPanel();
072:            JLabel whereLabel = new JLabel();
073:            JScrollPane scrollPane = new JScrollPane();
074:            JTextPane wherePane = new JTextPane();
075:            JLabel destLabel = new JLabel();
076:            JRadioButton clipRadioButton = new JRadioButton();
077:            JRadioButton fileRadioButton = new JRadioButton();
078:            JLabel fileLabel = new JLabel();
079:            JTextField filenameTF = new JTextField();
080:            JButton filenameButton = new JButton();
081:            JCheckBox schemaCheckBox = new JCheckBox();
082:            GridBagLayout gridBagLayout2 = new GridBagLayout();
083:            ButtonGroup dest = new ButtonGroup();
084:            private String tableName = null;
085:            private JFrame frame = null;
086:            GridBagLayout gridBagLayout3 = new GridBagLayout();
087:            JScrollPane colsScrollPane = new JScrollPane();
088:            JTable colsTable = new JTable();
089:            JCheckBox nullCheckBox = new JCheckBox();
090:            JCheckBox pkCheckBox = new JCheckBox();
091:            JButton selButton = new JButton();
092:            JButton unselButton = new JButton();
093:            private DbConnectionUtil dbConnUtil = null;
094:            private Hashtable pk = null;
095:            private boolean enableListener = true;
096:            JLabel formatLabel = new JLabel();
097:            JRadioButton sqlRadioButton = new JRadioButton();
098:            ButtonGroup formatButtonGroup = new ButtonGroup();
099:            JRadioButton txtRadioButton = new JRadioButton();
100:            JTextField delimTF = new JTextField();
101:            JRadioButton xlsRadioButton = new JRadioButton();
102:
103:            public TableExportDialog(JFrame frame, DbConnectionUtil dbConnUtil,
104:                    String tableName) {
105:                super (frame, Options.getInstance().getResource("data export"),
106:                        true);
107:                this .frame = frame;
108:                this .tableName = tableName;
109:                this .dbConnUtil = dbConnUtil;
110:                try {
111:                    init();
112:                    jbInit();
113:                    pack();
114:                    setSize(450, 400);
115:                    Dimension screenSize = Toolkit.getDefaultToolkit()
116:                            .getScreenSize();
117:                    Dimension frameSize = this .getSize();
118:                    if (frameSize.height > screenSize.height) {
119:                        frameSize.height = screenSize.height;
120:                    }
121:                    if (frameSize.width > screenSize.width) {
122:                        frameSize.width = screenSize.width;
123:                    }
124:                    this .setLocation((screenSize.width - frameSize.width) / 2,
125:                            (screenSize.height - frameSize.height) / 2);
126:                    setVisible(true);
127:                } catch (Exception ex) {
128:                    ex.printStackTrace();
129:                }
130:            }
131:
132:            public TableExportDialog() {
133:                this (null, null, null);
134:            }
135:
136:            private void init() {
137:                // set table name...
138:                tableTF.setText(tableName);
139:
140:                // fill in columns list...
141:                CustomTableModel model = (CustomTableModel) dbConnUtil
142:                        .getTableColumns(tableName);
143:                Vector colData = new Vector();
144:                for (int i = 0; i < model.getRowCount(); i++)
145:                    colData.add(new Boolean(false));
146:                model.addColumn(Options.getInstance().getResource("selection"),
147:                        colData, Boolean.class, 30);
148:                model.setEditableCols(new boolean[] { false, false, false,
149:                        false, false, true });
150:                model.setEditMode(model.EDIT_REC);
151:                // identifiers of the model: "Column","Data Type","PK","Null?","Default","Selected"
152:                colsTable.setModel(model);
153:                colsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
154:                colsTable.getColumnModel().moveColumn(5, 0);
155:                colsTable.getColumnModel().removeColumn(
156:                        colsTable.getColumnModel().getColumn(2));
157:                colsTable.getColumnModel().removeColumn(
158:                        colsTable.getColumnModel().getColumn(2));
159:                colsTable.getColumnModel().removeColumn(
160:                        colsTable.getColumnModel().getColumn(2));
161:                colsTable.getColumnModel().removeColumn(
162:                        colsTable.getColumnModel().getColumn(2));
163:                colsTable.getColumnModel().getColumn(0).setPreferredWidth(30);
164:                colsTable.getColumnModel().getColumn(1).setPreferredWidth(150);
165:                colsTable.setShowGrid(false);
166:                colsTable.setRowSelectionAllowed(false);
167:                colsTable.setColumnSelectionAllowed(false);
168:
169:                // initialization of pk cols...
170:                pk = dbConnUtil.getPK(tableName);
171:
172:                // select all columns...
173:                model.addTableModelListener(this );
174:                selButton_actionPerformed(null);
175:            }
176:
177:            private void jbInit() throws Exception {
178:                mainPanel.setLayout(borderLayout1);
179:                tabPanel.setLayout(borderLayout2);
180:                cancelButton.setMnemonic(Options.getInstance().getResource(
181:                        "cancelbutton.mnemonic").charAt(0));
182:                cancelButton.setText(Options.getInstance().getResource(
183:                        "cancelbutton.text"));
184:                cancelButton
185:                        .addActionListener(new TableExportDialog_cancelButton_actionAdapter(
186:                                this ));
187:                okButton.setMnemonic(Options.getInstance().getResource(
188:                        "okbutton.mnemonic").charAt(0));
189:                okButton.setText(Options.getInstance().getResource(
190:                        "okbutton.text"));
191:                okButton
192:                        .addActionListener(new TableExportDialog_okButton_actionAdapter(
193:                                this ));
194:                headPanel.setLayout(gridBagLayout1);
195:                tableTF.setEnabled(true);
196:                tableTF.setDisabledTextColor(Color.gray);
197:                tableTF.setEditable(false);
198:                optionsPanel.setToolTipText(Options.getInstance().getResource(
199:                        "export options"));
200:                optionsPanel.setLayout(gridBagLayout2);
201:                colPanel.setToolTipText(Options.getInstance().getResource(
202:                        "exported columns"));
203:                colPanel.setVerifyInputWhenFocusTarget(true);
204:                colPanel.setLayout(gridBagLayout3);
205:                whereLabel.setText(Options.getInstance().getResource(
206:                        "Optional WHERE clause (you must include \'Where\')"));
207:                wherePane.setText("");
208:                destLabel.setText(Options.getInstance().getResource(
209:                        "destination"));
210:                clipRadioButton.setText(Options.getInstance().getResource(
211:                        "to clipboard"));
212:                clipRadioButton
213:                        .addItemListener(new TableExportDialog_clipRadioButton_itemAdapter(
214:                                this ));
215:                fileRadioButton.setSelected(true);
216:                fileRadioButton.setText(Options.getInstance().getResource(
217:                        "to file"));
218:                fileRadioButton
219:                        .addItemListener(new TableExportDialog_fileRadioButton_itemAdapter(
220:                                this ));
221:                fileLabel
222:                        .setText(Options.getInstance().getResource("filename"));
223:                filenameButton.setText("...");
224:                filenameButton
225:                        .addActionListener(new TableExportDialog_filenameButton_actionAdapter(
226:                                this ));
227:                filenameTF.setText("");
228:                schemaCheckBox.setText(Options.getInstance().getResource(
229:                        "include schema/owner name in insert statements"));
230:                nullCheckBox.setText(Options.getInstance().getResource(
231:                        "exclude null columns"));
232:                nullCheckBox
233:                        .addItemListener(new TableExportDialog_nullCheckBox_itemAdapter(
234:                                this ));
235:                pkCheckBox.setText(Options.getInstance().getResource(
236:                        "exclude primary key columns"));
237:                pkCheckBox
238:                        .addItemListener(new TableExportDialog_pkCheckBox_itemAdapter(
239:                                this ));
240:                selButton.setMnemonic(Options.getInstance().getResource(
241:                        "selectall.mnemonic").charAt(0));
242:                selButton.setText(Options.getInstance().getResource(
243:                        "selectall.text"));
244:                selButton
245:                        .addActionListener(new TableExportDialog_selButton_actionAdapter(
246:                                this ));
247:                unselButton.setMnemonic(Options.getInstance().getResource(
248:                        "deselectall.menmonic").charAt(0));
249:                unselButton.setText(Options.getInstance().getResource(
250:                        "deselectall.text"));
251:                unselButton
252:                        .addActionListener(new TableExportDialog_unselButton_actionAdapter(
253:                                this ));
254:                formatLabel.setText(Options.getInstance().getResource(
255:                        "export format"));
256:                sqlRadioButton.setSelected(true);
257:                sqlRadioButton.setText(Options.getInstance().getResource(
258:                        "SQL (insert)"));
259:                sqlRadioButton
260:                        .addItemListener(new TableExportDialog_sqlRadioButton_itemAdapter(
261:                                this ));
262:                txtRadioButton.setText(Options.getInstance().getResource(
263:                        "txt with delim"));
264:                txtRadioButton
265:                        .addItemListener(new TableExportDialog_txtRadioButton_itemAdapter(
266:                                this ));
267:                delimTF.setEditable(false);
268:                delimTF.setText(",");
269:                delimTF.setColumns(10);
270:                xlsRadioButton.setText(Options.getInstance().getResource(
271:                        "excel (xls)"));
272:                getContentPane().add(mainPanel);
273:                mainPanel.add(headPanel, BorderLayout.NORTH);
274:                mainPanel.add(tabPanel, BorderLayout.CENTER);
275:                tabPanel.add(tabbedPane, BorderLayout.CENTER);
276:                tabbedPane.add(optionsPanel, Options.getInstance().getResource(
277:                        "options"));
278:                tabbedPane.add(colPanel, Options.getInstance().getResource(
279:                        "columns"));
280:                tabbedPane.setSelectedIndex(1);
281:                colPanel.add(colsScrollPane, new GridBagConstraints(0, 0, 1, 5,
282:                        1.0, 1.0, GridBagConstraints.WEST,
283:                        GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
284:                colPanel
285:                        .add(nullCheckBox, new GridBagConstraints(1, 1, 1, 1,
286:                                0.0, 0.0, GridBagConstraints.WEST,
287:                                GridBagConstraints.NONE,
288:                                new Insets(50, 5, 5, 5), 0, 0));
289:                colPanel.add(pkCheckBox, new GridBagConstraints(1, 2, 1, 1,
290:                        0.0, 0.0, GridBagConstraints.WEST,
291:                        GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
292:                colPanel.add(selButton, new GridBagConstraints(1, 3, 1, 1, 0.0,
293:                        0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
294:                        new Insets(5, 20, 5, 20), 12, 0));
295:                colPanel.add(unselButton,
296:                        new GridBagConstraints(1, 4, 1, 1, 0.0, 1.0,
297:                                GridBagConstraints.NORTHWEST,
298:                                GridBagConstraints.NONE, new Insets(5, 20, 5,
299:                                        20), 0, 0));
300:                colsScrollPane.getViewport().add(colsTable, null);
301:                headPanel.add(tableTF, new GridBagConstraints(0, 0, 1, 1, 1.0,
302:                        0.0, GridBagConstraints.WEST,
303:                        GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
304:                        0, 0));
305:                headPanel.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0,
306:                        0.0, GridBagConstraints.EAST, GridBagConstraints.NONE,
307:                        new Insets(5, 5, 5, 5), 0, 0));
308:                headPanel.add(cancelButton, new GridBagConstraints(2, 0, 1, 1,
309:                        0.0, 0.0, GridBagConstraints.EAST,
310:                        GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
311:                optionsPanel.add(whereLabel, new GridBagConstraints(0, 0, 5, 1,
312:                        0.0, 0.0, GridBagConstraints.WEST,
313:                        GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
314:                optionsPanel.add(scrollPane, new GridBagConstraints(0, 1, 5, 1,
315:                        1.0, 1.0, GridBagConstraints.CENTER,
316:                        GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
317:                scrollPane.getViewport().add(wherePane, null);
318:                optionsPanel.add(destLabel, new GridBagConstraints(0, 2, 1, 1,
319:                        0.0, 0.0, GridBagConstraints.WEST,
320:                        GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
321:                optionsPanel.add(clipRadioButton, new GridBagConstraints(0, 3,
322:                        1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
323:                        GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
324:                optionsPanel.add(fileRadioButton, new GridBagConstraints(1, 3,
325:                        3, 1, 0.0, 0.0, GridBagConstraints.WEST,
326:                        GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
327:                optionsPanel
328:                        .add(fileLabel, new GridBagConstraints(0, 6, 1, 1, 0.0,
329:                                0.0, GridBagConstraints.WEST,
330:                                GridBagConstraints.NONE,
331:                                new Insets(10, 5, 5, 5), 0, 0));
332:                optionsPanel.add(filenameTF, new GridBagConstraints(0, 7, 4, 1,
333:                        1.0, 0.0, GridBagConstraints.WEST,
334:                        GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
335:                        0, 0));
336:                optionsPanel.add(filenameButton, new GridBagConstraints(4, 7,
337:                        1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
338:                        GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
339:                optionsPanel.add(schemaCheckBox, new GridBagConstraints(0, 8,
340:                        4, 1, 0.0, 1.0, GridBagConstraints.NORTHWEST,
341:                        GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
342:                optionsPanel
343:                        .add(formatLabel, new GridBagConstraints(0, 4, 1, 1,
344:                                0.0, 0.0, GridBagConstraints.WEST,
345:                                GridBagConstraints.NONE,
346:                                new Insets(10, 5, 5, 5), 0, 0));
347:                dest.add(clipRadioButton);
348:                dest.add(fileRadioButton);
349:                optionsPanel.add(sqlRadioButton, new GridBagConstraints(0, 5,
350:                        1, 1, 0.0, 0.0, GridBagConstraints.WEST,
351:                        GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
352:                formatButtonGroup.add(sqlRadioButton);
353:                optionsPanel.add(txtRadioButton, new GridBagConstraints(1, 5,
354:                        1, 1, 0.0, 0.0, GridBagConstraints.WEST,
355:                        GridBagConstraints.NONE, new Insets(5, 5, 5, 0), 0, 0));
356:                formatButtonGroup.add(txtRadioButton);
357:                optionsPanel.add(delimTF, new GridBagConstraints(2, 5, 1, 1,
358:                        0.0, 0.0, GridBagConstraints.WEST,
359:                        GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0));
360:                optionsPanel.add(xlsRadioButton, new GridBagConstraints(3, 5,
361:                        1, 1, 0.0, 0.0, GridBagConstraints.WEST,
362:                        GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
363:                formatButtonGroup.add(xlsRadioButton);
364:            }
365:
366:            public void tableChanged(TableModelEvent e) {
367:                if (!enableListener)
368:                    return;
369:                CustomTableModel model = (CustomTableModel) colsTable
370:                        .getModel();
371:                if (pkCheckBox.isSelected()) {
372:                    enableListener = false;
373:                    Iterator it = pk.values().iterator();
374:                    while (it.hasNext())
375:                        model.setValueAt(new Boolean(false), ((Integer) it
376:                                .next()).intValue(), 5);
377:                    enableListener = true;
378:                }
379:                if (nullCheckBox.isSelected()) {
380:                    enableListener = false;
381:                    for (int i = 0; i < model.getRowCount(); i++)
382:                        if (((Boolean) model.getValueAt(i, 3)).booleanValue())
383:                            model.setValueAt(new Boolean(false), i, 5);
384:                    enableListener = true;
385:                }
386:            }
387:
388:            void okButton_actionPerformed(ActionEvent e) {
389:                try {
390:                    PrintWriter pw = null;
391:                    HSSFWorkbook hssfworkbook = null;
392:                    HSSFSheet sheet = null;
393:                    HSSFRow row = null;
394:                    HSSFCell cell = null;
395:                    String clipText = "";
396:                    if (txtRadioButton.isSelected()
397:                            && delimTF.getText().length() == 0) {
398:                        JOptionPane.showMessageDialog(frame, Options
399:                                .getInstance().getResource(
400:                                        "please define a field delimiter."),
401:                                Options.getInstance()
402:                                        .getResource("export rows"),
403:                                JOptionPane.WARNING_MESSAGE);
404:                        return;
405:                    }
406:                    if (fileRadioButton.isSelected()) {
407:                        if (filenameTF.getText().length() == 0) {
408:                            JOptionPane
409:                                    .showMessageDialog(
410:                                            frame,
411:                                            Options
412:                                                    .getInstance()
413:                                                    .getResource(
414:                                                            "please select filename to store exporting rows."),
415:                                            Options.getInstance().getResource(
416:                                                    "export rows"),
417:                                            JOptionPane.WARNING_MESSAGE);
418:                            return;
419:                        }
420:
421:                        if (xlsRadioButton.isSelected()) {
422:                            hssfworkbook = new HSSFWorkbook();
423:                            sheet = hssfworkbook.createSheet();
424:                        } else
425:                            pw = new PrintWriter(new FileOutputStream(
426:                                    filenameTF.getText()));
427:                    }
428:                    String query = "SELECT ";
429:                    String select = "";
430:                    CustomTableModel model = (CustomTableModel) colsTable
431:                            .getModel();
432:                    for (int i = 0; i < model.getRowCount(); i++)
433:                        if (((Boolean) model.getValueAt(i, 5)).booleanValue())
434:                            select += model.getValueAt(i, 0) + ",";
435:                    if (select.length() == 0)
436:                        return;
437:                    select = select.substring(0, select.length() - 1);
438:                    query += select + " FROM " + tableName;
439:                    FilterModel fm = (FilterModel) dbConnUtil.getDbConnection()
440:                            .getFilters().get(tableName);
441:                    if (fm == null) {
442:                        fm = new FilterModel();
443:                        dbConnUtil.getDbConnection().getFilters().put(
444:                                tableName, fm);
445:                    }
446:
447:                    String filter = fm.getWhereClause();
448:                    query += filter;
449:                    if (wherePane.getText().length() > 0) {
450:                        if (filter.length() > 0) {
451:                            query += " AND "
452:                                    + wherePane.getText().replace('\n', ' ')
453:                                            .substring(6);
454:                        } else
455:                            query += " "
456:                                    + wherePane.getText().replace('\n', ' ');
457:                    }
458:
459:                    int count = 0;
460:                    Statement stmt = dbConnUtil.getConn().createStatement();
461:                    ResultSet rset = stmt.executeQuery(query);
462:                    String values = "";
463:                    Object obj = null;
464:                    String tName = tableName;
465:                    if (tName.indexOf(".") > -1 && !schemaCheckBox.isSelected())
466:                        tName = tName.substring(tName.indexOf(".") + 1);
467:                    String line = null;
468:                    SimpleDateFormat sdf = new SimpleDateFormat(Options
469:                            .getInstance().getDateFormat());
470:
471:                    while (rset.next()) {
472:                        if (sqlRadioButton.isSelected()) {
473:                            // export in SQL format...
474:                            values = "";
475:                            for (int i = 0; i < rset.getMetaData()
476:                                    .getColumnCount(); i++) {
477:                                obj = rset.getObject(i + 1);
478:                                if (obj == null)
479:                                    obj = "null";
480:                                else if (obj instanceof  java.sql.Timestamp
481:                                        || obj instanceof  java.sql.Date)
482:                                    obj = dbConnUtil
483:                                            .convertDateToString((java.util.Date) obj);
484:                                else if (obj instanceof  String)
485:                                    obj = "'" + obj + "'";
486:                                values += obj + ",";
487:                            }
488:                            values = values.substring(0, values.length() - 1);
489:                            line = "INSERT INTO " + tName + "(" + select
490:                                    + ") VALUES(" + values + ");";
491:                        } else if (txtRadioButton.isSelected()) {
492:                            // export in TXT format...
493:                            values = "";
494:                            for (int i = 0; i < rset.getMetaData()
495:                                    .getColumnCount(); i++) {
496:                                obj = rset.getObject(i + 1);
497:                                if (obj == null)
498:                                    obj = "";
499:                                else if (obj instanceof  java.sql.Timestamp
500:                                        || obj instanceof  java.sql.Date)
501:                                    obj = sdf.format((java.util.Date) obj);
502:                                values += obj + delimTF.getText();
503:                            }
504:                            values = values.substring(0, values.length()
505:                                    - delimTF.getText().length());
506:                            line = values;
507:                        } else if (xlsRadioButton.isSelected()) {
508:                            row = sheet.createRow(count);
509:                            for (int i = 0; i < rset.getMetaData()
510:                                    .getColumnCount(); i++) {
511:                                obj = rset.getObject(i + 1);
512:                                if (obj != null) {
513:                                    cell = row.createCell((short) i);
514:                                    if (obj instanceof  java.sql.Timestamp
515:                                            || obj instanceof  java.sql.Date) {
516:                                        obj = sdf.format((java.util.Date) obj);
517:                                        cell
518:                                                .setCellType(HSSFCell.CELL_TYPE_STRING);
519:                                        cell.setCellValue(obj.toString());
520:                                    } else if (obj instanceof  String) {
521:                                        cell
522:                                                .setCellType(HSSFCell.CELL_TYPE_STRING);
523:                                        cell.setCellValue(obj.toString());
524:                                    } else if (obj instanceof  Number) {
525:                                        cell
526:                                                .setCellType(HSSFCell.CELL_TYPE_NUMERIC);
527:                                        cell.setCellValue(((Number) obj)
528:                                                .doubleValue());
529:                                    }
530:                                }
531:                            }
532:                        }
533:
534:                        // write to file/clipboard...
535:                        if (fileRadioButton.isSelected()) {
536:                            if (!xlsRadioButton.isSelected()) {
537:                                pw.println(line);
538:                                pw.flush();
539:                            }
540:                        } else {
541:                            clipText += line + "\n";
542:                        }
543:                        count++;
544:                    }
545:                    rset.close();
546:                    stmt.close();
547:                    if (fileRadioButton.isSelected()) {
548:                        if (xlsRadioButton.isSelected()) {
549:                            FileOutputStream fileOut = new FileOutputStream(
550:                                    filenameTF.getText());
551:                            hssfworkbook.write(fileOut);
552:                            fileOut.close();
553:                        } else
554:                            pw.close();
555:                    } else {
556:                        Clipboard clip = Toolkit.getDefaultToolkit()
557:                                .getSystemClipboard();
558:                        clip.setContents(new StringSelection(clipText), null);
559:                    }
560:                    JOptionPane.showMessageDialog(frame, Options.getInstance()
561:                            .getResource("process completed.")
562:                            + " "
563:                            + count
564:                            + " "
565:                            + Options.getInstance().getResource(
566:                                    "rows were exported."), Options
567:                            .getInstance().getResource("export rows"),
568:                            JOptionPane.INFORMATION_MESSAGE);
569:                    setVisible(false);
570:                    dispose();
571:                } catch (Exception ex) {
572:                    ex.printStackTrace();
573:                    JOptionPane.showMessageDialog(frame, Options.getInstance()
574:                            .getResource("error while exporting data")
575:                            + ":\n" + ex.getMessage(), Options.getInstance()
576:                            .getResource("error"), JOptionPane.ERROR_MESSAGE);
577:                }
578:            }
579:
580:            void cancelButton_actionPerformed(ActionEvent e) {
581:                setVisible(false);
582:                dispose();
583:            }
584:
585:            void filenameButton_actionPerformed(ActionEvent e) {
586:                JFileChooser chooser = null;
587:                try {
588:                    String path = System.getProperty("user.dir");
589:                    if (path.charAt(0) == '/' || path.charAt(0) == '\\')
590:                        path = path.substring(1);
591:                    if (!path.endsWith("/") && !path.endsWith("\\"))
592:                        path += "/";
593:                    chooser = new JFileChooser(path);
594:                } catch (NullPointerException ex) {
595:                    chooser = new JFileChooser(".");
596:                }
597:                chooser.setDialogType(chooser.SAVE_DIALOG);
598:                int returnVal = chooser.showDialog(this , Options.getInstance()
599:                        .getResource("save data"));
600:                if (returnVal == JFileChooser.APPROVE_OPTION) {
601:                    filenameTF.setText(chooser.getSelectedFile().toString());
602:                }
603:            }
604:
605:            void clipRadioButton_itemStateChanged(ItemEvent e) {
606:                filenameTF.setEnabled(false);
607:                filenameTF.setBackground(Color.lightGray);
608:                filenameTF.setText("");
609:            }
610:
611:            void fileRadioButton_itemStateChanged(ItemEvent e) {
612:                filenameTF.setEnabled(true);
613:                filenameTF.setBackground(Color.white);
614:                xlsRadioButton.setEnabled(fileRadioButton.isSelected());
615:            }
616:
617:            void unselButton_actionPerformed(ActionEvent e) {
618:                CustomTableModel model = (CustomTableModel) colsTable
619:                        .getModel();
620:                for (int i = 0; i < model.getRowCount(); i++)
621:                    model.setValueAt(new Boolean(false), i, 5);
622:            }
623:
624:            void selButton_actionPerformed(ActionEvent e) {
625:                CustomTableModel model = (CustomTableModel) colsTable
626:                        .getModel();
627:                for (int i = 0; i < model.getRowCount(); i++)
628:                    model.setValueAt(new Boolean(true), i, 5);
629:            }
630:
631:            void nullCheckBox_itemStateChanged(ItemEvent e) {
632:                tableChanged(null);
633:            }
634:
635:            void pkCheckBox_itemStateChanged(ItemEvent e) {
636:                tableChanged(null);
637:            }
638:
639:            void txtRadioButton_itemStateChanged(ItemEvent e) {
640:                delimTF.setEditable(txtRadioButton.isSelected());
641:            }
642:
643:            void sqlRadioButton_itemStateChanged(ItemEvent e) {
644:                schemaCheckBox.setEnabled(sqlRadioButton.isSelected());
645:            }
646:
647:        }
648:
649:        class TableExportDialog_okButton_actionAdapter implements 
650:                java.awt.event.ActionListener {
651:            TableExportDialog adaptee;
652:
653:            TableExportDialog_okButton_actionAdapter(TableExportDialog adaptee) {
654:                this .adaptee = adaptee;
655:            }
656:
657:            public void actionPerformed(ActionEvent e) {
658:                adaptee.okButton_actionPerformed(e);
659:            }
660:        }
661:
662:        class TableExportDialog_cancelButton_actionAdapter implements 
663:                java.awt.event.ActionListener {
664:            TableExportDialog adaptee;
665:
666:            TableExportDialog_cancelButton_actionAdapter(
667:                    TableExportDialog adaptee) {
668:                this .adaptee = adaptee;
669:            }
670:
671:            public void actionPerformed(ActionEvent e) {
672:                adaptee.cancelButton_actionPerformed(e);
673:            }
674:        }
675:
676:        class TableExportDialog_filenameButton_actionAdapter implements 
677:                java.awt.event.ActionListener {
678:            TableExportDialog adaptee;
679:
680:            TableExportDialog_filenameButton_actionAdapter(
681:                    TableExportDialog adaptee) {
682:                this .adaptee = adaptee;
683:            }
684:
685:            public void actionPerformed(ActionEvent e) {
686:                adaptee.filenameButton_actionPerformed(e);
687:            }
688:        }
689:
690:        class TableExportDialog_clipRadioButton_itemAdapter implements 
691:                java.awt.event.ItemListener {
692:            TableExportDialog adaptee;
693:
694:            TableExportDialog_clipRadioButton_itemAdapter(
695:                    TableExportDialog adaptee) {
696:                this .adaptee = adaptee;
697:            }
698:
699:            public void itemStateChanged(ItemEvent e) {
700:                adaptee.clipRadioButton_itemStateChanged(e);
701:            }
702:        }
703:
704:        class TableExportDialog_fileRadioButton_itemAdapter implements 
705:                java.awt.event.ItemListener {
706:            TableExportDialog adaptee;
707:
708:            TableExportDialog_fileRadioButton_itemAdapter(
709:                    TableExportDialog adaptee) {
710:                this .adaptee = adaptee;
711:            }
712:
713:            public void itemStateChanged(ItemEvent e) {
714:                adaptee.fileRadioButton_itemStateChanged(e);
715:            }
716:        }
717:
718:        class TableExportDialog_unselButton_actionAdapter implements 
719:                java.awt.event.ActionListener {
720:            TableExportDialog adaptee;
721:
722:            TableExportDialog_unselButton_actionAdapter(
723:                    TableExportDialog adaptee) {
724:                this .adaptee = adaptee;
725:            }
726:
727:            public void actionPerformed(ActionEvent e) {
728:                adaptee.unselButton_actionPerformed(e);
729:            }
730:        }
731:
732:        class TableExportDialog_selButton_actionAdapter implements 
733:                java.awt.event.ActionListener {
734:            TableExportDialog adaptee;
735:
736:            TableExportDialog_selButton_actionAdapter(TableExportDialog adaptee) {
737:                this .adaptee = adaptee;
738:            }
739:
740:            public void actionPerformed(ActionEvent e) {
741:                adaptee.selButton_actionPerformed(e);
742:            }
743:        }
744:
745:        class TableExportDialog_nullCheckBox_itemAdapter implements 
746:                java.awt.event.ItemListener {
747:            TableExportDialog adaptee;
748:
749:            TableExportDialog_nullCheckBox_itemAdapter(TableExportDialog adaptee) {
750:                this .adaptee = adaptee;
751:            }
752:
753:            public void itemStateChanged(ItemEvent e) {
754:                adaptee.nullCheckBox_itemStateChanged(e);
755:            }
756:        }
757:
758:        class TableExportDialog_pkCheckBox_itemAdapter implements 
759:                java.awt.event.ItemListener {
760:            TableExportDialog adaptee;
761:
762:            TableExportDialog_pkCheckBox_itemAdapter(TableExportDialog adaptee) {
763:                this .adaptee = adaptee;
764:            }
765:
766:            public void itemStateChanged(ItemEvent e) {
767:                adaptee.pkCheckBox_itemStateChanged(e);
768:            }
769:        }
770:
771:        class TableExportDialog_txtRadioButton_itemAdapter implements 
772:                java.awt.event.ItemListener {
773:            TableExportDialog adaptee;
774:
775:            TableExportDialog_txtRadioButton_itemAdapter(
776:                    TableExportDialog adaptee) {
777:                this .adaptee = adaptee;
778:            }
779:
780:            public void itemStateChanged(ItemEvent e) {
781:                adaptee.txtRadioButton_itemStateChanged(e);
782:            }
783:        }
784:
785:        class TableExportDialog_sqlRadioButton_itemAdapter implements 
786:                java.awt.event.ItemListener {
787:            TableExportDialog adaptee;
788:
789:            TableExportDialog_sqlRadioButton_itemAdapter(
790:                    TableExportDialog adaptee) {
791:                this .adaptee = adaptee;
792:            }
793:
794:            public void itemStateChanged(ItemEvent e) {
795:                adaptee.sqlRadioButton_itemStateChanged(e);
796:            }
797:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.