Source Code Cross Referenced for ETLCollaborationWizardTablePanel.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) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:        package org.netbeans.modules.etl.ui.view.wizards;
042:
043:        import java.awt.BorderLayout;
044:        import java.awt.Color;
045:        import java.awt.Component;
046:        import java.awt.Font;
047:        import java.awt.Graphics;
048:        import java.util.ArrayList;
049:        import java.util.List;
050:
051:        import javax.swing.BorderFactory;
052:        import javax.swing.BoxLayout;
053:        import javax.swing.JCheckBox;
054:        import javax.swing.JLabel;
055:        import javax.swing.JPanel;
056:        import javax.swing.JScrollPane;
057:        import javax.swing.JTable;
058:        import javax.swing.SwingConstants;
059:        import javax.swing.UIManager;
060:        import javax.swing.border.Border;
061:        import javax.swing.table.AbstractTableModel;
062:        import javax.swing.table.DefaultTableCellRenderer;
063:        import javax.swing.table.JTableHeader;
064:        import javax.swing.table.TableCellRenderer;
065:        import javax.swing.table.TableColumn;
066:
067:        import net.java.hulp.i18n.Logger;
068:        import org.netbeans.modules.etl.logger.Localizer;
069:        import org.netbeans.modules.etl.logger.LogUtil;
070:        import org.netbeans.modules.sql.framework.model.SQLDBTable;
071:        import org.netbeans.modules.sql.framework.model.SourceTable;
072:        import org.netbeans.modules.sql.framework.model.TargetTable;
073:        import org.netbeans.modules.sql.framework.model.impl.AbstractDBTable;
074:
075:        /**
076:         * This class represents table for meta data. This holds a JTable for showing table meta
077:         * data.
078:         * 
079:         * @author Sanjeeth Duvuru
080:         * @version $Revision$
081:         */
082:        public class ETLCollaborationWizardTablePanel extends JPanel {
083:
084:            private static transient final Logger mLogger = LogUtil
085:                    .getLogger(ETLCollaborationWizardTablePanel.class.getName());
086:            private static transient final Localizer mLoc = Localizer.get();
087:
088:            class MetaTableComponent extends JTable {
089:                public MetaTableComponent() {
090:                    setDefaultRenderer(AbstractDBTable.class,
091:                            new MyTableModelCellRenderer());
092:                    setDefaultRenderer(Boolean.class, new MyBooleanRenderer());
093:
094:                    JTableHeader header = this .getTableHeader();
095:                    header.setReorderingAllowed(false);
096:                    header.setResizingAllowed(false);
097:                }
098:            }
099:
100:            static class MyBooleanRenderer extends JCheckBox implements 
101:                    TableCellRenderer {
102:                protected static Border noFocusBorder = BorderFactory
103:                        .createEmptyBorder(1, 1, 1, 1);
104:
105:                private JPanel myPanel;
106:
107:                /**
108:                 * Creates a default MyBooleanRenderer.
109:                 */
110:                public MyBooleanRenderer() {
111:                    super ();
112:                    setHorizontalAlignment(SwingConstants.CENTER);
113:                    setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
114:
115:                    myPanel = new JPanel();
116:                    myPanel.setLayout(new BorderLayout());
117:                    myPanel.add(this , BorderLayout.CENTER);
118:                    myPanel.setOpaque(true);
119:                    myPanel.setBorder(noFocusBorder);
120:                }
121:
122:                public Component getTableCellRendererComponent(JTable table,
123:                        Object value, boolean isSelected, boolean hasFocus,
124:                        int row, int column) {
125:                    RowDataWrapper rowDW = ((MyTableModel) table.getModel())
126:                            .getRowDataWrapper(row);
127:
128:                    if (rowDW != null && !rowDW.isEditable().booleanValue()) {
129:                        setEnabled(false);
130:                        setFocusable(false);
131:
132:                        setBackground(Color.LIGHT_GRAY);
133:
134:                        Object obj = rowDW.getTable();
135:
136:                        if (obj instanceof  TargetTable) {
137:                            TargetTable tt = (TargetTable) obj;
138:                            if (tt.isSelected()) {
139:                                String nbBundle1 = mLoc
140:                                        .t(
141:                                                "PRSR001: Table {0} already exists as target in this collaboration.",
142:                                                rowDW.getTable());
143:                                setToolTipText(Localizer.parse(nbBundle1));
144:                            } else {
145:                                String nbBundle2 = mLoc
146:                                        .t(
147:                                                "PRSR001: Table {0} already exists as source table in this collaboration.",
148:                                                rowDW.getTable());
149:                                setToolTipText(Localizer.parse(nbBundle2));
150:                            }
151:                        }
152:
153:                        if (obj instanceof  SourceTable) {
154:                            SourceTable st = (SourceTable) obj;
155:                            if (!st.isSelected()) {
156:                                String nbBundle3 = mLoc
157:                                        .t(
158:                                                "PRSR001: Table {0} already exists as target table in this collaboration.",
159:                                                rowDW.getTable());
160:                                setToolTipText(Localizer.parse(nbBundle3));
161:                            }
162:                        }
163:                        myPanel.setBorder(noFocusBorder);
164:                        myPanel.setBackground(Color.LIGHT_GRAY);
165:                    } else {
166:                        if (isSelected) {
167:                            setForeground(table.getSelectionForeground());
168:                            setBackground(table.getSelectionBackground());
169:
170:                            myPanel.setForeground(table
171:                                    .getSelectionForeground());
172:                            myPanel.setBackground(table
173:                                    .getSelectionBackground());
174:                        } else {
175:                            setForeground(table.getForeground());
176:                            setBackground(table.getBackground());
177:
178:                            myPanel.setForeground(table.getForeground());
179:                            myPanel.setBackground(table.getBackground());
180:                        }
181:
182:                        if (hasFocus) { // NOI18N this scope block
183:                            myPanel
184:                                    .setBorder(UIManager
185:                                            .getBorder("Table.focusCellHighlightBorder"));
186:                            if (table.isCellEditable(row, column)) {
187:                                setForeground(UIManager
188:                                        .getColor("Table.focusCellForeground"));
189:                                setBackground(UIManager
190:                                        .getColor("Table.focusCellBackground"));
191:                            }
192:                            myPanel.setForeground(UIManager
193:                                    .getColor("Table.focusCellForeground"));
194:                            myPanel.setBackground(UIManager
195:                                    .getColor("Table.focusCellBackground"));
196:                        } else {
197:                            myPanel.setBorder(noFocusBorder);
198:                        }
199:
200:                        setEnabled(true);
201:                        setFocusable(true);
202:                        setToolTipText("");
203:                    }
204:
205:                    setSelected((value != null && ((Boolean) value)
206:                            .booleanValue()));
207:                    return myPanel;
208:                }
209:
210:                /**
211:                 * Overrides <code>JComponent.setBackground</code> to assign the
212:                 * unselected-background color to the specified color.
213:                 * 
214:                 * @param c set the background color to this value
215:                 */
216:                public void setBackground(Color c) {
217:                    super .setBackground(c);
218:                }
219:
220:                /**
221:                 * Overrides <code>JComponent.setForeground</code> to assign the
222:                 * unselected-foreground color to the specified color.
223:                 * 
224:                 * @param c set the foreground color to this value
225:                 */
226:                public void setForeground(Color c) {
227:                    super .setForeground(c);
228:                }
229:            }
230:
231:            class MyTableModel extends AbstractTableModel {
232:                private String[] columnNames = { "Select", "Table Name" };
233:
234:                private List rowList;
235:
236:                public MyTableModel(List testList) {
237:                    rowList = new ArrayList();
238:
239:                    for (int i = 0; i < testList.size(); i++) {
240:                        RowDataWrapper rowData = new RowDataWrapper(
241:                                (SQLDBTable) testList.get(i));
242:                        rowList.add(rowData);
243:                    }
244:                }
245:
246:                /*
247:                 * JTable uses this method to determine the default renderer/ editor for each
248:                 * cell. If we didn't implement this method, then the last column would contain
249:                 * text ("true"/"false"), rather than a check box.
250:                 */
251:                public Class getColumnClass(int c) {
252:                    return getValueAt(0, c).getClass();
253:                }
254:
255:                public int getColumnCount() {
256:                    return columnNames.length;
257:                }
258:
259:                public String getColumnName(int col) {
260:                    return columnNames[col];
261:                }
262:
263:                public int getRowCount() {
264:                    return rowList.size();
265:                }
266:
267:                public RowDataWrapper getRowDataWrapper(int row) {
268:                    if (row < rowList.size()) {
269:                        return (RowDataWrapper) rowList.get(row);
270:                    }
271:
272:                    return null;
273:                }
274:
275:                public ArrayList getTables() {
276:                    ArrayList tableList = new ArrayList();
277:
278:                    for (int i = 0; i < rowList.size(); i++) {
279:                        RowDataWrapper rowData = (RowDataWrapper) rowList
280:                                .get(i);
281:                        tableList.add(rowData.getTable());
282:                    }
283:
284:                    return tableList;
285:                }
286:
287:                public Object getValueAt(int row, int col) {
288:                    RowDataWrapper rowData = (RowDataWrapper) rowList.get(row);
289:                    switch (col) {
290:                    case 0:
291:                        return rowData.isSelected();
292:                    case 1:
293:                        return rowData.getTable();
294:
295:                    }
296:
297:                    return String.valueOf(col + "?");
298:                }
299:
300:                /*
301:                 * Don't need to implement this method unless your table's editable.
302:                 */
303:                public boolean isCellEditable(int row, int col) {
304:                    //Note that the data/cell address is constant,
305:                    //no matter where the cell appears onscreen.
306:                    Object rowObj = rowList.get(row);
307:                    return (rowObj != null) ? ((RowDataWrapper) rowObj)
308:                            .isEditable().booleanValue()
309:                            && (col == 0) : false;
310:                }
311:
312:                public void setCellEditable(int row, int col, boolean flag) {
313:                    Object rowObj = rowList.get(row);
314:                    if (rowObj != null) {
315:                        ((RowDataWrapper) rowObj)
316:                                .setEditable(flag ? Boolean.TRUE
317:                                        : Boolean.FALSE);
318:                    }
319:                }
320:
321:                /*
322:                 * Don't need to implement this method unless your table's data can change.
323:                 */
324:                public void setValueAt(Object value, int row, int col) {
325:                    RowDataWrapper rowData = (RowDataWrapper) rowList.get(row);
326:                    switch (col) {
327:                    case 0:
328:                        rowData.setSelected((Boolean) value);
329:                        fireTableRowsUpdated(row, row);
330:                        break;
331:                    }
332:                }
333:            }
334:
335:            static class MyTableModelCellRenderer extends
336:                    DefaultTableCellRenderer {
337:                protected static Border noFocusBorder1 = BorderFactory
338:                        .createEmptyBorder(1, 1, 1, 1);
339:
340:                public Component getTableCellRendererComponent(JTable table,
341:                        Object value, boolean isSelected, boolean hasFocus,
342:                        int row, int column) {
343:                    JLabel renderer = (JLabel) super 
344:                            .getTableCellRendererComponent(table, value,
345:                                    isSelected, hasFocus, row, column);
346:                    MyTableModel model = (MyTableModel) table.getModel();
347:
348:                    RowDataWrapper rowDW = model.getRowDataWrapper(row);
349:                    if (rowDW != null && !rowDW.isEditable().booleanValue()) {
350:                        renderer.setEnabled(false);
351:                        renderer.setBackground(Color.lightGray);
352:
353:                        Object obj = rowDW.getTable();
354:
355:                        if (obj instanceof  TargetTable) {
356:                            TargetTable tt = (TargetTable) obj;
357:                            if (tt.isSelected()) {
358:                                String nbBundle4 = mLoc
359:                                        .t(
360:                                                "PRSR001: Table {0} already exists as target in this collaboration.",
361:                                                rowDW.getTable());
362:                                renderer.setToolTipText(Localizer
363:                                        .parse(nbBundle4));
364:                            } else {
365:                                String nbBundle5 = mLoc
366:                                        .t(
367:                                                "PRSR001: Table {0} already exists as source table in this collaboration.",
368:                                                rowDW.getTable());
369:                                renderer.setToolTipText(Localizer
370:                                        .parse(nbBundle5));
371:                            }
372:                        }
373:
374:                        if (obj instanceof  SourceTable) {
375:                            SourceTable st = (SourceTable) obj;
376:                            if (!st.isSelected()) {
377:                                String nbBundle6 = mLoc
378:                                        .t(
379:                                                "PRSR001: Table {0} already exists as target table in this collaboration.",
380:                                                rowDW.getTable());
381:                                renderer.setToolTipText(Localizer
382:                                        .parse(nbBundle6));
383:                            }
384:                        }
385:
386:                        renderer.setBorder(noFocusBorder1);
387:                        renderer.setFocusable(false);
388:                    } else {
389:                        if (isSelected) {
390:                            renderer.setForeground(table
391:                                    .getSelectionForeground());
392:                            renderer.setBackground(table
393:                                    .getSelectionBackground());
394:                        } else {
395:                            renderer.setForeground(table.getForeground());
396:                            renderer.setBackground(table.getBackground());
397:                        }
398:
399:                        renderer.setToolTipText("");
400:                        renderer.setEnabled(true);
401:                        renderer.setFocusable(true);
402:                    }
403:
404:                    return renderer;
405:                }
406:            }
407:
408:            class RowDataWrapper {
409:                private SQLDBTable table;
410:
411:                public RowDataWrapper(SQLDBTable mTable) {
412:                    table = mTable;
413:                }
414:
415:                public Object getTable() {
416:                    return table;
417:                }
418:
419:                public Boolean isEditable() {
420:                    return table.isEditable() ? Boolean.TRUE : Boolean.FALSE;
421:                }
422:
423:                public Boolean isSelected() {
424:                    return table.isSelected() ? Boolean.TRUE : Boolean.FALSE;
425:                }
426:
427:                public void setEditable(Boolean isEditable) {
428:                    table.setEditable(isEditable.booleanValue());
429:                }
430:
431:                public void setSelected(Boolean isSelected) {
432:                    table.setSelected(isSelected.booleanValue());
433:                }
434:            }
435:
436:            /* font selection for column data in table body */
437:            private static final Font FONT_TABLE_COLUMNS = new Font("Dialog",
438:                    Font.PLAIN, 10);
439:
440:            /* font selection for column headers in table body */
441:            private static final Font FONT_TABLE_HEADER = new Font("Dialog",
442:                    Font.BOLD, 10);
443:
444:            private JPanel headerPnl;
445:
446:            /* table to display meta data */
447:            private MetaTableComponent metaDataTable;
448:
449:            /* scrollpane for columns JTable */
450:            private JScrollPane tableScroll;
451:
452:            /** Creates a default instance of ETLCollaborationWizardTablePanel */
453:            public ETLCollaborationWizardTablePanel() {
454:            }
455:
456:            /**
457:             * Creates a new instance of ETLCollaborationWizardTablePanel to render the selection
458:             * of tables participating in an ETL collaboration.
459:             * 
460:             * @param testList List of tables
461:             */
462:            public ETLCollaborationWizardTablePanel(List testList) {
463:                setOpaque(false);
464:
465:                JPanel p = new JPanel();
466:
467:                p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
468:                p.setOpaque(false);
469:
470:                headerPnl = new JPanel();
471:                headerPnl.setLayout(new BorderLayout());
472:                headerPnl.setOpaque(false);
473:                headerPnl.add(p, BorderLayout.NORTH);
474:
475:                addTable(testList);
476:            }
477:
478:            /**
479:             * Gets associated JTable.
480:             * 
481:             * @return JTable
482:             */
483:            public JTable getTable() {
484:                return this .metaDataTable;
485:            }
486:
487:            /**
488:             * Gets list of selected tables.
489:             * 
490:             * @return List of selected tables
491:             */
492:            public List getTables() {
493:                MyTableModel tableModel = (MyTableModel) metaDataTable
494:                        .getModel();
495:                return tableModel.getTables();
496:            }
497:
498:            /**
499:             * Paints this component
500:             * 
501:             * @param g graphics context
502:             */
503:            public void paint(Graphics g) {
504:                super .paint(g);
505:            }
506:
507:            /**
508:             * Populates selected tables using items contained in the given List.
509:             * 
510:             * @param tableNameList List of tables to use in repopulating set of selected tables
511:             */
512:            public void resetTable(List tableNameList) {
513:                MyTableModel myMod = new MyTableModel(tableNameList);
514:                metaDataTable.setModel(myMod);
515:
516:                //set checkbox column size
517:                TableColumn column = metaDataTable.getColumnModel()
518:                        .getColumn(0);
519:                column.setResizable(false);
520:                column.setMinWidth(40);
521:                column.setPreferredWidth(40);
522:                column.setMaxWidth(80);
523:
524:            }
525:
526:            private void addTable(List testList) {
527:                metaDataTable = new MetaTableComponent();
528:
529:                metaDataTable.setFont(FONT_TABLE_COLUMNS);
530:                metaDataTable.getTableHeader().setFont(FONT_TABLE_HEADER);
531:
532:                MyTableModel myModel = new MyTableModel(testList);
533:                metaDataTable.setModel(myModel);
534:
535:                setLayout(new BorderLayout());
536:                add(headerPnl, BorderLayout.NORTH);
537:
538:                //set checkbox column size
539:                TableColumn column = metaDataTable.getColumnModel()
540:                        .getColumn(0);
541:                column.setResizable(false);
542:                column.setMinWidth(40);
543:                column.setPreferredWidth(40);
544:                column.setMaxWidth(80);
545:
546:                tableScroll = new JScrollPane(metaDataTable);
547:
548:                javax.swing.border.Border inside = BorderFactory
549:                        .createCompoundBorder(BorderFactory.createEmptyBorder(
550:                                3, 3, 3, 3), BorderFactory
551:                                .createLineBorder(Color.GRAY));
552:
553:                tableScroll.setBorder(BorderFactory.createCompoundBorder(
554:                        BorderFactory.createEtchedBorder(), inside));
555:                add(tableScroll, BorderLayout.CENTER);
556:            }
557:        }
w__ww___.___j_av__a__2_s__._c___o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.