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


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         *
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * The contents of this file are subject to the terms of either the GNU
0007:         * General Public License Version 2 only ("GPL") or the Common
0008:         * Development and Distribution License("CDDL") (collectively, the
0009:         * "License"). You may not use this file except in compliance with the
0010:         * License. You can obtain a copy of the License at
0011:         * http://www.netbeans.org/cddl-gplv2.html
0012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013:         * specific language governing permissions and limitations under the
0014:         * License.  When distributing the software, include this License Header
0015:         * Notice in each file and include the License file at
0016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017:         * particular file as subject to the "Classpath" exception as provided
0018:         * by Sun in the GPL Version 2 section of the License file that
0019:         * accompanied this code. If applicable, add the following below the
0020:         * License Header, with the fields enclosed by brackets [] replaced by
0021:         * your own identifying information:
0022:         * "Portions Copyrighted [year] [name of copyright owner]"
0023:         *
0024:         * Contributor(s):
0025:         *
0026:         * The Original Software is NetBeans. The Initial Developer of the Original
0027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028:         * Microsystems, Inc. All Rights Reserved.
0029:         *
0030:         * If you wish your version of this file to be governed by only the CDDL
0031:         * or only the GPL Version 2, indicate your decision by adding
0032:         * "[Contributor] elects to include this software in this distribution
0033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034:         * single choice of license, a recipient has the option to distribute
0035:         * your version of this file under either the CDDL, the GPL Version 2 or
0036:         * to extend the choice of license to its licensees as provided above.
0037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
0038:         * Version 2 license, then the option applies only if the new code is
0039:         * made subject to such option by the copyright holder.
0040:         */
0041:        package org.netbeans.modules.etl.ui.view.wizards;
0042:
0043:        import java.awt.Component;
0044:        import java.awt.event.ActionEvent;
0045:        import java.awt.event.ActionListener;
0046:        import java.awt.event.MouseAdapter;
0047:        import java.awt.event.MouseEvent;
0048:        import java.beans.PropertyChangeEvent;
0049:        import java.beans.PropertyChangeListener;
0050:        import java.util.ArrayList;
0051:        import java.util.Arrays;
0052:        import java.util.Collection;
0053:        import java.util.Collections;
0054:        import java.util.HashMap;
0055:        import java.util.HashSet;
0056:        import java.util.Iterator;
0057:        import java.util.List;
0058:        import java.util.Set;
0059:        import java.util.Vector;
0060:
0061:        import javax.swing.DefaultComboBoxModel;
0062:        import javax.swing.DefaultListCellRenderer;
0063:        import javax.swing.DefaultListModel;
0064:        import javax.swing.JButton;
0065:        import javax.swing.JComboBox;
0066:        import javax.swing.JList;
0067:        import javax.swing.JPanel;
0068:        import javax.swing.ListModel;
0069:        import javax.swing.SwingUtilities;
0070:        import javax.swing.event.ChangeEvent;
0071:        import javax.swing.event.ChangeListener;
0072:        import javax.swing.event.ListSelectionEvent;
0073:        import javax.swing.event.ListSelectionListener;
0074:        import javax.swing.event.TableModelEvent;
0075:        import javax.swing.event.TableModelListener;
0076:        import javax.swing.table.DefaultTableModel;
0077:        import javax.swing.table.TableModel;
0078:
0079:        import org.netbeans.api.db.explorer.DatabaseConnection;
0080:        import org.netbeans.modules.sql.framework.model.DBMetaDataFactory;
0081:        import org.netbeans.modules.sql.framework.model.SQLConstants;
0082:        import org.netbeans.modules.sql.framework.model.SQLDBModel;
0083:        import org.netbeans.modules.sql.framework.model.SQLDBTable;
0084:        import org.netbeans.modules.sql.framework.model.SQLModelObjectFactory;
0085:        import org.netbeans.modules.sql.framework.model.impl.SourceTableImpl;
0086:        import org.netbeans.modules.sql.framework.model.impl.TargetTableImpl;
0087:        import org.openide.NotifyDescriptor;
0088:        import org.openide.WizardDescriptor;
0089:        import org.openide.util.HelpCtx;
0090:        import net.java.hulp.i18n.Logger;
0091:        import org.netbeans.modules.etl.logger.Localizer;
0092:        import org.netbeans.modules.etl.logger.LogUtil;
0093:        import org.netbeans.modules.sql.framework.common.utils.DBExplorerUtil;
0094:        import org.netbeans.modules.sql.framework.model.DBConnectionDefinition;
0095:        import org.netbeans.modules.sql.framework.model.DBTable;
0096:        import org.netbeans.modules.sql.framework.model.DatabaseModel;
0097:        import org.netbeans.modules.sql.framework.model.impl.AbstractDBTable;
0098:
0099:        /**
0100:         * Implements a two-list transfer panel with bulk add/remove capability.
0101:         *
0102:         * @author Sanjeeth Duvuru
0103:         * @author Jonathan Giron
0104:         * @version $Revision$
0105:         */
0106:        public class ETLCollaborationWizardTransferPanel extends JPanel
0107:                implements  ActionListener, ListSelectionListener,
0108:                WizardDescriptor.Panel, TableModelListener,
0109:                PropertyChangeListener {
0110:
0111:            /* Log4J category string */
0112:
0113:            private static final String LOG_CATEGORY = ETLCollaborationWizardTransferPanel.class
0114:                    .getName();
0115:            private static transient final Logger mLogger = LogUtil
0116:                    .getLogger(ETLCollaborationWizardTransferPanel.class
0117:                            .getName());
0118:            private static transient final Localizer mLoc = Localizer.get();
0119:
0120:            /**
0121:             * Extends ChangeEvent to convey information on an item being transferred to or from
0122:             * the source of the event.
0123:             *
0124:             * @author Jonathan Giron
0125:             * @version $Revision$
0126:             */
0127:            public static class TransferEvent extends ChangeEvent {
0128:
0129:                /** Indicates addition of an item to the source of the event */
0130:                public static final int ADDED = 0;
0131:                /** Indicates removal of an item from the source of the event */
0132:                public static final int REMOVED = 1;
0133:                private Object item;
0134:                private int type;
0135:
0136:                /**
0137:                 * Create a new TransferEvent instance with the given source, item and type.
0138:                 *
0139:                 * @param source source of this transfer event
0140:                 * @param item transferred item
0141:                 * @param type transfer type, either ADDED or REMOVED
0142:                 * @see #ADDED
0143:                 * @see #REMOVED
0144:                 */
0145:                public TransferEvent(Object source, Object item, int type) {
0146:                    super (source);
0147:                    this .item = item;
0148:                    this .type = type;
0149:                }
0150:
0151:                /**
0152:                 * Gets item that was transferred.
0153:                 *
0154:                 * @return transferred item
0155:                 */
0156:                public Object getItem() {
0157:                    return item;
0158:                }
0159:
0160:                /**
0161:                 * Gets type of transfer event.
0162:                 *
0163:                 * @return ADDED or REMOVED
0164:                 */
0165:                public int getType() {
0166:                    return type;
0167:                }
0168:            }
0169:
0170:            /**
0171:             * Container for ListModels associated with source and destination lists of a list
0172:             * transfer panel. Holds ButtonModels for controls that indicate selected addition and
0173:             * bulk addition to destination list and selected removal and bulk removal of items
0174:             * from the destination list.
0175:             *
0176:             * @author Jonathan Giron
0177:             * @version $Revision$
0178:             */
0179:            class ListTransferModel {
0180:
0181:                private HashSet<ChangeListener> changeListeners;
0182:                // Dropdown of schemas for a selected connection (source)
0183:                private DefaultComboBoxModel dest;
0184:                private String listPrototype;
0185:                // Connections from the DB explorer.
0186:                private DefaultListModel source;
0187:                // Tables for a selected schema.
0188:                private DefaultListModel schemaTables;
0189:                private DefaultTableModel selectedTableModel;
0190:                private HashMap<String, SQLDBTable> nameToModelMap;
0191:                private final String[] tableHeaders = new String[] { "Name",
0192:                        "Schema", "Catalog", "Connection" };
0193:
0194:                /**
0195:                 * Creates a new instance of ListTransferModel, using the data in the given
0196:                 * collections to initially populate the source and destination lists.
0197:                 *
0198:                 * @param srcColl Collection used to populate source list
0199:                 * @param dstColl Collection used to populate destination list
0200:                 */
0201:                public ListTransferModel(Collection srcColl, Collection dstColl) {
0202:
0203:                    if (srcColl == null || dstColl == null) {
0204:                        throw new IllegalArgumentException(
0205:                                "Must supply non-null collections for srcColl and dstColl");
0206:                    }
0207:
0208:                    listPrototype = "";
0209:
0210:                    source = new DefaultListModel();
0211:                    dest = new DefaultComboBoxModel();
0212:                    schemaTables = new DefaultListModel();
0213:                    nameToModelMap = new HashMap<String, SQLDBTable>();
0214:
0215:                    selectedTableModel = new DefaultTableModel(
0216:                            new Object[][] {}, tableHeaders) {
0217:
0218:                        @Override
0219:                        public boolean isCellEditable(int row, int col) {
0220:                            return false;
0221:                        }
0222:                    };
0223:
0224:                    setSourceList(srcColl);
0225:                    setDestinationList(dstColl);
0226:
0227:                    changeListeners = new HashSet<ChangeListener>();
0228:                }
0229:
0230:                /**
0231:                 * Moves indicated items from source to destination list.
0232:                 *
0233:                 * @param selections array of selected items
0234:                 * @param indices array of indices, each element corresponding to the item in
0235:                 *        selections array
0236:                 */
0237:                public void add(Object[] selections) {
0238:                    synchronized (dest) {
0239:                        synchronized (source) {
0240:
0241:                            for (int i = 0; i < selections.length; i++) {
0242:                                Object element = selections[i];
0243:                                dest.addElement(element);
0244:                            }
0245:                        }
0246:                    }
0247:                }
0248:
0249:                public void addToSelectedTables(Object[] rowData,
0250:                        SQLDBTable table) {
0251:                    if (rowData != null && rowData.length > 0) {
0252:                        selectedTableModel.addRow(rowData);
0253:                        String key = (String) rowData[1] + "."
0254:                                + (String) rowData[0];
0255:                        nameToModelMap.put(key, table);
0256:                    }
0257:                }
0258:
0259:                public String getConnectionNameForTable(
0260:                        String tableDisplayString, String schemaName) {
0261:                    String connName = null;
0262:                    String key = schemaName + "." + tableDisplayString;
0263:                    for (int i = 0; i < selectedTableModel.getRowCount(); i++) {
0264:                        String rowKey = (String) selectedTableModel.getValueAt(
0265:                                i, 1)
0266:                                + "."
0267:                                + (String) selectedTableModel.getValueAt(i, 0);
0268:                        if (rowKey.equals(key)) {
0269:                            connName = (String) selectedTableModel.getValueAt(
0270:                                    i, 3);
0271:                            break;
0272:                        }
0273:                    }
0274:                    return connName;
0275:                }
0276:
0277:                public void removeFromSelectedTables(int rowIndex) {
0278:                    try {
0279:                        selectedTableModel.removeRow(rowIndex);
0280:                    } catch (ArrayIndexOutOfBoundsException aix) {
0281:                        mLogger
0282:                                .errorNoloc(
0283:                                        mLoc
0284:                                                .t(
0285:                                                        "PRSR030: Failed to remove row from selected tables{0}",
0286:                                                        LOG_CATEGORY), aix);
0287:                    }
0288:                }
0289:
0290:                public DefaultTableModel getSelectedTablesModel() {
0291:                    return this .selectedTableModel;
0292:                }
0293:
0294:                public HashMap getNameToModelMap() {
0295:                    return this .nameToModelMap;
0296:                }
0297:
0298:                /**
0299:                 * Moves indicated items from source to destination list.
0300:                 *
0301:                 * @param selections
0302:                 *            array of selected items
0303:                 * @param indices
0304:                 *            array of indices, each element corresponding to the item
0305:                 *            in selections array
0306:                 */
0307:                public void addSchemas(Vector newSchemas) {
0308:                    synchronized (schemaTables) {
0309:                        for (int i = 0; i < newSchemas.size(); i++) {
0310:                            Object element = newSchemas.elementAt(i);
0311:                            schemaTables.addElement(element);
0312:                        }
0313:                    }
0314:                }
0315:
0316:                /**
0317:                 * Add a ChangeListener to this model.
0318:                 *
0319:                 * @param l ChangeListener to add
0320:                 */
0321:                public void addChangeListener(ChangeListener l) {
0322:                    if (l != null) {
0323:                        synchronized (changeListeners) {
0324:                            changeListeners.add(l);
0325:                        }
0326:                    }
0327:                }
0328:
0329:                /**
0330:                 * Gets copy of current contents of destination list
0331:                 *
0332:                 * @return List of current destination list contents
0333:                 */
0334:                public List getSelectedTablesList() {
0335:                    ArrayList<SQLDBTable> dstList = new ArrayList<SQLDBTable>();
0336:                    synchronized (this .selectedTableModel) {
0337:                        for (int i = 0; i < selectedTableModel.getRowCount(); i++) {
0338:                            String tableName = (String) selectedTableModel
0339:                                    .getValueAt(i, 0);
0340:                            String schemaName = (String) selectedTableModel
0341:                                    .getValueAt(i, 1);
0342:                            String key = schemaName + "." + tableName;
0343:                            SQLDBTable tableModel = this .nameToModelMap
0344:                                    .get(key);
0345:                            if (tableModel != null) {
0346:                                dstList.add(tableModel);
0347:                            }
0348:                        }
0349:                    }
0350:                    return dstList;
0351:                }
0352:
0353:                /**
0354:                 * Gets ListModel associated with destination list.
0355:                 *
0356:                 * @return source ListModel
0357:                 */
0358:                public ListModel getDestinationModel() {
0359:                    return dest;
0360:                }
0361:
0362:                /**
0363:                 * Gets ListModel associated with schemaTables JList (below combobox).
0364:                 *
0365:                 * @return source ListModel
0366:                 */
0367:                public ListModel getSchemaTablesModel() {
0368:                    return schemaTables;
0369:                }
0370:
0371:                /**
0372:                 * Gets maximum number of items expected in either the source or destination list.
0373:                 *
0374:                 * @return maximum count of items in any one list
0375:                 */
0376:                public int getMaximumListSize() {
0377:                    return source.size() + dest.getSize();
0378:                }
0379:
0380:                /**
0381:                 * Gets prototype String that has the largest width of an item in either list.
0382:                 *
0383:                 * @return String whose length is the largest among the items in either list
0384:                 */
0385:                public String getPrototypeCell() {
0386:                    return listPrototype;
0387:                }
0388:
0389:                /**
0390:                 * Returns index of source item matching the given string.
0391:                 *
0392:                 * @param searchStr string to search for in source list
0393:                 * @param startFrom index from which to start search
0394:                 * @return index of matching item, or -1 if no match exists
0395:                 */
0396:                public int getSourceIndexFor(String searchStr, int startFrom) {
0397:                    if (startFrom < 0 || startFrom > source.size()) {
0398:                        startFrom = 0;
0399:                    }
0400:
0401:                    if (searchStr != null && searchStr.trim().length() != 0) {
0402:                        return source.indexOf(searchStr, startFrom);
0403:                    }
0404:
0405:                    return -1;
0406:                }
0407:
0408:                /**
0409:                 * Gets copy of current contents of source list
0410:                 *
0411:                 * @return List of current source list contents
0412:                 */
0413:                public List getSourceList() {
0414:                    ArrayList<Object> srcList = new ArrayList<Object>();
0415:
0416:                    synchronized (source) {
0417:                        source.trimToSize();
0418:                        for (int i = 0; i < source.size(); i++) {
0419:                            srcList.add(source.get(i));
0420:                        }
0421:                    }
0422:                    return srcList;
0423:                }
0424:
0425:                /**
0426:                 * Gets ListModel associated with source list.
0427:                 *
0428:                 * @return source ListModel
0429:                 */
0430:                public ListModel getSourceModel() {
0431:                    return source;
0432:                }
0433:
0434:                /**
0435:                 * Moves indicated items from destination to source list.
0436:                 *
0437:                 * @param selections array of selected items
0438:                 * @param indices array of indices, each element corresponding to the item in
0439:                 *        selections array
0440:                 */
0441:                public void remove(Object[] selections, int[] indices) {
0442:                    synchronized (dest) {
0443:                        synchronized (source) {
0444:                            for (int i = 0; i < indices.length; i++) {
0445:                                Object element = selections[i];
0446:                                source.addElement(element);
0447:                                dest.removeElement(element);
0448:                                fireTransferEvent(dest, element,
0449:                                        TransferEvent.REMOVED);
0450:                            }
0451:                        }
0452:                    }
0453:                    List tableNameList = getTableNames(dest);
0454:                    ETLCollaborationWizardTransferPanel.this .tablePanel
0455:                            .resetTable(tableNameList);
0456:                    // fire change event so that next button can be enabled as we remove new rows
0457:                    // in table
0458:                    fireChangeEvent();
0459:                }
0460:
0461:                /**
0462:                 * Remove a ChangeListener from this model.
0463:                 *
0464:                 * @param l ChangeListener to remove
0465:                 */
0466:                public void removeChangeListener(ChangeListener l) {
0467:                    if (l != null) {
0468:                        synchronized (changeListeners) {
0469:                            changeListeners.remove(l);
0470:                        }
0471:                    }
0472:                }
0473:
0474:                /**
0475:                 * Sets destination list to include contents of given list. Clears current
0476:                 * contents before adding items from newList.
0477:                 *
0478:                 * @param newList List whose contents will supplant the current contents of the
0479:                 *        destination list
0480:                 */
0481:                public void setDestinationList(Collection newList) {
0482:                    if (newList == null) {
0483:                        throw new IllegalArgumentException(
0484:                                "Must supply non-null Collection for newList");
0485:                    }
0486:
0487:                    if (dest == null) {
0488:                        dest = new DefaultComboBoxModel();
0489:                    }
0490:
0491:                    synchronized (dest) {
0492:                        dest.removeAllElements();
0493:
0494:                        Iterator it = newList.iterator();
0495:                        while (it.hasNext()) {
0496:                            Object o = it.next();
0497:                            dest.addElement(o);
0498:                            if (o.toString().trim().length() > listPrototype
0499:                                    .length()) {
0500:                                listPrototype = o.toString().trim();
0501:                            }
0502:                        }
0503:                    }
0504:                }
0505:
0506:                /**
0507:                 * Sets source list to include contents of given list. Clears current contents
0508:                 * before adding items from newList.
0509:                 *
0510:                 * @param newList List whose contents will supplant the current contents of the
0511:                 *        source list
0512:                 */
0513:                public void setSourceList(Collection newList) {
0514:                    if (newList == null) {
0515:                        throw new IllegalArgumentException(
0516:                                "Must supply non-null Collection for newList");
0517:                    }
0518:
0519:                    if (source == null) {
0520:                        source = new DefaultListModel();
0521:                    }
0522:
0523:                    synchronized (source) {
0524:                        source.clear();
0525:
0526:                        Iterator it = newList.iterator();
0527:                        while (it.hasNext()) {
0528:                            Object o = it.next();
0529:                            source.addElement(o);
0530:                            if (o.toString().trim().length() > listPrototype
0531:                                    .length()) {
0532:                                listPrototype = o.toString().trim();
0533:                            }
0534:                        }
0535:                    }
0536:                }
0537:
0538:                private void fireTransferEvent(Object src, Object item, int type) {
0539:                    if (src != null && item != null) {
0540:                        TransferEvent e = new TransferEvent(src, item, type);
0541:                        synchronized (changeListeners) {
0542:                            Iterator iter = changeListeners.iterator();
0543:                            while (iter.hasNext()) {
0544:                                ChangeListener l = (ChangeListener) iter.next();
0545:                                l.stateChanged(e);
0546:                            }
0547:                        }
0548:                    }
0549:                }
0550:            }
0551:
0552:            class DBModelNameCellRenderer extends DefaultListCellRenderer {
0553:
0554:                public DBModelNameCellRenderer(String protoString) {
0555:                    super ();
0556:                    setText(protoString.toString());
0557:                }
0558:
0559:                @Override
0560:                public Component getListCellRendererComponent(JList list,
0561:                        Object value, int index, boolean isSelected,
0562:                        boolean cellHasFocus) {
0563:
0564:                    if (isSelected) {
0565:                        this .setBackground(list.getSelectionBackground());
0566:                        this .setForeground(list.getSelectionForeground());
0567:                    } else {
0568:                        this .setBackground(list.getBackground());
0569:                        this .setForeground(list.getForeground());
0570:                    }
0571:
0572:                    this .setEnabled(list.isEnabled());
0573:                    this .setFont(list.getFont());
0574:                    this .setOpaque(true);
0575:
0576:                    if (value instanceof  SQLDBModel) {
0577:                        SQLDBModel model = (SQLDBModel) value;
0578:                        if (model.getDisplayName() != null) {
0579:                            this .setText(model.getDisplayName());
0580:                        } else {
0581:                            this .setText(model.getModelName());
0582:                        }
0583:                    } else if (value instanceof  DatabaseConnection) {
0584:                        this .setText(DBExplorerUtil
0585:                                .getDisplayName(((DatabaseConnection) value)));
0586:                    } else if (value instanceof  String) {
0587:                        this .setText((String) value);
0588:                    }
0589:
0590:                    return this ;
0591:                }
0592:            }
0593:
0594:            /** Command requesting search of source list for a given string */
0595:            public static final String CMD_SEARCH = "Search";
0596:            /** Indicates addition of item(s). */
0597:            public static final String LBL_ADD = ">";
0598:            /** Label indicating that all elements should be moved. */
0599:            public static final String nbBundle1 = mLoc.t("PRSR001: ALL");
0600:            public static final String LBL_ALL = Localizer.parse(nbBundle1);
0601:            /** Indicates addition of all source items. */
0602:            public static final String LBL_ADD_ALL = LBL_ALL + " " + LBL_ADD;
0603:            /** Describes destination list */
0604:            public static final String nbBundle8 = mLoc.t("PRSR001: Schemas:");
0605:            public static final String LBL_DEST_MSG = Localizer
0606:                    .parse(nbBundle8);
0607:            /** Indicates removal of item(s). */
0608:            public static final String LBL_REMOVE = "<";
0609:            /** Indicates removal of all destination items. */
0610:            public static final String LBL_REMOVE_ALL = LBL_REMOVE + " "
0611:                    + LBL_ALL;
0612:            /** Describes source list and user task. */
0613:            public static final String nbBundle2 = mLoc
0614:                    .t("PRSR001: Available Connections:");
0615:            public static final String LBL_SOURCE_MSG = Localizer
0616:                    .parse(nbBundle2);
0617:            /** Maximum number of visible items in lists */
0618:            public static final int MAXIMUM_VISIBLE = 10;
0619:            /** Minimum number of visible items in lists */
0620:            public static final int MINIMUM_VISIBLE = 5;
0621:            /** Tooltip to describe addition of selected item(s). */
0622:            public static final String nbBundle3 = mLoc
0623:                    .t("PRSR001: Add to selected items");
0624:            public static final String TIP_ADD = Localizer.parse(nbBundle3);
0625:            /** Tooltip to describe addition of all source items. */
0626:            public static final String nbBundle4 = mLoc
0627:                    .t("PRSR001: Add all items");
0628:            public static final String TIP_ADD_ALL = Localizer.parse(nbBundle4);
0629:            /** Tooltip to describe addition of selected item(s). */
0630:            public static final String nbBundle5 = mLoc
0631:                    .t("PRSR001: Remove from selected items");
0632:            public static final String TIP_REMOVE = Localizer.parse(nbBundle5);
0633:            /** Tooltip to describe removal of all destination items. */
0634:            public static final String nbBundle6 = mLoc
0635:                    .t("PRSR001: Remove all items");
0636:            public static final String TIP_REMOVE_ALL = Localizer
0637:                    .parse(nbBundle6);
0638:
0639:            /**
0640:             * Indicates whether Databases in the given List have enough selected tables to allow for
0641:             * creation of a join from among the set of tables.
0642:             *
0643:             * @return true if number of selected tables is sufficient to create a join; false
0644:             *         otherwise
0645:             */
0646:            static boolean hasEnoughTablesForJoin(List db) {
0647:                return (getSelectedTableCount(db) >= 2);
0648:            }
0649:
0650:            /**
0651:             * Counts number of selected tables in the given List of Databases.
0652:             *
0653:             * @param srcDb List of Databases to iterate through
0654:             * @return count of selected tables in <code>srcDb</code>
0655:             */
0656:            private static int getSelectedTableCount(List db) {
0657:                int selected = 0;
0658:
0659:                Iterator dbIter = db.iterator();
0660:                while (dbIter.hasNext()) {
0661:                    SQLDBModel dbModel = (SQLDBModel) dbIter.next();
0662:                    Iterator tblIter = dbModel.getTables().iterator();
0663:                    while (tblIter.hasNext()) {
0664:                        if (((SQLDBTable) tblIter.next()).isSelected()) {
0665:                            selected++;
0666:                        }
0667:                    }
0668:                }
0669:
0670:                return selected;
0671:            }
0672:
0673:            private static List getTableNames(ListModel dest) {
0674:                ArrayList<DBTable> tabNameList = new ArrayList<DBTable>();
0675:                for (int i = 0; i < dest.getSize(); i++) {
0676:                    DatabaseModel db = (DatabaseModel) dest.getElementAt(i);
0677:                    if (db != null) {
0678:
0679:                        tabNameList.addAll(db.getTables());
0680:                    }
0681:                }
0682:                return tabNameList;
0683:            }
0684:
0685:            private javax.swing.JButton selectButton;
0686:            private javax.swing.JButton removeButton;
0687:            private javax.swing.JComboBox schemaComboBox;
0688:            private javax.swing.JLabel srcLabel;
0689:            private javax.swing.JLabel destLabel;
0690:            private javax.swing.JLabel jLabel3;
0691:            private javax.swing.JList sourceList;
0692:            private javax.swing.JList schemaTablesList;
0693:            private javax.swing.JScrollPane jScrollPane1;
0694:            private javax.swing.JScrollPane jScrollPane2;
0695:            private javax.swing.JScrollPane jScrollPane3;
0696:            private javax.swing.JTable jTable1;
0697:
0698:            private void initComponents() {
0699:                srcLabel = new javax.swing.JLabel();
0700:                srcLabel.setDisplayedMnemonic(LBL_SOURCE_MSG.charAt(0));
0701:                jScrollPane1 = new javax.swing.JScrollPane();
0702:                destLabel = new javax.swing.JLabel();
0703:                destLabel.setDisplayedMnemonic(LBL_DEST_MSG.charAt(0));
0704:                jScrollPane2 = new javax.swing.JScrollPane();
0705:                schemaTablesList = new javax.swing.JList();
0706:                jLabel3 = new javax.swing.JLabel();
0707:                jScrollPane3 = new javax.swing.JScrollPane();
0708:                jTable1 = new javax.swing.JTable();
0709:                jTable1.setAutoscrolls(true);
0710:                selectButton = new javax.swing.JButton();
0711:                removeButton = new javax.swing.JButton();
0712:                //jButton3 = new javax.swing.JButton();
0713:                srcLabel.setText(LBL_SOURCE_MSG);
0714:                srcLabel.setName("srcLabel");
0715:                srcLabel.getAccessibleContext().setAccessibleName(
0716:                        LBL_SOURCE_MSG);
0717:                jScrollPane1.setViewportView(sourceList);
0718:
0719:                destLabel.setText(LBL_DEST_MSG);
0720:                destLabel.setName("destLabel");
0721:                destLabel.getAccessibleContext()
0722:                        .setAccessibleName(LBL_DEST_MSG);
0723:                schemaTablesList.setModel(new javax.swing.AbstractListModel() {
0724:
0725:                    String[] strings = { "" };
0726:
0727:                    public int getSize() {
0728:                        return strings.length;
0729:                    }
0730:
0731:                    public Object getElementAt(int i) {
0732:                        return strings[i];
0733:                    }
0734:                });
0735:                String nbBundle20 = mLoc.t("PRSR001: schemaTables");
0736:                schemaTablesList.setName(Localizer.parse(nbBundle20));
0737:                schemaTablesList.getAccessibleContext().setAccessibleName(
0738:                        Localizer.parse(nbBundle20));
0739:                schemaTablesList
0740:                        .addMouseListener(new java.awt.event.MouseAdapter() {
0741:
0742:                            @Override
0743:                            public void mouseClicked(
0744:                                    java.awt.event.MouseEvent evt) {
0745:                                if (evt.getClickCount() == 2
0746:                                        && evt.getSource() instanceof  JList) {
0747:                                    moveSelectedTables();
0748:                                } // end if
0749:                            }
0750:                        });
0751:
0752:                jScrollPane2.setViewportView(schemaTablesList);
0753:                String nbBundle9 = mLoc.t("PRSR001: Selected Tables:");
0754:                jLabel3.setText(Localizer.parse(nbBundle9));
0755:                jLabel3.getAccessibleContext().setAccessibleName(
0756:                        Localizer.parse(nbBundle20));
0757:                jLabel3.setName("selectedTablesLabel");
0758:                jLabel3.setDisplayedMnemonic(Localizer.parse(nbBundle9).charAt(
0759:                        0));
0760:
0761:                jTable1.setModel(new javax.swing.table.DefaultTableModel(
0762:                        new Object[][] {}, new String[] { "Name", "Schema",
0763:                                "User", "Connection" }));
0764:                jTable1.setName("selectedTables");
0765:                jTable1.getAccessibleContext().setAccessibleName(
0766:                        Localizer.parse(nbBundle9));
0767:                jScrollPane3.setViewportView(jTable1);
0768:                jScrollPane3.setAutoscrolls(true);
0769:
0770:                String nbBundle30 = mLoc.t("PRSR001: Select");
0771:                selectButton.setText(Localizer.parse(nbBundle30));
0772:                selectButton.getAccessibleContext().setAccessibleName(
0773:                        Localizer.parse(nbBundle30));
0774:                selectButton.setMnemonic(Localizer.parse(nbBundle30).charAt(0));
0775:                selectButton.addActionListener(this );
0776:
0777:                String nbBundle31 = mLoc.t("PRSR001: Remove");
0778:                removeButton.setText(Localizer.parse(nbBundle31));
0779:                removeButton.getAccessibleContext().setAccessibleName(
0780:                        Localizer.parse(nbBundle31));
0781:                removeButton.setMnemonic(Localizer.parse(nbBundle31).charAt(0));
0782:                removeButton.addActionListener(this );
0783:                removeButton.setEnabled(false);
0784:
0785:                org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
0786:                        this );
0787:                this .setLayout(layout);
0788:                layout
0789:                        .setHorizontalGroup(layout
0790:                                .createParallelGroup(
0791:                                        org.jdesktop.layout.GroupLayout.LEADING)
0792:                                .add(
0793:                                        layout
0794:                                                .createSequentialGroup()
0795:                                                .addContainerGap()
0796:                                                .add(
0797:                                                        layout
0798:                                                                .createParallelGroup(
0799:                                                                        org.jdesktop.layout.GroupLayout.LEADING)
0800:                                                                .add(
0801:                                                                        layout
0802:                                                                                .createSequentialGroup()
0803:                                                                                .add(
0804:                                                                                        jLabel3)
0805:                                                                                .addContainerGap(
0806:                                                                                        519,
0807:                                                                                        Short.MAX_VALUE))
0808:                                                                .add(
0809:                                                                        org.jdesktop.layout.GroupLayout.TRAILING,
0810:                                                                        layout
0811:                                                                                .createSequentialGroup()
0812:                                                                                .add(
0813:                                                                                        layout
0814:                                                                                                .createParallelGroup(
0815:                                                                                                        org.jdesktop.layout.GroupLayout.TRAILING)
0816:                                                                                                .add(
0817:                                                                                                        org.jdesktop.layout.GroupLayout.LEADING,
0818:                                                                                                        jScrollPane3,
0819:                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0820:                                                                                                        421,
0821:                                                                                                        Short.MAX_VALUE)
0822:                                                                                                .add(
0823:                                                                                                        layout
0824:                                                                                                                .createSequentialGroup()
0825:                                                                                                                .add(
0826:                                                                                                                        layout
0827:                                                                                                                                .createParallelGroup(
0828:                                                                                                                                        org.jdesktop.layout.GroupLayout.LEADING)
0829:                                                                                                                                .add(
0830:                                                                                                                                        srcLabel)
0831:                                                                                                                                .add(
0832:                                                                                                                                        jScrollPane1,
0833:                                                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0834:                                                                                                                                        195,
0835:                                                                                                                                        Short.MAX_VALUE))
0836:                                                                                                                .add(
0837:                                                                                                                        26,
0838:                                                                                                                        26,
0839:                                                                                                                        26)
0840:                                                                                                                .add(
0841:                                                                                                                        layout
0842:                                                                                                                                .createParallelGroup(
0843:                                                                                                                                        org.jdesktop.layout.GroupLayout.TRAILING)
0844:                                                                                                                                .add(
0845:                                                                                                                                        layout
0846:                                                                                                                                                .createParallelGroup(
0847:                                                                                                                                                        org.jdesktop.layout.GroupLayout.LEADING)
0848:                                                                                                                                                .add(
0849:                                                                                                                                                        schemaComboBox,
0850:                                                                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0851:                                                                                                                                                        198,
0852:                                                                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0853:                                                                                                                                                .add(
0854:                                                                                                                                                        destLabel))
0855:                                                                                                                                .add(
0856:                                                                                                                                        jScrollPane2,
0857:                                                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0858:                                                                                                                                        200,
0859:                                                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
0860:                                                                                .add(
0861:                                                                                        23,
0862:                                                                                        23,
0863:                                                                                        23)
0864:                                                                                .add(
0865:                                                                                        layout
0866:                                                                                                .createParallelGroup(
0867:                                                                                                        org.jdesktop.layout.GroupLayout.TRAILING,
0868:                                                                                                        false)
0869:                                                                                                //.add(jButton3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
0870:                                                                                                .add(
0871:                                                                                                        removeButton,
0872:                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0873:                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0874:                                                                                                        Short.MAX_VALUE)
0875:                                                                                                .add(
0876:                                                                                                        selectButton,
0877:                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0878:                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0879:                                                                                                        Short.MAX_VALUE))
0880:                                                                                .add(
0881:                                                                                        35,
0882:                                                                                        35,
0883:                                                                                        35)))));
0884:                layout
0885:                        .setVerticalGroup(layout
0886:                                .createParallelGroup(
0887:                                        org.jdesktop.layout.GroupLayout.LEADING)
0888:                                .add(
0889:                                        layout
0890:                                                .createSequentialGroup()
0891:                                                .addContainerGap()
0892:                                                .add(
0893:                                                        layout
0894:                                                                .createParallelGroup(
0895:                                                                        org.jdesktop.layout.GroupLayout.TRAILING,
0896:                                                                        false)
0897:                                                                .add(
0898:                                                                        org.jdesktop.layout.GroupLayout.LEADING,
0899:                                                                        layout
0900:                                                                                .createSequentialGroup()
0901:                                                                                .add(
0902:                                                                                        srcLabel)
0903:                                                                                .addPreferredGap(
0904:                                                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0905:                                                                                .add(
0906:                                                                                        jScrollPane1,
0907:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0908:                                                                                        130,
0909:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
0910:                                                                .add(
0911:                                                                        org.jdesktop.layout.GroupLayout.LEADING,
0912:                                                                        layout
0913:                                                                                .createSequentialGroup()
0914:                                                                                .add(
0915:                                                                                        destLabel)
0916:                                                                                .addPreferredGap(
0917:                                                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0918:                                                                                .add(
0919:                                                                                        schemaComboBox,
0920:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0921:                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0922:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0923:                                                                                .addPreferredGap(
0924:                                                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0925:                                                                                .add(
0926:                                                                                        layout
0927:                                                                                                .createParallelGroup(
0928:                                                                                                        org.jdesktop.layout.GroupLayout.LEADING)
0929:                                                                                                .add(
0930:                                                                                                        layout
0931:                                                                                                                .createSequentialGroup()
0932:                                                                                                                //.add(jButton3)
0933:                                                                                                                .addPreferredGap(
0934:                                                                                                                        org.jdesktop.layout.LayoutStyle.RELATED,
0935:                                                                                                                        56,
0936:                                                                                                                        Short.MAX_VALUE)
0937:                                                                                                                .add(
0938:                                                                                                                        selectButton))
0939:                                                                                                .add(
0940:                                                                                                        jScrollPane2,
0941:                                                                                                        0,
0942:                                                                                                        0,
0943:                                                                                                        Short.MAX_VALUE))))
0944:                                                .add(20, 20, 20)
0945:                                                .add(
0946:                                                        layout
0947:                                                                .createParallelGroup(
0948:                                                                        org.jdesktop.layout.GroupLayout.TRAILING)
0949:                                                                .add(
0950:                                                                        layout
0951:                                                                                .createSequentialGroup()
0952:                                                                                .add(
0953:                                                                                        jLabel3)
0954:                                                                                .addPreferredGap(
0955:                                                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0956:                                                                                .add(
0957:                                                                                        jScrollPane3,
0958:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0959:                                                                                        214,
0960:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
0961:                                                                .add(
0962:                                                                        removeButton))
0963:                                                .addContainerGap(66,
0964:                                                        Short.MAX_VALUE)));
0965:            }// </editor-fold>
0966:
0967:            private JButton addButton;
0968:            private boolean isSource;
0969:            /* Set <ChangeListeners> */
0970:            private final Set<ChangeListener> listeners = new HashSet<ChangeListener>(
0971:                    1);
0972:            private ListTransferModel listModel;
0973:            /* private JLabel srcLabel;*/
0974:            private ETLCollaborationWizardTablePanel tablePanel;
0975:            /**
0976:             * place holder to determine the selected database connection
0977:             */
0978:            private DatabaseConnection selectedConnection = null;
0979:            private HashMap<String, DatabaseConnection> nameToConnMap = null;
0980:
0981:            /** Creates a default instance of ETLCollaborationWizardTransferPanel. */
0982:            public ETLCollaborationWizardTransferPanel() {
0983:            }
0984:
0985:            /**
0986:             * Creates a new instance of ETLCollaborationWizardTransferPanel using the given
0987:             * ListModels to initially populate the source and destination panels.
0988:             *
0989:             * @param title String to be displayed as title of this panel
0990:             * @param dsList List of DatabaseModels used to populate datasource panel
0991:             * @param destColl Collection of selected DatabaseModels
0992:             * @param sourceDb true if this panel displays available selections for source Databases;
0993:             *        false if it displays available destination Databases
0994:             */
0995:            public ETLCollaborationWizardTransferPanel(String title,
0996:                    List dsList, Collection destColl, boolean sourceDb) {
0997:                this ();
0998:                nameToConnMap = new HashMap<String, DatabaseConnection>();
0999:                if (title != null && title.trim().length() != 0) {
1000:                    setName(title);
1001:                }
1002:
1003:                this .isSource = sourceDb;
1004:                listModel = new ListTransferModel(dsList, destColl);
1005:                String largestString = listModel.getPrototypeCell();
1006:
1007:                if (largestString.length() < LBL_SOURCE_MSG.length()) {
1008:                    largestString = LBL_SOURCE_MSG;
1009:                } else if (largestString.length() < LBL_DEST_MSG.length()) {
1010:                    largestString = LBL_DEST_MSG;
1011:                }
1012:
1013:                int visibleCt = Math.min(Math.max(MINIMUM_VISIBLE, listModel
1014:                        .getMaximumListSize()), MAXIMUM_VISIBLE);
1015:                sourceList = new JList(listModel.getSourceModel());
1016:                sourceList.addMouseListener(new MouseAdapter() {
1017:
1018:                    @Override
1019:                    public void mouseClicked(MouseEvent e) {
1020:                        ((DefaultComboBoxModel) listModel.getDestinationModel())
1021:                                .removeAllElements();
1022:                        schemaTablesList.setListData(new Vector());
1023:                        DatabaseConnection conn = (DatabaseConnection) listModel
1024:                                .getSourceModel().getElementAt(
1025:                                        sourceList.getSelectedIndex());
1026:                        // assigning the conn to the placeholder for current selected
1027:                        // connection
1028:                        selectedConnection = conn;
1029:                        DBMetaDataFactory meta = new DBMetaDataFactory();
1030:                        try {
1031:                            meta.connectDB(DBExplorerUtil
1032:                                    .createConnection(selectedConnection));
1033:                            if (selectedConnection.getDatabaseURL().startsWith(
1034:                                    "jdbc:axiondb:")) {
1035:                                schemaComboBox.setEnabled(false);
1036:                                populateTableList("");
1037:                            } else if (selectedConnection.getDatabaseURL()
1038:                                    .startsWith("jdbc:mysql:")) {
1039:                                schemaComboBox.setEnabled(false);
1040:                                populateTableList("");
1041:                            } else {
1042:                                // Get all Schemas from meta
1043:                                schemaComboBox.setEnabled(true);
1044:                                String[] schemas = meta.getSchemas();
1045:                                listModel.add(schemas);
1046:                                schemaComboBox
1047:                                        .setSelectedItem(selectedConnection
1048:                                                .getUser().toUpperCase());
1049:                                populateTableList(selectedConnection.getUser()
1050:                                        .toUpperCase());
1051:
1052:                            }
1053:                        } catch (Exception ex) {
1054:                            mLogger.errorNoloc(mLoc.t(
1055:                                    "PRSR031: Error retrieving schemas{0}",
1056:                                    LOG_CATEGORY), ex);
1057:                            throw new RuntimeException(ex.getCause());
1058:                        } finally {
1059:                            meta.disconnectDB();
1060:                        }
1061:                    }
1062:                });
1063:                sourceList.addListSelectionListener(this );
1064:                DBModelNameCellRenderer srcRenderer = new DBModelNameCellRenderer(
1065:                        largestString);
1066:                sourceList.setPrototypeCellValue(srcRenderer);
1067:                sourceList.setCellRenderer(srcRenderer);
1068:                sourceList.setVisibleRowCount(visibleCt);
1069:
1070:                ArrayList testList = new ArrayList();
1071:                tablePanel = new ETLCollaborationWizardTablePanel(testList);
1072:                schemaComboBox = new JComboBox((DefaultComboBoxModel) listModel
1073:                        .getDestinationModel());
1074:
1075:                schemaComboBox.addActionListener(this );
1076:                initComponents();
1077:            }
1078:
1079:            private List getSelectedDBModels(boolean isSource) throws Exception {
1080:                AbstractDBTable newTable = null;
1081:                String connName = null;
1082:                HashMap<String, SQLDBModel> nameToDBModelMap = new HashMap<String, SQLDBModel>();
1083:                List<SQLDBModel> dbModels = new ArrayList<SQLDBModel>();
1084:                List tableList = this .listModel.getSelectedTablesList();
1085:                if (tableList != null) {
1086:                    for (int i = 0; i < tableList.size(); i++) {
1087:                        newTable = (AbstractDBTable) tableList.get(i);
1088:                        connName = this .listModel.getConnectionNameForTable(
1089:                                newTable.getQualifiedName(), newTable
1090:                                        .getSchema());
1091:                        DatabaseConnection conn = this .nameToConnMap
1092:                                .get(connName);
1093:                        if (conn != null) {
1094:
1095:                            // Add all tables to database
1096:                            DBMetaDataFactory meta = new DBMetaDataFactory();
1097:                            try {
1098:                                meta.connectDB(DBExplorerUtil
1099:                                        .createConnection(conn));
1100:
1101:                                // we are now using SQLDBModel and SQLTable etc
1102:                                SQLDBModel model = nameToDBModelMap
1103:                                        .get(connName);
1104:                                if (model == null) {
1105:                                    int type = SQLConstants.TARGET_DBMODEL;
1106:                                    if (isSource) {
1107:                                        type = SQLConstants.SOURCE_DBMODEL;
1108:                                    }
1109:                                    model = SQLModelObjectFactory.getInstance()
1110:                                            .createDBModel(type);
1111:                                    populateModel(model, conn, meta);
1112:                                    nameToDBModelMap.put(connName, model);
1113:                                }
1114:
1115:                                meta.populateColumns(newTable);
1116:                                newTable.setEditable(true);
1117:                                newTable.setSelected(true);
1118:                                model.addTable(newTable);
1119:                            } catch (Exception e) {
1120:                                throw e;
1121:                            } finally {
1122:                                meta.disconnectDB();
1123:                            }
1124:                        }
1125:                    }
1126:                }
1127:                Iterator iter = nameToDBModelMap.values().iterator();
1128:                while (iter.hasNext()) {
1129:                    SQLDBModel model = (SQLDBModel) iter.next();
1130:                    dbModels.add(model);
1131:                }
1132:                return dbModels;
1133:            }
1134:
1135:            private SQLDBModel populateModel(SQLDBModel model,
1136:                    DatabaseConnection conn, DBMetaDataFactory meta) {
1137:                DBConnectionDefinition def = null;
1138:                try {
1139:                    def = SQLModelObjectFactory
1140:                            .getInstance()
1141:                            .createDBConnectionDefinition(
1142:                                    conn.getDisplayName(), meta.getDBType(),
1143:                                    conn.getDriverClass(),
1144:                                    conn.getDatabaseURL(), conn.getUser(),
1145:                                    conn.getPassword(), "Descriptive info here");
1146:                } catch (Exception ex) {
1147:                    // ignore
1148:                }
1149:                model.setModelName(conn.getDisplayName());
1150:                model.setConnectionDefinition(def);
1151:                return model;
1152:            }
1153:
1154:            /**
1155:             * Invoked whenever one of the transfer buttons is clicked.
1156:             *
1157:             * @param e
1158:             *            ActionEvent to handle
1159:             */
1160:            public void actionPerformed(ActionEvent e) {
1161:                if (e.getSource() instanceof  JComboBox) {
1162:                    populateTableList((String) schemaComboBox.getSelectedItem());
1163:                }
1164:
1165:                String cmd = e.getActionCommand();
1166:                if ("Select".equals(cmd)) {
1167:                    moveSelectedTables();
1168:                } else if ("Remove".equals(cmd)) {
1169:                    int[] indexes = jTable1.getSelectedRows();
1170:                    for (int ii = 0; ii < indexes.length; ii++) {
1171:                        if ((indexes[ii] >= 0) && (jTable1.getRowCount() >= 1)) {
1172:                            listModel.removeFromSelectedTables(indexes[ii]);
1173:                        }
1174:                        for (int j = 0; j < indexes.length; j++) {
1175:                            indexes[j]--;
1176:                        }
1177:                    }
1178:
1179:                    jTable1.setModel(listModel.getSelectedTablesModel());
1180:                    if (listModel.getSelectedTablesModel().getRowCount() < 1) {
1181:                        this .removeButton.setEnabled(false);
1182:                    }
1183:                }
1184:            } //end actionPerformed
1185:
1186:            private void populateTableList(String schemaName) {
1187:                DBMetaDataFactory dbMeta = new DBMetaDataFactory();
1188:                try {
1189:                    if (ETLCollaborationWizardTransferPanel.this .selectedConnection == null) {
1190:                        mLogger.infoNoloc(mLoc.t(
1191:                                "PRSR032: selectedConn is null{0}",
1192:                                LOG_CATEGORY));
1193:                    }
1194:
1195:                    if ((selectedConnection != null)) {
1196:                        dbMeta.connectDB(DBExplorerUtil
1197:                                .createConnection(selectedConnection));
1198:                        String[][] tableList = dbMeta.getTablesAndViews("",
1199:                                schemaName, "", false);
1200:                        SQLDBTable aTable = null;
1201:                        String[] currTable = null;
1202:                        Vector<SQLDBTable> tableNameList = new Vector<SQLDBTable>();
1203:                        if (tableList != null) {
1204:                            for (int i = 0; i < tableList.length; i++) {
1205:                                currTable = tableList[i];
1206:                                if (isSource) {
1207:                                    aTable = new SourceTableImpl(
1208:                                            currTable[DBMetaDataFactory.NAME],
1209:                                            currTable[DBMetaDataFactory.SCHEMA],
1210:                                            currTable[DBMetaDataFactory.CATALOG]);
1211:                                } else {
1212:                                    aTable = new TargetTableImpl(
1213:                                            currTable[DBMetaDataFactory.NAME],
1214:                                            currTable[DBMetaDataFactory.SCHEMA],
1215:                                            currTable[DBMetaDataFactory.CATALOG]);
1216:                                }
1217:                                tableNameList.add(aTable);
1218:                            }
1219:                        }
1220:                        schemaTablesList.setListData(tableNameList);
1221:                    }
1222:                } catch (Exception ex) {
1223:                    mLogger
1224:                            .errorNoloc(
1225:                                    mLoc
1226:                                            .t(
1227:                                                    "PRSR033: Error trying to retrieve tables and views{0}",
1228:                                                    LOG_CATEGORY), ex);
1229:                } finally {
1230:                    dbMeta.disconnectDB();
1231:                }
1232:            }
1233:
1234:            private String generateTableAliasName(boolean isSource) {
1235:                int cnt = 1;
1236:                String aliasPrefix = isSource ? "S" : "T";
1237:                String aName = aliasPrefix + cnt;
1238:                while (isTableAliasNameExist(aName)) {
1239:                    cnt++;
1240:                    aName = aliasPrefix + cnt;
1241:                }
1242:
1243:                return aName;
1244:            }
1245:
1246:            private boolean isTableAliasNameExist(String aName) {
1247:                List sTables = this .listModel.getSelectedTablesList();
1248:                Iterator it = sTables.iterator();
1249:
1250:                while (it.hasNext()) {
1251:                    SQLDBTable tTable = (SQLDBTable) it.next();
1252:                    String tAlias = tTable.getAliasName();
1253:                    if (tAlias != null && tAlias.equals(aName)) {
1254:                        return true;
1255:                    }
1256:                }
1257:
1258:                return false;
1259:            }
1260:
1261:            /**
1262:             *
1263:             */
1264:            private void moveSelectedTables() {
1265:                // add selected tables from the list to table
1266:                try {
1267:                    if (ETLCollaborationWizardTransferPanel.this .selectedConnection == null) {
1268:                        mLogger.infoNoloc(mLoc.t(
1269:                                "PRSR034: selectedConn is null{0}",
1270:                                LOG_CATEGORY));
1271:                    }
1272:
1273:                    Object[] selectedTables = schemaTablesList
1274:                            .getSelectedValues();
1275:                    Object[] clonedTables = new Object[selectedTables.length];
1276:                    for (int i = 0; i < selectedTables.length; i++) {
1277:                        if (isSource) {
1278:                            clonedTables[i] = ((SourceTableImpl) selectedTables[i])
1279:                                    .clone();
1280:                        } else {
1281:                            clonedTables[i] = ((TargetTableImpl) selectedTables[i])
1282:                                    .clone();
1283:                        }
1284:                    }
1285:
1286:                    String[][] tablesList = new String[selectedTables.length][4];
1287:                    if (selectedTables.length > 0) {
1288:                        for (int i = 0; i < selectedTables.length; i++) {
1289:                            String tableAliasName = generateTableAliasName(isSource);
1290:
1291:                            if (isSource) {
1292:                                ((SourceTableImpl) clonedTables[i])
1293:                                        .setAliasName(tableAliasName);
1294:                                tablesList[i][0] = ((SourceTableImpl) clonedTables[i])
1295:                                        .getQualifiedName();
1296:                                tablesList[i][1] = ((SourceTableImpl) clonedTables[i])
1297:                                        .getSchema();
1298:                                tablesList[i][2] = ((SourceTableImpl) clonedTables[i])
1299:                                        .getCatalog();
1300:                            } else {
1301:                                ((TargetTableImpl) clonedTables[i])
1302:                                        .setAliasName(tableAliasName);
1303:                                tablesList[i][0] = ((TargetTableImpl) clonedTables[i])
1304:                                        .getQualifiedName();
1305:                                tablesList[i][1] = ((TargetTableImpl) clonedTables[i])
1306:                                        .getSchema();
1307:                                tablesList[i][2] = ((TargetTableImpl) clonedTables[i])
1308:                                        .getCatalog();
1309:                            }
1310:                            tablesList[i][3] = selectedConnection.getName();
1311:                            this .nameToConnMap.put(
1312:                                    selectedConnection.getName(),
1313:                                    selectedConnection);
1314:                            listModel.addToSelectedTables(tablesList[i],
1315:                                    (SQLDBTable) clonedTables[i]);
1316:                        }
1317:                    }
1318:
1319:                    jTable1.setModel(listModel.getSelectedTablesModel());
1320:                    if (listModel.getSelectedTablesModel().getRowCount() > 0) {
1321:                        this .removeButton.setEnabled(true);
1322:                    }
1323:                } catch (Exception ex) {
1324:                    mLogger
1325:                            .errorNoloc(
1326:                                    mLoc
1327:                                            .t(
1328:                                                    "PRSR035: Error trying to get selected table metadata{0}",
1329:                                                    LOG_CATEGORY), ex);
1330:                }
1331:            }
1332:
1333:            /**
1334:             * @see org.openide.WizardDescriptor.Panel#addChangeListener
1335:             */
1336:            public void addChangeListener(ChangeListener l) {
1337:                synchronized (listeners) {
1338:                    listeners.add(l);
1339:                }
1340:            }
1341:
1342:            /**
1343:             * Fires a ChangeEvent to all interested listeners to indicate a state change in one
1344:             * or more UI components.
1345:             */
1346:            public void fireChangeEvent() {
1347:                Iterator it;
1348:
1349:                synchronized (listeners) {
1350:                    it = new HashSet<ChangeListener>(listeners).iterator();
1351:                }
1352:
1353:                ChangeEvent ev = new ChangeEvent(this );
1354:                while (it.hasNext()) {
1355:                    ((ChangeListener) it.next()).stateChanged(ev);
1356:                }
1357:            }
1358:
1359:            /**
1360:             * @see org.openide.WizardDescriptor.Panel#getComponent
1361:             */
1362:            public Component getComponent() {
1363:                return this ;
1364:            }
1365:
1366:            /**
1367:             * @see org.openide.WizardDescriptor.Panel#getHelp
1368:             */
1369:            public HelpCtx getHelp() {
1370:                return HelpCtx.DEFAULT_HELP;
1371:            }
1372:
1373:            /**
1374:             * Gets ListTransferModel associated with this object.
1375:             *
1376:             * @return ListTransferModel
1377:             */
1378:            synchronized ListTransferModel getModel() {
1379:                return listModel;
1380:            }
1381:
1382:            // TODO add constructor flag to set whether panel is always valid, or
1383:            // if at least one item must be transferred to the destination list.
1384:            /**
1385:             * Indicates whether current state of panel is sufficient for enclosing window/dialog
1386:             * to close itself and read the contents of the source and destination panels.
1387:             *
1388:             * @return true if panel contents are in a valid state, false otherwise.
1389:             */
1390:            public boolean hasValidContents() {
1391:                // Return true if at least one item has been selected.
1392:                return (getModel().getDestinationModel().getSize() > 0);
1393:            }
1394:
1395:            /**
1396:             * @see org.openide.WizardDescriptor.Panel#isValid
1397:             */
1398:            @Override
1399:            public boolean isValid() {
1400:                return true;
1401:            }
1402:
1403:            /**
1404:             * @see java.beans.PropertyChangeListener#propertyChange
1405:             */
1406:            public void propertyChange(PropertyChangeEvent evt) {
1407:                if (evt.getPropertyName().equals("model")) {
1408:                    ((TableModel) evt.getNewValue())
1409:                            .addTableModelListener(this );
1410:                }
1411:            }
1412:
1413:            /**
1414:             * @see org.openide.WizardDescriptor.Panel#readSettings
1415:             */
1416:            public void readSettings(final Object settings) {
1417:                WizardDescriptor wizard = null;
1418:                if (settings instanceof  ETLWizardContext) {
1419:                    ETLWizardContext wizardContext = (ETLWizardContext) settings;
1420:                    wizard = (WizardDescriptor) wizardContext
1421:                            .getProperty(ETLWizardContext.WIZARD_DESCRIPTOR);
1422:
1423:                } else if (settings instanceof  WizardDescriptor) {
1424:                    wizard = (WizardDescriptor) settings;
1425:                }
1426:
1427:                if (wizard != null
1428:                        && WizardDescriptor.NEXT_OPTION.equals(wizard
1429:                                .getValue())) {
1430:                    /*
1431:                     * If coming from a previous window (i.e via its Next button)
1432:                     * then (re)set the "available" database(s) list and clear the
1433:                     * "selected" database list. Otherwise, for a "Back" button call,
1434:                     * just keep the current user selections.
1435:                     **/
1436:                    //TODO - more complicated logic to retain user selections across Back/Next buttons
1437:                    List models = null;
1438:                    if (isSource) { //In the source database mode
1439:                        Object[] sources = (Object[]) wizard
1440:                                .getProperty(ETLCollaborationWizard.DATABASE_SOURCES);
1441:                        models = Arrays.asList(sources);
1442:                    } else {
1443:                        Object[] targets = (Object[]) wizard
1444:                                .getProperty(ETLCollaborationWizard.DATABASE_TARGETS);
1445:                        models = Arrays.asList(targets);
1446:                    }
1447:                    listModel.setSourceList(models);
1448:                    ((DefaultComboBoxModel) listModel.getDestinationModel())
1449:                            .removeAllElements();
1450:                    tablePanel.resetTable(Collections.EMPTY_LIST);
1451:                }
1452:
1453:                if (sourceList != null) {
1454:                    SwingUtilities.invokeLater(new Runnable() {
1455:
1456:                        public void run() {
1457:                            if (sourceList != null
1458:                                    && sourceList.getModel().getSize() != 0) {
1459:                                sourceList.requestFocusInWindow();
1460:                            } else if (addButton != null) {
1461:                                addButton.requestFocusInWindow();
1462:                            }
1463:                        }
1464:                    });
1465:                }
1466:            }
1467:
1468:            /**
1469:             * @see org.openide.WizardDescriptor.Panel#removeChangeListener
1470:             */
1471:            public void removeChangeListener(ChangeListener l) {
1472:                synchronized (listeners) {
1473:                    listeners.remove(l);
1474:                }
1475:            }
1476:
1477:            /**
1478:             * @see org.openide.WizardDescriptor.Panel#storeSettings
1479:             */
1480:            public void storeSettings(Object settings) {
1481:                WizardDescriptor wizard = null;
1482:                if (settings instanceof  ETLWizardContext) {
1483:                    ETLWizardContext wizardContext = (ETLWizardContext) settings;
1484:                    wizard = (WizardDescriptor) wizardContext
1485:                            .getProperty(ETLWizardContext.WIZARD_DESCRIPTOR);
1486:
1487:                } else if (settings instanceof  WizardDescriptor) {
1488:                    wizard = (WizardDescriptor) settings;
1489:                }
1490:
1491:                if (wizard != null) {
1492:                    final Object selectedOption = wizard.getValue();
1493:                    if (NotifyDescriptor.CANCEL_OPTION == selectedOption
1494:                            || NotifyDescriptor.CLOSED_OPTION == selectedOption) {
1495:                        return;
1496:                    }
1497:
1498:                    boolean isAdvancingPanel = (selectedOption == WizardDescriptor.NEXT_OPTION)
1499:                            || (selectedOption == WizardDescriptor.FINISH_OPTION);
1500:                    if (isAdvancingPanel) {
1501:                        try {
1502:                            List list = this .getSelectedDBModels(isSource);
1503:                            if (isSource) {//In the source database mode
1504:                                wizard.putProperty(
1505:                                        ETLCollaborationWizard.SOURCE_DB, list);
1506:                                // We should null out JOIN_VIEW and JOIN_VIEW_VISIBLE_COLUMNS so that
1507:                                // if user goes to join panel then come back to source table panel and
1508:                                // clicks finish, then we should not have a join.
1509:                                wizard.putProperty(
1510:                                        ETLCollaborationWizard.JOIN_VIEW, null);
1511:                                wizard
1512:                                        .putProperty(
1513:                                                ETLCollaborationWizard.JOIN_VIEW_VISIBLE_COLUMNS,
1514:                                                null);
1515:                            } else {
1516:                                wizard.putProperty(
1517:                                        ETLCollaborationWizard.TARGET_DB, list);
1518:                            }
1519:                        } catch (Exception e) {
1520:                            mLogger
1521:                                    .errorNoloc(
1522:                                            mLoc
1523:                                                    .t(
1524:                                                            "PRSR036: Error trying to get selected table metadata{0}",
1525:                                                            LOG_CATEGORY), e);
1526:                        }
1527:                    }
1528:                }
1529:            }
1530:
1531:            /**
1532:             * @see javax.swing.event.TableModelListener#tableChanged
1533:             */
1534:            public void tableChanged(TableModelEvent e) {
1535:                fireChangeEvent();
1536:            }
1537:
1538:            public void updatePanelState() {
1539:                fireChangeEvent();
1540:            }
1541:
1542:            /**
1543:             * Called whenever the value of the selection changes.
1544:             *
1545:             * @param e the event that characterizes the change.
1546:             */
1547:            public void valueChanged(ListSelectionEvent e) {
1548:            }
1549:
1550:            /**
1551:             * Indicates whether this panel has enough selected tables to allow for creation of a
1552:             * join.
1553:             *
1554:             * @return true if number of selected tables is sufficient to create a join; false
1555:             *         otherwise
1556:             */
1557:            boolean hasEnoughTablesForJoin() {
1558:                return listModel.getSelectedTablesModel().getRowCount() > 1 ? true
1559:                        : false;
1560:            }
1561:        }
ww___w.___ja__v__a2__s__.__co___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.