Source Code Cross Referenced for JDBCConnectionConfigurationPanel.java in  » Report » pentaho-report » org » pentaho » reportdesigner » crm » report » datasetplugin » jdbc » 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 » Report » pentaho report » org.pentaho.reportdesigner.crm.report.datasetplugin.jdbc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006-2007 Pentaho Corporation.  All rights reserved.
003:         * This software was developed by Pentaho Corporation and is provided under the terms
004:         * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005:         * this file except in compliance with the license. If you need a copy of the license,
006:         * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
007:         *
008:         * Software distributed under the Mozilla Public License is distributed on an "AS IS"
009:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to
010:         * the license for the specific language governing your rights and limitations.
011:         *
012:         * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
013:         */
014:        package org.pentaho.reportdesigner.crm.report.datasetplugin.jdbc;
015:
016:        import com.jgoodies.forms.layout.CellConstraints;
017:        import com.jgoodies.forms.layout.FormLayout;
018:        import org.jetbrains.annotations.NonNls;
019:        import org.jetbrains.annotations.NotNull;
020:        import org.pentaho.reportdesigner.crm.report.PropertyKeys;
021:        import org.pentaho.reportdesigner.crm.report.settings.WorkspaceSettings;
022:        import org.pentaho.reportdesigner.crm.report.util.JFileChooserHelper;
023:        import org.pentaho.reportdesigner.crm.report.util.JOptionPaneHelper;
024:        import org.pentaho.reportdesigner.lib.client.components.CenterPanelDialog;
025:        import org.pentaho.reportdesigner.lib.client.components.ComponentFactory;
026:        import org.pentaho.reportdesigner.lib.client.components.ProgressDialog;
027:        import org.pentaho.reportdesigner.lib.client.components.TextComponentHelper;
028:        import org.pentaho.reportdesigner.lib.client.i18n.BundleAlreadyExistsException;
029:        import org.pentaho.reportdesigner.lib.client.i18n.TranslationManager;
030:        import org.pentaho.reportdesigner.lib.client.util.ExceptionUtils;
031:        import org.pentaho.reportdesigner.lib.client.util.TextFieldCompletionSupport;
032:        import org.pentaho.reportdesigner.lib.client.util.UncaughtExcpetionsModel;
033:        import org.pentaho.reportdesigner.lib.client.util.UndoHelper;
034:        import org.pentaho.reportdesigner.lib.common.util.LoggerUtil;
035:
036:        import javax.swing.*;
037:        import javax.swing.event.DocumentEvent;
038:        import javax.swing.event.DocumentListener;
039:        import javax.swing.event.ListSelectionEvent;
040:        import javax.swing.event.ListSelectionListener;
041:        import javax.swing.filechooser.FileFilter;
042:        import java.awt.*;
043:        import java.awt.event.ActionEvent;
044:        import java.awt.event.ActionListener;
045:        import java.beans.PropertyChangeEvent;
046:        import java.beans.PropertyChangeListener;
047:        import java.beans.PropertyChangeSupport;
048:        import java.io.File;
049:        import java.io.IOException;
050:        import java.util.ArrayList;
051:        import java.util.Arrays;
052:        import java.util.Collection;
053:        import java.util.HashMap;
054:        import java.util.Locale;
055:        import java.util.ResourceBundle;
056:        import java.util.TreeSet;
057:        import java.util.logging.Level;
058:        import java.util.logging.Logger;
059:
060:        /**
061:         * User: Martin
062:         * Date: 10.02.2006
063:         * Time: 07:51:54
064:         */
065:        public class JDBCConnectionConfigurationPanel extends JPanel {
066:            @NonNls
067:            @NotNull
068:            private static final Logger LOG = Logger
069:                    .getLogger(JDBCConnectionConfigurationPanel.class.getName());
070:
071:            @NotNull
072:            public static final String CONNECTION_TEST = "connectionTest";
073:            @NotNull
074:            private static final String JAR_ENDING = ".jar";
075:            @NotNull
076:            private static final String ZIP_ENDING = ".zip";
077:            @NotNull
078:            private static final String SAMPLE_DB_USERNAME = "sa";
079:
080:            public static void main(@NotNull
081:            String[] args) throws BundleAlreadyExistsException {
082:                LoggerUtil.initLogger();
083:
084:                Locale.setDefault(Locale.ENGLISH);
085:                TranslationManager.getInstance().addBundle(
086:                        "R",
087:                        ResourceBundle.getBundle("res.Translations", Locale
088:                                .getDefault()));//NON-NLS
089:                TranslationManager.getInstance().addSupportedLocale(
090:                        Locale.GERMAN);
091:                TranslationManager.getInstance().addSupportedLocale(
092:                        Locale.ENGLISH);
093:
094:                @NonNls
095:                JFrame frame = new JFrame("JDBCConnectionConfigurationPanel");
096:                WorkspaceSettings workspaceSettings = WorkspaceSettings
097:                        .getInstance();
098:                workspaceSettings
099:                        .put(
100:                                "JDBCConnectionConfigurationPanel.LastSelectedFile",
101:                                "C:\\Daten\\07_Projekte\\Report\\org.pentaho.reportdesigner.crm.report\\lib\\postgresql-8.1dev-403.jdbc3.jar");//NON-NLS
102:                frame.getContentPane().add(
103:                        new JDBCConnectionConfigurationPanel(frame,
104:                                workspaceSettings), BorderLayout.CENTER);
105:
106:                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
107:                frame.setBounds(100, 100, 500, 500);
108:                frame.setVisible(true);
109:
110:                Runtime.getRuntime().addShutdownHook(new Thread() {
111:                    public void run() {
112:                        Collection<String> missingKeysList = TranslationManager
113:                                .getInstance().getMissingKeysList();
114:                        if (LOG.isLoggable(Level.FINE))
115:                            LOG.log(Level.FINE, "MISSING KEYS");
116:                        for (String s : missingKeysList) {
117:                            //noinspection UseOfSystemOutOrSystemErr
118:                            System.out.println(s);
119:                        }
120:                    }
121:                });
122:            }
123:
124:            @NotNull
125:            private static final String ORG_HSQLDB_JDBC_DRIVER = "org.hsqldb.jdbcDriver";
126:            @NotNull
127:            private static final String[] DRIVER_CLASSES = new String[] {
128:                    ORG_HSQLDB_JDBC_DRIVER, "org.postgresql.Driver",
129:                    "com.mysql.jdbc.Driver", "COM.ibm.db2.jdbc.app.DB2Driver",
130:                    "oracle.jdbc.driver.OracleDriver", };
131:
132:            @NonNls
133:            @NotNull
134:            private static final HashMap<String, String> connectionStringMap = new HashMap<String, String>();
135:
136:            @NotNull
137:            private static final String JDBC_HSQLDB_MEM_SAMPLE = "jdbc:hsqldb:mem:sample";
138:
139:            static {
140:                connectionStringMap.put(DRIVER_CLASSES[0],
141:                        JDBC_HSQLDB_MEM_SAMPLE);
142:                connectionStringMap.put(DRIVER_CLASSES[1], "jdbc:postgresql:");
143:                connectionStringMap.put(DRIVER_CLASSES[2], "jdbc:mysql:");
144:                connectionStringMap.put(DRIVER_CLASSES[3], "jdbc:db2:");
145:                connectionStringMap.put(DRIVER_CLASSES[4], "jdbc:oracle:thin:");
146:            }
147:
148:            @NotNull
149:            private Component parent;
150:            @NotNull
151:            private WorkspaceSettings workspaceSettings;
152:
153:            @NotNull
154:            private JLabel jarLabel;
155:            @NotNull
156:            private JList jarList;
157:            @NotNull
158:            private JarListModel jarListModel;
159:            @NotNull
160:            private JButton jarAddButton;
161:            @NotNull
162:            private JButton jarRemoveButton;
163:
164:            @NotNull
165:            private JLabel classLabel;
166:            @NotNull
167:            private JComboBox driverComboBox;
168:            @NotNull
169:            private JLabel connectionStringLabel;
170:            @NotNull
171:            private JComboBox connectionStringComboBox;
172:            @NotNull
173:            private JLabel usernameLabel;
174:            @NotNull
175:            private JTextField usernameTextField;
176:            @NotNull
177:            private JLabel passwordLabel;
178:            @NotNull
179:            private JPasswordField passwordField;
180:            @NotNull
181:            private JButton testConnectionButton;
182:
183:            @NotNull
184:            private TreeSet<String> usernameSet;
185:            @NotNull
186:            private TreeSet<String> connectionStringSet;
187:            @NotNull
188:            private TreeSet<String> driversSet;
189:
190:            @NotNull
191:            private PropertyChangeSupport propertyChangeSupport;
192:
193:            public JDBCConnectionConfigurationPanel(@NotNull
194:            Component parent, @NotNull
195:            WorkspaceSettings workspaceSettings) {
196:                //noinspection ConstantConditions
197:                if (parent == null) {
198:                    throw new IllegalArgumentException(
199:                            "parent must not be null");
200:                }
201:                //noinspection ConstantConditions
202:                if (workspaceSettings == null) {
203:                    throw new IllegalArgumentException(
204:                            "workspaceSettings must not be null");
205:                }
206:
207:                this .parent = parent;
208:                this .workspaceSettings = workspaceSettings;
209:                propertyChangeSupport = new PropertyChangeSupport(this );
210:
211:                initGUI();
212:                initLogic();
213:            }
214:
215:            private void initLogic() {
216:                jarList.getSelectionModel().addListSelectionListener(
217:                        new ListSelectionListener() {
218:                            public void valueChanged(@NotNull
219:                            ListSelectionEvent e) {
220:                                if (!e.getValueIsAdjusting()) {
221:                                    jarRemoveButton.setEnabled(jarList
222:                                            .getSelectedIndex() != -1);
223:                                }
224:                            }
225:                        });
226:
227:                jarRemoveButton.addActionListener(new ActionListener() {
228:                    public void actionPerformed(@NotNull
229:                    ActionEvent e) {
230:                        String[] oldJars = jarListModel.getJars();
231:                        int[] selectedIndices = jarList.getSelectedIndices();
232:                        for (int i = selectedIndices.length - 1; i >= 0; i--) {
233:                            int selectedIndex = selectedIndices[i];
234:                            jarListModel.remove(selectedIndex);
235:                        }
236:                        validateDriverComboBox();
237:                        firePropertyChange(PropertyKeys.JARS, oldJars,
238:                                jarListModel.getJars());
239:                    }
240:                });
241:
242:                jarAddButton.addActionListener(new ActionListener() {
243:                    public void actionPerformed(@NotNull
244:                    ActionEvent e) {
245:                        String lastSelectedFile = workspaceSettings
246:                                .getString("JDBCConnectionConfigurationPanel.LastSelectedFile");
247:                        JFileChooser fileChooser;
248:                        if (lastSelectedFile != null) {
249:                            File file = new File(lastSelectedFile);
250:                            fileChooser = new JFileChooserHelper(
251:                                    file,
252:                                    CenterPanelDialog.ModalityType.DOCUMENT_MODAL);
253:                            fileChooser.setSelectedFile(file);
254:                        } else {
255:                            fileChooser = new JFileChooserHelper(
256:                                    CenterPanelDialog.ModalityType.DOCUMENT_MODAL);
257:                        }
258:
259:                        fileChooser.setFileFilter(new FileFilter() {
260:                            public boolean accept(@NotNull
261:                            File f) {
262:                                return f.isDirectory()
263:                                        || f.getName().toLowerCase().endsWith(
264:                                                JAR_ENDING)
265:                                        || f.getName().toLowerCase().endsWith(
266:                                                ZIP_ENDING);
267:                            }
268:
269:                            @NotNull
270:                            public String getDescription() {
271:                                return TranslationManager
272:                                        .getInstance()
273:                                        .getTranslation("R",
274:                                                "JDBCConnectionConfigurationPanel.FileTypeDescription");
275:                            }
276:                        });
277:
278:                        int i = fileChooser.showOpenDialog(parent);
279:                        if (i == JFileChooser.APPROVE_OPTION) {
280:                            try {
281:                                String[] oldJars = jarListModel.getJars();
282:                                String newJar = fileChooser.getSelectedFile()
283:                                        .getCanonicalPath();
284:                                for (String jar : oldJars) {
285:                                    if (jar.equals(newJar)) {
286:                                        return;
287:                                    }
288:                                }
289:                                jarListModel.addElement(newJar);
290:                                String[] newJars = jarListModel.getJars();
291:                                workspaceSettings
292:                                        .put(
293:                                                "JDBCConnectionConfigurationPanel.LastSelectedFile",
294:                                                newJar);
295:                                workspaceSettings
296:                                        .put(
297:                                                "JDBCConnectionConfigurationPanel.LastSelectedFiles",
298:                                                Arrays.asList(newJars));
299:
300:                                propertyChangeSupport.firePropertyChange(
301:                                        PropertyKeys.JARS, oldJars, newJars);
302:                            } catch (IOException e1) {
303:                                if (LOG.isLoggable(Level.FINE))
304:                                    LOG
305:                                            .log(
306:                                                    Level.FINE,
307:                                                    "JDBCConnectionConfigurationPanel.actionPerformed ",
308:                                                    e1);
309:                            }
310:                        }
311:                    }
312:                });
313:
314:                propertyChangeSupport.addPropertyChangeListener(
315:                        PropertyKeys.JARS, new PropertyChangeListener() {
316:                            public void propertyChange(@NotNull
317:                            PropertyChangeEvent evt) {
318:                                validateDriverComboBox();
319:                            }
320:                        });
321:
322:                Component editorComponent = driverComboBox.getEditor()
323:                        .getEditorComponent();
324:                if (editorComponent instanceof  JTextField) {
325:                    JTextField textField = (JTextField) editorComponent;
326:                    textField.getDocument().addDocumentListener(
327:                            new DocumentListener() {
328:                                public void insertUpdate(@NotNull
329:                                DocumentEvent e) {
330:                                    validateDriverComboBox();
331:                                }
332:
333:                                public void removeUpdate(@NotNull
334:                                DocumentEvent e) {
335:                                    validateDriverComboBox();
336:                                }
337:
338:                                public void changedUpdate(@NotNull
339:                                DocumentEvent e) {
340:                                    validateDriverComboBox();
341:                                }
342:                            });
343:                }
344:
345:                testConnectionButton.addActionListener(new ActionListener() {
346:                    public void actionPerformed(@NotNull
347:                    ActionEvent e) {
348:                        Component editorComponent = driverComboBox.getEditor()
349:                                .getEditorComponent();
350:                        if (editorComponent instanceof  JTextField) {
351:                            testConnection();
352:                        }
353:                    }
354:                });
355:
356:                DocumentListener modificationListener = new DocumentListener() {
357:                    public void insertUpdate(@NotNull
358:                    DocumentEvent e) {
359:                        propertyChangeSupport.firePropertyChange(
360:                                CONNECTION_TEST, Boolean.TRUE, Boolean.FALSE);
361:                    }
362:
363:                    public void removeUpdate(@NotNull
364:                    DocumentEvent e) {
365:                        propertyChangeSupport.firePropertyChange(
366:                                CONNECTION_TEST, Boolean.TRUE, Boolean.FALSE);
367:                    }
368:
369:                    public void changedUpdate(@NotNull
370:                    DocumentEvent e) {
371:                        propertyChangeSupport.firePropertyChange(
372:                                CONNECTION_TEST, Boolean.TRUE, Boolean.FALSE);
373:                    }
374:                };
375:
376:                if (editorComponent instanceof  JTextField) {
377:                    JTextField textField = (JTextField) editorComponent;
378:                    textField.getDocument().addDocumentListener(
379:                            modificationListener);
380:                    UndoHelper.installUndoSupport(textField);
381:                    TextComponentHelper.installDefaultPopupMenu(textField);
382:                }
383:
384:                Component csEditorComponent = connectionStringComboBox
385:                        .getEditor().getEditorComponent();
386:                if (csEditorComponent instanceof  JTextField) {
387:                    JTextField textField = (JTextField) csEditorComponent;
388:                    textField.getDocument().addDocumentListener(
389:                            modificationListener);
390:                    UndoHelper.installUndoSupport(textField);
391:                    TextComponentHelper.installDefaultPopupMenu(textField);
392:                }
393:
394:                usernameTextField.getDocument().addDocumentListener(
395:                        modificationListener);
396:                UndoHelper.installUndoSupport(usernameTextField);
397:                TextComponentHelper.installDefaultPopupMenu(usernameTextField);
398:
399:                passwordField.getDocument().addDocumentListener(
400:                        modificationListener);
401:                UndoHelper.installUndoSupport(passwordField);
402:                TextComponentHelper.installDefaultPopupMenu(passwordField);
403:
404:                validateDriverComboBox();
405:            }
406:
407:            private void testConnection() {
408:                final ProgressDialog progressDialog = ProgressDialog
409:                        .createProgressDialog(
410:                                parent,
411:                                TranslationManager
412:                                        .getInstance()
413:                                        .getTranslation("R",
414:                                                "JDBCConnectionConfigurationPanel.ProgressDialog.Title"),
415:                                "");
416:
417:                final String url = connectionStringComboBox.getSelectedItem()
418:                        .toString();
419:                final String username = usernameTextField.getText();
420:                final String password = new String(passwordField.getPassword());
421:
422:                Thread t = new Thread() {
423:                    public void run() {
424:                        boolean success = false;
425:                        String errorMessage = "";
426:
427:                        try {
428:                            JDBCClassLoader.getConnection(getJars(),
429:                                    getDriverClass(), url, username, password);
430:                            success = true;
431:                        } catch (Throwable e1) {
432:                            if (LOG.isLoggable(Level.FINE))
433:                                LOG
434:                                        .log(
435:                                                Level.FINE,
436:                                                "JDBCConnectionConfigurationPanel.actionPerformed ",
437:                                                e1);
438:                            //noinspection InstanceofCatchParameter
439:                            if (e1 instanceof  JDBCClassLoader.CompoundException
440:                                    && e1.getCause() instanceof  ClassNotFoundException) {
441:                                errorMessage = TranslationManager
442:                                        .getInstance()
443:                                        .getTranslation(
444:                                                "R",
445:                                                "JDBCConnectionConfigurationPanel.ClassNotFoundException",
446:                                                e1.getMessage());
447:                            } else {
448:                                errorMessage = e1.getMessage();
449:                            }
450:                        }
451:
452:                        try {
453:                            final boolean ts = success;
454:                            final String em = errorMessage;
455:                            EventQueue.invokeAndWait(new Runnable() {
456:                                public void run() {
457:                                    propertyChangeSupport.firePropertyChange(
458:                                            CONNECTION_TEST, Boolean
459:                                                    .valueOf(!ts), Boolean
460:                                                    .valueOf(ts));
461:                                    progressDialog.dispose();
462:                                    if (!ts) {
463:                                        JOptionPaneHelper
464:                                                .showMessageDialog(
465:                                                        parent,
466:                                                        TranslationManager
467:                                                                .getInstance()
468:                                                                .getTranslation(
469:                                                                        "R",
470:                                                                        "ConnectionTest.Error.Message",
471:                                                                        em),
472:                                                        TranslationManager
473:                                                                .getInstance()
474:                                                                .getTranslation(
475:                                                                        "R",
476:                                                                        "ConnectionTest.Error.Title"),
477:                                                        JOptionPaneHelper.ERROR_MESSAGE,
478:                                                        CenterPanelDialog.ModalityType.DOCUMENT_MODAL);
479:                                    } else {
480:                                        JOptionPaneHelper
481:                                                .showMessageDialog(
482:                                                        parent,
483:                                                        TranslationManager
484:                                                                .getInstance()
485:                                                                .getTranslation(
486:                                                                        "R",
487:                                                                        "ConnectionTest.Success.Message"),
488:                                                        TranslationManager
489:                                                                .getInstance()
490:                                                                .getTranslation(
491:                                                                        "R",
492:                                                                        "ConnectionTest.Success.Title"),
493:                                                        JOptionPaneHelper.INFORMATION_MESSAGE,
494:                                                        CenterPanelDialog.ModalityType.DOCUMENT_MODAL);
495:                                    }
496:                                }
497:                            });
498:                        } catch (Exception e) {
499:                            if (LOG.isLoggable(Level.FINE))
500:                                LOG
501:                                        .log(
502:                                                Level.FINE,
503:                                                "JDBCConnectionConfigurationPanel.run ",
504:                                                e);
505:                            ExceptionUtils.disposeDialogInEDT(progressDialog);
506:                            UncaughtExcpetionsModel.getInstance().addException(
507:                                    e);
508:                        }
509:                    }
510:                };
511:
512:                t.setDaemon(true);
513:                t.setPriority(Thread.NORM_PRIORITY - 1);
514:                t.start();
515:
516:                if (t.isAlive()) {
517:                    progressDialog.setVisible(true);
518:                }
519:            }
520:
521:            private void validateDriverComboBox() {
522:                Component editorComponent = driverComboBox.getEditor()
523:                        .getEditorComponent();
524:                if (editorComponent instanceof  JTextField) {
525:                    JTextField textField = (JTextField) editorComponent;
526:
527:                    if (JDBCClassLoader.tryToFindClass(getJars(), textField
528:                            .getText())) {
529:                        textField.setForeground(Color.BLACK);
530:                        return;
531:                    }
532:
533:                    textField.setForeground(Color.RED);
534:                }
535:            }
536:
537:            private void initGUI() {
538:                @NonNls
539:                FormLayout formLayout = new FormLayout(
540:                        "0dlu, default, 4dlu, fill:10dlu:grow, 2dlu, pref, 0dlu",
541:                        "0dlu, " + "pref, " + "4dlu, " + "pref, " + "4dlu, "
542:                                + "pref, " + "4dlu, " + "pref, " + "4dlu, "
543:                                + "pref, " + "4dlu, " + "pref, " + "4dlu, "
544:                                + "pref, " + "0dlu");
545:
546:                @NonNls
547:                CellConstraints cc = new CellConstraints();
548:                setLayout(formLayout);
549:
550:                ArrayList<String> lastSelectedFiles = workspaceSettings
551:                        .getList("JDBCConnectionConfigurationPanel.LastSelectedFiles");
552:                jarListModel = new JarListModel();
553:                jarListModel.setJars(lastSelectedFiles
554:                        .toArray(new String[lastSelectedFiles.size()]));
555:                jarList = new JList(jarListModel);
556:                jarAddButton = ComponentFactory.createButton("R",
557:                        "JDBCConnectionConfigurationPanel.ButtonJar");
558:
559:                jarLabel = ComponentFactory.createLabel("R",
560:                        "JDBCConnectionConfigurationPanel.LabelJar", jarList);
561:
562:                jarRemoveButton = ComponentFactory.createButton("R",
563:                        "JDBCConnectionConfigurationPanel.ButtonCleanJar");
564:                jarRemoveButton.setEnabled(false);
565:
566:                add(jarLabel, cc.xy(2, 2));
567:                add(new JScrollPane(jarList), cc.xywh(4, 2, 1, 3));
568:                add(jarAddButton, cc.xy(6, 2));
569:                add(jarRemoveButton, cc.xy(6, 4));
570:
571:                driversSet = new TreeSet<String>(
572:                        workspaceSettings
573:                                .getList("JDBCConnectionConfigurationPanel.Drivers.Completion"));
574:                driversSet.addAll(Arrays.asList(DRIVER_CLASSES));
575:                driverComboBox = new JComboBox(driversSet.toArray());
576:                driverComboBox.setEditable(true);
577:
578:                classLabel = ComponentFactory.createLabel("R",
579:                        "JDBCConnectionConfigurationPanel.LabelDriverClass",
580:                        driverComboBox);
581:
582:                boolean defaultDriver = false;
583:                String lastSelectedDriver = workspaceSettings
584:                        .getString("JDBCConnectionConfigurationPanel.Drivers.LastSelectedValue");
585:                if (lastSelectedDriver != null) {
586:                    driverComboBox.setSelectedItem(lastSelectedDriver);
587:                } else {
588:                    driverComboBox.setSelectedItem(ORG_HSQLDB_JDBC_DRIVER);
589:                }
590:
591:                if (ORG_HSQLDB_JDBC_DRIVER.equals(driverComboBox
592:                        .getSelectedItem())) {
593:                    defaultDriver = true;
594:                }
595:
596:                add(classLabel, cc.xy(2, 6));
597:                add(driverComboBox, cc.xy(4, 6));
598:
599:                connectionStringSet = new TreeSet<String>(
600:                        workspaceSettings
601:                                .getList("JDBCConnectionConfigurationPanel.ConnectionString.Completion"));
602:                connectionStringSet.add(JDBC_HSQLDB_MEM_SAMPLE);
603:                connectionStringSet.addAll(connectionStringMap.values());
604:                connectionStringComboBox = new JComboBox(connectionStringSet
605:                        .toArray());
606:                connectionStringComboBox.setEditable(true);
607:
608:                connectionStringLabel = ComponentFactory
609:                        .createLabel(
610:                                "R",
611:                                "JDBCConnectionConfigurationPanel.LabelConnectionString",
612:                                connectionStringComboBox);
613:
614:                boolean defaultConnectionString = false;
615:                String lastSelectedConnectionString = workspaceSettings
616:                        .getString("JDBCConnectionConfigurationPanel.ConnectionString.LastSelectedValue");
617:                if (lastSelectedConnectionString != null) {
618:                    connectionStringComboBox
619:                            .setSelectedItem(lastSelectedConnectionString);
620:                } else {
621:                    connectionStringComboBox
622:                            .setSelectedItem(JDBC_HSQLDB_MEM_SAMPLE);
623:                }
624:
625:                if (JDBC_HSQLDB_MEM_SAMPLE.equals(connectionStringComboBox
626:                        .getSelectedItem())) {
627:                    defaultConnectionString = true;
628:                }
629:
630:                add(connectionStringLabel, cc.xy(2, 8));
631:                add(connectionStringComboBox, cc.xy(4, 8));
632:
633:                usernameTextField = new JTextField();
634:                usernameLabel = ComponentFactory.createLabel("R",
635:                        "JDBCConnectionConfigurationPanel.LabelUsername",
636:                        usernameTextField);
637:                usernameSet = new TreeSet<String>(
638:                        workspaceSettings
639:                                .getList("JDBCConnectionConfigurationPanel.Username.Completion"));
640:                TextFieldCompletionSupport.initCompletionSupport(usernameSet,
641:                        usernameTextField);
642:
643:                if (defaultDriver && defaultConnectionString) {
644:                    usernameTextField.setText(SAMPLE_DB_USERNAME);
645:                }
646:
647:                add(usernameLabel, cc.xy(2, 10));
648:                add(usernameTextField, cc.xy(4, 10));
649:
650:                passwordField = new JPasswordField();
651:                passwordLabel = ComponentFactory.createLabel("R",
652:                        "JDBCConnectionConfigurationPanel.LabelPassword",
653:                        passwordField);
654:                if (passwordField.getFont().canDisplay('\u2022')) {
655:                    passwordField.setEchoChar('\u2022');
656:                }
657:
658:                add(passwordLabel, cc.xy(2, 12));
659:                add(passwordField, cc.xy(4, 12));
660:
661:                testConnectionButton = ComponentFactory
662:                        .createButton("R",
663:                                "JDBCConnectionConfigurationPanel.ButtonTestConnection");
664:                add(testConnectionButton, cc.xy(4, 14, "right, center"));
665:            }
666:
667:            public void storeSettings() {
668:                workspaceSettings.put(
669:                        "JDBCConnectionConfigurationPanel.Username.Completion",
670:                        usernameSet);
671:
672:                driversSet.add(driverComboBox.getSelectedItem().toString());
673:                workspaceSettings.put(
674:                        "JDBCConnectionConfigurationPanel.Drivers.Completion",
675:                        driversSet);
676:                workspaceSettings
677:                        .put(
678:                                "JDBCConnectionConfigurationPanel.Drivers.LastSelectedValue",
679:                                driverComboBox.getSelectedItem().toString());
680:
681:                connectionStringSet.add(connectionStringComboBox
682:                        .getSelectedItem().toString());
683:                workspaceSettings
684:                        .put(
685:                                "JDBCConnectionConfigurationPanel.ConnectionString.Completion",
686:                                connectionStringSet);
687:                workspaceSettings
688:                        .put(
689:                                "JDBCConnectionConfigurationPanel.ConnectionString.LastSelectedValue",
690:                                connectionStringComboBox.getSelectedItem()
691:                                        .toString());
692:            }
693:
694:            @NotNull
695:            public String[] getJars() {
696:                return jarListModel.getJars();
697:            }
698:
699:            public void setJars(@NotNull
700:            String[] jars) {
701:                jarListModel.setJars(jars);
702:            }
703:
704:            @NotNull
705:            public String getDriverClass() {
706:                return driverComboBox.getSelectedItem().toString();
707:            }
708:
709:            public void setDriverClass(@NotNull
710:            String driverClass) {
711:                driverComboBox.setSelectedItem(driverClass);
712:            }
713:
714:            @NotNull
715:            public String getConnectionString() {
716:                return connectionStringComboBox.getSelectedItem().toString();
717:            }
718:
719:            public void setConnectionString(@NotNull
720:            String cs) {
721:                connectionStringComboBox.setSelectedItem(cs);
722:            }
723:
724:            @NotNull
725:            public String getUsername() {
726:                return usernameTextField.getText();
727:            }
728:
729:            public void setUsername(@NotNull
730:            String username) {
731:                usernameTextField.setText(username);
732:            }
733:
734:            @NotNull
735:            public String getPassword() {
736:                return new String(passwordField.getPassword());
737:            }
738:
739:            public void setPassword(@NotNull
740:            String password) {
741:                passwordField.setText(password);
742:            }
743:
744:            public void addPropertyChangeListener2(@NotNull
745:            PropertyChangeListener listener) {
746:                propertyChangeSupport.addPropertyChangeListener(listener);
747:            }
748:
749:            public void removePropertyChangeListener2(@NotNull
750:            PropertyChangeListener listener) {
751:                propertyChangeSupport.removePropertyChangeListener(listener);
752:            }
753:
754:            public void addPropertyChangeListener2(@NotNull
755:            String propertyName, @NotNull
756:            PropertyChangeListener listener) {
757:                propertyChangeSupport.addPropertyChangeListener(propertyName,
758:                        listener);
759:            }
760:
761:            public void removePropertyChangeListener2(@NotNull
762:            String propertyName, @NotNull
763:            PropertyChangeListener listener) {
764:                propertyChangeSupport.removePropertyChangeListener(
765:                        propertyName, listener);
766:            }
767:
768:            private static class JarListModel extends DefaultListModel {
769:                private JarListModel() {
770:                }
771:
772:                @NotNull
773:                public String[] getJars() {
774:                    String[] jars = new String[getSize()];
775:                    for (int i = 0; i < getSize(); i++) {
776:                        jars[i] = (String) getElementAt(i);
777:                    }
778:
779:                    return jars;
780:                }
781:
782:                public void setJars(@NotNull
783:                String[] jars) {
784:                    removeAllElements();
785:                    for (String jar : jars) {
786:                        addElement(jar);
787:                    }
788:                }
789:            }
790:        }
ww__w.__j__av___a_2_s_.__co___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.