Source Code Cross Referenced for JDBCWizardSelectionPanel.java in  » IDE-Netbeans » sql.project » org » netbeans » modules » jdbcwizard » wizards » 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 » IDE Netbeans » sql.project » org.netbeans.modules.jdbcwizard.wizards 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * 
0003:         * Copyright 2005 Sun Microsystems, Inc.
0004:         * 
0005:         * Licensed under the Apache License, Version 2.0 (the "License");
0006:         * you may not use this file except in compliance with the License.
0007:         * You may obtain a copy of the License at
0008:         * 
0009:         * 	http://www.apache.org/licenses/LICENSE-2.0
0010:         * 
0011:         * Unless required by applicable law or agreed to in writing, software
0012:         * distributed under the License is distributed on an "AS IS" BASIS,
0013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         * See the License for the specific language governing permissions and
0015:         * limitations under the License.
0016:         * 
0017:         */
0018:        package org.netbeans.modules.jdbcwizard.wizards;
0019:
0020:        import java.awt.Component;
0021:        import java.awt.event.ActionEvent;
0022:        import java.awt.event.ActionListener;
0023:        import java.util.ArrayList;
0024:        import java.util.HashSet;
0025:        import java.util.Iterator;
0026:        import java.util.Set;
0027:        import javax.swing.DefaultListModel;
0028:        import javax.swing.event.ChangeEvent;
0029:        import javax.swing.event.ChangeListener;
0030:        import org.openide.WizardDescriptor;
0031:        import org.openide.util.HelpCtx;
0032:        import org.openide.windows.WindowManager;
0033:        import org.netbeans.api.db.explorer.DatabaseConnection;
0034:        import org.netbeans.api.db.explorer.ConnectionManager;
0035:        import org.openide.ErrorManager;
0036:        import org.openide.util.NbBundle;
0037:        import org.openide.NotifyDescriptor;
0038:        import org.netbeans.modules.jdbcwizard.builder.dbmodel.DBConnectionDefinition;
0039:        import org.netbeans.modules.jdbcwizard.builder.dbmodel.DatabaseModel;
0040:        import org.netbeans.modules.jdbcwizard.builder.dbmodel.impl.DatabaseModelImpl;
0041:        import org.netbeans.modules.jdbcwizard.builder.dbmodel.DBTable;
0042:        import org.netbeans.modules.jdbcwizard.builder.dbmodel.impl.DBTableImpl;
0043:        import org.netbeans.modules.jdbcwizard.builder.DBMetaData;
0044:        import org.netbeans.modules.jdbcwizard.builder.dbmodel.impl.DatabaseObjectFactory;
0045:        import org.netbeans.modules.jdbcwizard.builder.Table;
0046:        import org.netbeans.modules.jdbcwizard.builder.TableColumn;
0047:        import org.netbeans.modules.jdbcwizard.builder.dbmodel.DBColumn;
0048:        import org.netbeans.modules.jdbcwizard.builder.dbmodel.impl.DBColumnImpl;
0049:        import org.netbeans.modules.jdbcwizard.builder.util.XMLCharUtil;
0050:
0051:        import javax.swing.DefaultComboBoxModel;
0052:        import javax.swing.event.ListSelectionEvent;
0053:        import javax.swing.event.ListSelectionListener;
0054:        import javax.swing.ListModel;
0055:        import javax.swing.ListSelectionModel;
0056:        import javax.swing.ButtonModel;
0057:        import javax.swing.DefaultButtonModel;
0058:        import javax.swing.DefaultListCellRenderer;
0059:        import javax.swing.JList;
0060:        import javax.swing.JOptionPane;
0061:        import java.util.Arrays;
0062:        import java.util.Collection;
0063:        import java.util.List;
0064:        import java.awt.event.MouseAdapter;
0065:        import java.awt.event.MouseEvent;
0066:        import java.sql.Connection;
0067:        import java.util.Collections;
0068:
0069:        /**
0070:         * @author
0071:         */
0072:        public class JDBCWizardSelectionPanel extends javax.swing.JPanel
0073:                implements  WizardDescriptor.Panel, ActionListener,
0074:                ListSelectionListener {
0075:            /**
0076:             * 
0077:             */
0078:            private static final long serialVersionUID = 1L;
0079:
0080:            /* Set <ChangeListeners> */
0081:            protected final Set listeners = new HashSet(1);
0082:
0083:            private DatabaseConnection selectedConnection;
0084:
0085:            DBConnectionDefinition def;
0086:
0087:            DBModelNameCellRenderer srcRenderer;
0088:
0089:            DBModelNameCellRenderer destRenderer;
0090:
0091:            DefaultComboBoxModel providers;
0092:
0093:            private static final String NEW_DATA_SOURCE = "New DataSource...";
0094:
0095:            int visibleCt;
0096:
0097:            String dbtype;
0098:
0099:            private int selTableLen = 0;
0100:
0101:            private static class ConnectionWrapper {
0102:                private DatabaseConnection conn;
0103:
0104:                ConnectionWrapper(final DatabaseConnection conn) {
0105:                    this .conn = conn;
0106:                }
0107:
0108:                public DatabaseConnection getDatabaseConnection() {
0109:                    return this .conn;
0110:                }
0111:
0112:                public String toString() {
0113:                    return this .conn.getDisplayName();
0114:                }
0115:            }
0116:
0117:            private class AddJDBCDataSourceActionListener implements 
0118:                    ActionListener {
0119:                public void actionPerformed(final ActionEvent evt) {
0120:                    JDBCWizardSelectionPanel.this 
0121:                            .dbschemaComboBoxActionPerformed(evt);
0122:                }
0123:            }
0124:
0125:            /** Creates new form JDBCWizardSelectionPanel */
0126:            public JDBCWizardSelectionPanel(final String title) {
0127:                if (title != null && title.trim().length() != 0) {
0128:                    this .setName(title);
0129:                }
0130:            }
0131:
0132:            /**
0133:             * initializing componentas
0134:             */
0135:            public void initialize() {
0136:                this .initComponents();
0137:                this .initDataSourceCombo();
0138:                this .datasourceComboBox
0139:                        .addActionListener(new AddJDBCDataSourceActionListener());
0140:            }
0141:
0142:            public void initDataSourceCombo() {
0143:                providers = new DefaultComboBoxModel();
0144:                final DatabaseConnection[] conns = ConnectionManager
0145:                        .getDefault().getConnections();
0146:                if (conns.length == 1) {
0147:                    providers.addElement("");
0148:                }
0149:                if (conns.length > 0) {
0150:                    for (int i = 0; i < conns.length; i++) {
0151:                        providers.addElement(new ConnectionWrapper(conns[i]));
0152:                    }
0153:                } else {
0154:                    providers.addElement("<None>");
0155:                }
0156:
0157:                this .datasourceComboBox.setModel(providers);
0158:                this .datasourceComboBox.setSelectedIndex(0);
0159:
0160:            }
0161:
0162:            /**
0163:             * This method is called from within the constructor to initialize the form. WARNING: Do NOT
0164:             * modify this code. The content of this method is always regenerated by the Form Editor.
0165:             */
0166:            private void initComponents() {
0167:                this .jPanel1 = new javax.swing.JPanel();
0168:                this .jLabel1 = new javax.swing.JLabel();
0169:                this .datasourceComboBox = new javax.swing.JComboBox();
0170:                this .jPanel2 = new javax.swing.JPanel();
0171:
0172:                this .availableTablesList = new javax.swing.JList();
0173:                this .jScrollPane2 = new javax.swing.JScrollPane(
0174:                        this .availableTablesList);
0175:
0176:                this .selectedTablesList = new javax.swing.JList();
0177:                this .jScrollPane3 = new javax.swing.JScrollPane(
0178:                        this .selectedTablesList);
0179:
0180:                this .addButton = new javax.swing.JButton(
0181:                        JDBCWizardSelectionPanel.LBL_ADD);
0182:                this .removeButton = new javax.swing.JButton(
0183:                        JDBCWizardSelectionPanel.LBL_REMOVE);
0184:                this .addAllButton = new javax.swing.JButton(
0185:                        JDBCWizardSelectionPanel.LBL_ADD_ALL);
0186:                this .removeAllButton = new javax.swing.JButton(
0187:                        JDBCWizardSelectionPanel.LBL_REMOVE_ALL);
0188:
0189:                this .availableTablesLabel = new javax.swing.JLabel();
0190:                this .selectedTablesLabel = new javax.swing.JLabel();
0191:
0192:                // Adding actionlisteners
0193:                this .addButton
0194:                        .setActionCommand(JDBCWizardSelectionPanel.LBL_ADD);
0195:                this .removeButton
0196:                        .setActionCommand(JDBCWizardSelectionPanel.LBL_REMOVE);
0197:                this .addAllButton
0198:                        .setActionCommand(JDBCWizardSelectionPanel.LBL_ADD_ALL);
0199:                this .removeAllButton
0200:                        .setActionCommand(JDBCWizardSelectionPanel.LBL_REMOVE_ALL);
0201:
0202:                this .addButton.addActionListener(this );
0203:                this .removeButton.addActionListener(this );
0204:                this .addAllButton.addActionListener(this );
0205:                this .removeAllButton.addActionListener(this );
0206:                this .addButton.setEnabled(false);
0207:                this .removeButton.setEnabled(false);
0208:                this .addAllButton.setEnabled(false);
0209:                this .removeAllButton.setEnabled(false);
0210:                this .jLabel1.setText("Data Source");
0211:
0212:                this .availableTablesLabel.setText("Available Tables:");
0213:
0214:                this .selectedTablesLabel.setText("Selected Tables");
0215:                org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
0216:                        this );
0217:                this .setLayout(layout);
0218:                layout
0219:                        .setHorizontalGroup(layout
0220:                                .createParallelGroup(
0221:                                        org.jdesktop.layout.GroupLayout.LEADING)
0222:                                .add(
0223:                                        layout
0224:                                                .createSequentialGroup()
0225:                                                .add(44, 44, 44)
0226:                                                .add(
0227:                                                        layout
0228:                                                                .createParallelGroup(
0229:                                                                        org.jdesktop.layout.GroupLayout.TRAILING,
0230:                                                                        false)
0231:                                                                .add(
0232:                                                                        org.jdesktop.layout.GroupLayout.LEADING,
0233:                                                                        layout
0234:                                                                                .createSequentialGroup()
0235:                                                                                .add(
0236:                                                                                        this .jLabel1,
0237:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0238:                                                                                        69,
0239:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0240:                                                                                .add(
0241:                                                                                        25,
0242:                                                                                        25,
0243:                                                                                        25)
0244:                                                                                .add(
0245:                                                                                        this .datasourceComboBox,
0246:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0247:                                                                                        288,
0248:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
0249:                                                                .add(
0250:                                                                        layout
0251:                                                                                .createSequentialGroup()
0252:                                                                                .add(
0253:                                                                                        layout
0254:                                                                                                .createParallelGroup(
0255:                                                                                                        org.jdesktop.layout.GroupLayout.LEADING)
0256:                                                                                                .add(
0257:                                                                                                        layout
0258:                                                                                                                .createSequentialGroup()
0259:                                                                                                                .add(
0260:                                                                                                                        this .jScrollPane2,
0261:                                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0262:                                                                                                                        110,
0263:                                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0264:                                                                                                                .addPreferredGap(
0265:                                                                                                                        org.jdesktop.layout.LayoutStyle.RELATED,
0266:                                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0267:                                                                                                                        Short.MAX_VALUE)
0268:                                                                                                                .add(
0269:                                                                                                                        layout
0270:                                                                                                                                .createParallelGroup(
0271:                                                                                                                                        org.jdesktop.layout.GroupLayout.TRAILING,
0272:                                                                                                                                        false)
0273:                                                                                                                                .add(
0274:                                                                                                                                        this .addButton,
0275:                                                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0276:                                                                                                                                        116,
0277:                                                                                                                                        Short.MAX_VALUE)
0278:                                                                                                                                .add(
0279:                                                                                                                                        this .removeButton,
0280:                                                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0281:                                                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0282:                                                                                                                                        Short.MAX_VALUE)
0283:                                                                                                                                .add(
0284:                                                                                                                                        this .addAllButton,
0285:                                                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0286:                                                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0287:                                                                                                                                        Short.MAX_VALUE)
0288:                                                                                                                                .add(
0289:                                                                                                                                        this .removeAllButton,
0290:                                                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0291:                                                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0292:                                                                                                                                        Short.MAX_VALUE))
0293:                                                                                                                .add(
0294:                                                                                                                        26,
0295:                                                                                                                        26,
0296:                                                                                                                        26))
0297:                                                                                                .add(
0298:                                                                                                        layout
0299:                                                                                                                .createSequentialGroup()
0300:                                                                                                                .add(
0301:                                                                                                                        this .availableTablesLabel)
0302:                                                                                                                .add(
0303:                                                                                                                        190,
0304:                                                                                                                        190,
0305:                                                                                                                        190)))
0306:                                                                                .add(
0307:                                                                                        layout
0308:                                                                                                .createParallelGroup(
0309:                                                                                                        org.jdesktop.layout.GroupLayout.LEADING)
0310:                                                                                                .add(
0311:                                                                                                        this .selectedTablesLabel,
0312:                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0313:                                                                                                        92,
0314:                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0315:                                                                                                .add(
0316:                                                                                                        this .jScrollPane3,
0317:                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0318:                                                                                                        111,
0319:                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
0320:                                                .addContainerGap(35,
0321:                                                        Short.MAX_VALUE)));
0322:                layout
0323:                        .setVerticalGroup(layout
0324:                                .createParallelGroup(
0325:                                        org.jdesktop.layout.GroupLayout.LEADING)
0326:                                .add(
0327:                                        layout
0328:                                                .createSequentialGroup()
0329:                                                .add(53, 53, 53)
0330:                                                .add(
0331:                                                        layout
0332:                                                                .createParallelGroup(
0333:                                                                        org.jdesktop.layout.GroupLayout.BASELINE)
0334:                                                                .add(
0335:                                                                        this .jLabel1)
0336:                                                                .add(
0337:                                                                        this .datasourceComboBox,
0338:                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0339:                                                                        18,
0340:                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
0341:                                                .add(
0342:                                                        layout
0343:                                                                .createParallelGroup(
0344:                                                                        org.jdesktop.layout.GroupLayout.LEADING)
0345:                                                                .add(
0346:                                                                        layout
0347:                                                                                .createSequentialGroup()
0348:                                                                                .add(
0349:                                                                                        89,
0350:                                                                                        89,
0351:                                                                                        89)
0352:                                                                                .add(
0353:                                                                                        this .addButton)
0354:                                                                                .addPreferredGap(
0355:                                                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0356:                                                                                .add(
0357:                                                                                        this .removeButton)
0358:                                                                                .add(
0359:                                                                                        16,
0360:                                                                                        16,
0361:                                                                                        16)
0362:                                                                                .add(
0363:                                                                                        this .addAllButton)
0364:                                                                                .addPreferredGap(
0365:                                                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0366:                                                                                .add(
0367:                                                                                        this .removeAllButton))
0368:                                                                .add(
0369:                                                                        layout
0370:                                                                                .createSequentialGroup()
0371:                                                                                .add(
0372:                                                                                        31,
0373:                                                                                        31,
0374:                                                                                        31)
0375:                                                                                .add(
0376:                                                                                        layout
0377:                                                                                                .createParallelGroup(
0378:                                                                                                        org.jdesktop.layout.GroupLayout.BASELINE)
0379:                                                                                                .add(
0380:                                                                                                        this .availableTablesLabel)
0381:                                                                                                .add(
0382:                                                                                                        this .selectedTablesLabel))
0383:                                                                                .add(
0384:                                                                                        14,
0385:                                                                                        14,
0386:                                                                                        14)
0387:                                                                                .add(
0388:                                                                                        layout
0389:                                                                                                .createParallelGroup(
0390:                                                                                                        org.jdesktop.layout.GroupLayout.LEADING)
0391:                                                                                                .add(
0392:                                                                                                        this .jScrollPane2,
0393:                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0394:                                                                                                        163,
0395:                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0396:                                                                                                .add(
0397:                                                                                                        this .jScrollPane3,
0398:                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0399:                                                                                                        163,
0400:                                                                                                        Short.MAX_VALUE))))
0401:                                                .addContainerGap(44,
0402:                                                        Short.MAX_VALUE)));
0403:            }// </editor-fold>
0404:
0405:            /**
0406:             * @param evt
0407:             */
0408:            private void dbschemaComboBoxActionPerformed(
0409:                    final java.awt.event.ActionEvent evt) {
0410:                this .updateSourceSchema();
0411:            }
0412:
0413:            /**
0414:             * Connect to the datasource selected in the combo
0415:             */
0416:            private void updateSourceSchema() {
0417:                Set oldConnections = new HashSet(
0418:                        Arrays.asList(ConnectionManager.getDefault()
0419:                                .getConnections()));
0420:
0421:                final Object item = this .datasourceComboBox.getSelectedItem();
0422:                if (item instanceof  ConnectionWrapper) {
0423:                    final ConnectionWrapper cw = (ConnectionWrapper) item;
0424:                    this .selectedConnection = cw.getDatabaseConnection();
0425:                    ConnectionManager.getDefault().showConnectionDialog(
0426:                            this .selectedConnection);
0427:                    providers.removeElement("");
0428:                    this .persistModel();
0429:                }/*else{
0430:                             ConnectionManager.getDefault().showAddConnectionDialog(null);
0431:                        }*/
0432:                // try to find the new connection
0433:                DatabaseConnection[] newConnections = ConnectionManager
0434:                        .getDefault().getConnections();
0435:                if (newConnections.length == oldConnections.size()) {
0436:                    // no new connection, so...
0437:                    return;
0438:                }
0439:
0440:                providers.removeElement(new String(NEW_DATA_SOURCE));
0441:                for (int i = 0; i < newConnections.length; i++) {
0442:                    if (!oldConnections.contains(newConnections[i])) {
0443:                        providers.addElement(new ConnectionWrapper(
0444:                                newConnections[i]));
0445:                        break;
0446:                    }
0447:                }
0448:            }
0449:
0450:            public void persistModel() {
0451:                //final DBMetaData meta = new DBMetaData();
0452:                final Connection connection = this .selectedConnection
0453:                        .getJDBCConnection();
0454:                List recycleBinTables = null;
0455:                if (connection != null) {
0456:                    try {
0457:                        //meta.connectDB(this.selectedConnection.getJDBCConnection());
0458:                        def = DatabaseObjectFactory
0459:                                .createDBConnectionDefinition(
0460:                                        this .selectedConnection
0461:                                                .getDisplayName(),
0462:                                        this .selectedConnection
0463:                                                .getDriverClass(),
0464:                                        this .selectedConnection
0465:                                                .getDatabaseURL(),
0466:                                        this .selectedConnection.getUser(),
0467:                                        this .selectedConnection.getPassword(),
0468:                                        "Descriptive info here", DBMetaData
0469:                                                .getDBType(connection));
0470:
0471:                        this .dbtype = DBMetaData
0472:                                .getDBType(this .selectedConnection
0473:                                        .getJDBCConnection());
0474:                        this .dbmodel = new DatabaseModelImpl(
0475:                                this .selectedConnection.getDisplayName(), def);
0476:
0477:                        final String[][] tableList = DBMetaData
0478:                                .getTablesAndViews("", this .selectedConnection
0479:                                        .getSchema(), "", true, connection);
0480:                        if ("ORACLE".equalsIgnoreCase(this .dbtype)
0481:                                && DBMetaData
0482:                                        .getDatabaseMajorVersion(connection) >= 10) { // NOI18N
0483:                            recycleBinTables = DBMetaData
0484:                                    .getOracleRecycleBinTables(connection);
0485:                        } else {
0486:                            recycleBinTables = Collections.EMPTY_LIST;
0487:                        }
0488:
0489:                        String[] currTable = null;
0490:                        List tableNamesList = new ArrayList();
0491:                        if (tableList != null) {
0492:                            for (int i = 0; i < tableList.length; i++) {
0493:                                currTable = tableList[i];
0494:                                if (!recycleBinTables
0495:                                        .contains(currTable[DBMetaData.NAME])) {
0496:                                    tableNamesList
0497:                                            .add(currTable[DBMetaData.NAME]);
0498:                                }
0499:                            }
0500:
0501:                        }
0502:                        this .initListModel(tableNamesList);
0503:
0504:                    } catch (final Exception ex) {
0505:                        ex.printStackTrace();
0506:                        ErrorManager.getDefault().log(ErrorManager.ERROR,
0507:                                ex.getMessage());
0508:                        ErrorManager.getDefault()
0509:                                .notify(ErrorManager.ERROR, ex);
0510:                    }
0511:                }
0512:            }
0513:
0514:            /**
0515:             * 
0516:             *
0517:             */
0518:
0519:            public void initListModel(List tableList) {
0520:                final DefaultListModel tempListModel = new DefaultListModel();
0521:                final Iterator itr = tableList.iterator();
0522:                while (itr.hasNext()) {
0523:                    final String tabName = (String) itr.next();
0524:                    if (tabName != null) {
0525:                        tempListModel.addElement(tabName);
0526:                    }
0527:                }
0528:                this .listModel = new ListTransferModel();
0529:                this .listModel.setSourceList(Arrays.asList(tempListModel
0530:                        .toArray()));
0531:
0532:                String largestString = this .listModel.getPrototypeCell();
0533:
0534:                if (largestString.length() < JDBCWizardSelectionPanel.LBL_SOURCE_MSG
0535:                        .length()) {
0536:                    largestString = JDBCWizardSelectionPanel.LBL_SOURCE_MSG;
0537:                } else if (largestString.length() < JDBCWizardSelectionPanel.LBL_DEST_MSG
0538:                        .length()) {
0539:                    largestString = JDBCWizardSelectionPanel.LBL_DEST_MSG;
0540:                }
0541:
0542:                this .srcRenderer = new DBModelNameCellRenderer(largestString);
0543:                this .destRenderer = new DBModelNameCellRenderer(largestString);
0544:
0545:                this .visibleCt = Math.min(Math.max(
0546:                        JDBCWizardSelectionPanel.MINIMUM_VISIBLE,
0547:                        this .listModel.getMaximumListSize()),
0548:                        JDBCWizardSelectionPanel.MAXIMUM_VISIBLE);
0549:
0550:                this .addButton.setModel(this .listModel.getAddButtonModel());
0551:                this .removeButton.setModel(this .listModel
0552:                        .getRemoveButtonModel());
0553:                this .addAllButton.setModel(this .listModel
0554:                        .getAddAllButtonModel());
0555:                this .removeAllButton.setModel(this .listModel
0556:                        .getRemoveAllButtonModel());
0557:
0558:                this .availableTablesList = new JList((this .listModel
0559:                        .getSourceList()).toArray());
0560:                this .availableTablesList
0561:                        .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
0562:                this .availableTablesList.addMouseListener(new MouseAdapter() {
0563:                    public void mouseClicked(final MouseEvent e) {
0564:                        if (e.getClickCount() == 2
0565:                                && e.getSource() instanceof  JList) {
0566:                            final JList list = (JList) e.getSource();
0567:                            final int[] indices = list.getSelectedIndices();
0568:                            final Object[] selections = list
0569:                                    .getSelectedValues();
0570:                            JDBCWizardSelectionPanel.this .listModel.add(
0571:                                    selections, indices);
0572:                        }
0573:                    }
0574:                });
0575:                this .availableTablesList.addListSelectionListener(this );
0576:
0577:                this .availableTablesList
0578:                        .setPrototypeCellValue(this .srcRenderer);
0579:                this .availableTablesList.setCellRenderer(this .srcRenderer);
0580:                this .availableTablesList.setVisibleRowCount(this .visibleCt);
0581:
0582:                this .selectedTablesList = new JList();
0583:                this .selectedTablesList
0584:                        .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
0585:                this .selectedTablesList.addMouseListener(new MouseAdapter() {
0586:                    public void mouseClicked(final MouseEvent e) {
0587:                        if (e.getClickCount() == 2
0588:                                && e.getSource() instanceof  JList) {
0589:                            final JList list = (JList) e.getSource();
0590:                            final int[] indices = list.getSelectedIndices();
0591:                            final Object[] selections = list
0592:                                    .getSelectedValues();
0593:                            JDBCWizardSelectionPanel.this .listModel.remove(
0594:                                    selections, indices);
0595:                        }
0596:                    }
0597:                });
0598:
0599:                this .selectedTablesList
0600:                        .setPrototypeCellValue(this .destRenderer);
0601:                this .selectedTablesList.setCellRenderer(this .destRenderer);
0602:                this .selectedTablesList.setVisibleRowCount(this .visibleCt);
0603:
0604:                this .selectedTablesList.addListSelectionListener(this );
0605:                this .jScrollPane2.setViewportView(this .availableTablesList);
0606:                this .jScrollPane3.setViewportView(this .selectedTablesList);
0607:            }
0608:
0609:            /**
0610:             * 
0611:             */
0612:            public Component getComponent() {
0613:                return this ;
0614:            }
0615:
0616:            /**
0617:             * 
0618:             */
0619:            public HelpCtx getHelp() {
0620:                // Show no Help button for this panel:
0621:                return new HelpCtx(JDBCWizardSelectionPanel.class);
0622:            }
0623:
0624:            /**
0625:             * @param settings
0626:             */
0627:            public void readSettings(final Object settings) {
0628:                WizardDescriptor wd = null;
0629:                if (settings instanceof  JDBCWizardContext) {
0630:                    final JDBCWizardContext wizardContext = (JDBCWizardContext) settings;
0631:                    wd = (WizardDescriptor) wizardContext
0632:                            .getProperty(JDBCWizardContext.WIZARD_DESCRIPTOR);
0633:
0634:                } else if (settings instanceof  WizardDescriptor) {
0635:                    wd = (WizardDescriptor) settings;
0636:                }
0637:
0638:            }
0639:
0640:            /**
0641:             * @param settings
0642:             */
0643:            public void storeSettings(final Object settings) {
0644:                WizardDescriptor wd = null;
0645:                if (settings instanceof  JDBCWizardContext) {
0646:                    final JDBCWizardContext wizardContext = (JDBCWizardContext) settings;
0647:                    wd = (WizardDescriptor) wizardContext
0648:                            .getProperty(JDBCWizardContext.WIZARD_DESCRIPTOR);
0649:
0650:                } else if (settings instanceof  WizardDescriptor) {
0651:                    wd = (WizardDescriptor) settings;
0652:                }
0653:
0654:                final Object selectedOption = wd.getValue();
0655:                if (NotifyDescriptor.CANCEL_OPTION == selectedOption
0656:                        || NotifyDescriptor.CLOSED_OPTION == selectedOption) {
0657:                    return;
0658:                }
0659:
0660:                //populateDBModel();
0661:                if (selectedOption.toString().equals("PREVIOUS_OPTION")) {
0662:                    //listModel = null;
0663:                    if (this .availableTablesList != null) {
0664:                        if (listModel != null) {
0665:                            this .listModel.getSourceList().clear();
0666:                            this .jScrollPane2
0667:                                    .setViewportView(this .availableTablesList);
0668:                        }
0669:                    }
0670:                    if (this .selectedTablesList != null) {
0671:                        if (listModel != null) {
0672:                            this .listModel.getSourceList().clear();
0673:                            this .jScrollPane3
0674:                                    .setViewportView(this .selectedTablesList);
0675:                        }
0676:                    }
0677:                    return;
0678:                }
0679:
0680:                if (listModel != null) {
0681:                    List selList = this .listModel.getDestinationList();
0682:                    List selTabList = new ArrayList();
0683:                    Iterator itr = selList.iterator();
0684:                    while (itr.hasNext()) {
0685:                        DBTable tabObj = (DBTable) populateDBTable((String) itr
0686:                                .next());
0687:                        // By default make the table selected
0688:                        tabObj.setSelected(true);
0689:                        selTabList.add(tabObj);
0690:                    }
0691:                    if (wd != null) {
0692:                        wd.putProperty(JDBCWizardContext.SELECTEDTABLES,
0693:                                selTabList.toArray());
0694:                        wd.putProperty(JDBCWizardContext.DBTYPE, this .dbtype);
0695:                        wd.putProperty(JDBCWizardContext.CONNECTION_INFO, def);
0696:                    }
0697:                }
0698:            }
0699:
0700:            /**
0701:             * 
0702:             * @param tableName
0703:             * @return
0704:             */
0705:            public DBTable populateDBTable(String tableName) {
0706:                final Connection connection = this .selectedConnection
0707:                        .getJDBCConnection();
0708:                try {
0709:                    final String[][] tableList = DBMetaData.getTablesAndViews(
0710:                            "", "", "", true, connection);
0711:                    DBTable ffTable = null;
0712:                    String[] currTable = null;
0713:                    if (tableList != null) {
0714:                        for (int i = 0; i < tableList.length; i++) {
0715:                            currTable = tableList[i];
0716:                            if (tableName.equals(currTable[DBMetaData.NAME])) {
0717:                                ffTable = new DBTableImpl(
0718:                                        currTable[DBMetaData.NAME],
0719:                                        currTable[DBMetaData.SCHEMA],
0720:                                        currTable[DBMetaData.CATALOG]);
0721:                                Table t = null;
0722:                                String driverName = connection.getMetaData()
0723:                                        .getDriverName();
0724:                                //For JDBC-ODBC driver we need to select columns by order otherwise, driver throws 
0725:                                //Invalid Descriptor Index exception
0726:                                if (driverName.startsWith("JDBC-ODBC")) {
0727:                                    t = DBMetaData
0728:                                            .getTableMetaDataForODBCDriver(
0729:                                                    currTable[DBMetaData.CATALOG],
0730:                                                    currTable[DBMetaData.SCHEMA],
0731:                                                    currTable[DBMetaData.NAME],
0732:                                                    currTable[DBMetaData.TYPE],
0733:                                                    connection);
0734:                                } else {
0735:                                    t = DBMetaData.getTableMetaData(
0736:                                            currTable[DBMetaData.CATALOG],
0737:                                            currTable[DBMetaData.SCHEMA],
0738:                                            currTable[DBMetaData.NAME],
0739:                                            currTable[DBMetaData.TYPE],
0740:                                            connection);
0741:
0742:                                }
0743:
0744:                                final TableColumn[] cols = t.getColumns();
0745:                                TableColumn tc = null;
0746:                                DBColumn ffColumn = null;
0747:                                for (int j = 0; j < cols.length; j++) {
0748:                                    tc = cols[j];
0749:                                    ffColumn = new DBColumnImpl(tc.getName(),
0750:                                            tc.getSqlTypeCode(), tc
0751:                                                    .getNumericScale(), tc
0752:                                                    .getNumericPrecision(), tc
0753:                                                    .getIsPrimaryKey(), tc
0754:                                                    .getIsForeignKey(),
0755:                                            false /* isIndexed */, tc
0756:                                                    .getIsNullable());
0757:                                    final String ncName = XMLCharUtil
0758:                                            .makeValidNCName(tc.getName());
0759:                                    ffColumn.setJavaName(ncName);
0760:                                    ffTable.addColumn(ffColumn);
0761:                                }
0762:                                return ((DBTable) ffTable);
0763:                            }
0764:                            if (ffTable != null) {
0765:                                break;
0766:                            }
0767:                        }
0768:                    }
0769:                } catch (final Exception ex) {
0770:                    ex.printStackTrace();
0771:                    ErrorManager.getDefault().log(ErrorManager.ERROR,
0772:                            ex.getMessage());
0773:                    ErrorManager.getDefault().notify(ErrorManager.ERROR, ex);
0774:                }
0775:                return null;
0776:            }
0777:
0778:            /**
0779:             * @see JDBCWizardPanel#addChangeListener
0780:             */
0781:            public final void addChangeListener(final ChangeListener l) {
0782:                synchronized (this .listeners) {
0783:                    this .listeners.add(l);
0784:                }
0785:            }
0786:
0787:            /**
0788:             * @see JDBCWizardPanel#removeChangeListener
0789:             */
0790:            public final void removeChangeListener(final ChangeListener l) {
0791:                synchronized (this .listeners) {
0792:                    this .listeners.remove(l);
0793:                }
0794:            }
0795:
0796:            /**
0797:             * @see JDBCWizardPanel#fireChangeEvent
0798:             */
0799:            public void fireChangeEvent() {
0800:                Iterator it;
0801:
0802:                synchronized (this .listeners) {
0803:                    it = new HashSet(this .listeners).iterator();
0804:                }
0805:
0806:                final ChangeEvent ev = new ChangeEvent(this );
0807:                while (it.hasNext()) {
0808:                    ((ChangeListener) it.next()).stateChanged(ev);
0809:                }
0810:            }
0811:
0812:            /**
0813:             * @see JDBCWizardPanel#isValid
0814:             */
0815:            public boolean isValid() {
0816:                boolean returnVal = false;
0817:                if (selTableLen > 0) {
0818:                    returnVal = true;
0819:                }
0820:                return returnVal;
0821:            }
0822:
0823:            /**
0824:             * Extends ChangeEvent to convey information on an item being transferred to or from the source
0825:             * of the event.
0826:             */
0827:            public static class TransferEvent extends ChangeEvent {
0828:                /**
0829:                 * 
0830:                 */
0831:                private static final long serialVersionUID = 1L;
0832:
0833:                /** Indicates addition of an item to the source of the event */
0834:                public static final int ADDED = 0;
0835:
0836:                /** Indicates removal of an item from the source of the event */
0837:                public static final int REMOVED = 1;
0838:
0839:                private Object item;
0840:
0841:                private int type;
0842:
0843:                /**
0844:                 * Create a new TransferEvent instance with the given source, item and type.
0845:                 * 
0846:                 * @param source source of this transfer event
0847:                 * @param item transferred item
0848:                 * @param type transfer type, either ADDED or REMOVED
0849:                 * @see #ADDED
0850:                 * @see #REMOVED
0851:                 */
0852:                public TransferEvent(final Object source, final Object item,
0853:                        final int type) {
0854:                    super (source);
0855:                    this .item = item;
0856:                    this .type = type;
0857:                }
0858:
0859:                /**
0860:                 * Gets item that was transferred.
0861:                 * 
0862:                 * @return transferred item
0863:                 */
0864:                public Object getItem() {
0865:                    return this .item;
0866:                }
0867:
0868:                /**
0869:                 * Gets type of transfer event.
0870:                 * 
0871:                 * @return ADDED or REMOVED
0872:                 */
0873:                public int getType() {
0874:                    return this .type;
0875:                }
0876:            }
0877:
0878:            /**
0879:             * Container for ListModels associated with source and destination lists of a list transfer
0880:             * panel. Holds ButtonModels for controls that indicate selected addition and bulk addition to
0881:             * destination list and selected removal and bulk removal of items from the destination list.
0882:             */
0883:            class ListTransferModel {
0884:                private ButtonModel addAllButtonModel;
0885:
0886:                private ButtonModel addButtonModel;
0887:
0888:                private HashSet changeListeners;
0889:
0890:                private DefaultListModel dest;
0891:
0892:                private String listPrototype;
0893:
0894:                private ButtonModel removeAllButtonModel;
0895:
0896:                private ButtonModel removeButtonModel;
0897:
0898:                private DefaultListModel source;
0899:
0900:                /**
0901:                 * Creates a new instance of ListTransferModel, using the data in the given collections to
0902:                 * initially populate the source and destination lists.
0903:                 * 
0904:                 * @param srcColl Collection used to populate source list
0905:                 * @param dstColl Collection used to populate destination list
0906:                 */
0907:                public ListTransferModel() {
0908:                    this .listPrototype = "";
0909:                    this .source = new DefaultListModel();
0910:                    this .dest = new DefaultListModel();
0911:
0912:                    this .addButtonModel = new DefaultButtonModel();
0913:                    this .addAllButtonModel = new DefaultButtonModel();
0914:                    this .removeButtonModel = new DefaultButtonModel();
0915:                    this .removeAllButtonModel = new DefaultButtonModel();
0916:
0917:                    this .changeListeners = new HashSet();
0918:                }
0919:
0920:                /**
0921:                 * Moves indicated items from source to destination list.
0922:                 * 
0923:                 * @param selections array of selected items
0924:                 * @param indices array of indices, each element corresponding to the item in selections
0925:                 *            array
0926:                 */
0927:                public void add(final Object[] selections, final int[] indices) {
0928:                    synchronized (this .dest) {
0929:                        synchronized (this .source) {
0930:                            for (int i = 0; i < indices.length; i++) {
0931:                                final Object element = selections[i];
0932:                                this .dest.addElement(element);
0933:                                this .source.removeElement(element);
0934:                                this .fireTransferEvent(this .dest, element,
0935:                                        TransferEvent.ADDED);
0936:                            }
0937:
0938:                            this .updateButtonState();
0939:                        }
0940:                    }
0941:                    selTableLen = this .dest.getSize();
0942:
0943:                    this .updateButtonState();
0944:                    this .updateUI();
0945:                    JDBCWizardSelectionPanel.this .fireChangeEvent();
0946:                }
0947:
0948:                /**
0949:                 * Moves all remaining items from source to destination list.
0950:                 */
0951:                public void addAll() {
0952:                    synchronized (this .dest) {
0953:                        synchronized (this .source) {
0954:                            final int size = this .source.getSize();
0955:                            for (int i = 0; i < size; i++) {
0956:                                final Object element = this .source.elementAt(i);
0957:                                this .dest.addElement(element);
0958:                                this .fireTransferEvent(this .dest, element,
0959:                                        TransferEvent.ADDED);
0960:                            }
0961:                            this .source.removeAllElements();
0962:                        }
0963:                    }
0964:                    selTableLen = this .dest.getSize();
0965:                    this .updateButtonState();
0966:
0967:                    JDBCWizardSelectionPanel.this .fireChangeEvent();
0968:                    this .updateUI();
0969:                }
0970:
0971:                /**
0972:                 * Add a ChangeListener to this model.
0973:                 * 
0974:                 * @param l ChangeListener to add
0975:                 */
0976:                public void addChangeListener(final ChangeListener l) {
0977:                    if (l != null) {
0978:                        synchronized (this .changeListeners) {
0979:                            this .changeListeners.add(l);
0980:                        }
0981:                    }
0982:                }
0983:
0984:                /**
0985:                 * Gets ButtonModel associated with add all button action.
0986:                 * 
0987:                 * @return add all ButtonModel
0988:                 */
0989:                public ButtonModel getAddAllButtonModel() {
0990:                    return this .addAllButtonModel;
0991:                }
0992:
0993:                /**
0994:                 * Gets ButtonModel associated with add button action.
0995:                 * 
0996:                 * @return add ButtonModel
0997:                 */
0998:                public ButtonModel getAddButtonModel() {
0999:                    return this .addButtonModel;
1000:                }
1001:
1002:                /**
1003:                 * Gets copy of current contents of destination list
1004:                 * 
1005:                 * @return List of current destination list contents
1006:                 */
1007:                public List getDestinationList() {
1008:                    final ArrayList dstList = new ArrayList();
1009:
1010:                    synchronized (this .dest) {
1011:                        this .dest.trimToSize();
1012:                        for (int i = 0; i < this .dest.size(); i++) {
1013:                            dstList.add(this .dest.get(i));
1014:                        }
1015:                    }
1016:
1017:                    return dstList;
1018:                }
1019:
1020:                /**
1021:                 * Gets ListModel associated with destination list.
1022:                 * 
1023:                 * @return source ListModel
1024:                 */
1025:                public ListModel getDestinationModel() {
1026:                    return this .dest;
1027:                }
1028:
1029:                /**
1030:                 * Gets maximum number of items expected in either the source or destination list.
1031:                 * 
1032:                 * @return maximum count of items in any one list
1033:                 */
1034:                public int getMaximumListSize() {
1035:                    return this .source.size() + this .dest.size();
1036:                }
1037:
1038:                /**
1039:                 * Gets prototype String that has the largest width of an item in either list.
1040:                 * 
1041:                 * @return String whose length is the largest among the items in either list
1042:                 */
1043:                public String getPrototypeCell() {
1044:                    return this .listPrototype;
1045:                }
1046:
1047:                /**
1048:                 * Gets ButtonModel associated with remove all button action
1049:                 * 
1050:                 * @return remove all ButtonModel
1051:                 */
1052:                public ButtonModel getRemoveAllButtonModel() {
1053:                    return this .removeAllButtonModel;
1054:                }
1055:
1056:                /**
1057:                 * Gets ButtonModel associated with remove button action.
1058:                 * 
1059:                 * @return remove ButtonModel
1060:                 */
1061:                public ButtonModel getRemoveButtonModel() {
1062:                    return this .removeButtonModel;
1063:                }
1064:
1065:                /**
1066:                 * Returns index of source item matching the given string.
1067:                 * 
1068:                 * @param searchStr string to search for in source list
1069:                 * @param startFrom index from which to start search
1070:                 * @return index of matching item, or -1 if no match exists
1071:                 */
1072:                public int getSourceIndexFor(final String searchStr,
1073:                        final int startFrom) {
1074:                    int tsttFrom = 0;
1075:                    if (startFrom < 0 || startFrom > this .source.size()) {
1076:                        tsttFrom = 0;
1077:                    }
1078:
1079:                    if (searchStr != null && searchStr.trim().length() != 0) {
1080:                        return this .source.indexOf(searchStr, tsttFrom);
1081:                    }
1082:
1083:                    return -1;
1084:                }
1085:
1086:                /**
1087:                 * Gets copy of current contents of source list
1088:                 * 
1089:                 * @return List of current source list contents
1090:                 */
1091:                public List getSourceList() {
1092:                    final ArrayList srcList = new ArrayList();
1093:
1094:                    synchronized (this .source) {
1095:                        this .source.trimToSize();
1096:                        for (int i = 0; i < this .source.size(); i++) {
1097:                            srcList.add(this .source.get(i));
1098:                        }
1099:                    }
1100:
1101:                    return srcList;
1102:                }
1103:
1104:                /**
1105:                 * Gets ListModel associated with source list.
1106:                 * 
1107:                 * @return source ListModel
1108:                 */
1109:                public ListModel getSourceModel() {
1110:                    return this .source;
1111:                }
1112:
1113:                /**
1114:                 * Moves indicated items from destination to source list.
1115:                 * 
1116:                 * @param selections array of selected items
1117:                 * @param indices array of indices, each element corresponding to the item in selections
1118:                 *            array
1119:                 */
1120:                public void remove(final Object[] selections,
1121:                        final int[] indices) {
1122:                    synchronized (this .dest) {
1123:                        synchronized (this .source) {
1124:                            for (int i = 0; i < indices.length; i++) {
1125:                                final Object element = selections[i];
1126:                                this .source.addElement(element);
1127:                                this .dest.removeElement(element);
1128:                                this .fireTransferEvent(this .dest, element,
1129:                                        TransferEvent.REMOVED);
1130:                            }
1131:                        }
1132:                    }
1133:                    selTableLen = this .dest.getSize();
1134:                    this .updateButtonState();
1135:                    JDBCWizardSelectionPanel.this .fireChangeEvent();
1136:                    this .updateUI();
1137:                }
1138:
1139:                /**
1140:                 * Moves all remaining items from destination to source list.
1141:                 */
1142:                public void removeAll() {
1143:                    synchronized (this .dest) {
1144:                        synchronized (this .source) {
1145:                            final int size = this .dest.getSize();
1146:                            for (int i = 0; i < size; i++) {
1147:                                final Object element = this .dest.elementAt(i);
1148:                                this .source.addElement(element);
1149:                            }
1150:                            this .dest.removeAllElements();
1151:                        }
1152:                    }
1153:                    selTableLen = this .dest.getSize();
1154:                    this .updateButtonState();
1155:                    JDBCWizardSelectionPanel.this .fireChangeEvent();
1156:                    this .updateUI();
1157:                }
1158:
1159:                /**
1160:                 * Remove a ChangeListener from this model.
1161:                 * 
1162:                 * @param l ChangeListener to remove
1163:                 */
1164:                public void removeChangeListener(final ChangeListener l) {
1165:                    if (l != null) {
1166:                        synchronized (this .changeListeners) {
1167:                            this .changeListeners.remove(l);
1168:                        }
1169:                    }
1170:                }
1171:
1172:                /**
1173:                 * Sets destination list to include contents of given list. Clears current contents before
1174:                 * adding items from newList.
1175:                 * 
1176:                 * @param newList List whose contents will supplant the current contents of the destination
1177:                 *            list
1178:                 */
1179:                public void setDestinationList(final Collection newList) {
1180:                    if (newList == null) {
1181:                        throw new IllegalArgumentException(
1182:                                "Must supply non-null Collection for newList");
1183:                    }
1184:
1185:                    if (this .dest == null) {
1186:                        this .dest = new DefaultListModel();
1187:                    }
1188:
1189:                    synchronized (this .dest) {
1190:                        this .dest.clear();
1191:
1192:                        final Iterator it = newList.iterator();
1193:                        while (it.hasNext()) {
1194:                            final Object o = it.next();
1195:                            this .dest.addElement(o);
1196:                            if (o.toString().trim().length() > this .listPrototype
1197:                                    .length()) {
1198:                                this .listPrototype = o.toString().trim();
1199:                            }
1200:                        }
1201:                    }
1202:
1203:                    this .updateButtonState();
1204:                }
1205:
1206:                /**
1207:                 * Sets source list to include contents of given list. Clears current contents before adding
1208:                 * items from newList.
1209:                 * 
1210:                 * @param newList List whose contents will supplant the current contents of the source list
1211:                 */
1212:                public void setSourceList(final Collection newList) {
1213:                    if (newList == null) {
1214:                        throw new IllegalArgumentException(
1215:                                "Must supply non-null Collection for newList");
1216:                    }
1217:
1218:                    if (this .source == null) {
1219:                        this .source = new DefaultListModel();
1220:                    }
1221:
1222:                    synchronized (this .source) {
1223:                        this .source.clear();
1224:
1225:                        final Iterator it = newList.iterator();
1226:                        while (it.hasNext()) {
1227:                            final Object o = it.next();
1228:                            this .source.addElement(o);
1229:                            if (o.toString().trim().length() > this .listPrototype
1230:                                    .length()) {
1231:                                this .listPrototype = o.toString().trim();
1232:                            }
1233:                        }
1234:                    }
1235:
1236:                    this .updateButtonState();
1237:                }
1238:
1239:                /**
1240:                 * Updates button states
1241:                 */
1242:                public void updateButtonState() {
1243:                    final boolean canAdd = !this .source.isEmpty();
1244:                    final boolean canRemove = !this .dest.isEmpty();
1245:                    if (canRemove) {
1246:                        this .addButtonModel.setEnabled(false);
1247:                        this .addAllButtonModel.setEnabled(false);
1248:                        this .removeButtonModel.setEnabled(canRemove);
1249:                        this .removeAllButtonModel.setEnabled(canRemove);
1250:                    } else {
1251:                        this .addButtonModel.setEnabled(canAdd);
1252:                        this .addAllButtonModel.setEnabled(canRemove);
1253:                        this .removeButtonModel.setEnabled(canRemove);
1254:                        this .removeAllButtonModel.setEnabled(canRemove);
1255:                    }
1256:                }
1257:
1258:                public void updateUI() {
1259:                    // List is not getting refreshed, temporary workaround to handle this.
1260:                    // Need to have a better way to refresh the ui
1261:                    JDBCWizardSelectionPanel.this .availableTablesList = new JList(
1262:                            (JDBCWizardSelectionPanel.this .listModel
1263:                                    .getSourceList()).toArray());
1264:                    JDBCWizardSelectionPanel.this .selectedTablesList = new JList(
1265:                            (JDBCWizardSelectionPanel.this .listModel
1266:                                    .getDestinationList()).toArray());
1267:                    JDBCWizardSelectionPanel.this .availableTablesList
1268:                            .setPrototypeCellValue(JDBCWizardSelectionPanel.this .srcRenderer);
1269:                    JDBCWizardSelectionPanel.this .availableTablesList
1270:                            .setCellRenderer(JDBCWizardSelectionPanel.this .srcRenderer);
1271:                    JDBCWizardSelectionPanel.this .availableTablesList
1272:                            .setVisibleRowCount(JDBCWizardSelectionPanel.this .visibleCt);
1273:
1274:                    JDBCWizardSelectionPanel.this .selectedTablesList
1275:                            .setPrototypeCellValue(JDBCWizardSelectionPanel.this .destRenderer);
1276:                    JDBCWizardSelectionPanel.this .selectedTablesList
1277:                            .setCellRenderer(JDBCWizardSelectionPanel.this .destRenderer);
1278:                    JDBCWizardSelectionPanel.this .selectedTablesList
1279:                            .setVisibleRowCount(JDBCWizardSelectionPanel.this .visibleCt);
1280:
1281:                    JDBCWizardSelectionPanel.this .jScrollPane2
1282:                            .setViewportView(JDBCWizardSelectionPanel.this .availableTablesList);
1283:                    JDBCWizardSelectionPanel.this .jScrollPane3
1284:                            .setViewportView(JDBCWizardSelectionPanel.this .selectedTablesList);
1285:                }
1286:
1287:                private void fireTransferEvent(final Object src,
1288:                        final Object item, final int type) {
1289:                    if (src != null && item != null) {
1290:                        final TransferEvent e = new TransferEvent(src, item,
1291:                                type);
1292:                        synchronized (this .changeListeners) {
1293:                            final Iterator iter = this .changeListeners
1294:                                    .iterator();
1295:                            while (iter.hasNext()) {
1296:                                final ChangeListener l = (ChangeListener) iter
1297:                                        .next();
1298:                                l.stateChanged(e);
1299:                            }
1300:                        }
1301:                    }
1302:                }
1303:            }
1304:
1305:            /**
1306:             * Invoked whenever one of the transfer buttons is clicked.
1307:             * 
1308:             * @param e ActionEvent to handle
1309:             */
1310:            public void actionPerformed(final ActionEvent e) {
1311:                final String cmd = e.getActionCommand();
1312:
1313:                if (JDBCWizardSelectionPanel.LBL_ADD.equals(cmd)) {
1314:                    final int[] indices = this .availableTablesList
1315:                            .getSelectedIndices();
1316:                    if (indices.length <= 1) {
1317:                        final Object[] selections = this .availableTablesList
1318:                                .getSelectedValues();
1319:                        this .listModel.add(selections, indices);
1320:                    } else {
1321:                        Object[] options = { "OK" };
1322:                        JOptionPane.showOptionDialog(WindowManager.getDefault()
1323:                                .getMainWindow(), NbBundle.getMessage(
1324:                                JDBCWizardSelectionPanel.class,
1325:                                "WARNING_IN_SELECTING_TABLES"), "Warning",
1326:                                JOptionPane.DEFAULT_OPTION,
1327:                                JOptionPane.WARNING_MESSAGE, null, options,
1328:                                options[0]);
1329:                    }
1330:                } else if (JDBCWizardSelectionPanel.LBL_ADD_ALL.equals(cmd)) {
1331:                    this .listModel.addAll();
1332:                } else if (JDBCWizardSelectionPanel.LBL_REMOVE.equals(cmd)) {
1333:                    final int[] indices = this .selectedTablesList
1334:                            .getSelectedIndices();
1335:                    final Object[] selections = this .selectedTablesList
1336:                            .getSelectedValues();
1337:                    this .listModel.remove(selections, indices);
1338:                } else if (JDBCWizardSelectionPanel.LBL_REMOVE_ALL.equals(cmd)) {
1339:                    this .listModel.removeAll();
1340:                } else {
1341:                    // Log this as an invalid or unknown command.
1342:                    // System.err.println("Unknown cmd: " + cmd);
1343:                }
1344:            }
1345:
1346:            /**
1347:             * Called whenever the value of the selection changes.
1348:             * 
1349:             * @param e the event that characterizes the change.
1350:             */
1351:            public void valueChanged(final ListSelectionEvent e) {
1352:                final Object src = e.getSource();
1353:
1354:                // Enforce mutually exclusive focus between source and destination
1355:                // lists.
1356:                if (this .availableTablesList.equals(src)) {
1357:                    if (!this .selectedTablesList.isSelectionEmpty()) {
1358:                        this .selectedTablesList.clearSelection();
1359:                    }
1360:                } else if (this .selectedTablesList.equals(src)) {
1361:                    if (!this .availableTablesList.isSelectionEmpty()) {
1362:                        this .availableTablesList.clearSelection();
1363:                    }
1364:                } else {
1365:                    // TODO Log unhandled ListSelectionEvent as DEBUG message.
1366:                }
1367:            }
1368:
1369:            class DBModelNameCellRenderer extends DefaultListCellRenderer {
1370:                /**
1371:                 * 
1372:                 */
1373:                private static final long serialVersionUID = 1L;
1374:
1375:                public DBModelNameCellRenderer(final String protoString) {
1376:                    super ();
1377:                    this .setText(protoString.toString());
1378:                }
1379:
1380:                public Component getListCellRendererComponent(final JList list,
1381:                        final Object value, final int index,
1382:                        final boolean isSelected, final boolean cellHasFocus) {
1383:
1384:                    if (isSelected) {
1385:                        this .setBackground(list.getSelectionBackground());
1386:                        this .setForeground(list.getSelectionForeground());
1387:                    } else {
1388:                        this .setBackground(list.getBackground());
1389:                        this .setForeground(list.getForeground());
1390:                    }
1391:
1392:                    this .setEnabled(list.isEnabled());
1393:                    this .setFont(list.getFont());
1394:                    this .setOpaque(true);
1395:
1396:                    if (value instanceof  DBTable) {
1397:                        final DBTable model = (DBTable) value;
1398:                        if (model.getName() != null) {
1399:                            this .setText(model.getName());
1400:                        } else {
1401:                            this .setText(model.getName());
1402:                        }
1403:                    } else if (value instanceof  String) {
1404:                        this .setText(value.toString());
1405:                    }
1406:
1407:                    return this ;
1408:                }
1409:
1410:            }
1411:
1412:            private ListTransferModel listModel;
1413:
1414:            private final List dsList = new ArrayList();
1415:
1416:            // private JList destList;
1417:
1418:            private final List destColl = new ArrayList();
1419:
1420:            // private JList sourceList;
1421:
1422:            public static final String LBL_DEST_MSG = "Selected Tables:";
1423:
1424:            public static final String LBL_SOURCE_MSG = "Available Tables:";
1425:
1426:            /** Maximum number of visible items in lists */
1427:            public static final int MAXIMUM_VISIBLE = 10;
1428:
1429:            /** Minimum number of visible items in lists */
1430:            public static final int MINIMUM_VISIBLE = 5;
1431:
1432:            /** Indicates addition of item(s). */
1433:            public static final String LBL_ADD = ">";
1434:
1435:            /** Label indicating that all elements should be moved. */
1436:            public static final String LBL_ALL = "ALL";
1437:
1438:            /** Indicates addition of all source items. */
1439:            public static final String LBL_ADD_ALL = JDBCWizardSelectionPanel.LBL_ALL
1440:                    + " " + JDBCWizardSelectionPanel.LBL_ADD;
1441:
1442:            /** Indicates removal of item(s). */
1443:            public static final String LBL_REMOVE = "<";
1444:
1445:            /** Indicates removal of all destination items. */
1446:            public static final String LBL_REMOVE_ALL = JDBCWizardSelectionPanel.LBL_REMOVE
1447:                    + " " + JDBCWizardSelectionPanel.LBL_ALL;
1448:
1449:            private DatabaseModel dbmodel;
1450:
1451:            private javax.swing.JButton addButton;
1452:
1453:            private javax.swing.JButton removeButton;
1454:
1455:            private javax.swing.JButton addAllButton;
1456:
1457:            private javax.swing.JButton removeAllButton;
1458:
1459:            private javax.swing.JComboBox datasourceComboBox;
1460:
1461:            private javax.swing.JLabel jLabel1;
1462:
1463:            private javax.swing.JLabel availableTablesLabel;
1464:
1465:            private javax.swing.JLabel selectedTablesLabel;
1466:
1467:            private javax.swing.JList availableTablesList;
1468:
1469:            private javax.swing.JList selectedTablesList;
1470:
1471:            private javax.swing.JPanel jPanel1;
1472:
1473:            private javax.swing.JPanel jPanel2;
1474:
1475:            private javax.swing.JScrollPane jScrollPane2;
1476:
1477:            private javax.swing.JScrollPane jScrollPane3;
1478:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.