1 30 package com.genimen.djeneric.tools.administrator.helpers; 31 32 import java.awt.BorderLayout ; 33 import java.awt.Dimension ; 34 import java.awt.FlowLayout ; 35 import java.awt.Toolkit ; 36 import java.awt.event.ActionEvent ; 37 import java.awt.event.ActionListener ; 38 39 import javax.swing.ButtonGroup ; 40 import javax.swing.DefaultComboBoxModel ; 41 import javax.swing.JButton ; 42 import javax.swing.JComboBox ; 43 import javax.swing.JDialog ; 44 import javax.swing.JLabel ; 45 import javax.swing.JPanel ; 46 import javax.swing.JTextField ; 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 59 public class DescriptorWizard extends JDialog 60 { 61 private static final String DERBY = "Derby"; 62 private static final String SQL_SERVER_JTDS = "SQL Server (JTDS)"; 63 private static final String DB2 = "DB2"; 64 private static final String HYPERSONIC = "Hypersonic"; 65 private static final String ORACLE = "Oracle"; 66 private static final String SQL_SERVER_UNA2000 = "SQL_Server_(UNA2000)"; 67 private static final String POINTBASE = "Pointbase"; 68 private String OTHER = Messages.getString("DescriptorWizard.Other"); 69 70 private static final long serialVersionUID = 1L; 71 JPanel panel1 = new JPanel (); 72 BorderLayout borderLayout1 = new BorderLayout (); 73 JPanel jPanel1 = new JPanel (); 74 JPanel jPanel2 = new JPanel (); 75 JPanel jPanel3 = new JPanel (); 76 BorderLayout borderLayout2 = new BorderLayout (); 77 JPanel jPanel4 = new JPanel (); 78 JButton _butOk = new JButton (); 79 JButton _butCancel = new JButton (); 80 DjVerticalFlowLayout verticalFlowLayout1 = new DjVerticalFlowLayout(); 81 DjVerticalFlowLayout verticalFlowLayout2 = new DjVerticalFlowLayout(); 82 boolean _wasCancelled = true; 83 Administrator _administrator; 84 JLabel jLabel1 = new JLabel (); 85 JLabel _lblHost = new JLabel (); 86 JTextField _edtHost = new JTextField (); 87 JLabel _lblSID = new JLabel (); 88 JTextField _edtSID = new JTextField (); 89 JLabel _lblDatabaseName = new JLabel (); 90 JTextField _edtDbName = new JTextField (); 91 ButtonGroup buttonGroup = new ButtonGroup (); 92 JPanel jPanel5 = new JPanel (); 93 FlowLayout flowLayout1 = new FlowLayout (); 94 JPanel jPanel6 = new JPanel (); 95 DjVerticalFlowLayout verticalFlowLayout3 = new DjVerticalFlowLayout(); 96 JComboBox _cbbDatabase = new JComboBox (); 97 98 106 public DescriptorWizard(Administrator administrator) throws Exception 107 { 108 super(administrator, Messages.getString("DescriptorWizard.NewRepositoryDescriptor"), true); 109 _administrator = administrator; 110 jbInit(); 111 112 setSize(new Dimension (280, 150)); 113 114 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 115 Dimension 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 127 public boolean wasCancelled() 128 { 129 return _wasCancelled; 130 } 131 132 void jbInit() throws Exception 133 { 134 DefaultComboBoxModel mdl = new DefaultComboBoxModel (new String []{ORACLE, DB2, DERBY, HYPERSONIC, SQL_SERVER_UNA2000, 135 SQL_SERVER_JTDS, POINTBASE, OTHER}); 136 _cbbDatabase.setModel(mdl); 137 _cbbDatabase.addActionListener(new ActionListener () 138 { 139 public void actionPerformed(ActionEvent 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 () 149 { 150 public void actionPerformed(ActionEvent e) 151 { 152 _butOk_actionPerformed(e); 153 } 154 }); 155 _butCancel.setText(Messages.getString("global.Cancel")); 156 _butCancel.addActionListener(new java.awt.event.ActionListener () 157 { 158 public void actionPerformed(ActionEvent e) 159 { 160 _butCancel_actionPerformed(e); 161 } 162 }); 163 jPanel1.setLayout(verticalFlowLayout1); 164 jPanel2.setLayout(verticalFlowLayout2); 165 jLabel1.setPreferredSize(new Dimension (90, 20)); 166 jLabel1.setText(Messages.getString("DescriptorWizard.Database")); 167 _lblHost.setPreferredSize(new Dimension (26, 20)); 168 _lblHost.setText(Messages.getString("DescriptorWizard.Host")); 169 _edtHost.setText("localhost"); 170 _lblSID.setPreferredSize(new Dimension (19, 20)); 171 _lblSID.setText("SID"); 172 _edtSID.setText("ORCL"); 173 _lblDatabaseName.setPreferredSize(new Dimension (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 e) 207 { 208 setVisible(false); 209 } 210 211 void _butOk_actionPerformed(ActionEvent e) 212 { 213 _wasCancelled = false; 214 215 setVisible(false); 216 } 217 218 public String getDriver() 219 { 220 String 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 getUrl() 234 { 235 String 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 getName() 251 { 252 String 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 getUser() 265 { 266 String 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 getPassword() 273 { 274 String 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 e) 281 { 282 String 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 |