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


001:        package net.sourceforge.squirrel_sql.client.gui.session;
002:
003:        import java.awt.Dimension;
004:        import java.awt.GridBagConstraints;
005:        import java.awt.GridBagLayout;
006:        import java.awt.Insets;
007:        import java.awt.event.ActionListener;
008:        import java.beans.PropertyChangeEvent;
009:        import java.beans.PropertyChangeListener;
010:        import java.sql.SQLException;
011:
012:        import javax.swing.JComponent;
013:        import javax.swing.JLabel;
014:        import javax.swing.JPanel;
015:
016:        import net.sourceforge.squirrel_sql.client.session.ISession;
017:        import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
018:        import net.sourceforge.squirrel_sql.fw.gui.SQLCatalogsComboBox;
019:        import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
020:        import net.sourceforge.squirrel_sql.fw.util.StringManager;
021:        import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
022:        import net.sourceforge.squirrel_sql.fw.util.StringUtilities;
023:        import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
024:        import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
025:
026:        public class CatalogsPanel extends JPanel {
027:            /** Internationalized strings for this class. */
028:            private static final StringManager s_stringMgr = StringManagerFactory
029:                    .getStringManager(CatalogsPanel.class);
030:
031:            private static final ILogger s_log = LoggerController
032:                    .createLogger(CatalogsPanel.class);
033:
034:            private ISession _session;
035:            private JComponent _parent;
036:            private SQLCatalogsComboBox _catalogsCmb;
037:            private PropertyChangeListener _connectionPropetryListener;
038:
039:            public CatalogsPanel(ISession session, JComponent parent) {
040:                _session = session;
041:                _parent = parent;
042:
043:                _connectionPropetryListener = new PropertyChangeListener() {
044:                    public void propertyChange(PropertyChangeEvent evt) {
045:                        onConnectionPropertyChanged(evt);
046:                    }
047:                };
048:
049:                setVisible(false);
050:
051:                initInBackground();
052:            }
053:
054:            private void onConnectionPropertyChanged(PropertyChangeEvent evt) {
055:                try {
056:                    final String propName = evt.getPropertyName();
057:                    if (propName == null
058:                            || propName
059:                                    .equals(ISQLConnection.IPropertyNames.CATALOG)) {
060:                        if (_catalogsCmb != null) {
061:                            final ISQLConnection conn = _session
062:                                    .getSQLConnection();
063:                            if (!StringUtilities.areStringsEqual(conn
064:                                    .getCatalog(), _catalogsCmb
065:                                    .getSelectedCatalog())) {
066:                                _catalogsCmb.setSelectedCatalog(conn
067:                                        .getCatalog());
068:                            }
069:                        }
070:                    }
071:                } catch (SQLException e) {
072:                    s_log.error("Error processing Property ChangeEvent", e);
073:                }
074:            }
075:
076:            private void initInBackground() {
077:                try {
078:                    if (false == _session.getSQLConnection().getSQLMetaData()
079:                            .supportsCatalogs()) {
080:                        return;
081:                    }
082:
083:                    final String[] catalogs = _session.getSQLConnection()
084:                            .getSQLMetaData().getCatalogs();
085:
086:                    if (null == catalogs || 0 == catalogs.length) {
087:                        return;
088:                    }
089:
090:                    final String selected = _session.getSQLConnection()
091:                            .getCatalog();
092:
093:                    _session.getSQLConnection().removePropertyChangeListener(
094:                            _connectionPropetryListener);
095:                    _session.getSQLConnection().addPropertyChangeListener(
096:                            _connectionPropetryListener);
097:
098:                    GUIUtils.processOnSwingEventThread(new Runnable() {
099:                        public void run() {
100:                            initGuiInForeground(catalogs, selected);
101:                        }
102:                    });
103:
104:                } catch (SQLException e) {
105:                    s_log
106:                            .error(
107:                                    s_stringMgr
108:                                            .getString("SessionPanel.error.retrievecatalog"),
109:                                    e);
110:                }
111:            }
112:
113:            private void initGuiInForeground(String[] catalogs, String selected) {
114:                setLayout(new GridBagLayout());
115:                GridBagConstraints gbc;
116:
117:                gbc = new GridBagConstraints(0, 0, 1, 1, 0, 0,
118:                        GridBagConstraints.WEST, GridBagConstraints.NONE,
119:                        new Insets(0, 0, 0, 5), 0, 0);
120:                JLabel lblCatalogs = new JLabel(s_stringMgr
121:                        .getString("SessionPanel.catalog"));
122:                add(lblCatalogs, gbc);
123:
124:                _catalogsCmb = new SQLCatalogsComboBox();
125:                gbc = new GridBagConstraints(1, 0, 1, 1, 1, 0,
126:                        GridBagConstraints.WEST, GridBagConstraints.NONE,
127:                        new Insets(0, 0, 0, 5), 0, 0);
128:                add(_catalogsCmb, gbc);
129:
130:                _catalogsCmb.setCatalogs(catalogs, selected);
131:
132:                Dimension prefSize = getPreferredSize();
133:                prefSize.width = lblCatalogs.getPreferredSize().width
134:                        + _catalogsCmb.getPreferredSize().width + 20;
135:                setPreferredSize(prefSize);
136:                setMaximumSize(prefSize);
137:
138:                setVisible(true);
139:
140:                _parent.validate();
141:            }
142:
143:            public void addActionListener(ActionListener catalogsComboListener) {
144:                if (null != _catalogsCmb) {
145:                    _catalogsCmb.addActionListener(catalogsComboListener);
146:                }
147:            }
148:
149:            public void removeActionListener(
150:                    ActionListener catalogsComboListener) {
151:                if (null != _catalogsCmb) {
152:                    _catalogsCmb.addActionListener(catalogsComboListener);
153:                }
154:            }
155:
156:            public void refreshCatalogs() {
157:                removeAll();
158:
159:                _session.getApplication().getThreadPool().addTask(
160:                        new Runnable() {
161:                            public void run() {
162:                                initInBackground();
163:                            }
164:                        });
165:            }
166:
167:            public String getSelectedCatalog() {
168:                return (String) _catalogsCmb.getSelectedItem();
169:            }
170:
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.