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


001:        package net.sourceforge.squirrel_sql.fw.gui;
002:
003:        /*
004:         * Copyright (C) 2002-2003 Colin Bell
005:         * colbell@users.sourceforge.net
006:         *
007:         * This library is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:         *
012:         * This library is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this library; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
020:         */
021:        import java.sql.SQLException;
022:        import java.util.Map;
023:        import java.util.TreeMap;
024:
025:        import javax.swing.JComboBox;
026:
027:        import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
028:        import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
029:        import net.sourceforge.squirrel_sql.fw.util.StringManager;
030:        import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
031:
032:        /**
033:         * This <TT>JComboBox</TT> will display all the catalogs
034:         * in an SQL connection.
035:         *
036:         * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
037:         */
038:        public class SQLCatalogsComboBox extends JComboBox {
039:            private static final long serialVersionUID = 1L;
040:
041:            /** Internationalized strings for this class. */
042:            private static final StringManager s_stringMgr = StringManagerFactory
043:                    .getStringManager(SQLCatalogsComboBox.class);
044:
045:            private interface i18n {
046:                // i18n[SQLCatalogsComboBox.noneLabel=None]
047:                String NONE_LABEL = s_stringMgr
048:                        .getString("SQLCatalogsComboBox.noneLabel");
049:            }
050:
051:            /**
052:             * Default ctor. Builds an empty combo box.
053:             */
054:            public SQLCatalogsComboBox() {
055:                super ();
056:            }
057:
058:            /**
059:             * Sets the catalogs that should appear in the catalog drop-down menu. Clear control and places all the
060:             * catalog names from the list in it in alphabetic sequence. Selects the specified catalog; If the
061:             * selectedCatalog is null, then selects the first catalog.
062:             * 
063:             * @param catalogs
064:             *           an array of catalogs names that should in the catalogs drop-down menu.
065:             * @param selectedCatalog
066:             *           the catalog for the current connection that should be selected.
067:             */
068:            public void setCatalogs(String[] catalogs, String selectedCatalog) {
069:                super .removeAllItems();
070:                if (catalogs != null) {
071:                    final Map<String, String> map = new TreeMap<String, String>();
072:                    for (String catalog : catalogs) {
073:                        if (!isEmptyCatalog(catalog)) {
074:                            map.put(catalog, catalog);
075:                        }
076:                    }
077:                    if (isEmptyCatalog(selectedCatalog)) {
078:                        addItem(new NoCatalogPlaceHolder());
079:                    }
080:                    for (String catalog : map.values()) {
081:                        addItem(catalog);
082:                    }
083:                    if (!isEmptyCatalog(selectedCatalog)) {
084:                        setSelectedCatalog(selectedCatalog);
085:                    }
086:                }
087:                setMaximumSize(getPreferredSize());
088:            }
089:
090:            private boolean isEmptyCatalog(String catalog) {
091:                return catalog == null || "".equals(catalog);
092:            }
093:
094:            /**
095:             * Set the <TT>SQLConnection</TT> for this control. Clear control and place all the catalog names from
096:             * the connection in it in alphabetic sequence. Select the first catalog.
097:             * 
098:             * @param conn
099:             *           <TT>SQLConnection</TT> to retrieve catalog names from.
100:             * @throws IllegalArgumentException
101:             *            Thrown if a <TT>null</TT> <TT>SQLConnection</TT> passed.
102:             * @throws SQLException
103:             *            Thrown if an SQL exception occurs.
104:             * @deprecated This method has been deprecated because the view should not have direct access to the model.
105:             *             Use the setCatalogs method instead.
106:             */
107:            public void setConnection(ISQLConnection conn) throws SQLException {
108:                if (conn == null) {
109:                    throw new IllegalArgumentException("SQLConnection == null");
110:                }
111:                final SQLDatabaseMetaData md = conn.getSQLMetaData();
112:                if (md.supportsCatalogs()) {
113:                    final String[] catalogs = md.getCatalogs();
114:                    if (catalogs != null) {
115:                        setCatalogs(catalogs, conn.getCatalog());
116:                    }
117:                }
118:            }
119:
120:            public String getSelectedCatalog() {
121:                return getSelectedItem().toString();
122:            }
123:
124:            public void setSelectedCatalog(String selectedCatalog) {
125:                if (selectedCatalog != null) {
126:                    getModel().setSelectedItem(selectedCatalog);
127:                }
128:            }
129:
130:            /**
131:             * @see javax.swing.JComboBox#setSelectedItem(java.lang.Object)
132:             */
133:            @Override
134:            public void setSelectedItem(Object o) {
135:                super .setSelectedItem(o);
136:                // If the "None" place-holder is in the list in the first position, remove it.  It is not possible to 
137:                // select the "None" place-holder upon startup, because it is already selected in the list if it is 
138:                // present.
139:                if (super .getItemAt(0) instanceof  NoCatalogPlaceHolder) {
140:                    super .removeItemAt(0);
141:                    validate();
142:                }
143:            }
144:
145:            /**
146:             * A place holder for the label "None" which is only intended to appear at startup if: 
147:             * 
148:             * 	1) the database uses catalogs and 
149:             *    2) it supports connections where the catalog is not specified.  
150:             * 
151:             * We want to allow the user to switch to any other catalog when in this state. The selected catalog by
152:             * default is the first item in the list. However, it is confusing to have that be an actual catalog, when
153:             * in fact the user did not specify one in the connection URL. So, when we connect, if the driver says that
154:             * the catalog is null, this place-holder is created to take the first position in the combobox to allow
155:             * the user to choose any other "real" catalog, and when they do, this place-holder gets removed, since it
156:             * is no longer needed at that point.
157:             * 
158:             * Note: This placeholder allows us to do instanceof instead of a string comparison, which would prevent 
159:             * the user from ever having and using a catalog called "None" (or whatever the equivalent i18n message 
160:             * label is for their internationalized strings)
161:             * 
162:             * @author manningr
163:             */
164:            private class NoCatalogPlaceHolder {
165:                public String toString() {
166:                    return i18n.NONE_LABEL;
167:                }
168:            }
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.