KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > administrator > helpers > DescriptorWizard


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, is permitted
5  * provided that the following conditions are met:
6  * - Redistributions of source code must retain the above copyright notice, this list of conditions
7  * and the following disclaimer.
8  * - Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * - All advertising materials mentioning features or use of this software must display the
12  * following acknowledgment: "This product includes Djeneric."
13  * - Products derived from this software may not be called "Djeneric" nor may
14  * "Djeneric" appear in their names without prior written permission of Genimen BV.
15  * - Redistributions of any form whatsoever must retain the following acknowledgment: "This
16  * product includes Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30 package com.genimen.djeneric.tools.administrator.helpers;
31
32 import java.awt.BorderLayout JavaDoc;
33 import java.awt.Dimension JavaDoc;
34 import java.awt.FlowLayout JavaDoc;
35 import java.awt.Toolkit JavaDoc;
36 import java.awt.event.ActionEvent JavaDoc;
37 import java.awt.event.ActionListener JavaDoc;
38
39 import javax.swing.ButtonGroup JavaDoc;
40 import javax.swing.DefaultComboBoxModel JavaDoc;
41 import javax.swing.JButton JavaDoc;
42 import javax.swing.JComboBox JavaDoc;
43 import javax.swing.JDialog JavaDoc;
44 import javax.swing.JLabel JavaDoc;
45 import javax.swing.JPanel JavaDoc;
46 import javax.swing.JTextField JavaDoc;
47
48 import com.genimen.djeneric.language.Messages;
49 import com.genimen.djeneric.tools.administrator.Administrator;
50 import com.genimen.djeneric.ui.DjVerticalFlowLayout;
51 import com.genimen.djeneric.ui.Util;
52
53 /**
54  * Description of the Class
55  *
56  *@author Wido Riezebos
57  *@created 27 mei 2002
58  */

