001: /*
002: * Copyright (C) 2004 Nicky BRAMANTE
003: *
004: * This file is part of FreeQueryBuilder
005: *
006: * FreeQueryBuilder is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: * Send questions or suggestions to nickyb@interfree.it
021: */
022:
023: package it.frb.admin;
024:
025: import it.frb.*;
026:
027: import java.awt.Cursor;
028: import java.awt.Dimension;
029: import java.awt.GridBagConstraints;
030: import java.awt.GridBagLayout;
031: import java.awt.Insets;
032:
033: import java.awt.event.ActionEvent;
034: import java.awt.event.ActionListener;
035:
036: import javax.swing.Box;
037: import javax.swing.BoxLayout;
038: import javax.swing.JButton;
039: import javax.swing.JLabel;
040: import javax.swing.JPanel;
041: import javax.swing.JPasswordField;
042: import javax.swing.JTextField;
043:
044: import javax.swing.border.EmptyBorder;
045:
046: public class InfoProfilePane extends DefaultPanel implements
047: ActionListener {
048: private InfoProfilePane.InfoElement info;
049: private DialogAdministrator admin;
050:
051: private JTextField txtName;
052: private JTextField txtUrl;
053: private JTextField txtUid;
054: private JPasswordField txtPwd;
055:
056: private JButton btnApply;
057: private JButton btnConnect;
058:
059: public InfoProfilePane(DialogAdministrator admin) {
060: super (2, 2);
061: this .admin = admin;
062:
063: JPanel detail = new JPanel();
064: detail.setPreferredSize(new Dimension(199, 199));
065:
066: GridBagLayout gbl = new GridBagLayout();
067: detail.setLayout(gbl);
068: detail.setBorder(new EmptyBorder(4, 4, 4, 4));
069:
070: GridBagConstraints gbc = new GridBagConstraints();
071: gbc.gridwidth = GridBagConstraints.REMAINDER;
072: gbc.fill = GridBagConstraints.BOTH;
073: gbc.weightx = 1.0;
074:
075: JLabel lbl;
076: gbl.setConstraints(lbl = new JLabel("name:"), gbc);
077: detail.add(lbl);
078:
079: gbc.insets = new Insets(0, 0, 30, 0);
080: gbl.setConstraints(txtName = new JTextField(), gbc);
081: detail.add(txtName);
082:
083: gbc.insets = new Insets(0, 0, 0, 0);
084: gbl.setConstraints(lbl = new JLabel("url:"), gbc);
085: detail.add(lbl);
086: gbl.setConstraints(txtUrl = new JTextField(), gbc);
087: detail.add(txtUrl);
088:
089: gbl.setConstraints(lbl = new JLabel("user:"), gbc);
090: detail.add(lbl);
091: gbl.setConstraints(txtUid = new JTextField(), gbc);
092: detail.add(txtUid);
093:
094: gbl.setConstraints(lbl = new JLabel("password:"), gbc);
095: detail.add(lbl);
096:
097: gbc.insets = new Insets(0, 0, 30, 0);
098: gbl.setConstraints(txtPwd = new JPasswordField(), gbc);
099: detail.add(txtPwd);
100:
101: Box bar = new Box(BoxLayout.X_AXIS);
102: bar.add(btnApply = UIUtilities
103: .createCustomButton("apply", this ));
104: bar.add(btnConnect = UIUtilities.createCustomButton("connect",
105: this ));
106: bar.add(Box.createHorizontalGlue());
107:
108: setCenterComponent(new DefaultScrollPane("edit profile",
109: detail, false));
110: setSouthComponent(bar);
111: }
112:
113: void setInfo(InfoProfilePane.InfoElement info) {
114: this .info = info;
115:
116: txtName.setText(info.name);
117: txtUrl.setText(info.url);
118: txtUid.setText(info.uid);
119: txtPwd.setText(null);
120: }
121:
122: public void actionPerformed(ActionEvent e) {
123: String name = txtName.getText();
124: if (name.indexOf(';') != -1)
125: return;
126: if (!name.equals(info.name)
127: && UserSession.jdbc.containsKey(name + ".drv"))
128: return;
129:
130: info.name = name;
131: info.url = txtUrl.getText();
132: info.uid = txtUid.getText();
133:
134: admin.save();
135: if (e.getSource() == btnConnect) {
136: this .setCursor(new Cursor(Cursor.WAIT_CURSOR));
137: String pwd = new String(txtPwd.getPassword());
138: if (pwd.equals(""))
139: pwd = null;
140:
141: ConnDefinition connDef = new ConnDefinition(info.name,
142: info.url, info.uid, pwd, null);
143: ConnectionPool.setConnectionDefinition(connDef);
144: ConnectionPool.openConnection(info.dinfo.driver, info.url,
145: info.uid, pwd);
146: admin.dispose();
147: this .setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
148: }
149: }
150:
151: static class InfoElement {
152: private static int counter = 0;
153:
154: String name = new String();
155: String url = new String();
156: String uid = new String();
157:
158: InfoDriverPane.InfoElement dinfo;
159:
160: InfoElement(InfoDriverPane.InfoElement dinfo) {
161: this (dinfo, "new_profile_" + (++counter));
162: }
163:
164: InfoElement(InfoDriverPane.InfoElement dinfo, String name) {
165: this .dinfo = dinfo;
166: this .name = name;
167:
168: url = dinfo.example;
169: }
170:
171: public String toString() {
172: return name;
173: }
174: }
175: }
|