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


001:        package net.sourceforge.squirrel_sql.client.gui.db;
002:
003:        /*
004:         * Copyright (C) 2001-2004 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:
022:        import static net.sourceforge.squirrel_sql.client.preferences.PreferenceType.ALIAS_DEFINITIONS;
023:        import static net.sourceforge.squirrel_sql.client.preferences.PreferenceType.GLOBAL_PREFERENCES;
024:
025:        import java.awt.GridBagConstraints;
026:        import java.awt.GridBagLayout;
027:        import java.awt.Insets;
028:        import java.awt.event.ActionEvent;
029:        import java.awt.event.ActionListener;
030:        import java.awt.event.ItemEvent;
031:        import java.awt.event.ItemListener;
032:        import java.awt.event.KeyEvent;
033:        import java.io.Serializable;
034:        import java.util.ArrayList;
035:        import java.util.Collections;
036:        import java.util.Comparator;
037:        import java.util.HashMap;
038:        import java.util.Iterator;
039:        import java.util.List;
040:        import java.util.Map;
041:
042:        import javax.swing.AbstractAction;
043:        import javax.swing.BorderFactory;
044:        import javax.swing.Box;
045:        import javax.swing.JButton;
046:        import javax.swing.JCheckBox;
047:        import javax.swing.JComboBox;
048:        import javax.swing.JComponent;
049:        import javax.swing.JLabel;
050:        import javax.swing.JPanel;
051:        import javax.swing.JPasswordField;
052:        import javax.swing.JSeparator;
053:        import javax.swing.JTextField;
054:        import javax.swing.KeyStroke;
055:        import javax.swing.SwingConstants;
056:
057:        import net.sourceforge.squirrel_sql.client.IApplication;
058:        import net.sourceforge.squirrel_sql.client.gui.BaseInternalFrame;
059:        import net.sourceforge.squirrel_sql.client.mainframe.action.AliasPropertiesCommand;
060:        import net.sourceforge.squirrel_sql.client.mainframe.action.ConnectToAliasCommand;
061:        import net.sourceforge.squirrel_sql.client.preferences.SquirrelPreferences;
062:        import net.sourceforge.squirrel_sql.client.resources.SquirrelResources;
063:        import net.sourceforge.squirrel_sql.client.session.ISession;
064:        import net.sourceforge.squirrel_sql.client.util.IdentifierFactory;
065:        import net.sourceforge.squirrel_sql.fw.gui.Dialogs;
066:        import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
067:        import net.sourceforge.squirrel_sql.fw.id.IIdentifier;
068:        import net.sourceforge.squirrel_sql.fw.id.IIdentifierFactory;
069:        import net.sourceforge.squirrel_sql.fw.persist.ValidationException;
070:        import net.sourceforge.squirrel_sql.fw.sql.ISQLAlias;
071:        import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
072:        import net.sourceforge.squirrel_sql.fw.sql.ISQLDriver;
073:        import net.sourceforge.squirrel_sql.fw.sql.SQLConnection;
074:        import net.sourceforge.squirrel_sql.fw.util.DuplicateObjectException;
075:        import net.sourceforge.squirrel_sql.fw.util.IObjectCacheChangeListener;
076:        import net.sourceforge.squirrel_sql.fw.util.ObjectCacheChangeEvent;
077:        import net.sourceforge.squirrel_sql.fw.util.StringManager;
078:        import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
079:        import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
080:        import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
081:
082:        /**
083:         * This internal frame allows the maintenance of an database alias.
084:         *
085:         * @author	<A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
086:         */
087:        @SuppressWarnings("serial")
088:        public class AliasInternalFrame extends BaseInternalFrame {
089:            /**
090:             * Maintenance types.
091:             */
092:            public interface IMaintenanceType {
093:                /** A new alias is being created. */
094:                int NEW = 1;
095:
096:                /** An existing alias is being maintained. */
097:                int MODIFY = 2;
098:
099:                /** A new alias is being created as a copy of an existing one. */
100:                int COPY = 3;
101:            }
102:
103:            /** Internationalized strings for this class. */
104:            private static final StringManager s_stringMgr = StringManagerFactory
105:                    .getStringManager(AliasInternalFrame.class);
106:
107:            /** Number of characters to show in text fields. */
108:            private static final int COLUMN_COUNT = 25;
109:
110:            /** Logger for this class. */
111:            private static final ILogger s_log = LoggerController
112:                    .createLogger(AliasInternalFrame.class);
113:
114:            /** Application API. */
115:            transient private final IApplication _app;
116:
117:            /** The <TT>ISQLAlias</TT> being maintained. */
118:            private final ISQLAlias _sqlAlias;
119:
120:            /** Frame title. */
121:            private final JLabel _titleLbl = new JLabel();
122:
123:            /**
124:             * The requested type of maintenace.
125:             * @see IMaintenanceType
126:             */
127:            private final int _maintType;
128:
129:            /** Listener to the drivers cache. */
130:            transient private DriversCacheListener _driversCacheLis;
131:
132:            /** Alias name text field.. */
133:            private final JTextField _aliasName = new JTextField();
134:
135:            /** Dropdown of all the drivers in the system. */
136:            private DriversCombo _drivers;
137:
138:            /** URL to the data source text field. */
139:            private final JTextField _url = new JTextField();
140:
141:            /** User name text field */
142:            private final JTextField _userName = new JTextField();
143:
144:            /** Password */
145:            private final JPasswordField _password = new JPasswordField();
146:
147:            /** Autologon checkbox. */
148:            private final JCheckBox _autoLogonChk = new JCheckBox(s_stringMgr
149:                    .getString("AliasInternalFrame.autologon"));
150:
151:            /** Connect at startup checkbox. */
152:            private final JCheckBox _connectAtStartupChk = new JCheckBox(
153:                    s_stringMgr
154:                            .getString("AliasInternalFrame.connectatstartup"));
155:
156:            //	/** If checked use the extended driver properties. */
157:            //	private final JCheckBox _useDriverPropsChk = new JCheckBox(s_stringMgr.getString("AliasInternalFrame.userdriverprops"));
158:
159:            /** Button that brings up the driver properties dialog. */
160:            private final JButton _aliasPropsBtn = new JButton(s_stringMgr
161:                    .getString("AliasInternalFrame.props"));
162:
163:            /** Collection of the driver properties. */
164:            //	private SQLDriverPropertyCollection _sqlDriverProps;
165:            /**
166:             * Ctor.
167:             *
168:             * @param	app			Application API.
169:             * @param	sqlAlias	The <TT>ISQLAlias</TT> to be maintained.
170:             * @param	maintType	The maintenance type.
171:             *
172:             * @throws	IllegalArgumentException
173:             * 			Thrown if <TT>null</TT> passed for <TT>app</TT> or
174:             * 			<TT>ISQLAlias</TT> or an invalid value passed for
175:             *			<TT>maintType</TT>.
176:             */
177:            AliasInternalFrame(IApplication app, ISQLAlias sqlAlias,
178:                    int maintType) {
179:                super ("", true);
180:                if (app == null) {
181:                    throw new IllegalArgumentException("IApplication == null");
182:                }
183:                if (sqlAlias == null) {
184:                    throw new IllegalArgumentException("ISQLAlias == null");
185:                }
186:                if (maintType < IMaintenanceType.NEW
187:                        || maintType > IMaintenanceType.COPY) {
188:                    // i18n[AliasInternalFrame.illegalValue=Illegal value of {0} passed for Maintenance type]
189:                    final String msg = s_stringMgr.getString(
190:                            "AliasInternalFrame.illegalValue", Integer
191:                                    .valueOf(maintType));
192:                    throw new IllegalArgumentException(msg);
193:                }
194:
195:                _app = app;
196:                _sqlAlias = sqlAlias;
197:                _maintType = maintType;
198:                createUserInterface();
199:                loadData();
200:                pack();
201:            }
202:
203:            /**
204:             * Remove listeners and then dispose of this sheet.
205:             */
206:            public void dispose() {
207:                if (_driversCacheLis != null) {
208:                    _app.getDataCache().removeDriversListener(_driversCacheLis);
209:                    _driversCacheLis = null;
210:                }
211:                super .dispose();
212:            }
213:
214:            /**
215:             * Set title of this frame. Ensure that the title label
216:             * matches the frame title.
217:             *
218:             * @param	title	New title text.
219:             */
220:            public void setTitle(String title) {
221:                super .setTitle(title);
222:                _titleLbl.setText(title);
223:            }
224:
225:            /**
226:             * Return the alias that is being maintained.
227:             *
228:             * @return	the alias that is being maintained.
229:             */
230:            ISQLAlias getSQLAlias() {
231:                return _sqlAlias;
232:            }
233:
234:            /**
235:             * Load data from the alias into GUI controls.
236:             */
237:            private void loadData() {
238:                _aliasName.setText(_sqlAlias.getName());
239:                _userName.setText(_sqlAlias.getUserName());
240:
241:                _password.setText(_sqlAlias.getPassword());
242:
243:                _autoLogonChk.setSelected(_sqlAlias.isAutoLogon());
244:                _connectAtStartupChk
245:                        .setSelected(_sqlAlias.isConnectAtStartup());
246:                //_useDriverPropsChk.setSelected(_sqlAlias.getUseDriverProperties());
247:
248:                if (_maintType != IMaintenanceType.NEW) {
249:                    _drivers.setSelectedItem(_sqlAlias.getDriverIdentifier());
250:                    _url.setText(_sqlAlias.getUrl());
251:                } else {
252:                    final ISQLDriver driver = _drivers.getSelectedDriver();
253:                    if (driver != null) {
254:                        _url.setText(driver.getUrl());
255:                    }
256:                }
257:            }
258:
259:            private void performClose() {
260:                dispose();
261:            }
262:
263:            /**
264:             * OK button pressed. Edit data and if ok save to aliases model
265:             * and then close dialog.
266:             */
267:            private void performOk() {
268:                try {
269:                    applyFromDialog(_sqlAlias);
270:                    if (_maintType == IMaintenanceType.NEW
271:                            || _maintType == IMaintenanceType.COPY) {
272:                        _app.getDataCache().addAlias(_sqlAlias);
273:                    }
274:                    _app.savePreferences(ALIAS_DEFINITIONS);
275:                    _app.savePreferences(GLOBAL_PREFERENCES);
276:                    dispose();
277:                } catch (ValidationException ex) {
278:                    _app.showErrorDialog(ex);
279:                } catch (DuplicateObjectException ex) {
280:                    _app.showErrorDialog(ex);
281:                }
282:            }
283:
284:            private void applyFromDialog(ISQLAlias alias)
285:                    throws ValidationException {
286:                ISQLDriver driver = _drivers.getSelectedDriver();
287:                if (driver == null) {
288:                    throw new ValidationException(s_stringMgr
289:                            .getString("AliasInternalFrame.error.nodriver"));
290:                }
291:                alias.setName(_aliasName.getText().trim());
292:                alias.setDriverIdentifier(_drivers.getSelectedDriver()
293:                        .getIdentifier());
294:                alias.setUrl(_url.getText().trim());
295:                alias.setUserName(_userName.getText().trim());
296:
297:                StringBuffer buf = new StringBuffer();
298:                buf.append(_password.getPassword());
299:                alias.setPassword(buf.toString());
300:
301:                alias.setAutoLogon(_autoLogonChk.isSelected());
302:                alias.setConnectAtStartup(_connectAtStartupChk.isSelected());
303:                //		alias.setUseDriverProperties(_useDriverPropsChk.isSelected());
304:                //		alias.setDriverProperties(_sqlDriverProps);
305:            }
306:
307:            private void showNewDriverDialog() {
308:                _app.getWindowManager().showNewDriverInternalFrame();
309:            }
310:
311:            private void showDriverPropertiesDialog() {
312:                try {
313:                    applyFromDialog(_sqlAlias);
314:                    new AliasPropertiesCommand(_sqlAlias, _app).execute();
315:                } catch (Exception ex) {
316:                    _app.showErrorDialog(ex);
317:                }
318:            }
319:
320:            /**
321:             * Create user interface for this sheet.
322:             */
323:            private void createUserInterface() {
324:                setDefaultCloseOperation(DISPOSE_ON_CLOSE);
325:
326:                // This is a tool window.
327:                GUIUtils.makeToolWindow(this , true);
328:
329:                String winTitle;
330:                if (_maintType == IMaintenanceType.MODIFY) {
331:                    winTitle = s_stringMgr.getString(
332:                            "AliasInternalFrame.changealias", _sqlAlias
333:                                    .getName());
334:                } else {
335:                    winTitle = s_stringMgr
336:                            .getString("AliasInternalFrame.addalias");
337:                }
338:                setTitle(winTitle);
339:
340:                _aliasName.setColumns(COLUMN_COUNT);
341:                _url.setColumns(COLUMN_COUNT);
342:                _userName.setColumns(COLUMN_COUNT);
343:                _password.setColumns(COLUMN_COUNT);
344:
345:                // This seems to be necessary to get background colours
346:                // correct. Without it labels added to the content pane
347:                // have a dark background while those added to a JPanel
348:                // in the content pane have a light background under
349:                // the java look and feel. Similar effects occur for other
350:                // look and feels.
351:                final JPanel contentPane = new JPanel();
352:                contentPane.setBorder(BorderFactory.createEmptyBorder(5, 10, 5,
353:                        10));
354:                setContentPane(contentPane);
355:
356:                GridBagConstraints gbc = new GridBagConstraints();
357:                contentPane.setLayout(new GridBagLayout());
358:
359:                gbc.anchor = GridBagConstraints.NORTHWEST;
360:                gbc.gridwidth = GridBagConstraints.REMAINDER;
361:                gbc.weightx = 1;
362:
363:                // Title label at top.
364:                gbc.gridx = 0;
365:                gbc.gridy = 0;
366:                gbc.insets = new Insets(5, 10, 5, 10);
367:                gbc.fill = GridBagConstraints.HORIZONTAL;
368:                contentPane.add(_titleLbl, gbc);
369:
370:                // Separated by a line.
371:                ++gbc.gridy;
372:                gbc.insets = new Insets(0, 10, 5, 10);
373:                contentPane.add(new JSeparator(), gbc);
374:
375:                contentPane.add(createDataEntryPanel(), gbc);
376:
377:                // Separated by a line.
378:                gbc.weighty = 0;
379:                ++gbc.gridy;
380:                gbc.fill = GridBagConstraints.HORIZONTAL;
381:                gbc.insets = new Insets(5, 10, 5, 10);
382:                contentPane.add(new JSeparator(), gbc);
383:
384:                gbc.insets = new Insets(0, 0, 0, 0);
385:
386:                // Next the buttons.
387:                ++gbc.gridy;
388:                contentPane.add(createButtonsPanel(), gbc);
389:
390:                _driversCacheLis = new DriversCacheListener();
391:                _app.getDataCache().addDriversListener(_driversCacheLis);
392:
393:                AbstractAction closeAction = new AbstractAction() {
394:                    public void actionPerformed(ActionEvent actionEvent) {
395:                        performClose();
396:                    }
397:                };
398:                KeyStroke escapeStroke = KeyStroke.getKeyStroke(
399:                        KeyEvent.VK_ESCAPE, 0);
400:                getRootPane().getInputMap(
401:                        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
402:                        escapeStroke, "CloseAction");
403:                getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
404:                        .put(escapeStroke, "CloseAction");
405:                getRootPane().getInputMap(JComponent.WHEN_FOCUSED).put(
406:                        escapeStroke, "CloseAction");
407:                getRootPane().getActionMap().put("CloseAction", closeAction);
408:
409:            }
410:
411:            private JPanel createDataEntryPanel() {
412:                _aliasPropsBtn.addActionListener(new ActionListener() {
413:                    public void actionPerformed(ActionEvent evt) {
414:                        showDriverPropertiesDialog();
415:                    }
416:
417:                });
418:
419:                //		_useDriverPropsChk.addActionListener(new ActionListener()
420:                //		{
421:                //			public void actionPerformed(ActionEvent evt)
422:                //			{
423:                //				_aliasPropsBtn.setEnabled(_useDriverPropsChk.isSelected());
424:                //			}
425:                //
426:                //		});
427:
428:                JPanel pnl = new JPanel(new GridBagLayout());
429:
430:                GridBagConstraints gbc;
431:
432:                gbc = new GridBagConstraints(0, 0, 1, 1, 0, 0,
433:                        GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
434:                        new Insets(5, 5, 5, 5), 0, 0);
435:                pnl.add(new JLabel(s_stringMgr
436:                        .getString("AliasInternalFrame.name"),
437:                        SwingConstants.RIGHT), gbc);
438:
439:                gbc = new GridBagConstraints(1, 0, 1, 1, 0, 0,
440:                        GridBagConstraints.NORTHWEST,
441:                        GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
442:                        0, 0);
443:                pnl.add(_aliasName, gbc);
444:
445:                gbc = new GridBagConstraints(0, 1, 1, 1, 0, 0,
446:                        GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
447:                        new Insets(5, 5, 5, 5), 0, 0);
448:                pnl.add(new JLabel(s_stringMgr
449:                        .getString("AliasInternalFrame.driver"),
450:                        SwingConstants.RIGHT), gbc);
451:
452:                _drivers = new DriversCombo();
453:                _drivers.addItemListener(new DriversComboItemListener());
454:
455:                final Box driverPnl = Box.createHorizontalBox();
456:                driverPnl.add(_drivers);
457:                driverPnl.add(Box.createHorizontalStrut(5));
458:                JButton newDriverBtn = new JButton(s_stringMgr
459:                        .getString("AliasInternalFrame.new"));
460:                newDriverBtn.addActionListener(new ActionListener() {
461:                    public void actionPerformed(ActionEvent evt) {
462:                        showNewDriverDialog();
463:                    }
464:                });
465:                driverPnl.add(newDriverBtn);
466:
467:                gbc = new GridBagConstraints(1, 1, 1, 1, 0, 0,
468:                        GridBagConstraints.NORTHWEST,
469:                        GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
470:                        0, 0);
471:                pnl.add(driverPnl, gbc);
472:
473:                gbc = new GridBagConstraints(0, 2, 1, 1, 0, 0,
474:                        GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
475:                        new Insets(5, 5, 5, 5), 0, 0);
476:                pnl.add(new JLabel(s_stringMgr
477:                        .getString("AliasInternalFrame.url"),
478:                        SwingConstants.RIGHT), gbc);
479:
480:                gbc = new GridBagConstraints(1, 2, 1, 1, 0, 0,
481:                        GridBagConstraints.NORTHWEST,
482:                        GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
483:                        0, 0);
484:                pnl.add(_url, gbc);
485:
486:                gbc = new GridBagConstraints(0, 3, 1, 1, 0, 0,
487:                        GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
488:                        new Insets(5, 5, 5, 5), 0, 0);
489:                pnl.add(new JLabel(s_stringMgr
490:                        .getString("AliasInternalFrame.username"),
491:                        SwingConstants.RIGHT), gbc);
492:
493:                gbc = new GridBagConstraints(1, 3, 1, 1, 0, 0,
494:                        GridBagConstraints.NORTHWEST,
495:                        GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
496:                        0, 0);
497:                pnl.add(_userName, gbc);
498:
499:                gbc = new GridBagConstraints(0, 4, 1, 1, 0, 0,
500:                        GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
501:                        new Insets(5, 5, 5, 5), 0, 0);
502:                pnl.add(new JLabel(s_stringMgr
503:                        .getString("AliasInternalFrame.password"),
504:                        SwingConstants.RIGHT), gbc);
505:
506:                gbc = new GridBagConstraints(1, 4, 1, 1, 0, 0,
507:                        GridBagConstraints.NORTHWEST,
508:                        GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
509:                        0, 0);
510:                pnl.add(_password, gbc);
511:
512:                gbc = new GridBagConstraints(0, 5, 1, 1, 0, 0,
513:                        GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
514:                        new Insets(5, 5, 5, 5), 0, 0);
515:                pnl.add(_autoLogonChk, gbc);
516:
517:                gbc = new GridBagConstraints(1, 5, 1, 1, 0, 0,
518:                        GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
519:                        new Insets(5, 5, 5, 5), 0, 0);
520:                pnl.add(_connectAtStartupChk, gbc);
521:
522:                gbc = new GridBagConstraints(1, 6, 1, 1, 0, 0,
523:                        GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
524:                        new Insets(5, 5, 5, 5), 0, 0);
525:                _aliasPropsBtn.setIcon(_app.getResources().getIcon(
526:                        SquirrelResources.IImageNames.ALIAS_PROPERTIES));
527:                pnl.add(_aliasPropsBtn, gbc);
528:
529:                gbc = new GridBagConstraints(0, 7, 2, 1, 0, 0,
530:                        GridBagConstraints.NORTHWEST,
531:                        GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
532:                        0, 0);
533:                pnl.add(new JLabel(s_stringMgr
534:                        .getString("AliasInternalFrame.cleartext")), gbc);
535:
536:                return pnl;
537:            }
538:
539:            private JPanel createButtonsPanel() {
540:                JPanel pnl = new JPanel();
541:
542:                JButton okBtn = new JButton(s_stringMgr
543:                        .getString("AliasInternalFrame.ok"));
544:                okBtn.addActionListener(new ActionListener() {
545:                    public void actionPerformed(ActionEvent evt) {
546:                        performOk();
547:                    }
548:                });
549:                JButton closeBtn = new JButton(s_stringMgr
550:                        .getString("AliasInternalFrame.close"));
551:                closeBtn.addActionListener(new ActionListener() {
552:                    public void actionPerformed(ActionEvent evt) {
553:                        performClose();
554:                    }
555:                });
556:
557:                JButton testBtn = new JButton(s_stringMgr
558:                        .getString("AliasInternalFrame.test"));
559:                testBtn.addActionListener(new ActionListener() {
560:                    public void actionPerformed(ActionEvent evt) {
561:                        final DataCache cache = _app.getDataCache();
562:                        final IIdentifierFactory factory = IdentifierFactory
563:                                .getInstance();
564:                        final SQLAlias testAlias = cache.createAlias(factory
565:                                .createIdentifier());
566:                        try {
567:                            applyFromDialog(testAlias);
568:                            ConnectionCallBack cb = new ConnectionCallBack(
569:                                    _app, testAlias);
570:                            ConnectToAliasCommand cmd = new ConnectToAliasCommand(
571:                                    _app, testAlias, false, cb);
572:                            cmd.execute();
573:                        } catch (ValidationException ex) {
574:                            _app.showErrorDialog(ex);
575:                        }
576:                    }
577:                });
578:
579:                pnl.add(okBtn);
580:                pnl.add(closeBtn);
581:                pnl.add(testBtn);
582:
583:                GUIUtils.setJButtonSizesTheSame(new JButton[] { okBtn,
584:                        closeBtn, testBtn });
585:                getRootPane().setDefaultButton(okBtn);
586:
587:                return pnl;
588:            }
589:
590:            private final class DriversComboItemListener implements 
591:                    ItemListener {
592:                public void itemStateChanged(ItemEvent evt) {
593:                    ISQLDriver driver = (ISQLDriver) evt.getItem();
594:                    if (driver != null) {
595:                        _url.setText(driver.getUrl());
596:                    }
597:                }
598:            }
599:
600:            /**
601:             * This combobox displays all the JDBC drivers defined in SQuirreL.
602:             */
603:            private final class DriversCombo extends JComboBox {
604:                private Map<IIdentifier, ISQLDriver> _map = new HashMap<IIdentifier, ISQLDriver>();
605:                SquirrelPreferences prefs = _app.getSquirrelPreferences();
606:
607:                @SuppressWarnings("unchecked")
608:                DriversCombo() {
609:                    super ();
610:                    SquirrelResources res = _app.getResources();
611:                    setRenderer(new DriverListCellRenderer(res
612:                            .getIcon("list.driver.found"), res
613:                            .getIcon("list.driver.notfound")));
614:                    List<ISQLDriver> list = new ArrayList<ISQLDriver>();
615:                    for (Iterator it = AliasInternalFrame.this ._app
616:                            .getDataCache().drivers(); it.hasNext();) {
617:                        ISQLDriver sqlDriver = ((ISQLDriver) it.next());
618:                        if (prefs.getShowLoadedDriversOnly()
619:                                && !sqlDriver.isJDBCDriverClassLoaded()) {
620:                            continue;
621:                        }
622:                        _map.put(sqlDriver.getIdentifier(), sqlDriver);
623:                        list.add(sqlDriver);
624:                    }
625:                    Collections.sort(list, new DriverComparator());
626:                    for (Iterator it = list.iterator(); it.hasNext();) {
627:                        addItem(it.next());
628:                    }
629:                }
630:
631:                void setSelectedItem(IIdentifier id) {
632:                    super .setSelectedItem(_map.get(id));
633:                }
634:
635:                ISQLDriver getSelectedDriver() {
636:                    return (ISQLDriver) getSelectedItem();
637:                }
638:
639:                private class DriverComparator implements 
640:                        Comparator<ISQLDriver>, Serializable {
641:                    public int compare(ISQLDriver o1, ISQLDriver o2) {
642:                        return o1.toString().compareToIgnoreCase(o2.toString());
643:                    }
644:
645:                }
646:            }
647:
648:            private final class ConnectionCallBack extends
649:                    ConnectToAliasCallBack {
650:                private ConnectionCallBack(IApplication app, SQLAlias alias) {
651:                    super (app, alias);
652:                }
653:
654:                /**
655:                 * @see CompletionCallback#connected(SQLConnection)
656:                 */
657:                public void connected(ISQLConnection conn) {
658:                    try {
659:                        conn.close();
660:                    } catch (Throwable th) {
661:                        String msg = s_stringMgr
662:                                .getString("AliasInternalFrame.error.errorclosingconn");
663:                        s_log.error(msg, th);
664:                        _app.showErrorDialog(msg + ": " + th.toString());
665:                    }
666:                    Dialogs.showOk(AliasInternalFrame.this , s_stringMgr
667:                            .getString("AliasInternalFrame.connsuccess"));
668:
669:                    if (getAlias().isAutoLogon()) {
670:                        // If Auto Logon is true in ConnectToAliasCommand user name/password
671:                        // of the Alias definiton may have changed.
672:                        // Here we transfere this information back into the controls.
673:                        _userName.setText(getAlias().getUserName());
674:                        _password.setText(getAlias().getPassword());
675:                    }
676:                }
677:
678:                /**
679:                 * @see CompletionCallback#sessionCreated(ISession)
680:                 */
681:                public void sessionCreated(ISession session) {
682:                    // i18n[AliasInternalFrame.error.sessioncreation=Test Button has created a session, this is a programming error]
683:                    s_log
684:                            .error(s_stringMgr
685:                                    .getString("AliasInternalFrame.error.sessioncreation"));
686:                }
687:            }
688:
689:            /**
690:             * Listens to changes in the drivers cache and adds/removes drivers from the dropdown
691:             * as they are added/removed from the cache.
692:             */
693:            private final class DriversCacheListener implements 
694:                    IObjectCacheChangeListener {
695:                public void objectAdded(ObjectCacheChangeEvent evt) {
696:                    _drivers.addItem(evt.getObject());
697:                }
698:
699:                public void objectRemoved(ObjectCacheChangeEvent evt) {
700:                    _drivers.removeItem(evt.getObject());
701:                }
702:            }
703:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.