59 public class DescriptorWizard extends JDialog JavaDoc
60 {
61   private static final String JavaDoc DERBY = "Derby";
62   private static final String JavaDoc SQL_SERVER_JTDS = "SQL Server (JTDS)";
63   private static final String JavaDoc DB2 = "DB2";
64   private static final String JavaDoc HYPERSONIC = "Hypersonic";
65   private static final String JavaDoc ORACLE = "Oracle";
66   private static final String JavaDoc SQL_SERVER_UNA2000 = "SQL_Server_(UNA2000)";
67   private static final String JavaDoc POINTBASE = "Pointbase";
68   private String JavaDoc OTHER = Messages.getString("DescriptorWizard.Other");
69
70   private static final long serialVersionUID = 1L;
71   JPanel JavaDoc panel1 = new JPanel JavaDoc();
72   BorderLayout JavaDoc borderLayout1 = new BorderLayout JavaDoc();
73   JPanel JavaDoc jPanel1 = new JPanel JavaDoc();
74   JPanel JavaDoc jPanel2 = new JPanel JavaDoc();
75   JPanel JavaDoc jPanel3 = new JPanel JavaDoc();
76   BorderLayout JavaDoc borderLayout2 = new BorderLayout JavaDoc();
77   JPanel JavaDoc jPanel4 = new JPanel JavaDoc();
78   JButton JavaDoc _butOk = new JButton JavaDoc();
79   JButton JavaDoc _butCancel = new JButton JavaDoc();
80   DjVerticalFlowLayout verticalFlowLayout1 = new DjVerticalFlowLayout();
81   DjVerticalFlowLayout verticalFlowLayout2 = new DjVerticalFlowLayout();
82   boolean _wasCancelled = true;
83   Administrator _administrator;
84   JLabel JavaDoc jLabel1 = new JLabel JavaDoc();
85   JLabel JavaDoc _lblHost = new JLabel JavaDoc();
86   JTextField JavaDoc _edtHost = new JTextField JavaDoc();
87   JLabel JavaDoc _lblSID = new JLabel JavaDoc();
88   JTextField JavaDoc _edtSID = new JTextField JavaDoc();
89   JLabel JavaDoc _lblDatabaseName = new JLabel JavaDoc();
90   JTextField JavaDoc _edtDbName = new JTextField JavaDoc();
91   ButtonGroup JavaDoc buttonGroup = new ButtonGroup JavaDoc();
92   JPanel JavaDoc jPanel5 = new JPanel JavaDoc();
93   FlowLayout JavaDoc flowLayout1 = new FlowLayout JavaDoc();
94   JPanel JavaDoc jPanel6 = new JPanel JavaDoc();
95   DjVerticalFlowLayout verticalFlowLayout3 = new DjVerticalFlowLayout();
96   JComboBox JavaDoc _cbbDatabase = new JComboBox JavaDoc();
97
98   /**
99    * Constructor for the DefineRepositoryDialog object
100    *
101    *@param administrator Description of the Parameter
102    *@param title Description of the Parameter
103    *@param descr Description of the Parameter
104    *@exception Exception Description of the Exception
105    */

106   public DescriptorWizard(Administrator administrator) throws Exception JavaDoc
107   {
108     super(administrator, Messages.getString("DescriptorWizard.NewRepositoryDescriptor"), true);
109     _administrator = administrator;
110     jbInit();
111
112     setSize(new Dimension JavaDoc(280, 150));
113
114     Dimension JavaDoc screenSize = Toolkit.getDefaultToolkit().getScreenSize();
115     Dimension JavaDoc frameSize = getSize();
116     setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
117
118     _cbbDatabase_actionPerformed(null);
119     setVisible(true);
120   }
121
122   /**
123    * Description of the Method
124    *
125    *@return Description of the Return Value
126    */

127   public boolean wasCancelled()
128   {
129     return _wasCancelled;
130   }
131
132   void jbInit() throws Exception JavaDoc
133   {
134     DefaultComboBoxModel JavaDoc mdl = new DefaultComboBoxModel JavaDoc(new String JavaDoc[]{ORACLE, DB2, DERBY, HYPERSONIC, SQL_SERVER_UNA2000,
135         SQL_SERVER_JTDS, POINTBASE, OTHER});
136     _cbbDatabase.setModel(mdl);
137     _cbbDatabase.addActionListener(new ActionListener JavaDoc()
138     {
139       public void actionPerformed(ActionEvent JavaDoc e)
140       {
141         _cbbDatabase_actionPerformed(e);
142       }
143     });
144
145     panel1.setLayout(borderLayout1);
146     jPanel3.setLayout(borderLayout2);
147     _butOk.setText(Messages.getString("global.Ok"));
148     _butOk.addActionListener(new java.awt.event.ActionListener JavaDoc()
149     {
150       public void actionPerformed(ActionEvent JavaDoc e)
151       {
152         _butOk_actionPerformed(e);
153       }
154     });
155     _butCancel.setText(Messages.getString("global.Cancel"));
156     _butCancel.addActionListener(new java.awt.event.ActionListener JavaDoc()
157     {
158       public void actionPerformed(ActionEvent JavaDoc e)
159       {
160         _butCancel_actionPerformed(e);
161       }
162     });
163     jPanel1.setLayout(verticalFlowLayout1);
164     jPanel2.setLayout(verticalFlowLayout2);
165     jLabel1.setPreferredSize(new Dimension JavaDoc(90, 20));
166     jLabel1.setText(Messages.getString("DescriptorWizard.Database"));
167     _lblHost.setPreferredSize(new Dimension JavaDoc(26, 20));
168     _lblHost.setText(Messages.getString("DescriptorWizard.Host"));
169     _edtHost.setText("localhost");
170     _lblSID.setPreferredSize(new Dimension JavaDoc(19, 20));
171     _lblSID.setText("SID");
172     _edtSID.setText("ORCL");
173     _lblDatabaseName.setPreferredSize(new Dimension JavaDoc(52, 20));
174     _lblDatabaseName.setText(Messages.getString("DescriptorWizard.DBName"));
175     _edtDbName.setText("djeneric");
176     jPanel5.setLayout(flowLayout1);
177     flowLayout1.setAlignment(FlowLayout.LEFT);
178     flowLayout1.setHgap(0);
179     flowLayout1.setVgap(0);
180     jPanel6.setLayout(verticalFlowLayout3);
181     verticalFlowLayout2.setHgap(0);
182     verticalFlowLayout2.setVgap(0);
183     verticalFlowLayout1.setVgap(0);
184     verticalFlowLayout3.setHgap(0);
185     verticalFlowLayout3.setVgap(0);
186     getContentPane().add(panel1);
187     panel1.add(jPanel1, BorderLayout.WEST);
188     jPanel1.add(jLabel1, null);
189     jPanel1.add(jPanel5, null);
190     jPanel1.add(_lblHost, null);
191     jPanel1.add(_lblDatabaseName, null);
192     jPanel1.add(_lblSID, null);
193     panel1.add(jPanel2, BorderLayout.CENTER);
194     jPanel2.add(_cbbDatabase);
195     jPanel2.add(jPanel6, null);
196     jPanel2.add(_edtHost, null);
197     jPanel2.add(_edtDbName, null);
198     jPanel2.add(_edtSID, null);
199     panel1.add(jPanel3, BorderLayout.SOUTH);
200     jPanel3.add(jPanel4, BorderLayout.EAST);
201     jPanel4.add(_butCancel, null);
202     jPanel4.add(_butOk, null);
203     Util.sizeButtons(jPanel4);
204   }
205
206   void _butCancel_actionPerformed(ActionEvent JavaDoc e)
207   {
208     setVisible(false);
209   }
210
211   void _butOk_actionPerformed(ActionEvent JavaDoc e)
212   {
213     _wasCancelled = false;
214
215     setVisible(false);
216   }
217
218   public String JavaDoc getDriver()
219   {
220     String JavaDoc curDbs = _cbbDatabase.getSelectedItem().toString();
221
222     if (curDbs.equals(HYPERSONIC)) return DefineRepositoryDialog.HYPERSONIC_DRIVER;
223     if (curDbs.equals(DERBY)) return DefineRepositoryDialog.DERBY_DRIVER;
224     if (curDbs.equals(DB2)) return DefineRepositoryDialog.DB2_DRIVER;
225     if (curDbs.equals(ORACLE)) return DefineRepositoryDialog.ORACLE_DRIVER;
226     if (curDbs.equals(POINTBASE)) return DefineRepositoryDialog.POINTBASE_DRIVER;
227     if (curDbs.equals(SQL_SERVER_UNA2000)) return DefineRepositoryDialog.UNA_DRIVER;
228     if (curDbs.equals(SQL_SERVER_JTDS)) return DefineRepositoryDialog.JTDS_DRIVER;
229
230     return "";
231   }
232
233   public String JavaDoc getUrl()
234   {
235     String JavaDoc curDbs = _cbbDatabase.getSelectedItem().toString();
236
237     if (curDbs.equals(HYPERSONIC)) return "jdbc:hsqldb:hsql://" + _edtHost.getText();
238     if (curDbs.equals(DERBY)) return "jdbc:derby:net://" + _edtHost.getText() + ":1527/" + _edtDbName.getText()
239                                      + ";create=true";
240     if (curDbs.equals(DB2)) return "jdbc:db2:" + _edtDbName.getText();
241     if (curDbs.equals(ORACLE)) return "jdbc:oracle:thin:@" + _edtHost.getText() + ":1521:" + _edtSID.getText();
242     if (curDbs.equals(POINTBASE)) return "jdbc:pointbase:server://" + _edtHost.getText() + "/" + _edtDbName.getText();
243     if (curDbs.equals(SQL_SERVER_UNA2000)) return "jdbc:inetdae:" + _edtHost.getText() + "?database="
244                                                   + _edtDbName.getText() + "&sql7=true&charset=Cp1250";
245     if (curDbs.equals(SQL_SERVER_JTDS)) return "jdbc:jtds:sqlserver://" + _edtHost.getText() + "/"
246                                                + _edtDbName.getText() + ";charset=Cp1250";
247     return "";
248   }
249
250   public String JavaDoc getName()
251   {
252     String JavaDoc curDbs = _cbbDatabase.getSelectedItem().toString();
253
254     if (curDbs.equals(HYPERSONIC)) return Messages.getString("DescriptorWizard.HypersonicOn", _edtHost.getText());
255     if (curDbs.equals(DERBY)) return Messages.getString("DescriptorWizard.DerbyOn", _edtHost.getText());
256     if (curDbs.equals(DB2)) return Messages.getString("DescriptorWizard.DB2On", _edtHost.getText());
257     if (curDbs.equals(ORACLE)) return Messages.getString("DescriptorWizard.OracleOn", _edtHost.getText());
258     if (curDbs.equals(POINTBASE)) return Messages.getString("DescriptorWizard.PointbaseOn", _edtHost.getText());
259     if (curDbs.equals(SQL_SERVER_UNA2000)) return Messages.getString("global.SqlServeron", _edtHost.getText());
260     if (curDbs.equals(SQL_SERVER_JTDS)) return Messages.getString("global.SqlServeron", _edtHost.getText());
261     return Messages.getString("DescriptorWizard.MyRepository");
262   }
263
264   public String JavaDoc getUser()
265   {
266     String JavaDoc curDbs = _cbbDatabase.getSelectedItem().toString();
267     if (curDbs.equals(HYPERSONIC)) return "sa";
268     if (curDbs.equals(POINTBASE)) return "PBPUBLIC";
269     return "djeneric";
270   }
271
272   public String JavaDoc getPassword()
273   {
274     String JavaDoc curDbs = _cbbDatabase.getSelectedItem().toString();
275     if (curDbs.equals(HYPERSONIC)) return "";
276     if (curDbs.equals(POINTBASE)) return "";
277     return "djeneric";
278   }
279
280   public void _cbbDatabase_actionPerformed(ActionEvent JavaDoc e)
281   {
282     String JavaDoc curDbs = _cbbDatabase.getSelectedItem().toString();
283
284     boolean dbNameVisible = curDbs.equals(DERBY) || curDbs.equals(DB2) || curDbs.equals(POINTBASE) || curDbs.equals(SQL_SERVER_UNA2000)
285                             || curDbs.equals(SQL_SERVER_JTDS);
286
287     _lblDatabaseName.setVisible(dbNameVisible);
288     _edtDbName.setVisible(dbNameVisible);
289
290     boolean sidVisible = curDbs.equals(ORACLE);
291     _lblSID.setVisible(sidVisible);
292     _edtSID.setVisible(sidVisible);
293
294     boolean hostVisible = !curDbs.equals(OTHER);
295     _lblHost.setVisible(hostVisible);
296     _edtHost.setVisible(hostVisible);
297   }
298 }
299
Popular Tags