Source Code Cross Referenced for TreeTableModelAdapter.java in  » Database-Client » iSQL-Viewer » org » isqlviewer » swing » outline » Java Source Code / Java DocumentationJava Source Code and Java Documentation

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


001:        /*
002:         * The contents of this file are subject to the Mozilla Public License
003:         * Version 1.1 (the "License"); you may not use this file except in
004:         * compliance with the License. You may obtain a copy of the License at
005:         * http://www.mozilla.org/MPL/
006:         *
007:         * Software distributed under the License is distributed on an "AS IS"
008:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
009:         * License for the specific language governing rights and limitations
010:         * under the License.
011:         * 
012:         * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
013:         *
014:         * The Initial Developer of the Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
015:         * Portions created by Mark A. Kobold are Copyright (C) 2000-2007. All Rights Reserved.
016:         *
017:         * Contributor(s): 
018:         *  Mark A. Kobold [mkobold <at> isqlviewer <dot> com].
019:         *  
020:         * If you didn't download this code from the following link, you should check
021:         * if you aren't using an obsolete version: http://www.isqlviewer.com
022:         */
023:        package org.isqlviewer.swing.outline;
024:
025:        import javax.swing.JTree;
026:        import javax.swing.SwingUtilities;
027:        import javax.swing.event.TreeExpansionEvent;
028:        import javax.swing.event.TreeExpansionListener;
029:        import javax.swing.event.TreeModelEvent;
030:        import javax.swing.event.TreeModelListener;
031:        import javax.swing.table.AbstractTableModel;
032:        import javax.swing.tree.TreePath;
033:
034:        /**
035:         * TreeTableModel is the model used by a JTreeTable.
036:         * <p>
037:         * It extends TreeModel to add methods for getting inforamtion about the set of columns each node in the TreeTableModel
038:         * may have. Each column, like a column in a TableModel, has a name and a type associated with it. Each node in the
039:         * TreeTableModel can return a value for each of the columns and set that value if isCellEditable() returns true.
040:         * 
041:         * @author Philip Milne
042:         * @author Scott Violet
043:         */
044:        public class TreeTableModelAdapter extends AbstractTableModel {
045:
046:            private static final long serialVersionUID = 1531337763071850568L;
047:
048:            private JTree tree;
049:            private OutlineModel treeTableModel;
050:
051:            public TreeTableModelAdapter(OutlineModel treeTableModel, JTree tree) {
052:
053:                this .tree = tree;
054:                this .treeTableModel = treeTableModel;
055:
056:                tree.addTreeExpansionListener(new TreeExpansionListener() {
057:
058:                    // Don't use fireTableRowsInserted() here; the selection model
059:                    // would get updated twice.
060:                    public void treeExpanded(TreeExpansionEvent event) {
061:
062:                        fireTableDataChanged();
063:                    }
064:
065:                    public void treeCollapsed(TreeExpansionEvent event) {
066:
067:                        fireTableDataChanged();
068:                    }
069:                });
070:
071:                // Install a TreeModelListener that can update the table when
072:                // tree changes. We use delayedFireTableDataChanged as we can
073:                // not be guaranteed the tree will have finished processing
074:                // the event before us.
075:                treeTableModel.addTreeModelListener(new TreeModelListener() {
076:
077:                    public void treeNodesChanged(TreeModelEvent e) {
078:
079:                        delayedFireTableDataChanged();
080:                    }
081:
082:                    public void treeNodesInserted(TreeModelEvent e) {
083:
084:                        delayedFireTableDataChanged();
085:                    }
086:
087:                    public void treeNodesRemoved(TreeModelEvent e) {
088:
089:                        delayedFireTableDataChanged();
090:                    }
091:
092:                    public void treeStructureChanged(TreeModelEvent e) {
093:
094:                        delayedFireTableDataChanged();
095:                    }
096:                });
097:            }
098:
099:            // Wrappers, implementing TableModel interface.
100:
101:            public int getColumnCount() {
102:
103:                return treeTableModel.getColumnCount();
104:            }
105:
106:            @Override
107:            public String getColumnName(int column) {
108:
109:                return treeTableModel.getColumnName(column);
110:            }
111:
112:            @Override
113:            public Class<?> getColumnClass(int column) {
114:
115:                return treeTableModel.getColumnClass(column);
116:            }
117:
118:            public int getRowCount() {
119:
120:                return tree.getRowCount();
121:            }
122:
123:            protected Object nodeForRow(int row) {
124:
125:                TreePath treePath = tree.getPathForRow(row);
126:                if (treePath == null) {
127:                    return null;
128:                }
129:                return treePath.getLastPathComponent();
130:            }
131:
132:            public Object getValueAt(int row, int column) {
133:
134:                return treeTableModel.getValueAt(nodeForRow(row), column);
135:            }
136:
137:            @Override
138:            public boolean isCellEditable(int row, int column) {
139:
140:                return treeTableModel.isCellEditable(nodeForRow(row), column);
141:            }
142:
143:            @Override
144:            public void setValueAt(Object value, int row, int column) {
145:
146:                treeTableModel.setValueAt(value, nodeForRow(row), column);
147:            }
148:
149:            /**
150:             * Invokes fireTableDataChanged after all the pending events have been processed. SwingUtilities.invokeLater is used
151:             * to handle this.
152:             */
153:            protected void delayedFireTableDataChanged() {
154:
155:                SwingUtilities.invokeLater(new Runnable() {
156:
157:                    public void run() {
158:
159:                        fireTableDataChanged();
160:                    }
161:                });
162:            }
163:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.