Source Code Cross Referenced for GenerateSqlDialog.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » plugins » mssql » 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 » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.plugins.mssql.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.squirrel_sql.plugins.mssql.gui;
002:
003:        /*
004:         * Copyright (C) 2004 Ryan Walberg <generalpf@yahoo.com>
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or (at your option) any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         */
020:
021:        import java.awt.BorderLayout;
022:        import java.awt.Frame;
023:        import java.awt.GridBagConstraints;
024:        import java.awt.GridBagLayout;
025:        import java.awt.event.ActionEvent;
026:        import java.awt.event.ActionListener;
027:        import java.awt.event.ItemEvent;
028:        import java.awt.event.ItemListener;
029:        import java.sql.SQLException;
030:        import java.util.ArrayList;
031:
032:        import javax.swing.BorderFactory;
033:        import javax.swing.ButtonGroup;
034:        import javax.swing.JButton;
035:        import javax.swing.JCheckBox;
036:        import javax.swing.JComponent;
037:        import javax.swing.JDialog;
038:        import javax.swing.JLabel;
039:        import javax.swing.JPanel;
040:        import javax.swing.JRadioButton;
041:        import javax.swing.JScrollPane;
042:        import javax.swing.JTabbedPane;
043:        import javax.swing.JTable;
044:        import javax.swing.JTextArea;
045:        import javax.swing.table.DefaultTableModel;
046:
047:        import net.sourceforge.squirrel_sql.client.gui.builders.UIFactory;
048:        import net.sourceforge.squirrel_sql.client.session.ISession;
049:        import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
050:        import net.sourceforge.squirrel_sql.fw.sql.IProcedureInfo;
051:        import net.sourceforge.squirrel_sql.fw.sql.ITableInfo;
052:        import net.sourceforge.squirrel_sql.fw.sql.IUDTInfo;
053:        import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
054:        import net.sourceforge.squirrel_sql.fw.util.StringManager;
055:        import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
056:        import net.sourceforge.squirrel_sql.plugins.mssql.MssqlPlugin;
057:        import net.sourceforge.squirrel_sql.plugins.mssql.util.DatabaseObjectInfoRenderer;
058:        import net.sourceforge.squirrel_sql.plugins.mssql.util.DatabaseObjectInfoTableModel;
059:        import net.sourceforge.squirrel_sql.plugins.mssql.util.MssqlIntrospector;
060:
061:        import com.jgoodies.forms.builder.ButtonBarBuilder;
062:        import com.jgoodies.forms.factories.Borders;
063:
064:        public class GenerateSqlDialog extends JDialog {
065:
066:            private static final StringManager s_stringMgr = StringManagerFactory
067:                    .getStringManager(GenerateSqlDialog.class);
068:
069:            private ISession _session;
070:            private MssqlPlugin _plugin;
071:            private IDatabaseObjectInfo[] _dbObjs;
072:
073:            private JTable _availableTable;
074:            private JTable _selectedTable;
075:            private JCheckBox _generateCreateCheckbox;
076:            private JCheckBox _generateDropCheckbox;
077:            private JCheckBox _generateDependentCheckbox;
078:            private JCheckBox _includeHeadersCheckbox;
079:            private JCheckBox _extendedPropsCheckbox;
080:            private JCheckBox _onlySevenCheckbox;
081:            private JTextArea _templateArea;
082:            private JCheckBox _scriptDatabaseCheckbox;
083:            private JCheckBox _scriptUsersAndRolesCheckbox;
084:            private JCheckBox _scriptLoginsCheckbox;
085:            private JCheckBox _scriptPermissionsCheckbox;
086:            private JCheckBox _scriptIndexesCheckbox;
087:            private JCheckBox _scriptFTIndexesCheckbox;
088:            private JCheckBox _scriptTriggersCheckbox;
089:            private JCheckBox _scriptConstraintsCheckbox;
090:            private JRadioButton _OEMRadio;
091:            private JRadioButton _ANSIRadio;
092:            private JRadioButton _UnicodeRadio;
093:            private JRadioButton _oneFileRadio;
094:            private JRadioButton _separateFilesRadio;
095:
096:            private boolean _wasCompleted;
097:
098:            public GenerateSqlDialog(ISession session, MssqlPlugin plugin,
099:                    IDatabaseObjectInfo[] dbObjs) throws SQLException {
100:                super (ctorHelper(session, plugin, dbObjs), true);
101:
102:                _session = session;
103:                _plugin = plugin;
104:                _dbObjs = dbObjs;
105:
106:                _wasCompleted = false;
107:
108:                createGUI();
109:            }
110:
111:            private void createGUI() throws SQLException {
112:                // i18n[mssql.generateSqlScript=Generate SQL Script]
113:                setTitle(s_stringMgr.getString("mssql.generateSqlScript"));
114:                setContentPane(buildContentPane());
115:            }
116:
117:            private JComponent buildContentPane() throws SQLException {
118:                final JPanel pnl = new JPanel(new BorderLayout());
119:                pnl.add(buildMainPanel(), BorderLayout.CENTER);
120:                pnl.add(buildToolBar(), BorderLayout.SOUTH);
121:                pnl.setBorder(Borders.TABBED_DIALOG_BORDER);
122:
123:                return pnl;
124:            }
125:
126:            private JTabbedPane buildMainPanel() throws SQLException {
127:                final JTabbedPane tabPanel = UIFactory.getInstance()
128:                        .createTabbedPane();
129:                // i18n[mssql.general=General]
130:                tabPanel.addTab(s_stringMgr.getString("mssql.general"), null,
131:                        buildGeneralPanel());
132:                // i18n[mssql.foematting=Formatting]
133:                tabPanel.addTab(s_stringMgr.getString("mssql.foematting"),
134:                        null, buildFormattingPanel());
135:                // i18n[mssql.options=Options]
136:                tabPanel.addTab(s_stringMgr.getString("mssql.options"), null,
137:                        buildOptionsPanel());
138:                return tabPanel;
139:            }
140:
141:            private JPanel buildGeneralPanel() {
142:                JPanel panel = new JPanel();
143:                GridBagLayout gridBag = new GridBagLayout();
144:                panel.setLayout(gridBag);
145:
146:                GridBagConstraints c = new GridBagConstraints();
147:                c.fill = GridBagConstraints.BOTH;
148:                c.weightx = 0.0;
149:
150:                JLabel objectsLabel = new JLabel();
151:                // i18n[mssql.toScript=Objects to script:]
152:                objectsLabel.setText(s_stringMgr.getString("mssql.toScript"));
153:                gridBag.setConstraints(objectsLabel, c);
154:                panel.add(objectsLabel);
155:
156:                // i18n[mssql.allObjects=All objects]
157:                final JCheckBox allObjectsCheckbox = new JCheckBox(s_stringMgr
158:                        .getString("mssql.allObjects"));
159:                // i18n[mssql.allTables=All tables]
160:                final JCheckBox allTablesCheckbox = new JCheckBox(s_stringMgr
161:                        .getString("mssql.allTables"));
162:                // i18n[mssql.allRules=All rules]
163:                final JCheckBox allRulesCheckbox = new JCheckBox(s_stringMgr
164:                        .getString("mssql.allRules"));
165:                // i18n[mssql.allViews=All views]
166:                final JCheckBox allViewsCheckbox = new JCheckBox(s_stringMgr
167:                        .getString("mssql.allViews"));
168:                // i18n[mssql.allUserDef=All user-defined data types]
169:                final JCheckBox allUddtCheckbox = new JCheckBox(s_stringMgr
170:                        .getString("mssql.allUserDef"));
171:                // i18n[mssql.allSps=All stored procedures]
172:                final JCheckBox allProceduresCheckbox = new JCheckBox(
173:                        s_stringMgr.getString("mssql.allSps"));
174:                // i18n[mssql.allUDFs=All user-defined functions]
175:                final JCheckBox allUdfsCheckbox = new JCheckBox(s_stringMgr
176:                        .getString("mssql.allUDFs"));
177:                // i18n[mssql.allDefaults=All defaults]
178:                final JCheckBox allDefaultsCheckbox = new JCheckBox(s_stringMgr
179:                        .getString("mssql.allDefaults"));
180:
181:                c.gridx = 0;
182:                c.gridy = 1;
183:                allObjectsCheckbox.addItemListener(new ItemListener() {
184:                    public void itemStateChanged(ItemEvent e) {
185:                        if (e.getStateChange() == ItemEvent.SELECTED)
186:                            transferObjectsOfType(
187:                                    0,
188:                                    (DatabaseObjectInfoTableModel) _availableTable
189:                                            .getModel(),
190:                                    (DatabaseObjectInfoTableModel) _selectedTable
191:                                            .getModel());
192:                        else if (e.getStateChange() == ItemEvent.DESELECTED)
193:                            transferObjectsOfType(
194:                                    0,
195:                                    (DatabaseObjectInfoTableModel) _selectedTable
196:                                            .getModel(),
197:                                    (DatabaseObjectInfoTableModel) _availableTable
198:                                            .getModel());
199:
200:                        boolean isSelected = (e.getStateChange() == ItemEvent.SELECTED);
201:
202:                        allTablesCheckbox.setSelected(isSelected);
203:                        allRulesCheckbox.setSelected(isSelected);
204:                        allViewsCheckbox.setSelected(isSelected);
205:                        allUddtCheckbox.setSelected(isSelected);
206:                        allProceduresCheckbox.setSelected(isSelected);
207:                        allUdfsCheckbox.setSelected(isSelected);
208:                        allDefaultsCheckbox.setSelected(isSelected);
209:
210:                        allTablesCheckbox.setEnabled(!isSelected);
211:                        allRulesCheckbox.setEnabled(!isSelected);
212:                        allViewsCheckbox.setEnabled(!isSelected);
213:                        allUddtCheckbox.setEnabled(!isSelected);
214:                        allProceduresCheckbox.setEnabled(!isSelected);
215:                        allUdfsCheckbox.setEnabled(!isSelected);
216:                        allDefaultsCheckbox.setEnabled(!isSelected);
217:                    }
218:                });
219:                gridBag.setConstraints(allObjectsCheckbox, c);
220:                panel.add(allObjectsCheckbox);
221:
222:                c.gridx = 0;
223:                c.gridy = 2;
224:                allTablesCheckbox.addItemListener(new ItemListener() {
225:                    public void itemStateChanged(ItemEvent e) {
226:                        if (e.getStateChange() == ItemEvent.SELECTED)
227:                            transferObjectsOfType(
228:                                    MssqlIntrospector.MSSQL_TABLE,
229:                                    (DatabaseObjectInfoTableModel) _availableTable
230:                                            .getModel(),
231:                                    (DatabaseObjectInfoTableModel) _selectedTable
232:                                            .getModel());
233:                        else if (e.getStateChange() == ItemEvent.DESELECTED)
234:                            transferObjectsOfType(
235:                                    MssqlIntrospector.MSSQL_TABLE,
236:                                    (DatabaseObjectInfoTableModel) _selectedTable
237:                                            .getModel(),
238:                                    (DatabaseObjectInfoTableModel) _availableTable
239:                                            .getModel());
240:                    }
241:                });
242:                gridBag.setConstraints(allTablesCheckbox, c);
243:                panel.add(allTablesCheckbox);
244:
245:                c.gridx = 2;
246:                c.gridy = 2;
247:                allRulesCheckbox.addItemListener(new ItemListener() {
248:                    public void itemStateChanged(ItemEvent e) {
249:                        if (e.getStateChange() == ItemEvent.SELECTED)
250:                            transferObjectsOfType(
251:                                    MssqlIntrospector.MSSQL_RULE,
252:                                    (DatabaseObjectInfoTableModel) _availableTable
253:                                            .getModel(),
254:                                    (DatabaseObjectInfoTableModel) _selectedTable
255:                                            .getModel());
256:                        else if (e.getStateChange() == ItemEvent.DESELECTED)
257:                            transferObjectsOfType(
258:                                    MssqlIntrospector.MSSQL_RULE,
259:                                    (DatabaseObjectInfoTableModel) _selectedTable
260:                                            .getModel(),
261:                                    (DatabaseObjectInfoTableModel) _availableTable
262:                                            .getModel());
263:                    }
264:                });
265:                gridBag.setConstraints(allRulesCheckbox, c);
266:                panel.add(allRulesCheckbox);
267:
268:                c.gridx = 0;
269:                c.gridy = 3;
270:                allViewsCheckbox.addItemListener(new ItemListener() {
271:                    public void itemStateChanged(ItemEvent e) {
272:                        if (e.getStateChange() == ItemEvent.SELECTED)
273:                            transferObjectsOfType(
274:                                    MssqlIntrospector.MSSQL_VIEW,
275:                                    (DatabaseObjectInfoTableModel) _availableTable
276:                                            .getModel(),
277:                                    (DatabaseObjectInfoTableModel) _selectedTable
278:                                            .getModel());
279:                        else if (e.getStateChange() == ItemEvent.DESELECTED)
280:                            transferObjectsOfType(
281:                                    MssqlIntrospector.MSSQL_VIEW,
282:                                    (DatabaseObjectInfoTableModel) _selectedTable
283:                                            .getModel(),
284:                                    (DatabaseObjectInfoTableModel) _availableTable
285:                                            .getModel());
286:                    }
287:                });
288:                gridBag.setConstraints(allViewsCheckbox, c);
289:                panel.add(allViewsCheckbox);
290:
291:                c.gridx = 2;
292:                c.gridy = 3;
293:                allUddtCheckbox.addItemListener(new ItemListener() {
294:                    public void itemStateChanged(ItemEvent e) {
295:                        if (e.getStateChange() == ItemEvent.SELECTED)
296:                            transferObjectsOfType(
297:                                    MssqlIntrospector.MSSQL_UDT,
298:                                    (DatabaseObjectInfoTableModel) _availableTable
299:                                            .getModel(),
300:                                    (DatabaseObjectInfoTableModel) _selectedTable
301:                                            .getModel());
302:                        else if (e.getStateChange() == ItemEvent.DESELECTED)
303:                            transferObjectsOfType(
304:                                    MssqlIntrospector.MSSQL_UDT,
305:                                    (DatabaseObjectInfoTableModel) _selectedTable
306:                                            .getModel(),
307:                                    (DatabaseObjectInfoTableModel) _availableTable
308:                                            .getModel());
309:                    }
310:                });
311:                gridBag.setConstraints(allUddtCheckbox, c);
312:                panel.add(allUddtCheckbox);
313:
314:                c.gridx = 0;
315:                c.gridy = 4;
316:                allProceduresCheckbox.addItemListener(new ItemListener() {
317:                    public void itemStateChanged(ItemEvent e) {
318:                        if (e.getStateChange() == ItemEvent.SELECTED)
319:                            transferObjectsOfType(
320:                                    MssqlIntrospector.MSSQL_STOREDPROCEDURE,
321:                                    (DatabaseObjectInfoTableModel) _availableTable
322:                                            .getModel(),
323:                                    (DatabaseObjectInfoTableModel) _selectedTable
324:                                            .getModel());
325:                        else if (e.getStateChange() == ItemEvent.DESELECTED)
326:                            transferObjectsOfType(
327:                                    MssqlIntrospector.MSSQL_STOREDPROCEDURE,
328:                                    (DatabaseObjectInfoTableModel) _selectedTable
329:                                            .getModel(),
330:                                    (DatabaseObjectInfoTableModel) _availableTable
331:                                            .getModel());
332:                    }
333:                });
334:                gridBag.setConstraints(allProceduresCheckbox, c);
335:                panel.add(allProceduresCheckbox);
336:
337:                c.gridx = 2;
338:                c.gridy = 4;
339:                allUdfsCheckbox.addItemListener(new ItemListener() {
340:                    public void itemStateChanged(ItemEvent e) {
341:                        if (e.getStateChange() == ItemEvent.SELECTED)
342:                            transferObjectsOfType(
343:                                    MssqlIntrospector.MSSQL_UDF,
344:                                    (DatabaseObjectInfoTableModel) _availableTable
345:                                            .getModel(),
346:                                    (DatabaseObjectInfoTableModel) _selectedTable
347:                                            .getModel());
348:                        else if (e.getStateChange() == ItemEvent.DESELECTED)
349:                            transferObjectsOfType(
350:                                    MssqlIntrospector.MSSQL_UDF,
351:                                    (DatabaseObjectInfoTableModel) _selectedTable
352:                                            .getModel(),
353:                                    (DatabaseObjectInfoTableModel) _availableTable
354:                                            .getModel());
355:                    }
356:                });
357:                gridBag.setConstraints(allUdfsCheckbox, c);
358:                panel.add(allUdfsCheckbox);
359:
360:                c.gridx = 0;
361:                c.gridy = 5;
362:                allDefaultsCheckbox.addItemListener(new ItemListener() {
363:                    public void itemStateChanged(ItemEvent e) {
364:                        if (e.getStateChange() == ItemEvent.SELECTED)
365:                            transferObjectsOfType(
366:                                    MssqlIntrospector.MSSQL_DEFAULT,
367:                                    (DatabaseObjectInfoTableModel) _availableTable
368:                                            .getModel(),
369:                                    (DatabaseObjectInfoTableModel) _selectedTable
370:                                            .getModel());
371:                        else if (e.getStateChange() == ItemEvent.DESELECTED)
372:                            transferObjectsOfType(
373:                                    MssqlIntrospector.MSSQL_DEFAULT,
374:                                    (DatabaseObjectInfoTableModel) _selectedTable
375:                                            .getModel(),
376:                                    (DatabaseObjectInfoTableModel) _availableTable
377:                                            .getModel());
378:                    }
379:                });
380:                gridBag.setConstraints(allDefaultsCheckbox, c);
381:                panel.add(allDefaultsCheckbox);
382:
383:                JLabel availableLabel = new JLabel();
384:                c.gridx = 0;
385:                c.gridy = 6;
386:
387:                // i18n[mssql.objectsOn=Objects on {0}:]
388:                objectsLabel.setText(s_stringMgr.getString("mssql.objectsOn",
389:                        _dbObjs[0].getCatalogName()));
390:                gridBag.setConstraints(availableLabel, c);
391:                panel.add(availableLabel);
392:
393:                JLabel selectedLabel = new JLabel();
394:                c.gridx = 2;
395:                c.gridy = 6;
396:                // i18n[mssql.objectsToBeScripted=Objects to be scripted]
397:                objectsLabel.setText("Objects to be scripted:");
398:                gridBag.setConstraints(selectedLabel, c);
399:                panel.add(selectedLabel);
400:
401:                JButton addButton = new JButton();
402:                c.gridx = 1;
403:                c.gridy = 8;
404:                // i18n[mssql.add=Add >>]
405:                addButton.setText(s_stringMgr.getString("mssql.add"));
406:                // i18n[mssql.add_Menmonic="]
407:                addButton.setMnemonic("A".charAt(0));
408:                addButton.addActionListener(new ActionListener() {
409:                    public void actionPerformed(ActionEvent e) {
410:                        transferSelectedItems(_availableTable, _selectedTable);
411:                    }
412:                });
413:                gridBag.setConstraints(addButton, c);
414:                panel.add(addButton);
415:
416:                JButton removeButton = new JButton();
417:                c.gridx = 1;
418:                c.gridy = 9;
419:                // i18n[mssql.remove=<< Remove]
420:                removeButton.setText(s_stringMgr.getString("mssql.remove"));
421:                // i18n[mssql.remove_Mnemonic=R]
422:                removeButton.setMnemonic(s_stringMgr.getString(
423:                        "mssql.remove_Mnemonic").charAt(0));
424:                removeButton.addActionListener(new ActionListener() {
425:                    public void actionPerformed(ActionEvent e) {
426:                        transferSelectedItems(_selectedTable, _availableTable);
427:                    }
428:                });
429:                gridBag.setConstraints(removeButton, c);
430:                panel.add(removeButton);
431:
432:                /*Component glue = Box.createGlue();
433:                c.gridx = 1;
434:                c.gridy = 10;
435:                gridBag.setConstraints(glue, c);
436:                panel.add(glue);*/
437:
438:                _availableTable = new JTable(new DefaultTableModel(0, 0));
439:                _availableTable.setModel(new DatabaseObjectInfoTableModel());
440:                _availableTable.getColumnModel().getColumn(0).setCellRenderer(
441:                        new DatabaseObjectInfoRenderer());
442:                JScrollPane availablePane = new JScrollPane(_availableTable);
443:                c.gridx = 0;
444:                c.gridy = 7;
445:                c.gridheight = 3;
446:                gridBag.setConstraints(availablePane, c);
447:                panel.add(availablePane);
448:
449:                populateAvailableTable(_availableTable);
450:
451:                _selectedTable = new JTable(new DefaultTableModel(0, 0));
452:                _selectedTable.setModel(new DatabaseObjectInfoTableModel());
453:                _selectedTable.getColumnModel().getColumn(0).setCellRenderer(
454:                        new DatabaseObjectInfoRenderer());
455:                JScrollPane selectedPane = new JScrollPane(_selectedTable);
456:                c.gridx = 2;
457:                c.gridy = 7;
458:                c.gridheight = 3;
459:                gridBag.setConstraints(selectedPane, c);
460:                panel.add(selectedPane);
461:
462:                return panel;
463:            }
464:
465:            private void transferObjectsOfType(int mssqlType,
466:                    DatabaseObjectInfoTableModel fromModel,
467:                    DatabaseObjectInfoTableModel toModel) {
468:                int i = 0;
469:                while (i < fromModel.getRowCount()) {
470:                    IDatabaseObjectInfo oi = (IDatabaseObjectInfo) fromModel
471:                            .getValueAt(i, 0);
472:                    if (mssqlType == 0
473:                            || MssqlIntrospector.getObjectInfoType(oi) == mssqlType) {
474:                        if (fromModel.removeElement(oi))
475:                            toModel.addElement(oi);
476:                        // don't increment i if you're removing something; otherwise, you'd skip the next item.
477:                    } else
478:                        i++;
479:                }
480:            }
481:
482:            private void transferSelectedItems(JTable fromTable, JTable toTable) {
483:                DatabaseObjectInfoTableModel fromModel = (DatabaseObjectInfoTableModel) fromTable
484:                        .getModel();
485:                DatabaseObjectInfoTableModel toModel = (DatabaseObjectInfoTableModel) toTable
486:                        .getModel();
487:                int[] selectedRows = fromTable.getSelectedRows();
488:
489:                /* we must iterate through this in descending order to avoid removing, say, item #2, making 
490:                 * item #4 into item #3, inadvertently removing item #5. */
491:                for (int i = selectedRows.length - 1; i >= 0; i--) {
492:                    IDatabaseObjectInfo oi = (IDatabaseObjectInfo) fromModel
493:                            .getValueAt(selectedRows[i], 0);
494:                    if (fromModel.removeElement(oi))
495:                        toModel.addElement(oi);
496:                }
497:
498:                /* TODO: sort the list. */
499:            }
500:
501:            private void populateAvailableTable(JTable table) {
502:                DatabaseObjectInfoTableModel model = (DatabaseObjectInfoTableModel) table
503:                        .getModel();
504:
505:                try {
506:                    String catalog = _session.getSQLConnection().getCatalog();
507:                    SQLDatabaseMetaData metaData = _session.getSQLConnection()
508:                            .getSQLMetaData();
509:
510:                    int i;
511:
512:                    /* add the tables. */
513:                    ITableInfo[] tables = _session.getSchemaInfo()
514:                            .getITableInfos(catalog, null, null,
515:                                    new String[] { "TABLE" });
516:                    for (i = 0; i < tables.length; i++)
517:                        model.addElement(tables[i]);
518:
519:                    /* add the views. */
520:                    ITableInfo[] views = _session.getSchemaInfo()
521:                            .getITableInfos(catalog, null, null,
522:                                    new String[] { "VIEW" });
523:                    for (i = 0; i < views.length; i++)
524:                        model.addElement(views[i]);
525:
526:                    /* add the procedures. */
527:                    //IProcedureInfo[] procs = metaData.getProcedures(catalog,null,null);
528:                    IProcedureInfo[] procs = _session.getSchemaInfo()
529:                            .getStoredProceduresInfos(catalog, null, null);
530:                    for (i = 0; i < procs.length; i++)
531:                        if (!procs[i].getSimpleName().startsWith("dt_"))
532:                            model.addElement(procs[i]);
533:
534:                    /* add the UDTs. */
535:                    IUDTInfo[] udts = metaData.getUDTs(catalog, null, null,
536:                            null);
537:                    for (i = 0; i < udts.length; i++)
538:                        model.addElement(udts[i]);
539:                } catch (SQLException ex) {
540:                    _session.getApplication().showErrorDialog(ex.getMessage(),
541:                            ex);
542:                }
543:            }
544:
545:            private JPanel buildFormattingPanel() {
546:                JPanel panel = new JPanel();
547:                GridBagLayout gridBag = new GridBagLayout();
548:                panel.setLayout(gridBag);
549:
550:                GridBagConstraints c = new GridBagConstraints();
551:                c.fill = GridBagConstraints.BOTH;
552:                c.weightx = 0.0;
553:
554:                JLabel optionsLabel = new JLabel();
555:                // i18n[mssql.scriptingOptionsDlg=Scripting options allow you to specify how an object will be scripted.]
556:                optionsLabel.setText(s_stringMgr
557:                        .getString("mssql.scriptingOptionsDlg"));
558:                gridBag.setConstraints(optionsLabel, c);
559:                panel.add(optionsLabel);
560:
561:                // i18n[mssql.genereateCreate=Generate the CREATE <object> command for each object]
562:                _generateCreateCheckbox = new JCheckBox(s_stringMgr
563:                        .getString("mssql.genereateCreate"), true);
564:                c.gridx = 0;
565:                c.gridy = 1;
566:                _generateCreateCheckbox.addItemListener(new ItemListener() {
567:                    public void itemStateChanged(ItemEvent e) {
568:                        scriptOptionsChanged();
569:                    }
570:                });
571:                gridBag.setConstraints(_generateCreateCheckbox, c);
572:                panel.add(_generateCreateCheckbox);
573:
574:                // i18n[mssql.generateDrop=Generate the DROP <object> command for each object]
575:                _generateDropCheckbox = new JCheckBox(s_stringMgr
576:                        .getString("mssql.generateDrop"), true);
577:                c.gridx = 0;
578:                c.gridy = 2;
579:                _generateDropCheckbox.addItemListener(new ItemListener() {
580:                    public void itemStateChanged(ItemEvent e) {
581:                        scriptOptionsChanged();
582:                    }
583:                });
584:                gridBag.setConstraints(_generateDropCheckbox, c);
585:                panel.add(_generateDropCheckbox);
586:
587:                // i18n[mssql.generateDependend=Generate scripts for all dependent objects]
588:                _generateDependentCheckbox = new JCheckBox(s_stringMgr
589:                        .getString("mssql.generateDependend"), false);
590:                c.gridx = 0;
591:                c.gridy = 3;
592:                _generateDependentCheckbox.setEnabled(false);
593:                _generateDependentCheckbox.addItemListener(new ItemListener() {
594:                    public void itemStateChanged(ItemEvent e) {
595:                        scriptOptionsChanged();
596:                    }
597:                });
598:                gridBag.setConstraints(_generateDependentCheckbox, c);
599:                panel.add(_generateDependentCheckbox);
600:
601:                // i18n[mssql.includeHeaders=Include descriptive headers in the script files]
602:                _includeHeadersCheckbox = new JCheckBox(s_stringMgr
603:                        .getString("mssql.includeHeaders"), false);
604:                c.gridx = 0;
605:                c.gridy = 4;
606:                _includeHeadersCheckbox.addItemListener(new ItemListener() {
607:                    public void itemStateChanged(ItemEvent e) {
608:                        scriptOptionsChanged();
609:                    }
610:                });
611:                gridBag.setConstraints(_includeHeadersCheckbox, c);
612:                panel.add(_includeHeadersCheckbox);
613:
614:                // i18n[mssql.extProps=Include extended properties]
615:                _extendedPropsCheckbox = new JCheckBox(s_stringMgr
616:                        .getString("mssql.extProps"), false);
617:                c.gridx = 0;
618:                c.gridy = 5;
619:                _extendedPropsCheckbox.setEnabled(false);
620:                _extendedPropsCheckbox.addItemListener(new ItemListener() {
621:                    public void itemStateChanged(ItemEvent e) {
622:                        scriptOptionsChanged();
623:                    }
624:                });
625:                gridBag.setConstraints(_extendedPropsCheckbox, c);
626:                panel.add(_extendedPropsCheckbox);
627:
628:                // i18n[mssql.only70compatible=Only script 7.0 compatible features]
629:                _onlySevenCheckbox = new JCheckBox(s_stringMgr
630:                        .getString("mssql.only70compatible"), false);
631:                c.gridx = 0;
632:                c.gridy = 6;
633:                _onlySevenCheckbox.setEnabled(false);
634:                _onlySevenCheckbox.addItemListener(new ItemListener() {
635:                    public void itemStateChanged(ItemEvent e) {
636:                        scriptOptionsChanged();
637:                    }
638:                });
639:                gridBag.setConstraints(_onlySevenCheckbox, c);
640:                panel.add(_onlySevenCheckbox);
641:
642:                JLabel templateLabel = new JLabel();
643:                c.gridx = 0;
644:                c.gridy = 7;
645:                // i18n[mssql.scriptTemplate=Script template]
646:                templateLabel.setText(s_stringMgr
647:                        .getString("mssql.scriptTemplate"));
648:                gridBag.setConstraints(templateLabel, c);
649:                panel.add(templateLabel);
650:
651:                _templateArea = new JTextArea();
652:                JScrollPane templatePane = new JScrollPane(_templateArea);
653:                c.gridx = 0;
654:                c.gridy = 8;
655:                c.weightx = 2.0;
656:                c.weighty = 2.0;
657:                _templateArea.setEditable(false);
658:                gridBag.setConstraints(templatePane, c);
659:                panel.add(templatePane);
660:
661:                scriptOptionsChanged();
662:
663:                return panel;
664:            }
665:
666:            private void scriptOptionsChanged() {
667:                boolean generateCreate = _generateCreateCheckbox.isSelected();
668:                boolean generateDrop = _generateDropCheckbox.isSelected();
669:                boolean generateDependent = _generateDependentCheckbox
670:                        .isSelected();
671:                boolean includeHeaders = _includeHeadersCheckbox.isSelected();
672:
673:                StringBuffer buf = new StringBuffer();
674:
675:                if (includeHeaders)
676:                    buf
677:                            .append("/* OBJECT: table: SampleTable  SCRIPT DATE: 1/1/1999 */\n\n");
678:                if (generateDependent)
679:                    buf.append("sp_addtype SampleUDT, int\nGO\n\n");
680:                if (generateDrop)
681:                    buf.append("DROP TABLE SampleTable\nGO\n\n");
682:                if (generateCreate)
683:                    buf
684:                            .append("CREATE TABLE SampleTable\n(SampleColumn1 datetime NULL,\nSampleColumn2 SampleUDT)\nGO\n\n");
685:
686:                _templateArea.setText(buf.toString());
687:            }
688:
689:            private JPanel buildOptionsPanel() {
690:                JPanel panel = new JPanel();
691:                GridBagLayout gridBag = new GridBagLayout();
692:                panel.setLayout(gridBag);
693:
694:                GridBagConstraints c = new GridBagConstraints();
695:                c.fill = GridBagConstraints.BOTH;
696:                c.weightx = 0.0;
697:
698:                /* --- SECURITY PANEL ---------------------------------------------- */
699:                JPanel securityPanel = new JPanel();
700:                securityPanel.setBorder(BorderFactory
701:                        .createTitledBorder("Security Scripting Options"));
702:                GridBagLayout securityBag = new GridBagLayout();
703:                securityPanel.setLayout(securityBag);
704:                c.gridx = 0;
705:                c.gridy = 0;
706:                gridBag.setConstraints(securityPanel, c);
707:                panel.add(securityPanel);
708:
709:                // i18n[mssql.scriptDatabase=Script database]
710:                _scriptDatabaseCheckbox = new JCheckBox(s_stringMgr
711:                        .getString("mssql.scriptDatabase"));
712:                c.gridx = 0;
713:                c.gridy = 0;
714:                securityBag.setConstraints(_scriptDatabaseCheckbox, c);
715:                securityPanel.add(_scriptDatabaseCheckbox);
716:
717:                // i18n[mssql.scriptUsers=Script database users and database roles]
718:                _scriptUsersAndRolesCheckbox = new JCheckBox(s_stringMgr
719:                        .getString("mssql.scriptUsers"));
720:                c.gridx = 0;
721:                c.gridy = 1;
722:                securityBag.setConstraints(_scriptUsersAndRolesCheckbox, c);
723:                securityPanel.add(_scriptUsersAndRolesCheckbox);
724:
725:                // i18n[mssql.scriptLogins=Script SQL Server logins (Windows and SQL Server logins)]
726:                _scriptLoginsCheckbox = new JCheckBox(s_stringMgr
727:                        .getString("mssql.scriptLogins"));
728:                c.gridx = 0;
729:                c.gridy = 2;
730:                _scriptLoginsCheckbox.setEnabled(false);
731:                securityBag.setConstraints(_scriptLoginsCheckbox, c);
732:                securityPanel.add(_scriptLoginsCheckbox);
733:
734:                // i18n[mssql.scriptPermission=Script object-level permissions]
735:                _scriptPermissionsCheckbox = new JCheckBox(s_stringMgr
736:                        .getString("mssql.scriptPermission"));
737:                c.gridx = 0;
738:                c.gridy = 3;
739:                securityBag.setConstraints(_scriptPermissionsCheckbox, c);
740:                securityPanel.add(_scriptPermissionsCheckbox);
741:                /* ----------------------------------------------------------------- */
742:
743:                /* --- TABLE SCRIPTING PANEL ---------------------------------------------- */
744:                JPanel tablePanel = new JPanel();
745:                // i18n[mssql.scriptingOptions=Table Scripting Options]
746:                tablePanel.setBorder(BorderFactory
747:                        .createTitledBorder(s_stringMgr
748:                                .getString("mssql.scriptingOptions")));
749:                GridBagLayout tableBag = new GridBagLayout();
750:                tablePanel.setLayout(tableBag);
751:                c.gridx = 0;
752:                c.gridy = 1;
753:                gridBag.setConstraints(tablePanel, c);
754:                panel.add(tablePanel);
755:
756:                // i18n[mssql.scriptIndexses=Script indexes]
757:                _scriptIndexesCheckbox = new JCheckBox(s_stringMgr
758:                        .getString("mssql.scriptIndexses"));
759:                c.gridx = 0;
760:                c.gridy = 0;
761:                tableBag.setConstraints(_scriptIndexesCheckbox, c);
762:                tablePanel.add(_scriptIndexesCheckbox);
763:
764:                // i18n[mssql.scriptFullText=Script full-text indexes]
765:                _scriptFTIndexesCheckbox = new JCheckBox(s_stringMgr
766:                        .getString("mssql.scriptFullText"));
767:                c.gridx = 0;
768:                c.gridy = 1;
769:                _scriptFTIndexesCheckbox.setEnabled(false);
770:                tableBag.setConstraints(_scriptFTIndexesCheckbox, c);
771:                tablePanel.add(_scriptFTIndexesCheckbox);
772:
773:                _scriptTriggersCheckbox = new JCheckBox("Script triggers");
774:                c.gridx = 0;
775:                c.gridy = 2;
776:                tableBag.setConstraints(_scriptTriggersCheckbox, c);
777:                tablePanel.add(_scriptTriggersCheckbox);
778:
779:                // i18n[mssql.scriptPrimary=Script PRIMARY keys, FOREIGN keys, defaults, and check constraints]
780:                _scriptConstraintsCheckbox = new JCheckBox(s_stringMgr
781:                        .getString("mssql.scriptPrimary"));
782:                c.gridx = 0;
783:                c.gridy = 3;
784:                tableBag.setConstraints(_scriptConstraintsCheckbox, c);
785:                tablePanel.add(_scriptConstraintsCheckbox);
786:                /* ----------------------------------------------------------------- */
787:
788:                /* --- TABLE SCRIPTING PANEL ---------------------------------------------- */
789:                JPanel fileOptionsPanel = new JPanel();
790:                // i18n[mssql.fileOptions=File Options]
791:                fileOptionsPanel.setBorder(BorderFactory
792:                        .createTitledBorder(s_stringMgr
793:                                .getString("mssql.fileOptions")));
794:                c.gridx = 0;
795:                c.gridy = 2;
796:                gridBag.setConstraints(fileOptionsPanel, c);
797:                panel.add(fileOptionsPanel);
798:
799:                JPanel fileFormatPanel = new JPanel();
800:                // i18n[mssql.fileFormat=File Format]
801:                fileFormatPanel.setBorder(BorderFactory
802:                        .createTitledBorder(s_stringMgr
803:                                .getString("mssql.fileFormat")));
804:                fileOptionsPanel.add(fileFormatPanel);
805:
806:                ButtonGroup fileFormatGroup = new ButtonGroup();
807:                // i18n[mssql.msdos=MS-DOS text (OEM)]
808:                _OEMRadio = new JRadioButton(s_stringMgr
809:                        .getString("mssql.msdos"));
810:                // i18n[mssql.windows=Windows text (ANSI)]
811:                _ANSIRadio = new JRadioButton(s_stringMgr
812:                        .getString("mssql.windows"));
813:                // i18n[mssql.unicode=International text (Unicode)]
814:                _UnicodeRadio = new JRadioButton(s_stringMgr
815:                        .getString("mssql.unicode"), true);
816:                fileFormatGroup.add(_OEMRadio);
817:                fileFormatGroup.add(_ANSIRadio);
818:                fileFormatGroup.add(_UnicodeRadio);
819:                fileFormatPanel.add(_OEMRadio);
820:                fileFormatPanel.add(_ANSIRadio);
821:                fileFormatPanel.add(_UnicodeRadio);
822:                _OEMRadio.setEnabled(false);
823:                _ANSIRadio.setEnabled(false);
824:
825:                JPanel generatePanel = new JPanel();
826:                // i18n[mssql.filesToGenerate=Files to Generate]
827:                generatePanel.setBorder(BorderFactory
828:                        .createTitledBorder(s_stringMgr
829:                                .getString("mssql.filesToGenerate")));
830:                fileOptionsPanel.add(generatePanel);
831:
832:                ButtonGroup generateGroup = new ButtonGroup();
833:                // i18n[mssql.oneFile=Create one file]
834:                _oneFileRadio = new JRadioButton(s_stringMgr
835:                        .getString("mssql.oneFile"), true);
836:                // i18n[mssql.oneFilePerObject=Create one file per object]
837:                _separateFilesRadio = new JRadioButton(s_stringMgr
838:                        .getString("mssql.oneFilePerObject"));
839:                generateGroup.add(_oneFileRadio);
840:                generateGroup.add(_separateFilesRadio);
841:                generatePanel.add(_oneFileRadio);
842:                generatePanel.add(_separateFilesRadio);
843:                /* ----------------------------------------------------------------- */
844:
845:                return panel;
846:            }
847:
848:            private JPanel buildToolBar() {
849:                final ButtonBarBuilder builder = new ButtonBarBuilder();
850:                builder.addGlue();
851:                final GenerateSqlDialog dlg = this ;
852:
853:                // i18n[mssql.ok=OK]
854:                JButton okButton = new JButton(s_stringMgr
855:                        .getString("mssql.ok"));
856:                okButton.addActionListener(new ActionListener() {
857:                    public void actionPerformed(ActionEvent e) {
858:                        _wasCompleted = true;
859:                        dlg.setVisible(false);
860:                    }
861:                });
862:                builder.addGridded(okButton);
863:
864:                builder.addRelatedGap();
865:
866:                // i18n[mssql.cancel=Cancel]
867:                JButton cancelButton = new JButton(s_stringMgr
868:                        .getString("mssql.cancel"));
869:                cancelButton.addActionListener(new ActionListener() {
870:                    public void actionPerformed(ActionEvent e) {
871:                        _wasCompleted = false;
872:                        dlg.setVisible(false);
873:                    }
874:                });
875:                builder.addGridded(cancelButton);
876:
877:                return builder.getPanel();
878:            }
879:
880:            private static Frame ctorHelper(ISession session,
881:                    MssqlPlugin plugin, IDatabaseObjectInfo[] dbObjs) {
882:                if (session == null)
883:                    throw new IllegalArgumentException("ISession == null");
884:                if (plugin == null)
885:                    throw new IllegalArgumentException("MssqlPlugin == null");
886:                if (dbObjs == null)
887:                    throw new IllegalArgumentException(
888:                            "IDatabaseObjectInfo[] is null");
889:
890:                return session.getApplication().getMainFrame();
891:            }
892:
893:            public ArrayList<IDatabaseObjectInfo> getSelectedItems() {
894:                return ((DatabaseObjectInfoTableModel) (_selectedTable
895:                        .getModel())).getContents();
896:            }
897:
898:            public boolean getGenerateCreate() {
899:                return _generateCreateCheckbox.isSelected();
900:            }
901:
902:            public boolean getGenerateDrop() {
903:                return _generateDropCheckbox.isSelected();
904:            }
905:
906:            public boolean getGenerateDependent() {
907:                return _generateDependentCheckbox.isSelected();
908:            }
909:
910:            public boolean getIncludeHeaders() {
911:                return _includeHeadersCheckbox.isSelected();
912:            }
913:
914:            public boolean getExtendedProps() {
915:                return _extendedPropsCheckbox.isSelected();
916:            }
917:
918:            public boolean getOnlySeven() {
919:                return _onlySevenCheckbox.isSelected();
920:            }
921:
922:            public boolean getScriptDatabase() {
923:                return _scriptDatabaseCheckbox.isSelected();
924:            }
925:
926:            public boolean getScriptUsersAndRoles() {
927:                return _scriptUsersAndRolesCheckbox.isSelected();
928:            }
929:
930:            public boolean getScriptLogins() {
931:                return _scriptLoginsCheckbox.isSelected();
932:            }
933:
934:            public boolean getScriptPermissions() {
935:                return _scriptPermissionsCheckbox.isSelected();
936:            }
937:
938:            public boolean getScriptIndexes() {
939:                return _scriptIndexesCheckbox.isSelected();
940:            }
941:
942:            public boolean getScriptFTIndexes() {
943:                return _scriptFTIndexesCheckbox.isSelected();
944:            }
945:
946:            public boolean getScriptTriggers() {
947:                return _scriptTriggersCheckbox.isSelected();
948:            }
949:
950:            public boolean getScriptConstraints() {
951:                return _scriptConstraintsCheckbox.isSelected();
952:            }
953:
954:            public boolean getOEM() {
955:                return _OEMRadio.isSelected();
956:            }
957:
958:            public boolean getANSI() {
959:                return _ANSIRadio.isSelected();
960:            }
961:
962:            public boolean getUnicode() {
963:                return _UnicodeRadio.isSelected();
964:            }
965:
966:            public boolean getOneFile() {
967:                return _oneFileRadio.isSelected();
968:            }
969:
970:            public boolean showGeneralSqlDialog() {
971:                this .setVisible(true);
972:                return _wasCompleted;
973:            }
974:
975:            public void preselectObjects(IDatabaseObjectInfo[] objs) {
976:                /* this works because all the IDatabaseObjectInfo objects come from the same source, so
977:                 * their references are equal. */
978:
979:                DatabaseObjectInfoTableModel fromModel = (DatabaseObjectInfoTableModel) _availableTable
980:                        .getModel();
981:                DatabaseObjectInfoTableModel toModel = (DatabaseObjectInfoTableModel) _selectedTable
982:                        .getModel();
983:
984:                for (int i = 0; i < objs.length; i++) {
985:                    if (fromModel.removeElement(objs[i]))
986:                        toModel.addElement(objs[i]);
987:                }
988:            }
989:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.