1 23 24 25 package org.infoglue.cmsinstaller; 26 import javax.swing.*; 27 import java.awt.*; 28 import java.awt.event.*; 29 30 33 34 public class DatabaseDialog extends JPanel implements ActionListener 35 { 36 private InfoGlueInstaller infoglueInstaller = null; 37 38 private final static String introductionHeader = "Database setup"; 39 private final static String introductionMessage = "For the system to work you will have to state which database you wish to use. All fields have a help texts if you click on the question mark next to it."; 40 41 private final static String createDatabaseLabel = "The installer can automatically create a database and set up some basic data to make the basic functionality and examples work. If you would like the installer to do these tasks you mark the options you want below and then supply the installer with an administrative db-account. The account must have rights to create databases and tables on the server stated above."; 43 private final static String createInitialDataLabel = "The installer can automatically create a database and set up some basic data to make the basic functionality and examples work. If you would like the installer to do these tasks you mark the options you want below and then supply the installer with an administrative db-account. The account must have rights to create databases and tables on the server stated above."; 44 private final static String upgradeDatabaseEncodingLabelText = "Upgrade to utf-8?"; 45 46 private final static String databaseLabel = "Database type"; 47 private final static String databaseNameLabel = "Database name"; 48 private final static String databaseSuffixLabel = "Database suffix"; 49 private final static String databaseDriverNameLabel = "Database driver name"; 50 private final static String databaseServerLabel = "Database server"; 51 private final static String databasePortLabel = "Database port"; 52 private final static String databaseInstanceLabel = "Database instance"; 53 private final static String databaseUserLabel = "DBA name"; 54 private final static String databasePasswordLabel = "DBA password"; 55 private final static String infoGluePasswordLabel = "InfoGlue password"; 56 58 private final static Color fieldBackground = new Color(230, 230, 245); 59 60 private JComboBox databaseCombo = null; 61 private JTextField dbName = null; 62 private JTextField dbSuffix = null; 63 private JTextField dbServer = null; 65 private JTextField dbPort = null; 66 private JTextField dbInstance = null; 67 private JCheckBox createDatabase = null; 68 private JCheckBox createInitialData = null; 69 private JCheckBox createExamples = null; 70 private JCheckBox upgradeDatabaseEncoding = null; 71 private JTextField dbUser = null; 72 private JPasswordField dbPassword = null; 73 private JTextField infoGlueUserName = null; 74 private JPasswordField infoGluePassword = null; 75 76 private JTextArea errorMessage = null; 77 78 private int xPosLabels = 0; 79 private int xPosLabelsWidth = 170; 80 private int xPosValues = 180; 81 private int xPosValuesWidth = 190; 82 83 84 85 public DatabaseDialog(InfoGlueInstaller infoGlueInstaller) 86 { 87 this.infoglueInstaller = infoGlueInstaller; 88 89 this.setSize(300, 430); 90 this.setLayout(null); 91 this.setBackground(Color.white); 92 JLabel introductionLabel = new JLabel(introductionHeader); 93 introductionLabel.setBounds(xPosLabels, 0, 400, 30); 94 introductionLabel.setFont(new java.awt.Font ("Dialog", java.awt.Font.BOLD, 16)); 95 96 JTextArea textArea = new JTextArea(introductionMessage); 97 textArea.setEditable(false); 98 textArea.setBounds(xPosLabels, 30, 400, 40); 99 textArea.setWrapStyleWord(true); 100 textArea.setLineWrap(true); 101 102 JLabel dbLabel = new JLabel(databaseLabel); 104 dbLabel.setBounds(xPosLabels, 70, 130, 20); 105 dbLabel.setToolTipText("<html>The database brand you wish to install InfoGlue on.</html>"); 106 databaseCombo = new JComboBox(); 107 this.databaseCombo.addActionListener(this); 108 databaseCombo.addItem("MySQL"); 109 databaseCombo.addItem("SQL Server"); 110 databaseCombo.addItem("Oracle"); 111 databaseCombo.addItem("DB2"); 112 databaseCombo.setNextFocusableComponent(this.dbSuffix); 113 databaseCombo.setBounds(xPosValues, 70, xPosValuesWidth, 20); 114 HelpButton helpDBCombo = new HelpButton(dbLabel); 115 helpDBCombo.setBounds(xPosValues + xPosValuesWidth + 2, 70, 20, 20); 116 117 JLabel dbNameLabel = new JLabel(databaseNameLabel); 118 dbNameLabel.setBounds(xPosLabels, 90, 130, 20); 119 dbNameLabel.setToolTipText("<html>The name of the infoglue database. Only change this if you have a current installation you wish to use.</html>"); 120 this.dbName = new JTextField("infoglue"); 122 this.dbName.setBounds(xPosValues, 90, xPosValuesWidth, 20); 123 this.dbName.setBackground(fieldBackground); 124 HelpButton helpDBName = new HelpButton(dbNameLabel); 125 helpDBName.setBounds(xPosValues + xPosValuesWidth + 2, 90, 20, 20); 126 127 JLabel dbSuffixLabel = new JLabel(databaseSuffixLabel); 128 dbSuffixLabel.setBounds(xPosLabels, 110, 130, 20); 129 dbSuffixLabel.setToolTipText("<html>This field gives you an option to add a suffix to the database name<br>so you can have more than one InfoGlue installation in the same database.<br>Used primarily in hosting services.</html>"); 130 this.dbSuffix = new JTextField(""); 131 this.dbSuffix.setBounds(xPosValues, 110, xPosValuesWidth, 20); 132 this.dbSuffix.setBackground(fieldBackground); 133 this.dbSuffix.setNextFocusableComponent(this.dbServer); 134 HelpButton helpDBSuffix = new HelpButton(dbSuffixLabel); 135 helpDBSuffix.setBounds(xPosValues + xPosValuesWidth + 2, 110, 20, 20); 136 137 JLabel dbServerLabel = new JLabel(databaseServerLabel); 138 dbServerLabel.setBounds(xPosLabels, 130, 130, 20); 139 dbServerLabel.setToolTipText("<html>The hostname of the database server on which the database is located.<br>Can be an IP or a hostname.</html>"); 140 this.dbServer = new JTextField("localhost"); 141 this.dbServer.setBounds(xPosValues, 130, xPosValuesWidth, 20); 143 this.dbServer.setBackground(fieldBackground); 144 this.dbServer.setNextFocusableComponent(this.infoGluePassword); 145 HelpButton helpDBServer = new HelpButton(dbServerLabel); 146 helpDBServer.setBounds(xPosValues + xPosValuesWidth + 2, 130, 20, 20); 147 148 JLabel dbPortLabel = new JLabel(databasePortLabel); 149 dbPortLabel.setBounds(xPosLabels, 150, 130, 20); 150 dbPortLabel.setToolTipText("<html>The database portnumber.</html>"); 151 this.dbPort = new JTextField("3306"); 152 this.dbPort.setBounds(xPosValues, 150, xPosValuesWidth, 20); 153 this.dbPort.setBackground(fieldBackground); 154 this.dbPort.setNextFocusableComponent(this.infoGluePassword); 155 HelpButton helpDBPort = new HelpButton(dbPortLabel); 156 helpDBPort.setBounds(xPosValues + xPosValuesWidth + 2, 150, 20, 20); 157 158 JLabel dbInstanceLabel = new JLabel(databaseInstanceLabel); 159 dbInstanceLabel.setBounds(xPosLabels, 170, 130, 20); 160 dbInstanceLabel.setToolTipText("<html>The database instance - only applies to SQL SERVER.</html>"); 161 this.dbInstance = new JTextField(""); 162 this.dbInstance.setBounds(xPosValues, 170, xPosValuesWidth, 20); 163 this.dbInstance.setBackground(fieldBackground); 164 this.dbInstance.setNextFocusableComponent(this.infoGluePassword); 165 this.dbInstance.setEnabled(false); 166 HelpButton helpDBInstance = new HelpButton(dbInstanceLabel); 167 helpDBInstance.setBounds(xPosValues + xPosValuesWidth + 2, 170, 20, 20); 168 169 JLabel infoglueDBUserNameLabel = new JLabel("InfoGlue username"); 170 infoglueDBUserNameLabel.setBounds(xPosLabels, 190, 130, 20); 171 infoglueDBUserNameLabel.setToolTipText("<html>The username InfoGlue is to use for connecting to the database.<br>If you want to upgrade an existing installation you need to supply the username used there.<br>The username is not related to what users use to log into the CMS with.</html>"); 172 this.infoGlueUserName = new JTextField("INFOGLUE_CMS"); 174 this.infoGlueUserName.setBounds(xPosValues, 190, xPosValuesWidth, 20); 175 this.infoGlueUserName.setBackground(fieldBackground); 176 this.infoGlueUserName.setNextFocusableComponent(this.infoGluePassword); 177 HelpButton helpInfoGlueUserName = new HelpButton(infoglueDBUserNameLabel); 178 helpInfoGlueUserName.setBounds(xPosValues + xPosValuesWidth + 2, 190, 20, 20); 179 180 JLabel infoglueDBPasswordLabel = new JLabel(infoGluePasswordLabel); 181 infoglueDBPasswordLabel.setBounds(xPosLabels, 210, 130, 20); 182 infoglueDBPasswordLabel.setToolTipText("<html>The password InfoGlue is to use for connecting to the database.<br>This password is not related to what users use to log into the CMS with.</html>"); 183 this.infoGluePassword = new JPasswordField("INFOGLUEPASS"); 185 this.infoGluePassword.setBounds(xPosValues, 210, xPosValuesWidth, 20); 186 this.infoGluePassword.setBackground(fieldBackground); 187 this.infoGluePassword.setNextFocusableComponent(this.createDatabase); 188 HelpButton helpInfoGluePassword = new HelpButton(infoglueDBPasswordLabel); 190 helpInfoGluePassword.setBounds(xPosValues + xPosValuesWidth + 2, 210, 20, 20); 191 192 JTextArea createDBIntroTextArea = new JTextArea(createDatabaseLabel); 193 createDBIntroTextArea.setEditable(false); 194 createDBIntroTextArea.setBounds(xPosLabels, 235, 200 + xPosValuesWidth, 100); 195 createDBIntroTextArea.setWrapStyleWord(true); 196 createDBIntroTextArea.setLineWrap(true); 197 198 JLabel dbCreateDatabaseLabel = new JLabel("Create database"); 199 dbCreateDatabaseLabel.setBounds(xPosLabels, 340, 130, 20); 200 dbCreateDatabaseLabel.setToolTipText("<html>Do you wish to install a new InfoGlue database?<br>If you allready have a infoglue installation and <br>wish to keep the data you probably don't want to.</html>"); 201 this.createDatabase = new JCheckBox("Yes"); 202 createDatabase.setBackground(Color.white); 203 this.createDatabase.setBounds(xPosValues, 340, xPosValuesWidth, 20); 204 this.createDatabase.addActionListener(this); 205 this.createDatabase.setNextFocusableComponent(this.createInitialData); 206 HelpButton helpDBCreate = new HelpButton(dbCreateDatabaseLabel); 207 helpDBCreate.setBounds(xPosValues + xPosValuesWidth + 2, 340, 20, 20); 208 209 JLabel dbCreateTablesLabel = new JLabel("Create tables and initial data"); 210 dbCreateTablesLabel.setBounds(xPosLabels, 360, xPosLabelsWidth, 20); 211 dbCreateTablesLabel.setToolTipText("<html>Do you wish to setup the infoglue tables and initial data?<br>If you allready have a infoglue installation and <br>wish to keep the data you probably don't want to.</html>"); 212 this.createInitialData = new JCheckBox("Yes"); 213 this.createInitialData.setBackground(Color.white); 214 this.createInitialData.setBounds(xPosValues, 360, xPosValuesWidth, 20); 215 this.createInitialData.addActionListener(this); 216 this.createInitialData.setNextFocusableComponent(this.createExamples); 217 HelpButton helpDBCreateInitialData = new HelpButton(dbCreateTablesLabel); 218 helpDBCreateInitialData.setBounds(xPosValues + xPosValuesWidth + 2, 360, 20, 20); 219 220 JLabel dbCreateExamplesLabel = new JLabel("Create example sites"); 221 dbCreateExamplesLabel.setBounds(xPosLabels, 380, xPosLabelsWidth, 20); 222 dbCreateExamplesLabel.setToolTipText("<html>Do you wish to install the example sites.</html>"); 223 this.createExamples = new JCheckBox("Yes"); 224 this.createExamples.setBackground(Color.white); 225 this.createExamples.setBounds(xPosValues, 380, xPosValuesWidth, 20); 226 this.createExamples.addActionListener(this); 227 this.createExamples.setNextFocusableComponent(this.dbUser); 228 HelpButton helpDBCreateExamples = new HelpButton(dbCreateExamplesLabel); 229 helpDBCreateExamples.setBounds(xPosValues + xPosValuesWidth + 2, 380, 20, 20); 230 231 JLabel upgradeDatabaseEncodingLabel = new JLabel(upgradeDatabaseEncodingLabelText); 232 upgradeDatabaseEncodingLabel.setBounds(xPosLabels, 400, 130, 20); 233 upgradeDatabaseEncodingLabel.setToolTipText("<html>When users in 1.0, 1.1 and 1.2 of InfoGlue stored non-ascii-characters it was most likely encoded as ISO-8859-1.<br>This is not a very good approach and this version operates with full Unicode(utf-8).<br>Because of this we need to upgrade your database content if you have non-ascii (special international characters).<br>If you do not convert the data the special charaters will look broken in the tools and on the site until you correct them manually in the tools.</html>"); 234 this.upgradeDatabaseEncoding = new JCheckBox("Yes"); 235 this.upgradeDatabaseEncoding.setBounds(xPosValues, 400, xPosValuesWidth, 20); 236 this.upgradeDatabaseEncoding.setBackground(Color.white); 237 this.upgradeDatabaseEncoding.setNextFocusableComponent(this.createDatabase); 238 this.upgradeDatabaseEncoding.addActionListener(new AlertActionListener(this, "As this operation can seriously affect your data you must backup your database before continuing.", "Backup database", JOptionPane.WARNING_MESSAGE)); 239 HelpButton helpUpgradeDatabaseEncoding = new HelpButton(upgradeDatabaseEncodingLabel); 240 helpUpgradeDatabaseEncoding.setBounds(xPosValues + xPosValuesWidth + 2, 400, 20, 20); 241 242 JLabel dbUserLabel = new JLabel(databaseUserLabel); 243 dbUserLabel.setBounds(xPosLabels, 420, 130, 20); 244 dbUserLabel.setToolTipText("<html>The root username to the database.<br>InfoGlue needs it to be able to create the database.</html>"); 245 this.dbUser = new JTextField("root"); 247 this.dbUser.setBounds(xPosValues, 420, xPosValuesWidth, 20); 248 this.dbUser.setEnabled(false); 249 this.dbUser.setBackground(fieldBackground); 250 this.dbUser.setNextFocusableComponent(this.dbPassword); 251 HelpButton helpDBUser = new HelpButton(dbUserLabel); 252 helpDBUser.setBounds(xPosValues + xPosValuesWidth + 2, 420, 20, 20); 253 254 JLabel dbPasswordLabel = new JLabel(databasePasswordLabel); 255 dbPasswordLabel.setBounds(xPosLabels, 440, 130, 20); 256 dbPasswordLabel.setToolTipText("<html>The root password to the database.<br>InfoGlue needs it to be able to create the database.</html>"); 257 this.dbPassword = new JPasswordField(""); 259 this.dbPassword.setBounds(xPosValues, 440, xPosValuesWidth, 20); 260 this.dbPassword.setEnabled(false); 261 this.dbPassword.setBackground(fieldBackground); 262 HelpButton helpDBPassword = new HelpButton(dbPasswordLabel); 263 helpDBPassword.setBounds(xPosValues + xPosValuesWidth + 2, 440, 20, 20); 264 265 272 273 275 this.errorMessage = new JTextArea(""); 276 this.errorMessage.setForeground(Color.red); 277 this.errorMessage.setEditable(false); 278 this.errorMessage.setBounds(xPosLabels, 460, 450, 60); 279 this.errorMessage.setWrapStyleWord(true); 280 this.errorMessage.setLineWrap(true); 281 282 this.add(introductionLabel); 283 this.add(textArea); 284 this.add(dbLabel); 285 this.add(databaseCombo); 286 this.add(helpDBCombo); 287 this.add(dbNameLabel); 288 this.add(dbName); 289 this.add(helpDBName); 290 this.add(dbSuffixLabel); 291 this.add(dbSuffix); 292 this.add(helpDBSuffix); 293 this.add(createDBIntroTextArea); 294 295 this.add(dbServerLabel); 298 this.add(dbServer); 299 this.add(helpDBServer); 300 this.add(dbPortLabel); 301 this.add(dbPort); 302 this.add(helpDBPort); 303 this.add(dbInstanceLabel); 304 this.add(dbInstance); 305 this.add(helpDBInstance); 306 307 this.add(dbCreateDatabaseLabel); 308 this.add(createDatabase); 309 this.add(helpDBCreate); 310 this.add(dbCreateTablesLabel); 311 this.add(createInitialData); 312 this.add(dbCreateExamplesLabel); 313 this.add(createExamples); 314 this.add(helpDBCreateInitialData); 315 this.add(helpDBCreateExamples); 316 317 this.add(dbUserLabel); 318 this.add(dbUser); 319 this.add(helpDBUser); 320 321 this.add(dbPasswordLabel); 322 this.add(dbPassword); 323 this.add(helpDBPassword); 324 325 this.add(infoglueDBUserNameLabel); 326 this.add(infoGlueUserName); 327 this.add(helpInfoGlueUserName); 328 329 this.add(infoglueDBPasswordLabel); 330 this.add(infoGluePassword); 331 this.add(helpInfoGluePassword); 332 333 334 this.add(upgradeDatabaseEncodingLabel); 336 this.add(upgradeDatabaseEncoding); 337 this.add(helpUpgradeDatabaseEncoding); 338 339 340 this.add(errorMessage); 341 342 infoglueInstaller.setBackButtonCommand("ShowIntroductionDialog"); 343 infoGlueInstaller.setNextButtonCommand("ShowServerDialog"); 344 } 345 346 347 public void actionPerformed(ActionEvent e) 348 { 349 if(e.getSource().equals(this.databaseCombo)) 350 { 351 if(this.dbPort != null) 352 { 353 if(this.getDatabaseTypeName().equalsIgnoreCase("MySQL")) 354 { 355 this.dbPort.setText("3306"); 356 } 357 else if(this.getDatabaseTypeName().equalsIgnoreCase("SQL Server")) 358 { 359 this.dbPort.setText("1433"); 360 this.dbInstance.setEnabled(true); 361 } 362 else if(this.getDatabaseTypeName().equalsIgnoreCase("Oracle")) 363 { 364 this.dbPort.setText("1521"); 365 } 366 else if(this.getDatabaseTypeName().equalsIgnoreCase("DB2")) 367 { 368 this.dbPort.setText("50000"); 369 } 370 else 371 { 372 this.dbPort.setText("not_valid"); 373 } 374 } 375 } 376 else if(this.createDatabase != null && (this.createDatabase.isSelected() || this.createInitialData.isSelected() || this.createExamples.isSelected())) 377 { 378 this.dbUser.setEnabled(true); 379 this.dbPassword.setEnabled(true); 380 this.upgradeDatabaseEncoding.setEnabled(false); 382 } 383 else if(this.createDatabase != null && (!this.createDatabase.isSelected() && !this.createInitialData.isSelected() && !this.createExamples.isSelected())) 384 { 385 this.dbUser.setEnabled(false); 386 this.dbPassword.setEnabled(false); 387 this.upgradeDatabaseEncoding.setEnabled(true); 389 } 390 } 391 392 public void setErrorMessage(String errorMessage) 393 { 394 this.errorMessage.setText("An error made the installation stop: \n" + errorMessage); 395 } 396 397 public String getDatabaseTypeName() 398 { 399 return this.databaseCombo.getSelectedItem().toString(); 400 } 401 402 public String getDatabaseName() 403 { 404 return this.dbName.getText(); 405 } 406 407 public String getDatabaseDriverName() 408 { 409 if(getDatabaseTypeName().equalsIgnoreCase("MySQL")) 410 return "com.mysql.jdbc.Driver"; 411 else if(getDatabaseTypeName().equalsIgnoreCase("SQL Server")) 412 return "net.sourceforge.jtds.jdbc.Driver"; 413 else if(getDatabaseTypeName().equalsIgnoreCase("Oracle")) 415 return "oracle.jdbc.driver.OracleDriver"; 416 else if(getDatabaseTypeName().equalsIgnoreCase("DB2")) 417 return "com.ibm.db2.jcc.DB2Driver"; 418 else 419 return ""; 420 } 421 422 public String getDatabaseDialectName() 423 { 424 if(getDatabaseTypeName().equalsIgnoreCase("MySQL")) 425 return "net.sf.hibernate.dialect.MySQLDialect"; 426 else if(getDatabaseTypeName().equalsIgnoreCase("SQL Server")) 427 return "net.sf.hibernate.dialect.SQLServerDialect"; 428 else if(getDatabaseTypeName().equalsIgnoreCase("Oracle")) 430 return "net.sf.hibernate.dialect.OracleDialect"; 431 else if(getDatabaseTypeName().equalsIgnoreCase("DB2")) 432 return "net.sf.hibernate.dialect.DB2Dialect"; 433 else 434 return ""; 435 } 436 437 public String getDatabaseServer() 438 { 439 return this.dbServer.getText(); 440 } 441 442 public String getDatabasePort() 443 { 444 return this.dbPort.getText(); 445 } 446 447 public String getDatabaseInstance() 448 { 449 return this.dbInstance.getText(); 450 } 451 452 public String getDatabaseUser() 453 { 454 return this.dbUser.getText(); 455 } 456 457 public String getDatabasePassword() 458 { 459 return this.dbPassword.getText(); 460 } 461 462 public String getInfoGluePassword() 463 { 464 return this.infoGluePassword.getText(); 465 } 466 467 public boolean getCreateDatabase() 468 { 469 return createDatabase.isSelected(); 470 } 471 472 public boolean getCreateInitialData() 473 { 474 return createInitialData.isSelected(); 475 } 476 477 public boolean getCreateExamples() 478 { 479 return createExamples.isSelected(); 480 } 481 482 public String getDbSuffix() 483 { 484 return dbSuffix.getText(); 485 } 486 487 public boolean getUpgradeDatabaseEncoding() 488 { 489 return upgradeDatabaseEncoding.isSelected(); 490 } 491 492 public String getInfoGlueUserName() 493 { 494 return this.infoGlueUserName.getText(); 495 } 496 497 public void paint(Graphics g) 498 { 499 Graphics2D g2 = (Graphics2D)g; 500 g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); 501 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 502 503 super.paint(g); 504 } 505 506 } | Popular Tags |