001: package net.sourceforge.squirrel_sql.client.gui.db.aliasproperties;
002:
003: /*
004: * Copyright (C) 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.awt.GridBagConstraints;
022: import java.awt.GridBagLayout;
023: import java.awt.Insets;
024:
025: import javax.swing.*;
026: import javax.swing.table.TableCellEditor;
027: import javax.swing.event.ListSelectionEvent;
028: import javax.swing.event.ListSelectionListener;
029:
030: import net.sourceforge.squirrel_sql.fw.gui.MultipleLineLabel;
031: import net.sourceforge.squirrel_sql.fw.sql.SQLDriverPropertyCollection;
032: import net.sourceforge.squirrel_sql.fw.util.StringManager;
033: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
034:
035: /**
036: * This panel allows the user to review and maintain
037: * the properties for a JDBC driver.
038: *
039: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
040: */
041: public class DriverPropertiesPanel extends JPanel {
042: /** Internationalized strings for this class. */
043: private static final StringManager s_stringMgr = StringManagerFactory
044: .getStringManager(DriverPropertiesPanel.class);
045:
046: // i18n[DriverPropertiesPanel.useDriverProperties=Use driver properties]
047: JCheckBox chkUseDriverProperties = new JCheckBox(s_stringMgr
048: .getString("DriverPropertiesPanel.useDriverProperties"));
049:
050: private interface i18n {
051: String INSTRUCTIONS = s_stringMgr
052: .getString("DriverPropertiesPanel.instructions");
053: }
054:
055: /** JTable containing the properties. */
056: DriverPropertiesTable tbl;
057:
058: /**
059: * Display the description for the currently selected property in this
060: * control.
061: */
062: private final MultipleLineLabel _descriptionLbl = new MultipleLineLabel();
063:
064: public DriverPropertiesPanel(SQLDriverPropertyCollection props) {
065: super (new GridBagLayout());
066: if (props == null) {
067: throw new IllegalArgumentException(
068: "SQLDriverPropertyCollection == null");
069: }
070:
071: createUserInterface(props);
072: }
073:
074: /**
075: * Retrieve the database properties.
076: *
077: * @return the database properties.
078: */
079: public SQLDriverPropertyCollection getSQLDriverProperties() {
080: TableCellEditor cellEditor = tbl.getCellEditor();
081: if (null != cellEditor) {
082: cellEditor.stopCellEditing();
083: }
084: return tbl.getTypedModel().getSQLDriverProperties();
085: }
086:
087: private void createUserInterface(SQLDriverPropertyCollection props) {
088: tbl = new DriverPropertiesTable(props);
089:
090: final GridBagConstraints gbc = new GridBagConstraints();
091:
092: setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
093:
094: gbc.anchor = GridBagConstraints.WEST;
095: gbc.insets = new Insets(2, 2, 2, 2);
096: gbc.fill = GridBagConstraints.NONE;
097: gbc.anchor = GridBagConstraints.NORTHWEST;
098: gbc.gridx = 0;
099: gbc.gridy = 0;
100: gbc.weightx = 0;
101: gbc.weighty = 0;
102: add(chkUseDriverProperties, gbc);
103:
104: gbc.fill = GridBagConstraints.BOTH;
105: gbc.weighty = 1.0;
106: gbc.weightx = 1.0;
107: ++gbc.gridy;
108: JScrollPane sp = new JScrollPane(tbl);
109: add(sp, gbc);
110:
111: gbc.fill = GridBagConstraints.HORIZONTAL;
112: gbc.weighty = 0.0;
113: ++gbc.gridy;
114: add(createInfoPanel(), gbc);
115:
116: tbl.getSelectionModel().addListSelectionListener(
117: new ListSelectionListener() {
118: public void valueChanged(ListSelectionEvent evt) {
119: updateDescription(tbl.getSelectedRow());
120: }
121: });
122:
123: if (tbl.getRowCount() > 0) {
124: tbl.setRowSelectionInterval(0, 0);
125: }
126: }
127:
128: private void updateDescription(int idx) {
129: if (idx != -1) {
130: String desc = (String) tbl
131: .getValueAt(
132: idx,
133: DriverPropertiesTableModel.IColumnIndexes.IDX_DESCRIPTION);
134: _descriptionLbl.setText(desc);
135: } else {
136: _descriptionLbl.setText(" ");
137: }
138: }
139:
140: private Box createInfoPanel() {
141: final Box pnl = Box.createVerticalBox();
142: pnl.add(new JSeparator());
143: pnl.add(_descriptionLbl);
144: pnl.add(new JSeparator());
145: pnl.add(new MultipleLineLabel(i18n.INSTRUCTIONS));
146:
147: return pnl;
148: }
149: }
|