001: /*
002: * DriverEditorPanel.java
003: *
004: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005: *
006: * Copyright 2002-2008, Thomas Kellerer
007: * No part of this code maybe reused without the permission of the author
008: *
009: * To contact the author please send an email to: support@sql-workbench.net
010: *
011: */
012: package workbench.gui.profiles;
013:
014: import workbench.db.DbDriver;
015: import workbench.gui.components.ExtensionFileFilter;
016: import workbench.gui.components.TextComponentMouseListener;
017: import workbench.resource.ResourceMgr;
018: import workbench.util.StringUtil;
019:
020: /**
021: *
022: * @author support@sql-workbench.net
023: */
024: public class DriverEditorPanel extends javax.swing.JPanel {
025: private DbDriver currentDriver;
026:
027: /** Creates new form BeanForm */
028: public DriverEditorPanel() {
029: initComponents();
030: String text = ResourceMgr.getDescription("LblDriverLibrary");
031: text = text.replaceAll("%path_sep%", StringUtil
032: .getPathSeparator());
033: lblLibrary.setToolTipText(text);
034: libraryPath.setFileFilter(ExtensionFileFilter
035: .getJarFileFilter());
036: libraryPath.setLastDirProperty("workbench.drivers.lastlibdir");
037: libraryPath.setTextfieldTooltip(text);
038: libraryPath.setAllowMultiple(true);
039: text = ResourceMgr.getDescription("SelectDriverLibrary");
040: libraryPath.setButtonTooltip(text);
041: }
042:
043: /** This method is called from within the constructor to
044: * initialize the form.
045: * WARNING: Do NOT modify this code. The content of this method is
046: * always regenerated by the Form Editor.
047: */
048: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
049: private void initComponents() {
050: java.awt.GridBagConstraints gridBagConstraints;
051:
052: lblName = new javax.swing.JLabel();
053: tfName = new javax.swing.JTextField();
054: lblClassName = new javax.swing.JLabel();
055: tfClassName = new javax.swing.JTextField();
056: lblLibrary = new javax.swing.JLabel();
057: jPanel1 = new javax.swing.JPanel();
058: lblSample = new javax.swing.JLabel();
059: tfSampleUrl = new javax.swing.JTextField();
060: libraryPath = new workbench.gui.components.WbFilePicker();
061:
062: setFont(null);
063: setLayout(new java.awt.GridBagLayout());
064:
065: lblName.setFont(null);
066: lblName.setText(ResourceMgr.getString("LblDriverName"));
067: gridBagConstraints = new java.awt.GridBagConstraints();
068: gridBagConstraints.gridx = 0;
069: gridBagConstraints.gridy = 0;
070: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
071: gridBagConstraints.insets = new java.awt.Insets(11, 10, 0, 7);
072: add(lblName, gridBagConstraints);
073:
074: tfName.setHorizontalAlignment(javax.swing.JTextField.LEFT);
075: tfName.setMinimumSize(new java.awt.Dimension(50, 20));
076: tfName.addMouseListener(new TextComponentMouseListener());
077: tfName.addFocusListener(new java.awt.event.FocusAdapter() {
078: public void focusLost(java.awt.event.FocusEvent evt) {
079: DriverEditorPanel.this .focusLost(evt);
080: }
081: });
082: gridBagConstraints = new java.awt.GridBagConstraints();
083: gridBagConstraints.gridx = 1;
084: gridBagConstraints.gridy = 0;
085: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
086: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
087: gridBagConstraints.weightx = 1.0;
088: gridBagConstraints.insets = new java.awt.Insets(11, 3, 0, 3);
089: add(tfName, gridBagConstraints);
090:
091: lblClassName.setFont(null);
092: lblClassName.setText(ResourceMgr.getString("LblDriverClass"));
093: gridBagConstraints = new java.awt.GridBagConstraints();
094: gridBagConstraints.gridx = 0;
095: gridBagConstraints.gridy = 1;
096: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
097: gridBagConstraints.insets = new java.awt.Insets(4, 10, 0, 7);
098: add(lblClassName, gridBagConstraints);
099:
100: tfClassName.setColumns(10);
101: tfClassName.setHorizontalAlignment(javax.swing.JTextField.LEFT);
102: tfClassName.addMouseListener(new TextComponentMouseListener());
103: tfClassName.addFocusListener(new java.awt.event.FocusAdapter() {
104: public void focusLost(java.awt.event.FocusEvent evt) {
105: DriverEditorPanel.this .focusLost(evt);
106: }
107: });
108: gridBagConstraints = new java.awt.GridBagConstraints();
109: gridBagConstraints.gridx = 1;
110: gridBagConstraints.gridy = 1;
111: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
112: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
113: gridBagConstraints.insets = new java.awt.Insets(4, 3, 0, 3);
114: add(tfClassName, gridBagConstraints);
115:
116: lblLibrary.setFont(null);
117: lblLibrary.setText(ResourceMgr.getString("LblDriverLibrary"));
118: gridBagConstraints = new java.awt.GridBagConstraints();
119: gridBagConstraints.gridx = 0;
120: gridBagConstraints.gridy = 2;
121: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
122: gridBagConstraints.insets = new java.awt.Insets(4, 10, 0, 7);
123: add(lblLibrary, gridBagConstraints);
124: gridBagConstraints = new java.awt.GridBagConstraints();
125: gridBagConstraints.gridx = 0;
126: gridBagConstraints.gridy = 4;
127: gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
128: gridBagConstraints.weighty = 1.0;
129: add(jPanel1, gridBagConstraints);
130:
131: lblSample.setFont(null);
132: lblSample.setText(ResourceMgr.getString("LblSampleUrl"));
133: gridBagConstraints = new java.awt.GridBagConstraints();
134: gridBagConstraints.gridx = 0;
135: gridBagConstraints.gridy = 3;
136: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
137: gridBagConstraints.insets = new java.awt.Insets(4, 10, 0, 7);
138: add(lblSample, gridBagConstraints);
139:
140: tfSampleUrl.setColumns(10);
141: tfSampleUrl.setHorizontalAlignment(javax.swing.JTextField.LEFT);
142: tfSampleUrl.addMouseListener(new TextComponentMouseListener());
143: gridBagConstraints = new java.awt.GridBagConstraints();
144: gridBagConstraints.gridx = 1;
145: gridBagConstraints.gridy = 3;
146: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
147: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
148: gridBagConstraints.insets = new java.awt.Insets(4, 3, 0, 3);
149: add(tfSampleUrl, gridBagConstraints);
150: gridBagConstraints = new java.awt.GridBagConstraints();
151: gridBagConstraints.gridx = 1;
152: gridBagConstraints.gridy = 2;
153: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
154: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
155: gridBagConstraints.insets = new java.awt.Insets(4, 3, 0, 3);
156: add(libraryPath, gridBagConstraints);
157: }// </editor-fold>//GEN-END:initComponents
158:
159: private void focusLost(java.awt.event.FocusEvent evt)//GEN-FIRST:event_focusLost
160: {//GEN-HEADEREND:event_focusLost
161: this .updateDriver();
162: }//GEN-LAST:event_focusLost
163:
164: public void setDriver(DbDriver aDriver) {
165: this .currentDriver = aDriver;
166: this .tfName.setText(aDriver.getName());
167: this .tfClassName.setText(aDriver.getDriverClass());
168: this .libraryPath.setFilename(aDriver.getLibraryString());
169: this .tfSampleUrl.setText(aDriver.getSampleUrl());
170: }
171:
172: void updateDriver() {
173: this .currentDriver.setName(tfName.getText());
174: this .currentDriver.setDriverClass(tfClassName.getText());
175: this .currentDriver.setLibrary(libraryPath.getFilename());
176: this .currentDriver.setSampleUrl(tfSampleUrl.getText());
177: }
178:
179: public DbDriver getDriver() {
180: this .updateDriver();
181: return this .currentDriver;
182: }
183:
184: public void reset() {
185: this .currentDriver = null;
186: this .tfName.setText("");
187: this .tfClassName.setText("");
188: this .libraryPath.setFilename("");
189: this .tfSampleUrl.setText("");
190: }
191:
192: // Variables declaration - do not modify//GEN-BEGIN:variables
193: private javax.swing.JPanel jPanel1;
194: private javax.swing.JLabel lblClassName;
195: private javax.swing.JLabel lblLibrary;
196: private javax.swing.JLabel lblName;
197: private javax.swing.JLabel lblSample;
198: private workbench.gui.components.WbFilePicker libraryPath;
199: private javax.swing.JTextField tfClassName;
200: private javax.swing.JTextField tfName;
201: private javax.swing.JTextField tfSampleUrl;
202: // End of variables declaration//GEN-END:variables
203:
204: }
|