Source Code Cross Referenced for JDBCWizardTablePanel.java in  » IDE-Netbeans » sql.project » org » netbeans » modules » jdbcwizard » wizards » Java Source Code / Java DocumentationJava Source Code and Java Documentation

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


0001:        /*
0002:         * The contents of this file are subject to the terms of the Common Development
0003:         * and Distribution License (the License). You may not use this file except in
0004:         * compliance with the License.
0005:         * 
0006:         * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
0007:         * or http://www.netbeans.org/cddl.txt.
0008:         * 
0009:         * When distributing Covered Code, include this CDDL Header Notice in each file
0010:         * and include the License file at http://www.netbeans.org/cddl.txt.
0011:         * If applicable, add the following below the CDDL Header, with the fields
0012:         * enclosed by brackets [] replaced by your own identifying information:
0013:         * "Portions Copyrighted [year] [name of copyright owner]"
0014:         * 
0015:         * The Original Software is NetBeans. The Initial Developer of the Original
0016:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0017:         * Microsystems, Inc. All Rights Reserved.
0018:         */
0019:
0020:        /*
0021:         * 
0022:         * Copyright 2005 Sun Microsystems, Inc.
0023:         * 
0024:         * Licensed under the Apache License, Version 2.0 (the "License");
0025:         * you may not use this file except in compliance with the License.
0026:         * You may obtain a copy of the License at
0027:         * 
0028:         * 	http://www.apache.org/licenses/LICENSE-2.0
0029:         * 
0030:         * Unless required by applicable law or agreed to in writing, software
0031:         * distributed under the License is distributed on an "AS IS" BASIS,
0032:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0033:         * See the License for the specific language governing permissions and
0034:         * limitations under the License.
0035:         * 
0036:         */
0037:        package org.netbeans.modules.jdbcwizard.wizards;
0038:
0039:        import java.awt.BorderLayout;
0040:        import java.awt.Color;
0041:        import java.awt.Component;
0042:        import java.awt.Dialog;
0043:        import java.awt.Dimension;
0044:        import java.awt.event.ActionListener;
0045:        import java.awt.event.ActionEvent;
0046:        import java.awt.event.ItemListener;
0047:
0048:        import java.awt.Font;
0049:        import java.awt.Graphics;
0050:        import java.awt.Insets;
0051:        import java.awt.Rectangle;
0052:        import java.awt.Toolkit;
0053:        import java.awt.Window;
0054:
0055:        import java.util.ArrayList;
0056:        import java.util.Iterator;
0057:        import java.util.List;
0058:
0059:        import javax.swing.AbstractAction;
0060:        import javax.swing.BorderFactory;
0061:        import javax.swing.Box;
0062:        import javax.swing.BoxLayout;
0063:        import javax.swing.ButtonGroup;
0064:        import javax.swing.ButtonModel;
0065:        import javax.swing.DefaultCellEditor;
0066:        import javax.swing.JButton;
0067:        import javax.swing.JCheckBox;
0068:        import javax.swing.JDialog;
0069:        import javax.swing.JFrame;
0070:        import javax.swing.JLabel;
0071:        import javax.swing.JOptionPane;
0072:        import javax.swing.JPanel;
0073:        import javax.swing.JScrollPane;
0074:        import javax.swing.JTable;
0075:        import javax.swing.JTabbedPane;
0076:        import javax.swing.SwingConstants;
0077:        import javax.swing.SwingUtilities;
0078:        import javax.swing.UIManager;
0079:        import javax.swing.WindowConstants;
0080:        import javax.swing.border.Border;
0081:        import javax.swing.event.CellEditorListener;
0082:        import javax.swing.event.ChangeListener;
0083:        import javax.swing.event.ChangeEvent;
0084:        import javax.swing.table.AbstractTableModel;
0085:        import javax.swing.table.DefaultTableCellRenderer;
0086:        import javax.swing.table.JTableHeader;
0087:        import javax.swing.table.TableCellRenderer;
0088:        import javax.swing.table.TableColumn;
0089:        import javax.swing.table.TableModel;
0090:
0091:        import org.openide.util.NbBundle;
0092:
0093:        import org.netbeans.modules.jdbcwizard.builder.dbmodel.DBTable;
0094:        import org.netbeans.modules.jdbcwizard.builder.dbmodel.DBColumn;
0095:        import org.netbeans.modules.jdbcwizard.builder.dbmodel.impl.DBColumnImpl;
0096:        import org.netbeans.modules.jdbcwizard.builder.dbmodel.impl.DBTableImpl;
0097:
0098:        // import javax.swing.AbstractAction;
0099:        import javax.swing.table.TableCellEditor;
0100:
0101:        import java.util.EventObject;
0102:
0103:        /**
0104:         * This class represents table for meta data. This holds a JTable for showing table meta data.
0105:         * 
0106:         * @author
0107:         */
0108:        public class JDBCWizardTablePanel extends JPanel {
0109:            /**
0110:             * 
0111:             */
0112:            private static final long serialVersionUID = 1L;
0113:
0114:            class MetaTableComponent extends JTable {
0115:                /**
0116:                 * 
0117:                 */
0118:                private static final long serialVersionUID = 1L;
0119:
0120:                protected MyTableModelCellRenderer mytabmod;
0121:
0122:                protected MyBooleanRenderer mybool;
0123:
0124:                public MetaTableComponent() {
0125:                    // Need to revisit whether should use abstract model here??
0126:                    mytabmod = new MyTableModelCellRenderer();
0127:                    mybool = new MyBooleanRenderer();
0128:                    this .setDefaultRenderer(DBTableImpl.class, this .mytabmod);
0129:                    this .setDefaultRenderer(Boolean.class, this .mybool);
0130:                    final JTableHeader header = this .getTableHeader();
0131:
0132:                    header.setReorderingAllowed(false);
0133:                    header.setResizingAllowed(true);
0134:                }
0135:            }
0136:
0137:            static class MyBooleanRenderer extends JCheckBox implements 
0138:                    TableCellRenderer {
0139:                /**
0140:                 * 
0141:                 */
0142:                private static final long serialVersionUID = 1L;
0143:
0144:                protected static Border noFocusBorder = BorderFactory
0145:                        .createEmptyBorder(1, 1, 1, 1);
0146:
0147:                private JPanel myPanel;
0148:
0149:                /**
0150:                 * Creates a default MyBooleanRenderer.
0151:                 */
0152:                public MyBooleanRenderer() {
0153:                    super ();
0154:                    this .setHorizontalAlignment(SwingConstants.CENTER);
0155:                    this .setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
0156:                    this .myPanel = new JPanel();
0157:                    this .myPanel.setLayout(new BorderLayout());
0158:                    this .myPanel.add(this , BorderLayout.CENTER);
0159:                    this .myPanel.setOpaque(true);
0160:                    this .myPanel.setBorder(MyBooleanRenderer.noFocusBorder);
0161:                    this .setSelected(true);
0162:                }
0163:
0164:                public Component getTableCellRendererComponent(
0165:                        final JTable table, final Object value,
0166:                        final boolean isSelected, final boolean hasFocus,
0167:                        final int row, final int column) {
0168:                    final RowDataWrapper rowDW = ((MyTableModel) table
0169:                            .getModel()).getRowDataWrapper(row);
0170:                    if (rowDW != null && !rowDW.isEditable().booleanValue()) {
0171:                        this .setEnabled(false);
0172:                        this .setFocusable(false);
0173:                        this .setBackground(Color.LIGHT_GRAY);
0174:                        final Object obj = rowDW.getTable();
0175:                        if (obj instanceof  DBTable) {
0176:                            final DBTable st = (DBTable) obj;// SourceTable modified to
0177:                            if (!st.isSelected()) {
0178:                                this 
0179:                                        .setToolTipText(NbBundle
0180:                                                .getMessage(
0181:                                                        JDBCWizardTablePanel.class,
0182:                                                        "TOOLTIP_source_table_disabled_unselected",
0183:                                                        rowDW.getTable()));
0184:                            }
0185:                        }
0186:                        this .myPanel.setBorder(MyBooleanRenderer.noFocusBorder);
0187:                        this .myPanel.setBackground(Color.LIGHT_GRAY);
0188:                    } else {
0189:                        if (isSelected) {
0190:                            this .setForeground(table.getSelectionForeground());
0191:                            this .setBackground(table.getSelectionBackground());
0192:                            this .myPanel.setForeground(table
0193:                                    .getSelectionForeground());
0194:                            this .myPanel.setBackground(table
0195:                                    .getSelectionBackground());
0196:                        } else {
0197:                            this .setForeground(table.getForeground());
0198:                            this .setBackground(table.getBackground());
0199:                            this .myPanel.setForeground(table.getForeground());
0200:                            this .myPanel.setBackground(table.getBackground());
0201:                        }
0202:                        if (hasFocus) { // NOI18N this scope block
0203:                            this .myPanel
0204:                                    .setBorder(UIManager
0205:                                            .getBorder("Table.focusCellHighlightBorder"));
0206:                            if (table.isCellEditable(row, column)) {
0207:                                this .setForeground(UIManager
0208:                                        .getColor("Table.focusCellForeground"));
0209:                                this .setBackground(UIManager
0210:                                        .getColor("Table.focusCellBackground"));
0211:                            }
0212:                            this .myPanel.setForeground(UIManager
0213:                                    .getColor("Table.focusCellForeground"));
0214:                            this .myPanel.setBackground(UIManager
0215:                                    .getColor("Table.focusCellBackground"));
0216:                        } else {
0217:                            this .myPanel
0218:                                    .setBorder(MyBooleanRenderer.noFocusBorder);
0219:                        }
0220:                        this .setEnabled(true);
0221:                        this .setFocusable(true);
0222:                        this .setToolTipText("");
0223:                    }
0224:                    this .setSelected((value != null && ((Boolean) value)
0225:                            .booleanValue()));
0226:                    return this .myPanel;
0227:                }
0228:
0229:                /**
0230:                 * Overrides <code>JComponent.setBackground</code> to assign the unselected-background
0231:                 * color to the specified color.
0232:                 * 
0233:                 * @param c set the background color to this value
0234:                 */
0235:                public void setBackground(final Color c) {
0236:                    super .setBackground(c);
0237:                }
0238:
0239:                public void setSelected(boolean flag) {
0240:                    super .setSelected(flag);
0241:                }
0242:
0243:                /**
0244:                 * Overrides <code>JComponent.setForeground</code> to assign the unselected-foreground
0245:                 * color to the specified color.
0246:                 * 
0247:                 * @param c set the foreground color to this value
0248:                 */
0249:                public void setForeground(final Color c) {
0250:                    super .setForeground(c);
0251:                }
0252:
0253:            }
0254:
0255:            class MyButtonRenderer extends JButton implements 
0256:                    TableCellRenderer, TableCellEditor {
0257:                /**
0258:                 * 
0259:                 */
0260:                private static final long serialVersionUID = 1L;
0261:                private JPanel myButPanel;
0262:
0263:                MyButtonRenderer(final String disp) {
0264:                    super ();
0265:                    this .setText(disp);
0266:                    this .setOpaque(true);
0267:                    this .setHorizontalAlignment(SwingConstants.CENTER);
0268:                    this .myButPanel = new JPanel();
0269:                    this .setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
0270:                    this .myButPanel.setLayout(new BorderLayout());
0271:                    this .myButPanel.add(this , BorderLayout.CENTER);
0272:                    this .myButPanel.setOpaque(true);
0273:                    this .myButPanel.setEnabled(false);
0274:                }
0275:
0276:                public Component getTableCellRendererComponent(
0277:                        final JTable table, final Object value,
0278:                        final boolean isSelected, final boolean hasFocus,
0279:                        final int row, final int column) {
0280:                    final RowDataWrapper rowDW = ((MyTableModel) table
0281:                            .getModel()).getRowDataWrapper(row);
0282:                    if (rowDW != null && !rowDW.isEditable().booleanValue()) {
0283:                        this .setEnabled(false);
0284:                        this .setFocusable(false);
0285:                        this .setBackground(Color.LIGHT_GRAY);
0286:                        final Object obj = rowDW.getTable();
0287:                        if (obj instanceof  DBTable) {
0288:                            final DBTable st = (DBTable) obj;// SourceTable modified to
0289:                            // DBTable
0290:                            if (!st.isSelected()) {
0291:                                this 
0292:                                        .setToolTipText(NbBundle
0293:                                                .getMessage(
0294:                                                        JDBCWizardTablePanel.class,
0295:                                                        "TOOLTIP_source_table_disabled_unselected",
0296:                                                        rowDW.getTable()));
0297:                            }
0298:                        }
0299:                    } else {
0300:                        if (isSelected) {
0301:                            // myButPanel.setBorder(noFocusBorder);
0302:                            this .myButPanel.setBackground(Color.LIGHT_GRAY);
0303:                            this .setForeground(table.getSelectionForeground());
0304:                            this .setBackground(table.getSelectionBackground());
0305:                            this .myButPanel.setForeground(table
0306:                                    .getSelectionForeground());
0307:                            this .myButPanel.setBackground(table
0308:                                    .getSelectionBackground());
0309:                        } else {
0310:                            this .setForeground(table.getForeground());
0311:                            this .setBackground(table.getBackground());
0312:                            this .myButPanel
0313:                                    .setForeground(table.getForeground());
0314:                            this .myButPanel
0315:                                    .setBackground(table.getBackground());
0316:                        }
0317:                        if (hasFocus) { // NOI18N this scope block
0318:                            this .myButPanel
0319:                                    .setBorder(UIManager
0320:                                            .getBorder("Table.focusCellHighlightBorder"));
0321:                            if (table.isCellEditable(row, column)) {
0322:                                this .setForeground(UIManager
0323:                                        .getColor("Table.focusCellForeground"));
0324:                                this .setBackground(UIManager
0325:                                        .getColor("Table.focusCellBackground"));
0326:                            }
0327:                            this .myButPanel.setForeground(UIManager
0328:                                    .getColor("Table.focusCellForeground"));
0329:                            this .myButPanel.setBackground(UIManager
0330:                                    .getColor("Table.focusCellBackground"));
0331:                        }
0332:
0333:                        this .setEnabled(true);
0334:                        this .setFocusable(true);
0335:                        this .setText("Advanced..");
0336:                    }
0337:                    return this .myButPanel;
0338:                }
0339:
0340:                public Component getTableCellEditorComponent(
0341:                        final JTable table, final Object value,
0342:                        final boolean isSelected, final int row,
0343:                        final int column) {
0344:                    final RowDataWrapper rowDW = ((MyTableModel) table
0345:                            .getModel()).getRowDataWrapper(row);
0346:                    this .addActionListener(new ColumnAction(rowDW));
0347:                    if (rowDW != null && !rowDW.isEditable().booleanValue()) {
0348:                        this .setEnabled(false);
0349:                        this .setFocusable(false);
0350:                        this .setBackground(Color.LIGHT_GRAY);
0351:                        final Object obj = rowDW.getTable();
0352:                        if (obj instanceof  DBTable) {
0353:                            final DBTable st = (DBTable) obj;
0354:                            if (!st.isSelected()) {
0355:                                this 
0356:                                        .setToolTipText(NbBundle
0357:                                                .getMessage(
0358:                                                        JDBCWizardTablePanel.class,
0359:                                                        "TOOLTIP_source_table_disabled_unselected",
0360:                                                        rowDW.getTable()));
0361:                            }
0362:                        }
0363:                    } else {
0364:
0365:                        if (isSelected) {
0366:                            this .myButPanel.setBackground(Color.LIGHT_GRAY);
0367:                            this .myButPanel.add(this , BorderLayout.CENTER);
0368:                            this .setEnabled(true);
0369:                            this .myButPanel.setEnabled(true);
0370:                            this .myButPanel.setOpaque(true);
0371:                            //this.addActionListener(new ColumnAction(rowDW));
0372:                            this .setForeground(table.getSelectionForeground());
0373:                            this .setBackground(table.getSelectionBackground());
0374:                            this .myButPanel.setForeground(table
0375:                                    .getSelectionForeground());
0376:                            this .myButPanel.setBackground(table
0377:                                    .getSelectionBackground());
0378:                        } else {
0379:                            this .setForeground(table.getForeground());
0380:                            this .setBackground(table.getBackground());
0381:                            this .myButPanel
0382:                                    .setForeground(table.getForeground());
0383:                            this .myButPanel
0384:                                    .setBackground(table.getBackground());
0385:                        }
0386:                        this .setFocusable(true);
0387:                        this .setText("Advanced..");
0388:                    }
0389:                    return this .myButPanel;
0390:                }
0391:
0392:                /**
0393:                 * 
0394:                 */
0395:                public Object getCellEditorValue() {
0396:                    return this .getCellEditorValue();
0397:                }
0398:
0399:                /**
0400:                 * 
0401:                 */
0402:                public boolean isCellEditable(final EventObject anEvent) {
0403:                    return true;
0404:                }
0405:
0406:                /**
0407:                 * 
0408:                 */
0409:                public boolean shouldSelectCell(final EventObject anEvent) {
0410:                    return true;
0411:                }
0412:
0413:                /**
0414:                 * 
0415:                 */
0416:                public boolean stopCellEditing() {
0417:                    return true;
0418:                }
0419:
0420:                /**
0421:                 * 
0422:                 */
0423:                public void cancelCellEditing() {
0424:                    this .cancelCellEditing();
0425:                }
0426:
0427:                /**
0428:                 * 
0429:                 */
0430:                public void addCellEditorListener(final CellEditorListener l) {
0431:                }
0432:
0433:                /**
0434:                 * 
0435:                 */
0436:                public void removeCellEditorListener(final CellEditorListener l) {
0437:                }
0438:
0439:            }
0440:
0441:            class ColumnAction implements  ActionListener {
0442:                protected JButton okbutton = new JButton("OK");
0443:
0444:                protected JButton cancelbutton = new JButton("Cancel");
0445:
0446:                protected JButton selectallbutton = new JButton("Select All");
0447:
0448:                protected JButton clearallbutton = new JButton("Clear All");
0449:
0450:                protected JPanel buttonpanel = new JPanel();
0451:
0452:                protected InsertColumnPanel correspInsertCol;
0453:
0454:                protected UpdateColumnPanel correspUpdateCol;
0455:
0456:                protected ChosenColumnPanel correspChosenCol;
0457:
0458:                protected PolledColumnPanel correspPolledCol;
0459:
0460:                protected JTabbedPane myTabpane;
0461:
0462:                // protected JDialog columndisplay = new JDialog();
0463:                protected class ColumnDialog extends JDialog {
0464:                    /**
0465:                     * 
0466:                     */
0467:                    private static final long serialVersionUID = 1L;
0468:
0469:                    ColumnDialog(final JDialog parent, final boolean modal) {
0470:                        super (parent, modal);
0471:                    }
0472:                }
0473:
0474:                ColumnDialog columnDisplayDialog = null;
0475:
0476:                protected String title = "Columns";
0477:
0478:                RowDataWrapper takes;
0479:
0480:                public ColumnAction(final RowDataWrapper takes) {
0481:                    this .takes = takes;
0482:                    columnDisplayDialog = new ColumnDialog(new JDialog(), true);
0483:                    this .columnDisplayDialog.setAlwaysOnTop(true);
0484:                    this .columnDisplayDialog.setResizable(true);
0485:                    this .columnDisplayDialog.setEnabled(true);
0486:                    this .columnDisplayDialog.setFocusable(true);
0487:                }
0488:
0489:                // this is the default action when the button corresponding to the
0490:                // created table is clicked
0491:                /**
0492:                 * 
0493:                 */
0494:                public void actionPerformed(final ActionEvent anAct) {
0495:                    if (this .takes != null
0496:                            && this .takes.isSelected().booleanValue()) {
0497:                        this .correspInsertCol = new InsertColumnPanel();
0498:                        this .correspInsertCol
0499:                                .addColumnTable(((DBTable) this .takes
0500:                                        .getTable()).getColumnList());
0501:
0502:                        this .correspUpdateCol = new UpdateColumnPanel();
0503:                        this .correspUpdateCol
0504:                                .addColumnTable(((DBTable) this .takes
0505:                                        .getTable()).getColumnList());
0506:
0507:                        this .correspChosenCol = new ChosenColumnPanel();
0508:                        this .correspChosenCol
0509:                                .addColumnTable(((DBTable) this .takes
0510:                                        .getTable()).getColumnList());
0511:
0512:                        this .correspPolledCol = new PolledColumnPanel();
0513:                        this .correspPolledCol
0514:                                .addColumnTable(((DBTable) this .takes
0515:                                        .getTable()).getColumnList());
0516:                        this .title = this .title
0517:                                .concat(JDBCWizardTablePanel.SEPARATOR
0518:                                        + ((DBTable) this .takes.getTable())
0519:                                                .getName());
0520:                        this .initializeColumn();
0521:                    } else
0522:                        JOptionPane
0523:                                .showMessageDialog(
0524:                                        null,
0525:                                        "Please select the table to select additional properties",
0526:                                        "Column Selection",
0527:                                        JOptionPane.WARNING_MESSAGE);
0528:                }
0529:
0530:                /**
0531:                 *
0532:                 */
0533:                public void initializeColumn() {
0534:                    this .columnDisplayDialog.setTitle(this .title);
0535:                    this .correspInsertCol.setName("Insert");
0536:                    this .correspUpdateCol.setName("Update");
0537:                    this .correspChosenCol.setName("Find");//
0538:                    this .correspPolledCol.setName("PollRecords");
0539:
0540:                    this .myTabpane = new JTabbedPane();
0541:                    this .myTabpane.add(this .correspInsertCol);
0542:                    this .myTabpane.add(this .correspUpdateCol);
0543:                    this .myTabpane.add(this .correspChosenCol);
0544:                    this .myTabpane.add(this .correspPolledCol);
0545:                    this .columnDisplayDialog.add(this .myTabpane,
0546:                            BorderLayout.CENTER);
0547:                    this .cancelbutton.addActionListener(new ActionListener() {
0548:                        public void actionPerformed(final ActionEvent e) {
0549:                            ColumnAction.this .cleanUp();
0550:                        }
0551:                    });
0552:                    this .okbutton.addActionListener(new ActionListener() {
0553:                        public void actionPerformed(final ActionEvent e) {
0554:                            ColumnAction.this .okAction();
0555:                        }
0556:                    });
0557:                    this .selectallbutton
0558:                            .addActionListener(new ActionListener() {
0559:                                public void actionPerformed(final ActionEvent e) {
0560:                                    ColumnAction.this 
0561:                                            .selectAllAction(ColumnAction.this .myTabpane
0562:                                                    .getSelectedIndex());
0563:                                }
0564:                            });
0565:                    this .clearallbutton.addActionListener(new ActionListener() {
0566:                        public void actionPerformed(final ActionEvent e) {
0567:                            ColumnAction.this 
0568:                                    .clearAllAction(ColumnAction.this .myTabpane
0569:                                            .getSelectedIndex());
0570:                        }
0571:                    });
0572:
0573:                    this .buttonpanel.add(this .selectallbutton,
0574:                            BorderLayout.LINE_START);
0575:                    this .buttonpanel
0576:                            .add(this .clearallbutton, BorderLayout.WEST);
0577:                    this .buttonpanel.add(this .okbutton, BorderLayout.EAST);
0578:                    this .buttonpanel.add(this .cancelbutton,
0579:                            BorderLayout.LINE_END);
0580:                    this .columnDisplayDialog.add(this .buttonpanel,
0581:                            BorderLayout.SOUTH);
0582:                    this .centerWindowOnScreen(this .columnDisplayDialog);
0583:                    this .columnDisplayDialog.setSize(new Dimension(400, 300));
0584:                    this .columnDisplayDialog.setVisible(true);
0585:                }
0586:
0587:                /**
0588:                 * 
0589:                 *
0590:                 */
0591:                public void cleanUp() {
0592:                    int cnt = 0;
0593:                    while (cnt < this .correspInsertCol.getColumnTable()
0594:                            .getModel().getRowCount()) {
0595:                        ((DBColumn) (this .correspInsertCol.getColumnTables())
0596:                                .get(cnt)).setSelected(true);
0597:                        cnt++;
0598:                    }
0599:                    this .columnDisplayDialog.dispose();
0600:                    this .title = "Columns";
0601:                }
0602:
0603:                public void okAction() {
0604:                    this .columnDisplayDialog.dispose();
0605:                    this .title = "Columns";
0606:                }
0607:
0608:                public void selectAllAction(int index) {
0609:                    int cnt = 0;
0610:                    switch (index) {
0611:                    case 0:
0612:                        while (cnt < this .correspInsertCol.getColumnTable()
0613:                                .getModel().getRowCount()) {
0614:                            DBColumn db = (DBColumn) (this .correspInsertCol
0615:                                    .getColumnTables()).get(cnt);
0616:                            db.setInsertSelected(true);
0617:                            cnt++;
0618:                        }
0619:                        this .correspInsertCol.repaint();
0620:                        break;
0621:                    case 1:
0622:                        while (cnt < this .correspUpdateCol.getColumnTable()
0623:                                .getModel().getRowCount()) {
0624:                            DBColumn db = (DBColumn) (this .correspUpdateCol
0625:                                    .getColumnTables()).get(cnt);
0626:                            db.setUpdateSelected(true);
0627:                            cnt++;
0628:                        }
0629:                        this .correspUpdateCol.repaint();
0630:                        break;
0631:                    case 2:
0632:                        while (cnt < this .correspChosenCol.getColumnTable()
0633:                                .getModel().getRowCount()) {
0634:                            DBColumn db = (DBColumn) (this .correspChosenCol
0635:                                    .getColumnTables()).get(cnt);
0636:                            db.setChooseSelected(true);
0637:                            cnt++;
0638:                        }
0639:                        this .correspChosenCol.repaint();
0640:                        break;
0641:                    case 3:
0642:                        while (cnt < this .correspPolledCol.getColumnTable()
0643:                                .getModel().getRowCount()) {
0644:                            DBColumn db = (DBColumn) (this .correspPolledCol
0645:                                    .getColumnTables()).get(cnt);
0646:                            db.setPollSelected(true);
0647:                            cnt++;
0648:                        }
0649:                        this .correspPolledCol.repaint();
0650:                        break;
0651:                    }
0652:                }
0653:
0654:                public void clearAllAction(int index) {
0655:                    int cnt = 0;
0656:                    switch (index) {
0657:                    case 0:
0658:                        while (cnt < this .correspInsertCol.getColumnTable()
0659:                                .getModel().getRowCount()) {
0660:                            DBColumn db = (DBColumn) (this .correspInsertCol
0661:                                    .getColumnTables()).get(cnt);
0662:                            if (db.isNullable()) {
0663:                                db.setInsertSelected(false);
0664:                            }
0665:                            cnt++;
0666:                        }
0667:                        this .correspInsertCol.repaint();
0668:                        break;
0669:                    case 1:
0670:                        while (cnt < this .correspUpdateCol.getColumnTable()
0671:                                .getModel().getRowCount()) {
0672:                            DBColumn db = (DBColumn) (this .correspUpdateCol
0673:                                    .getColumnTables()).get(cnt);
0674:                            db.setUpdateSelected(false);
0675:                            cnt++;
0676:                        }
0677:                        this .correspUpdateCol.repaint();
0678:                        break;
0679:                    case 2:
0680:                        while (cnt < this .correspChosenCol.getColumnTable()
0681:                                .getModel().getRowCount()) {
0682:                            DBColumn db = (DBColumn) (this .correspChosenCol
0683:                                    .getColumnTables()).get(cnt);
0684:                            db.setChooseSelected(false);
0685:                            cnt++;
0686:                        }
0687:                        this .correspChosenCol.repaint();
0688:                        break;
0689:                    case 3:
0690:                        while (cnt < this .correspPolledCol.getColumnTable()
0691:                                .getModel().getRowCount()) {
0692:                            DBColumn db = (DBColumn) (this .correspPolledCol
0693:                                    .getColumnTables()).get(cnt);
0694:                            db.setPollSelected(false);
0695:                            cnt++;
0696:                        }
0697:                        this .correspPolledCol.repaint();
0698:                        break;
0699:                    }
0700:
0701:                }
0702:
0703:                /**
0704:                 * @param window
0705:                 */
0706:                public void centerWindowOnScreen(final Window window) {
0707:                    window.pack();
0708:                    final Rectangle rect = window.getBounds();
0709:                    final Dimension scrnDim = Toolkit.getDefaultToolkit()
0710:                            .getScreenSize();
0711:                    rect.x = Math.max(0, (scrnDim.width - rect.width) / 3);
0712:                    rect.y = Math.max(0, (scrnDim.height - rect.height) / 3);
0713:                    window.setBounds(rect);
0714:                }
0715:            }
0716:
0717:            class MyTableModel extends AbstractTableModel {
0718:                /**
0719:                 * 
0720:                 */
0721:                private static final long serialVersionUID = 1L;
0722:
0723:                private final String[] columnNames = { "Select", "Table Name",
0724:                        "Properties" };
0725:
0726:                private List rowList;
0727:
0728:                public MyTableModel(final List testList) {
0729:                    this .rowList = new ArrayList();
0730:                    for (int i = 0; i < testList.size(); i++) {
0731:                        final RowDataWrapper rowData = new RowDataWrapper(
0732:                                (DBTable) testList.get(i));
0733:                        this .rowList.add(rowData);
0734:                    }
0735:                }
0736:
0737:                /*
0738:                 * JTable uses this method to determine the default renderer/ editor for each cell. If we
0739:                 * didn't implement this method, then the last column would contain text ("true"/"false"),
0740:                 * rather than a check box.
0741:                 */
0742:                /**
0743:                 * 
0744:                 */
0745:                public Class getColumnClass(final int c) {
0746:                    return this .getValueAt(0, c).getClass();
0747:                }
0748:
0749:                /**
0750:                 * 
0751:                 */
0752:                public int getColumnCount() {
0753:                    return this .columnNames.length;
0754:                }
0755:
0756:                /**
0757:                 * 
0758:                 */
0759:                public String getColumnName(final int col) {
0760:                    return this .columnNames[col];
0761:                }
0762:
0763:                /**
0764:                 * 
0765:                 */
0766:                public int getRowCount() {
0767:                    return this .rowList.size();
0768:                }
0769:
0770:                /**
0771:                 * @param row
0772:                 * @return
0773:                 */
0774:                public RowDataWrapper getRowDataWrapper(final int row) {
0775:                    if (row < this .rowList.size()) {
0776:                        return (RowDataWrapper) this .rowList.get(row);
0777:                    }
0778:                    return null;
0779:                }
0780:
0781:                /**
0782:                 * @return
0783:                 */
0784:                public ArrayList getTables() {
0785:                    final ArrayList tableList = new ArrayList();
0786:                    for (int i = 0; i < this .rowList.size(); i++) {
0787:                        final RowDataWrapper rowData = (RowDataWrapper) this .rowList
0788:                                .get(i);
0789:                        tableList.add(rowData.getTable());
0790:                    }
0791:                    return tableList;
0792:                }
0793:
0794:                /**
0795:                 * 
0796:                 */
0797:                public Object getValueAt(final int row, final int col) {
0798:                    final RowDataWrapper rowData = (RowDataWrapper) this .rowList
0799:                            .get(row);
0800:                    switch (col) {
0801:                    case 0:
0802:                        return rowData.isSelected();
0803:                    case 1:
0804:                        return rowData.getTable();
0805:                    }
0806:                    return String.valueOf(col + "?");
0807:                }
0808:
0809:                /*
0810:                 * Don't need to implement this method unless your table's editable.
0811:                 */
0812:                /**
0813:                 * 
0814:                 */
0815:                public boolean isCellEditable(final int row, final int col) {
0816:                    // Note that the data/cell address is constant,
0817:                    // no matter where the cell appears onscreen.
0818:                    final Object rowObj = this .rowList.get(row);
0819:                    return true;
0820:                    // return (rowObj != null) ? ((RowDataWrapper) rowObj).isEditable().booleanValue() &&
0821:                    // (col == 0) : false;
0822:                }
0823:
0824:                /**
0825:                 * @param row
0826:                 * @param col
0827:                 * @param flag
0828:                 */
0829:                public void setCellEditable(final int row, final int col,
0830:                        final boolean flag) {
0831:                    final Object rowObj = this .rowList.get(row);
0832:                    if (rowObj != null) {
0833:                        ((RowDataWrapper) rowObj)
0834:                                .setEditable(flag ? Boolean.TRUE
0835:                                        : Boolean.FALSE);
0836:                    }
0837:                }
0838:
0839:                /*
0840:                 * Don't need to implement this method unless your table's data can change.
0841:                 */
0842:                /**
0843:                 * 
0844:                 */
0845:                public void setValueAt(final Object value, final int row,
0846:                        final int col) {
0847:                    final RowDataWrapper rowData = (RowDataWrapper) this .rowList
0848:                            .get(row);
0849:                    switch (col) {
0850:                    case 0:
0851:                        rowData.setSelected((Boolean) value);
0852:                        this .fireTableRowsUpdated(row, row);
0853:                        break;
0854:                    }
0855:                }
0856:            }
0857:
0858:            static class MyTableModelCellRenderer extends
0859:                    DefaultTableCellRenderer {
0860:                /**
0861:                 * 
0862:                 */
0863:                private static final long serialVersionUID = 1L;
0864:                protected static Border noFocusBorder1 = BorderFactory
0865:                        .createEmptyBorder(1, 1, 1, 1);
0866:
0867:                /**
0868:                 * Creates a default MyBooleanRenderer.
0869:                 */
0870:                public MyTableModelCellRenderer() {
0871:                    super ();
0872:                }
0873:
0874:                public Component getTableCellRendererComponent(
0875:                        final JTable table, final Object value,
0876:                        final boolean isSelected, final boolean hasFocus,
0877:                        final int row, final int column) {
0878:                    final JLabel renderer = (JLabel) super 
0879:                            .getTableCellRendererComponent(table, value,
0880:                                    isSelected, hasFocus, row, column);
0881:                    final MyTableModel model = (MyTableModel) table.getModel();
0882:                    final RowDataWrapper rowDW = model.getRowDataWrapper(row);
0883:                    if (rowDW != null && !rowDW.isEditable().booleanValue()) {
0884:                        renderer.setEnabled(false);
0885:                        renderer.setBackground(Color.lightGray);
0886:                        final Object obj = rowDW.getTable();
0887:                        final DBTable st = (DBTable) obj;
0888:                        if (!st.isSelected()) {
0889:                            renderer.setToolTipText(NbBundle.getMessage(
0890:                                    JDBCWizardTablePanel.class,
0891:                                    "TOOLTIP_source_table_disabled_unselected",
0892:                                    rowDW.getTable()));
0893:                        }
0894:                        renderer
0895:                                .setBorder(MyTableModelCellRenderer.noFocusBorder1);
0896:                        renderer.setFocusable(false);
0897:                    } else {
0898:                        if (isSelected) {
0899:                            renderer.setForeground(table
0900:                                    .getSelectionForeground());
0901:                            renderer.setBackground(table
0902:                                    .getSelectionBackground());
0903:                        } else {
0904:                            renderer.setForeground(table.getForeground());
0905:                            renderer.setBackground(table.getBackground());
0906:                        }
0907:                        if (value instanceof  DBTable) {
0908:                            final DBTable dbModleTbl = (DBTable) value;
0909:                            if (dbModleTbl.getName() != null) {
0910:                                this .setText(dbModleTbl.getName());
0911:                            }
0912:                        }
0913:                        renderer.setToolTipText("");
0914:                        renderer.setEnabled(true);
0915:                        renderer.setFocusable(true);
0916:                    }
0917:                    return renderer;
0918:                }
0919:            }
0920:
0921:            class RowDataWrapper {
0922:                private DBTable table;
0923:
0924:                public RowDataWrapper(final DBTable mTable) {
0925:                    this .table = mTable;
0926:                }
0927:
0928:                /**
0929:                 * @return
0930:                 */
0931:                public Object getTable() {
0932:                    return this .table;
0933:                }
0934:
0935:                /**
0936:                 * @return
0937:                 */
0938:                public Boolean isEditable() {
0939:                    return this .table.isEditable() ? Boolean.TRUE
0940:                            : Boolean.FALSE;
0941:                }
0942:
0943:                /**
0944:                 * @return
0945:                 */
0946:                public Boolean isSelected() {
0947:                    return this .table.isSelected() ? Boolean.TRUE
0948:                            : Boolean.FALSE;
0949:                }
0950:
0951:                /**
0952:                 * @param isEditable
0953:                 */
0954:                public void setEditable(final Boolean isEditable) {
0955:                    this .table.setEditable(isEditable.booleanValue());
0956:                }
0957:
0958:                /**
0959:                 * @param isSelected
0960:                 */
0961:                public void setSelected(final Boolean isSelected) {
0962:                    this .table.setSelected(isSelected.booleanValue());
0963:                }
0964:            }
0965:
0966:            /* font selection for column data in table body */
0967:            private static final Font FONT_TABLE_COLUMNS = new Font("Dialog",
0968:                    Font.PLAIN, 12);
0969:
0970:            /* font selection for column headers in table body */
0971:            private static final Font FONT_TABLE_HEADER = new Font("Dialog",
0972:                    Font.BOLD, 12);
0973:
0974:            private JPanel headerPnl;
0975:
0976:            /* table to display meta data */
0977:            private MetaTableComponent metaDataTable;
0978:
0979:            /* scrollpane for columns JTable */
0980:            private JScrollPane tableScroll;
0981:
0982:            /** Creates a default instance of JDBCWizardTablePanel */
0983:            private static final String SEPARATOR = " - ";
0984:
0985:            public JDBCWizardTablePanel() {
0986:            }
0987:
0988:            /**
0989:             * Creates a new instance of JDBCWizardTablePanel to render the selection of tables
0990:             * participating in an JDBC collaboration.
0991:             * 
0992:             * @param testList List of tables
0993:             */
0994:            public JDBCWizardTablePanel(final List testList) {
0995:                this .setOpaque(false);
0996:                final JPanel p = new JPanel();
0997:                p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
0998:                p.setOpaque(false);
0999:                this .headerPnl = new JPanel();
1000:                this .headerPnl.setLayout(new BorderLayout());
1001:                this .headerPnl.setOpaque(false);
1002:                this .headerPnl.add(p, BorderLayout.NORTH);
1003:                this .addTable(testList);
1004:            }
1005:
1006:            /**
1007:             * Gets associated JTable.
1008:             * 
1009:             * @return JTable
1010:             */
1011:            public JTable getTable() {
1012:                return this .metaDataTable;
1013:            }
1014:
1015:            /**
1016:             * Gets list of selected tables.
1017:             * 
1018:             * @return List of selected tables
1019:             */
1020:            public List getTables() {
1021:                final MyTableModel tableModel = (MyTableModel) this .metaDataTable
1022:                        .getModel();
1023:                return tableModel.getTables();
1024:            }
1025:
1026:            /**
1027:             * Paints this component
1028:             * 
1029:             * @param g graphics context
1030:             */
1031:            public void paint(final Graphics g) {
1032:                super .paint(g);
1033:            }
1034:
1035:            /**
1036:             * Populates selected tables using items contained in the given List.
1037:             * 
1038:             * @param tableNameList List of tables to use in repopulating set of selected tables
1039:             */
1040:            public void resetTable(final List tableNameList) {
1041:                final MyTableModel myMod = new MyTableModel(tableNameList);
1042:                this .metaDataTable.setModel(myMod);
1043:                this .metaDataTable.getColumn("Properties").setCellRenderer(
1044:                        new MyButtonRenderer("Advanced.."));
1045:                this .metaDataTable.getColumn("Properties").setCellEditor(
1046:                        new MyButtonRenderer("Advanced.."));
1047:                // set checkbox column size
1048:                final TableColumn column = this .metaDataTable.getColumnModel()
1049:                        .getColumn(0);
1050:                column.setResizable(true);
1051:                column.setMinWidth(40);
1052:                column.setPreferredWidth(80);
1053:                column.setMaxWidth(120);
1054:
1055:                final TableColumn columnAdv = this .metaDataTable
1056:                        .getColumnModel().getColumn(2);
1057:                columnAdv.setResizable(true);
1058:                columnAdv.setMinWidth(60);
1059:                columnAdv.setPreferredWidth(80);
1060:                columnAdv.setMaxWidth(100);
1061:            }
1062:
1063:            /**
1064:             * @param testList
1065:             */
1066:            public void addTable(final List testList) {
1067:                this .metaDataTable = new MetaTableComponent();
1068:                this .metaDataTable
1069:                        .setFont(JDBCWizardTablePanel.FONT_TABLE_COLUMNS);
1070:                this .metaDataTable.getTableHeader().setFont(
1071:                        JDBCWizardTablePanel.FONT_TABLE_HEADER);
1072:                final MyTableModel myModel = new MyTableModel(testList);
1073:                this .metaDataTable.setModel(myModel);
1074:                this .metaDataTable.getColumn("Properties").setCellRenderer(
1075:                        new MyButtonRenderer("Advacned.."));
1076:                this .metaDataTable.getColumn("Properties").setCellEditor(
1077:                        new MyButtonRenderer("Advanced.."));
1078:                this .setLayout(new BorderLayout());
1079:                // add(headerPnl, BorderLayout.NORTH);
1080:                this .setPreferredSize(new Dimension(100, 100));
1081:                this .setMaximumSize(new Dimension(150, 150));
1082:                // set checkbox column size
1083:                final TableColumn column = this .metaDataTable.getColumnModel()
1084:                        .getColumn(0);
1085:                column.setResizable(true);
1086:                column.setMinWidth(40);
1087:                column.setPreferredWidth(40);
1088:                column.setMaxWidth(80);
1089:                this .tableScroll = new JScrollPane(this .metaDataTable);
1090:                final javax.swing.border.Border inside = BorderFactory
1091:                        .createCompoundBorder(BorderFactory.createEmptyBorder(
1092:                                3, 3, 3, 3), BorderFactory
1093:                                .createLineBorder(Color.GRAY));
1094:                this.tableScroll.setBorder(BorderFactory.createCompoundBorder(
1095:                        BorderFactory.createEtchedBorder(), inside));
1096:                this.add(this.tableScroll, BorderLayout.CENTER);
1097:            }
1098:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.