Source Code Cross Referenced for MappedObjectPanelManager.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » plugins » hibernate » mapping » 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 » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.plugins.hibernate.mapping 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.squirrel_sql.plugins.hibernate.mapping;
002:
003:        import net.sourceforge.squirrel_sql.client.session.ISession;
004:        import net.sourceforge.squirrel_sql.plugins.hibernate.ConnectionListener;
005:        import net.sourceforge.squirrel_sql.plugins.hibernate.HibernateConnection;
006:        import net.sourceforge.squirrel_sql.plugins.hibernate.HibernatePluginResources;
007:        import net.sourceforge.squirrel_sql.plugins.hibernate.IHibernateConnectionProvider;
008:        import net.sourceforge.squirrel_sql.plugins.hibernate.configuration.HibernateConfiguration;
009:
010:        import javax.swing.*;
011:        import javax.swing.event.TreeExpansionEvent;
012:        import javax.swing.event.TreeExpansionListener;
013:        import javax.swing.event.TreeSelectionEvent;
014:        import javax.swing.event.TreeSelectionListener;
015:        import javax.swing.tree.DefaultMutableTreeNode;
016:        import javax.swing.tree.DefaultTreeModel;
017:        import java.awt.event.ActionEvent;
018:        import java.awt.event.ActionListener;
019:        import java.util.ArrayList;
020:        import java.util.HashMap;
021:        import java.util.Collections;
022:        import java.util.prefs.Preferences;
023:
024:        public class MappedObjectPanelManager {
025:
026:            private static final String PERF_KEY_OBJ_TAB_CHKSHOWQUALIFIED = "Squirrel.hibernateplugin.chkShowQualified";
027:
028:            private MappedObjectPanel _panel;
029:            private IHibernateConnectionProvider _connectionProvider;
030:            private ISession _session;
031:            private DefaultMutableTreeNode _root;
032:            private HashMap<String, MappedClassInfo> _mappedClassInfoByClassName;
033:            private DetailPanelController _detailPanelController;
034:            private ArrayList<MappedClassInfoTreeWrapper> _mappedClassInfoTreeWrappers;
035:
036:            public MappedObjectPanelManager(
037:                    IHibernateConnectionProvider connectionProvider,
038:                    ISession session, HibernatePluginResources resource) {
039:                _connectionProvider = connectionProvider;
040:                _session = session;
041:
042:                _detailPanelController = new DetailPanelController();
043:                _panel = new MappedObjectPanel(_detailPanelController
044:                        .getDetailComponent());
045:
046:                _root = new DefaultMutableTreeNode(new MappingRoot());
047:                _panel.objectTree.setModel(new DefaultTreeModel(_root));
048:
049:                _panel.objectTree.setCellRenderer(new MappingTreeCellRenderer(
050:                        resource));
051:
052:                nodeStructurChanged(_root);
053:
054:                _panel.objectTree
055:                        .addTreeExpansionListener(new TreeExpansionListener() {
056:                            public void treeExpanded(TreeExpansionEvent event) {
057:                                onTreeExpanded(event);
058:                            }
059:
060:                            public void treeCollapsed(TreeExpansionEvent event) {
061:                            }
062:                        });
063:
064:                _panel.objectTree
065:                        .addTreeSelectionListener(new TreeSelectionListener() {
066:                            public void valueChanged(TreeSelectionEvent e) {
067:                                onTreeSelectionChanged(e);
068:                            }
069:                        });
070:
071:                _connectionProvider
072:                        .addConnectionListener(new ConnectionListener() {
073:                            public void connectionOpened(
074:                                    HibernateConnection con,
075:                                    HibernateConfiguration cfg) {
076:                                initRoot(con, cfg);
077:                                initTree(con);
078:                            }
079:
080:                            public void connectionClosed() {
081:                                onConnectionClosed();
082:                            }
083:                        });
084:
085:                _panel.chkShowQualified.addActionListener(new ActionListener() {
086:                    public void actionPerformed(ActionEvent e) {
087:                        onChkQualified();
088:                    }
089:                });
090:
091:                _panel.chkShowQualified.setSelected(Preferences.userRoot()
092:                        .getBoolean(PERF_KEY_OBJ_TAB_CHKSHOWQUALIFIED, false));
093:
094:            }
095:
096:            private void initRoot(HibernateConnection con,
097:                    HibernateConfiguration cfg) {
098:                MappingRoot mr = (MappingRoot) _root.getUserObject();
099:
100:                mr.init(con, cfg);
101:
102:            }
103:
104:            private void onChkQualified() {
105:                HibernateConnection con = _connectionProvider
106:                        .getHibernateConnection();
107:
108:                if (null == con) {
109:                    return;
110:                }
111:
112:                _root.removeAllChildren();
113:
114:                initTree(con);
115:            }
116:
117:            private void onTreeSelectionChanged(TreeSelectionEvent e) {
118:                DefaultMutableTreeNode n = (DefaultMutableTreeNode) e.getPath()
119:                        .getLastPathComponent();
120:
121:                if (null != n && null != n.getUserObject()) {
122:                    _detailPanelController.selectionChanged(n.getUserObject());
123:                } else {
124:                    _detailPanelController.clearDetail();
125:                }
126:            }
127:
128:            private void onTreeExpanded(TreeExpansionEvent event) {
129:                DefaultMutableTreeNode mappedClassInfoWrapperNode = (DefaultMutableTreeNode) event
130:                        .getPath().getLastPathComponent();
131:
132:                Object userObject = mappedClassInfoWrapperNode.getUserObject();
133:
134:                if (userObject instanceof  MappedClassInfoTreeWrapper
135:                        && false == ((MappedClassInfoTreeWrapper) userObject)
136:                                .isExpanded()) {
137:
138:                    for (int i = 0; i < mappedClassInfoWrapperNode
139:                            .getChildCount(); ++i) {
140:                        DefaultMutableTreeNode propertyInfoNode = (DefaultMutableTreeNode) mappedClassInfoWrapperNode
141:                                .getChildAt(i);
142:                        PropertyInfoTreeWrapper propertyInfoTreeWrapper = (PropertyInfoTreeWrapper) propertyInfoNode
143:                                .getUserObject();
144:                        MappedClassInfo mappedClassInfo = propertyInfoTreeWrapper
145:                                .getMappedClassInfo();
146:                        addMappedClassInfoNode(
147:                                createMappedClassInfoTreeWrapper(mappedClassInfo),
148:                                propertyInfoNode);
149:                    }
150:
151:                    ((MappedClassInfoTreeWrapper) userObject).setExpanded(true);
152:
153:                    nodeStructurChanged(mappedClassInfoWrapperNode);
154:                }
155:            }
156:
157:            private MappedClassInfoTreeWrapper createMappedClassInfoTreeWrapper(
158:                    MappedClassInfo mappedClassInfo) {
159:                return new MappedClassInfoTreeWrapper(mappedClassInfo,
160:                        _panel.chkShowQualified.isSelected());
161:            }
162:
163:            private void onConnectionClosed() {
164:                MappingRoot mr = (MappingRoot) _root.getUserObject();
165:                mr.clear();
166:
167:                _root.removeAllChildren();
168:                nodeStructurChanged(_root);
169:                _detailPanelController.clearDetail();
170:            }
171:
172:            private void initTree(HibernateConnection con) {
173:                ArrayList<MappedClassInfo> mappedClassInfos = con
174:                        .getMappedClassInfos();
175:
176:                ArrayList<MappedClassInfoTreeWrapper> wrappers = initMappedClassInfos(mappedClassInfos);
177:
178:                for (MappedClassInfoTreeWrapper wrapper : wrappers) {
179:                    addMappedClassInfoNode(wrapper, _root);
180:                }
181:
182:                nodeStructurChanged(_root);
183:            }
184:
185:            private void nodeStructurChanged(DefaultMutableTreeNode node) {
186:                ((DefaultTreeModel) _panel.objectTree.getModel())
187:                        .nodeStructureChanged(node);
188:            }
189:
190:            private void addMappedClassInfoNode(
191:                    MappedClassInfoTreeWrapper mappedClassInfoTreeWrapper,
192:                    DefaultMutableTreeNode parent) {
193:                _mappedClassInfoTreeWrappers.add(mappedClassInfoTreeWrapper);
194:
195:                DefaultMutableTreeNode mappedClassInfoNode = new DefaultMutableTreeNode(
196:                        mappedClassInfoTreeWrapper);
197:
198:                PropertyInfo[] propertyInfos = mappedClassInfoTreeWrapper
199:                        .getMappedClassInfo().getAttributes();
200:
201:                for (PropertyInfo propertyInfo : propertyInfos) {
202:                    String className = propertyInfo.getHibernatePropertyInfo()
203:                            .getClassName();
204:                    if (_mappedClassInfoByClassName.containsKey(className)) {
205:                        PropertyInfoTreeWrapper propertyInfoTreeWrapper = new PropertyInfoTreeWrapper(
206:                                propertyInfo, _mappedClassInfoByClassName
207:                                        .get(className));
208:                        DefaultMutableTreeNode propertyInfoNode = new DefaultMutableTreeNode(
209:                                propertyInfoTreeWrapper);
210:                        mappedClassInfoNode.add(propertyInfoNode);
211:                    }
212:                }
213:
214:                parent.add(mappedClassInfoNode);
215:            }
216:
217:            private ArrayList<MappedClassInfoTreeWrapper> initMappedClassInfos(
218:                    ArrayList<MappedClassInfo> mappedClassInfos) {
219:                ArrayList<MappedClassInfoTreeWrapper> ret = new ArrayList<MappedClassInfoTreeWrapper>();
220:
221:                _mappedClassInfoByClassName = new HashMap<String, MappedClassInfo>();
222:                for (MappedClassInfo mappedClassInfo : mappedClassInfos) {
223:                    _mappedClassInfoByClassName.put(mappedClassInfo
224:                            .getClassName(), mappedClassInfo);
225:                    ret.add(createMappedClassInfoTreeWrapper(mappedClassInfo));
226:                }
227:
228:                _mappedClassInfoTreeWrappers = new ArrayList<MappedClassInfoTreeWrapper>();
229:
230:                Collections.sort(ret);
231:
232:                return ret;
233:            }
234:
235:            public JComponent getComponent() {
236:                return _panel;
237:            }
238:
239:            public void closing() {
240:                _panel.closing();
241:                Preferences.userRoot().putBoolean(
242:                        PERF_KEY_OBJ_TAB_CHKSHOWQUALIFIED,
243:                        _panel.chkShowQualified.isSelected());
244:            }
245:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.