1 /*
2 Bloof - visualize the evolution of your software project
3 Copyright ( C ) 2003 Lukasz Pekacki <lukasz@pekacki.de>
4 http://bloof.sf.net/
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc.,
16 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 $RCSfile: DialogDatabaseAdd.java,v $
19 Created on $Date: 2003/06/24 05:47:43 $
20 */
21 package net.sf.bloof.browser;
22
23 import net.sf.bloof.db.DbAccess;
24 import net.sf.bloof.db.DefaultDbAccess;
25 import net.sf.bloof.db.McKoiControl;
26 import net.sf.bloof.db.PostgresControl;
27
28 import java.awt.BorderLayout;
29 import java.awt.Dialog;
30 import java.awt.event.ActionEvent;
31 import java.awt.event.ActionListener;
32
33 import javax.swing.BoxLayout;
34 import javax.swing.JButton;
35 import javax.swing.JComboBox;
36 import javax.swing.JDialog;
37 import javax.swing.JPanel;
38 import javax.swing.JPasswordField;
39 import javax.swing.JTextField;
40
41 /**
42 *
43 * @author Lukasz Pekacki <pekacki@users.sourceforge.net>
44 * @version $Id: DialogDatabaseAdd.java,v 1.2 2003/06/24 05:47:43 pekacki Exp $
45 */
46 public class DialogDatabaseAdd extends JDialog {
47 private static final String[] SUPPORTED_DATABASES = { "McKoi", "PostgreSQL" },
48 DATABASES_URL_PREFIXES = { McKoiControl.MY_URL_PREFIX, PostgresControl.MY_URL_PREFIX };
49 /* Access objects created from user input */
50 private DbAccess mDbAccess;
51 /* data objects */
52 private JTextField mName;
53 private JTextField mUser;
54 private JPasswordField mPassword;
55 private JTextField mUrl;
56 private JComboBox mDatabaseCombo;
57
58 /**
59 * @see java.awt.Dialog#Dialog( Frame, String, boolean )
60 */
61 public DialogDatabaseAdd(Dialog aFrame, String aTitle, boolean aModal) {
62 super(aFrame, aTitle, aModal);
63 try {
64 initFrame();
65 pack();
66 } catch (Exception ex) {
67 ex.printStackTrace();
68 }
69 }
70
71 /**
72 * Method getdbAccess.
73 * @return DbAccess
74 */
75 public DbAccess getdbAccess() {
76 return mDbAccess;
77 }
78
79 private void initFrame() throws Exception {
80 /* init root pannel */
81 JPanel rootPanel = new JPanel(new BorderLayout());
82
83 /* init specify data panel */
84 JPanel specifyDataPanel = new JPanel();
85 specifyDataPanel.setLayout(new BoxLayout(specifyDataPanel, BoxLayout.Y_AXIS));
86 mName = new JTextField("new database");
87 mUser = new JTextField("bloof");
88 mPassword = new JPasswordField();
89 mUrl = new JTextField(McKoiControl.MY_URL_PREFIX);
90 mDatabaseCombo = new JComboBox();
91 for (int i = 0; i < DialogDatabaseAdd.SUPPORTED_DATABASES.length; i++) {
92 mDatabaseCombo.addItem(DialogDatabaseAdd.SUPPORTED_DATABASES[i]);
93 }
94 mDatabaseCombo.addActionListener(new ActionListener() {
95 public void actionPerformed(ActionEvent aE) {
96 mUrl.setText(DATABASES_URL_PREFIXES[mDatabaseCombo.getSelectedIndex()]);
97
98 }
99 });
100
101 /* init buttons panel */
102 JPanel buttonsPanel = new JPanel();
103 JButton cancelButton = new JButton("Cancel");
104 cancelButton.addActionListener(new java.awt.event.ActionListener() {
105 public void actionPerformed(ActionEvent aE) {
106 cancelButtonActionPerformed(aE);
107 }
108 });
109 JButton okButton = new JButton("OK");
110 okButton.addActionListener(new java.awt.event.ActionListener() {
111 public void actionPerformed(ActionEvent aE) {
112 okButtonActionPerformed(aE);
113 }
114 });
115 /* construct specify database panel */
116 specifyDataPanel.add(Main.getGuiControl().createLabel("Database type"));
117 specifyDataPanel.add(mDatabaseCombo);
118 specifyDataPanel.add(Main.getGuiControl().createLabel("Name of new connection"));
119 specifyDataPanel.add(mName);
120 specifyDataPanel.add(Main.getGuiControl().createLabel("Username"));
121 specifyDataPanel.add(mUser);
122 specifyDataPanel.add(Main.getGuiControl().createLabel("Password"));
123 specifyDataPanel.add(mPassword);
124 specifyDataPanel.add(Main.getGuiControl().createLabel("URL to the database"));
125 specifyDataPanel.add(mUrl);
126 /* construct buttons pane */
127 buttonsPanel.add(okButton, null);
128 buttonsPanel.add(cancelButton, null);
129 /* construct main panel */
130 rootPanel.add(specifyDataPanel, BorderLayout.CENTER);
131 rootPanel.add(buttonsPanel, BorderLayout.SOUTH);
132 getContentPane().add(rootPanel);
133
134 }
135
136 private void okButtonActionPerformed(ActionEvent aE) {
137 Main.getGuiControl().processUselessEvent(aE);
138 this.dispose();
139 mDbAccess =
140 new DefaultDbAccess(
141 mName.getText() + " - " + mDatabaseCombo.getSelectedItem().toString(),
142 mUser.getText(),
143 new String(mPassword.getPassword()),
144 mUrl.getText());
145 }
146
147 private void cancelButtonActionPerformed(ActionEvent aE) {
148 Main.getGuiControl().processUselessEvent(aE);
149 this.dispose();
150 }
151
152 }