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


001:        package net.sourceforge.squirrel_sql.plugins.hibernate;
002:
003:        import net.sourceforge.squirrel_sql.client.preferences.GlobalPreferencesSheet;
004:        import net.sourceforge.squirrel_sql.client.session.ISession;
005:        import net.sourceforge.squirrel_sql.client.session.mainpanel.IMainPanelTab;
006:        import net.sourceforge.squirrel_sql.fw.util.StringManager;
007:        import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
008:        import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
009:        import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
010:        import net.sourceforge.squirrel_sql.fw.xml.XMLBeanReader;
011:        import net.sourceforge.squirrel_sql.fw.xml.XMLException;
012:        import net.sourceforge.squirrel_sql.plugins.hibernate.configuration.HibernateConfiguration;
013:        import net.sourceforge.squirrel_sql.plugins.hibernate.configuration.HibernateConfigController;
014:        import net.sourceforge.squirrel_sql.plugins.hibernate.configuration.HibernateConfigPanel;
015:        import net.sourceforge.squirrel_sql.plugins.hibernate.mapping.MappedObjectPanelManager;
016:
017:        import javax.swing.*;
018:        import java.awt.*;
019:        import java.awt.event.ActionEvent;
020:        import java.awt.event.ActionListener;
021:        import java.io.File;
022:        import java.io.IOException;
023:        import java.util.ArrayList;
024:        import java.util.HashMap;
025:        import java.util.prefs.Preferences;
026:
027:        public class HibernateTabController implements  IMainPanelTab,
028:                IHibernateTabController, IHibernateConnectionProvider {
029:
030:            private static final StringManager s_stringMgr = StringManagerFactory
031:                    .getStringManager(HibernateTabController.class);
032:
033:            private static ILogger s_log = LoggerController
034:                    .createLogger(HibernateTabController.class);
035:
036:            private HibernateTabPanel _panel;
037:            private ISession _session;
038:            private HibernatePlugin _plugin;
039:            private static final String PREF_KEY_LAST_SELECTED_CONFIG = "SQuirreL.hibernateplugin.lastSelectedConfig";
040:            private HibernateConnection _con;
041:            private HibnerateConnector _hibnerateConnector;
042:            private HibernatePluginResources _resource;
043:            private HQLPanelController _hqlPanelController;
044:            private ArrayList<ConnectionListener> _listeners = new ArrayList<ConnectionListener>();
045:            private SQLPanelManager _sqlPanelManager;
046:            private MappedObjectPanelManager _mappedObjectsPanelManager;
047:
048:            public HibernateTabController(ISession session,
049:                    HibernatePlugin plugin, HibernatePluginResources resource) {
050:                _resource = resource;
051:                try {
052:                    _session = session;
053:                    _plugin = plugin;
054:
055:                    _hqlPanelController = new HQLPanelController(this ,
056:                            _session, resource);
057:                    _sqlPanelManager = new SQLPanelManager(_session);
058:                    _mappedObjectsPanelManager = new MappedObjectPanelManager(
059:                            this , _session, resource);
060:
061:                    _panel = new HibernateTabPanel(_mappedObjectsPanelManager
062:                            .getComponent(),
063:                            _hqlPanelController.getComponent(),
064:                            _sqlPanelManager.getComponent(), _resource);
065:                    _panel.btnConnected
066:                            .setIcon(resource
067:                                    .getIcon(HibernatePluginResources.IKeys.DISCONNECTED_IMAGE));
068:
069:                    Dimension oldSize = _panel.btnConnected.getPreferredSize();
070:                    Dimension newSize = new Dimension(oldSize.width - 20,
071:                            oldSize.height);
072:                    _panel.btnConnected.setPreferredSize(newSize);
073:
074:                    _hibnerateConnector = new HibnerateConnector(
075:                            new HibnerateConnectorListener() {
076:                                public void connected(HibernateConnection con,
077:                                        HibernateConfiguration cfg) {
078:                                    onConnected(con, cfg);
079:                                }
080:
081:                                public void connectFailed(Throwable t) {
082:                                    onConnectFailed(t);
083:                                }
084:                            });
085:
086:                    _panel.btnConnected.addActionListener(new ActionListener() {
087:                        public void actionPerformed(ActionEvent e) {
088:                            onConnect();
089:                        }
090:                    });
091:
092:                    _panel.btnOpenConfigs.setPreferredSize(_panel.btnConnected
093:                            .getPreferredSize());
094:                    _panel.btnOpenConfigs
095:                            .addActionListener(new ActionListener() {
096:                                public void actionPerformed(ActionEvent e) {
097:                                    onOpenConfigs();
098:                                }
099:                            });
100:
101:                    loadConfigsFromXml();
102:
103:                    _hqlPanelController.initActions();
104:
105:                } catch (Exception e) {
106:                    throw new RuntimeException(e);
107:                }
108:            }
109:
110:            private void onOpenConfigs() {
111:                _plugin.setHibernatePrefsListener(new HibernatePrefsListener() {
112:                    public void configurationChanged(
113:                            ArrayList<HibernateConfiguration> changedCfgs) {
114:                        onConfigurationChanged(changedCfgs);
115:                    }
116:
117:                    public HibernateConfiguration getPreselectedCfg() {
118:                        return onGetPreselectedCfg();
119:                    }
120:                });
121:                GlobalPreferencesSheet.showSheet(_plugin.getApplication(),
122:                        HibernateConfigPanel.class);
123:            }
124:
125:            private HibernateConfiguration onGetPreselectedCfg() {
126:                return (HibernateConfiguration) _panel.cboConfigurations
127:                        .getSelectedItem();
128:            }
129:
130:            private void onConfigurationChanged(
131:                    ArrayList<HibernateConfiguration> changedCfgs) {
132:                HibernateConfiguration selCfg = (HibernateConfiguration) _panel.cboConfigurations
133:                        .getSelectedItem();
134:
135:                if (null != selCfg) {
136:                    loadConfigs(changedCfgs, selCfg.getName());
137:                } else {
138:                    loadConfigs(changedCfgs, null);
139:                }
140:            }
141:
142:            private void loadConfigsFromXml() throws IOException, XMLException {
143:                XMLBeanReader reader = new XMLBeanReader();
144:                File pluginUserSettingsFolder = _plugin
145:                        .getPluginUserSettingsFolder();
146:
147:                File xmlFile = new File(pluginUserSettingsFolder.getPath(),
148:                        HibernateConfigController.HIBERNATE_CONFIGS_XML_FILE);
149:
150:                if (xmlFile.exists()) {
151:                    reader.load(xmlFile, _plugin.getClass().getClassLoader());
152:                    loadConfigs(reader, Preferences.userRoot().get(
153:                            PREF_KEY_LAST_SELECTED_CONFIG, null));
154:                }
155:            }
156:
157:            private void loadConfigs(Iterable reader, String cfgNameToSelect) {
158:                _panel.cboConfigurations.removeAllItems();
159:
160:                HashMap<String, HibernateConfiguration> cfgByName = new HashMap<String, HibernateConfiguration>();
161:                for (Object o : reader) {
162:                    HibernateConfiguration cfg = (HibernateConfiguration) o;
163:
164:                    cfgByName.put(cfg.getName(), cfg);
165:                    _panel.cboConfigurations.addItem(cfg);
166:                }
167:
168:                if (null != cfgNameToSelect) {
169:                    _panel.cboConfigurations.setSelectedItem(cfgByName
170:                            .get(cfgNameToSelect));
171:                }
172:            }
173:
174:            private void onConnect() {
175:                if (null == _con) {
176:                    if (null != _panel.cboConfigurations.getSelectedItem()) {
177:                        _panel.btnConnected.setEnabled(false);
178:                        _panel.btnConnected
179:                                .setDisabledSelectedIcon(_resource
180:                                        .getIcon(HibernatePluginResources.IKeys.CONNECTING_IMAGE));
181:                        _panel.btnConnected.repaint();
182:                        _hibnerateConnector
183:                                .connect(
184:                                        (HibernateConfiguration) _panel.cboConfigurations
185:                                                .getSelectedItem(), _session);
186:                    } else {
187:                        _panel.btnConnected.setSelected(false);
188:
189:                        // i18n[HibernateTabController.noConfigSelected=Please select a Hibernate configuration to connect to.\nHibernate configurations can be defined in the global preferences window.\nWould you like to open the window now?]
190:                        int opt = JOptionPane
191:                                .showConfirmDialog(
192:                                        _session.getApplication()
193:                                                .getMainFrame(),
194:                                        s_stringMgr
195:                                                .getString("HQLTabController.noConfigSelected"));
196:
197:                        if (JOptionPane.YES_OPTION == opt) {
198:                            GlobalPreferencesSheet.showSheet(_plugin
199:                                    .getApplication(),
200:                                    HibernateConfigPanel.class);
201:                        }
202:                    }
203:
204:                } else {
205:                    _panel.btnConnected
206:                            .setIcon(_resource
207:                                    .getIcon(HibernatePluginResources.IKeys.DISCONNECTED_IMAGE));
208:                    try {
209:                        closeConnection();
210:                    } catch (Exception e) {
211:                        s_log.error(e);
212:                    } finally {
213:                        _con = null;
214:                        _hqlPanelController.setConnection(null);
215:                    }
216:                }
217:            }
218:
219:            private void onConnected(HibernateConnection con,
220:                    HibernateConfiguration cfg) {
221:                _con = con;
222:                _panel.btnConnected
223:                        .setIcon(_resource
224:                                .getIcon(HibernatePluginResources.IKeys.CONNECTED_IMAGE));
225:                _panel.btnConnected.setEnabled(true);
226:                _hqlPanelController.setConnection(con);
227:
228:                for (ConnectionListener listener : _listeners) {
229:                    listener.connectionOpened(con, cfg);
230:                }
231:
232:            }
233:
234:            private void onConnectFailed(Throwable t) {
235:                _panel.btnConnected
236:                        .setIcon(_resource
237:                                .getIcon(HibernatePluginResources.IKeys.DISCONNECTED_IMAGE));
238:                _panel.btnConnected.setEnabled(true);
239:                _panel.btnConnected.setSelected(false);
240:                _session.showErrorMessage(t);
241:                s_log.error(t);
242:                _con = null;
243:                _hqlPanelController.setConnection(null);
244:
245:            }
246:
247:            public String getTitle() {
248:                // i18n[HibernateTabController.title=Hibernate]
249:                return s_stringMgr.getString("HQLTabController.title");
250:            }
251:
252:            public String getHint() {
253:                // i18n[HibernateTabController.hint=Support for Hibernate]
254:                return s_stringMgr.getString("HQLTabController.hint");
255:            }
256:
257:            public Component getComponent() {
258:                return _panel;
259:            }
260:
261:            public void sessionClosing(ISession session) {
262:                HibernateConfiguration cfg = (HibernateConfiguration) _panel.cboConfigurations
263:                        .getSelectedItem();
264:
265:                if (null != cfg) {
266:                    Preferences.userRoot().put(PREF_KEY_LAST_SELECTED_CONFIG,
267:                            cfg.getName());
268:                }
269:
270:                _panel.closing();
271:
272:                _mappedObjectsPanelManager.closing();
273:
274:            }
275:
276:            public void select() {
277:                _hqlPanelController.requestFocus();
278:            }
279:
280:            public void setSession(ISession session) {
281:            }
282:
283:            public void addToToolbar(AbstractAction action) {
284:                JButton btn = new JButton(action);
285:                Dimension size = btn.getPreferredSize();
286:                size.height = _panel.btnConnected.getPreferredSize().height;
287:                btn.setPreferredSize(size);
288:
289:                _panel.addToToolbar(btn);
290:            }
291:
292:            public void displaySqls(ArrayList<String> sqls) {
293:                _sqlPanelManager.displaySqls(sqls);
294:            }
295:
296:            public IHibernateConnectionProvider getHibernateConnectionProvider() {
297:                return this ;
298:            }
299:
300:            public void sessionEnding() {
301:                if (null != _con) {
302:                    closeConnection();
303:                }
304:            }
305:
306:            private void closeConnection() {
307:                _con.close();
308:
309:                for (ConnectionListener listener : _listeners) {
310:                    listener.connectionClosed();
311:                }
312:            }
313:
314:            public HibernateConnection getHibernateConnection() {
315:                return _con;
316:            }
317:
318:            public void addConnectionListener(
319:                    ConnectionListener connectionListener) {
320:                _listeners.add(connectionListener);
321:            }
322:
323:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.