|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2004-2006 Sybase, Inc. |
| 3 |
* |
| 4 |
* All rights reserved. This program and the accompanying materials are made |
| 5 |
* available under the terms of the Eclipse Public License v1.0 which |
| 6 |
* accompanies this distribution, and is available at |
| 7 |
* http://www.eclipse.org/legal/epl-v10.html |
| 8 |
* |
| 9 |
* Contributors: brianf - initial API and implementation |
| 10 |
******************************************************************************/ |
| 11 |
package org.eclipse.datatools.connectivity.derby.internal.ui.connection; |
| 12 |
|
| 13 |
import java.io.File; |
| 14 |
import java.util.ArrayList; |
| 15 |
import java.util.List; |
| 16 |
import java.util.StringTokenizer; |
| 17 |
|
| 18 |
import javax.swing.event.ChangeEvent; |
| 19 |
import javax.swing.event.ChangeListener; |
| 20 |
|
| 21 |
import org.eclipse.core.runtime.Path; |
| 22 |
import org.eclipse.datatools.connectivity.db.generic.IDBDriverDefinitionConstants; |
| 23 |
import org.eclipse.datatools.connectivity.derby.internal.ui.DerbyUIPlugin; |
| 24 |
import org.eclipse.datatools.connectivity.drivers.DriverInstance; |
| 25 |
import org.eclipse.datatools.connectivity.internal.derby.connection.IDerbyConnectionProfileConstants; |
| 26 |
import org.eclipse.datatools.connectivity.internal.ui.DelimitedStringList; |
| 27 |
import org.eclipse.datatools.connectivity.internal.ui.DriverListCombo; |
| 28 |
import org.eclipse.datatools.connectivity.ui.wizards.ConnectionProfileDetailsPage; |
| 29 |
import org.eclipse.datatools.help.ContextProviderDelegate; |
| 30 |
import org.eclipse.datatools.help.HelpUtil; |
| 31 |
import org.eclipse.help.IContext; |
| 32 |
import org.eclipse.help.IContextProvider; |
| 33 |
import org.eclipse.swt.SWT; |
| 34 |
import org.eclipse.swt.events.ModifyEvent; |
| 35 |
import org.eclipse.swt.events.ModifyListener; |
| 36 |
import org.eclipse.swt.events.SelectionEvent; |
| 37 |
import org.eclipse.swt.events.SelectionListener; |
| 38 |
import org.eclipse.swt.layout.GridData; |
| 39 |
import org.eclipse.swt.layout.GridLayout; |
| 40 |
import org.eclipse.swt.widgets.Button; |
| 41 |
import org.eclipse.swt.widgets.Composite; |
| 42 |
import org.eclipse.swt.widgets.Control; |
| 43 |
import org.eclipse.swt.widgets.DirectoryDialog; |
| 44 |
import org.eclipse.swt.widgets.Label; |
| 45 |
import org.eclipse.swt.widgets.Text; |
| 46 |
|
| 47 |
/** |
| 48 |
* This class gathers the properties for the derby embedded DB connection profile. |
| 49 |
* |
| 50 |
* @author brianf |
| 51 |
*/ |
| 52 |
public class DerbyEmbeddedDBProfileDetailsWizardPage |
| 53 |
extends ConnectionProfileDetailsPage |
| 54 |
implements IContextProvider { |
| 55 |
|
| 56 |
// ui pieces |
| 57 |
private Text mDatabaseNameText; |
| 58 |
|
| 59 |
private Text mURLText; |
| 60 |
|
| 61 |
private Text mDBUIDText; |
| 62 |
|
| 63 |
private Text mDBPWDText; |
| 64 |
|
| 65 |
private Button mSaveDBPWDCheckbox; |
| 66 |
|
| 67 |
private DelimitedStringList mDBConnProps; |
| 68 |
|
| 69 |
final DriverListCombo combo = new DriverListCombo(); |
| 70 |
|
| 71 |
private Button mCreateDBCheckbox; |
| 72 |
|
| 73 |
private Button mUpgradeDBCheckbox; |
| 74 |
|
| 75 |
private Text mDBFilePathText; |
| 76 |
|
| 77 |
private Button mBrowseFilePathButton; |
| 78 |
|
| 79 |
// stashed driver instance |
| 80 |
private DriverInstance mDriverInstance; |
| 81 |
|
| 82 |
private String mDriverCategory; |
| 83 |
|
| 84 |
/** |
| 85 |
* Constructor |
| 86 |
* |
| 87 |
* @param pageName |
| 88 |
*/ |
| 89 |
public DerbyEmbeddedDBProfileDetailsWizardPage(String pageName) { |
| 90 |
super(pageName); |
| 91 |
setTitle(Messages.getString( |
| 92 |
"DerbyEmbeddedDBProfileDetailsWizardPage.title")); //$NON-NLS-1$ |
| 93 |
setDescription(Messages.getString( |
| 94 |
"DerbyEmbeddedDBProfileDetailsWizardPage.msg")); //$NON-NLS-1$ |
| 95 |
setDriverCategory(IDerbyConnectionProfileConstants.DERBY_CATEGORY_ID); |
| 96 |
this.combo.setFilter("templateIDStartsWith = " + //$NON-NLS-1$ |
| 97 |
IDerbyConnectionProfileConstants.DERBY_ENABLEMENT_DRIVER_PREFIX + "," + //$NON-NLS-1$ |
| 98 |
"templateIDEndsWith = " + //$NON-NLS-1$ |
| 99 |
IDerbyConnectionProfileConstants.DERBY_ENABLEMENT_DRIVER_SUFFIX); |
| 100 |
} |
| 101 |
|
| 102 |
/* |
| 103 |
* (non-Javadoc) |
| 104 |
* |
| 105 |
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) |
| 106 |
*/ |
| 107 |
public void createCustomControl(Composite parent) { |
| 108 |
Composite content = new Composite(parent, SWT.NULL); |
| 109 |
GridLayout layout = new GridLayout(2, false); |
| 110 |
content.setLayout(layout); |
| 111 |
|
| 112 |
// set up the drivers combo |
| 113 |
this.combo.setLabelText(Messages.getString( |
| 114 |
"DerbyEmbeddedDBProfileDetailsWizardPage.driverCombo.label")); //$NON-NLS-1$ |
| 115 |
this.combo.setCategory(getDriverCategory()); |
| 116 |
this.combo.setNullDriverIsValid(false); |
| 117 |
this.combo.createContents(content); |
| 118 |
if (this.combo.getErrorMessage() != null) { |
| 119 |
setErrorMessage(this.combo.getErrorMessage()); |
| 120 |
} |
| 121 |
|
| 122 |
// set up the fields |
| 123 |
this.mDatabaseNameText = (Text) createLabelTextPair( |
| 124 |
content, |
| 125 |
Messages.getString( |
| 126 |
"DerbyEmbeddedDBProfileDetailsWizardPage.databaseName.label"), //$NON-NLS-1$ |
| 127 |
this.mURLText, SWT.BORDER, GridData.FILL_HORIZONTAL); |
| 128 |
|
| 129 |
Label label = new Label(content, SWT.NULL); |
| 130 |
label.setLayoutData(new GridData()); |
| 131 |
label.setText(Messages.getString("DerbyEmbeddedDBProfileDetailsWizardPage.0")); //$NON-NLS-1$ |
| 132 |
|
| 133 |
Composite textAndBrowseComposite = new Composite(content, SWT.NULL); |
| 134 |
GridLayout subCompositeLayout = new GridLayout(2, false); |
| 135 |
subCompositeLayout.marginLeft = -5; |
| 136 |
subCompositeLayout.marginRight = -5; |
| 137 |
subCompositeLayout.marginTop = -5; |
| 138 |
subCompositeLayout.marginBottom = -5; |
| 139 |
textAndBrowseComposite.setLayout(subCompositeLayout); |
| 140 |
textAndBrowseComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 141 |
this.mDBFilePathText = new Text(textAndBrowseComposite, SWT.BORDER); |
| 142 |
this.mDBFilePathText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 143 |
this.mBrowseFilePathButton = new Button(textAndBrowseComposite, SWT.PUSH); |
| 144 |
this.mBrowseFilePathButton.setText(Messages.getString("DerbyEmbeddedDBProfileDetailsWizardPage.1")); //$NON-NLS-1$ |
| 145 |
this.mBrowseFilePathButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); |
| 146 |
|
| 147 |
this.mDBUIDText = (Text) createLabelTextPair(content, Messages.getString( |
| 148 |
"DerbyEmbeddedDBProfileDetailsWizardPage.userName.label"), //$NON-NLS-1$ |
| 149 |
this.mDBUIDText, SWT.BORDER, GridData.FILL_HORIZONTAL); |
| 150 |
|
| 151 |
this.mDBPWDText = (Text) createLabelTextPair(content, Messages.getString( |
| 152 |
"DerbyEmbeddedDBProfileDetailsWizardPage.password.label"), //$NON-NLS-1$ |
| 153 |
this.mDBPWDText, SWT.BORDER | SWT.PASSWORD, GridData.FILL_HORIZONTAL); |
| 154 |
|
| 155 |
this.mURLText = (Text) createLabelTextPair(content, Messages.getString( |
| 156 |
"DerbyEmbeddedDBProfileDetailsWizardPage.url.label"), //$NON-NLS-1$ |
| 157 |
this.mURLText, SWT.BORDER, GridData.FILL_HORIZONTAL); |
| 158 |
|
| 159 |
this.mCreateDBCheckbox = new Button(content, SWT.CHECK); |
| 160 |
this.mCreateDBCheckbox.setText(Messages.getString("DerbyEmbeddedDBProfileDetailsWizardPage.2")); //$NON-NLS-1$ |
| 161 |
this.mCreateDBCheckbox.setLayoutData(new GridData(GridData.BEGINNING, |
| 162 |
GridData.CENTER, true, false, 2, 1)); |
| 163 |
|
| 164 |
this.mUpgradeDBCheckbox = new Button(content, SWT.CHECK); |
| 165 |
this.mUpgradeDBCheckbox.setText(Messages.getString("DerbyEmbeddedDBProfileDetailsWizardPage.3")); //$NON-NLS-1$ |
| 166 |
this.mUpgradeDBCheckbox.setLayoutData(new GridData(GridData.BEGINNING, |
| 167 |
GridData.CENTER, true, false, 2, 1)); |
| 168 |
|
| 169 |
this.mSaveDBPWDCheckbox = new Button(content, SWT.CHECK); |
| 170 |
this.mSaveDBPWDCheckbox.setText(Messages.getString( |
| 171 |
"DerbyEmbeddedDBProfileDetailsWizardPage.persistpassword.label")); //$NON-NLS-1$ |
| 172 |
this.mSaveDBPWDCheckbox.setLayoutData(new GridData(GridData.BEGINNING, |
| 173 |
GridData.CENTER, true, false, 2, 1)); |
| 174 |
|
| 175 |
// spacer |
| 176 |
Composite spacer = new Composite(content, SWT.NULL); |
| 177 |
GridData gdata = new GridData(GridData.FILL_HORIZONTAL); |
| 178 |
gdata.horizontalSpan = 2; |
| 179 |
gdata.heightHint = 20; |
| 180 |
spacer.setLayoutData(gdata); |
| 181 |
|
| 182 |
// followed by the optional properties |
| 183 |
label = new Label(content, SWT.NULL); |
| 184 |
gdata = new GridData(GridData.FILL_HORIZONTAL); |
| 185 |
gdata.horizontalSpan = 2; |
| 186 |
label.setLayoutData(gdata); |
| 187 |
label.setText(Messages.getString( |
| 188 |
"DerbyEmbeddedDBProfileDetailsWizardPage.optionalProps.label")); //$NON-NLS-1$ |
| 189 |
|
| 190 |
this.mDBConnProps = new DelimitedStringList(content, SWT.NONE); |
| 191 |
gdata = new GridData(GridData.FILL_HORIZONTAL); |
| 192 |
gdata.horizontalSpan = 2; |
| 193 |
this.mDBConnProps.setLayoutData(gdata); |
| 194 |
|
| 195 |
// // now set up the initial instance |
| 196 |
// if (this.mDriverInstance == null) |
| 197 |
// this.mDriverInstance = this.combo.getSelectedDriverInstance(); |
| 198 |
|
| 199 |
this.mDBConnProps.addChangeListener(new ChangeListener() { |
| 200 |
|
| 201 |
public void stateChanged(ChangeEvent arg0) { |
| 202 |
setErrorMessage(null); |
| 203 |
if (DerbyEmbeddedDBProfileDetailsWizardPage.this.mDBConnProps.getWarning() != null) { |
| 204 |
setErrorMessage(DerbyEmbeddedDBProfileDetailsWizardPage.this.mDBConnProps |
| 205 |
.getWarning()); |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
}); |
| 210 |
|
| 211 |
// add a change listener to the combo box so |
| 212 |
// we know when a new driver has been selected |
| 213 |
this.combo.addChangeListener(new ChangeListener() { |
| 214 |
|
| 215 |
public void stateChanged(ChangeEvent arg0) { |
| 216 |
DerbyEmbeddedDBProfileDetailsWizardPage.this.mDriverInstance = DerbyEmbeddedDBProfileDetailsWizardPage.this.combo |
| 217 |
.getSelectedDriverInstance(); |
| 218 |
setErrorMessage(null); |
| 219 |
if (DerbyEmbeddedDBProfileDetailsWizardPage.this.combo.getErrorMessage() != null) { |
| 220 |
setErrorMessage(DerbyEmbeddedDBProfileDetailsWizardPage.this.combo |
| 221 |
.getErrorMessage()); |
| 222 |
} |
| 223 |
DerbyEmbeddedDBProfileDetailsWizardPage.this.mDatabaseNameText |
| 224 |
.setText(getDriverDatabaseName()); |
| 225 |
|
| 226 |
DerbyEmbeddedDBProfileDetailsWizardPage.this.mURLText |
| 227 |
.setText(getDriverURL()); |
| 228 |
DerbyEmbeddedDBProfileDetailsWizardPage.this.updatePropsFromURL(); |
| 229 |
|
| 230 |
String username = DerbyEmbeddedDBProfileDetailsWizardPage.this |
| 231 |
.getPropertyFromDriverInstance(IDBDriverDefinitionConstants.USERNAME_PROP_ID); |
| 232 |
if (username == null || username.trim().length() == 0) |
| 233 |
username = new String(); |
| 234 |
DerbyEmbeddedDBProfileDetailsWizardPage.this.mDBUIDText.setText(username); |
| 235 |
|
| 236 |
String password = DerbyEmbeddedDBProfileDetailsWizardPage.this |
| 237 |
.getPropertyFromDriverInstance(IDBDriverDefinitionConstants.PASSWORD_PROP_ID); |
| 238 |
if (password == null || password.trim().length() == 0) |
| 239 |
password = new String(); |
| 240 |
DerbyEmbeddedDBProfileDetailsWizardPage.this.mDBPWDText.setText(password); |
| 241 |
|
| 242 |
setPageComplete(isValid()); |
| 243 |
} |
| 244 |
|
| 245 |
}); |
| 246 |
|
| 247 |
this.mDBFilePathText.addModifyListener(new ModifyListener() { |
| 248 |
public void modifyText(ModifyEvent e) { |
| 249 |
DerbyEmbeddedDBProfileDetailsWizardPage.this.updateURLFromProps(); |
| 250 |
} |
| 251 |
}); |
| 252 |
|
| 253 |
this.mCreateDBCheckbox.addSelectionListener(new SelectionListener() { |
| 254 |
|
| 255 |
public void widgetDefaultSelected(SelectionEvent e) { |
| 256 |
DerbyEmbeddedDBProfileDetailsWizardPage.this.updateURLFromProps(); |
| 257 |
} |
| 258 |
|
| 259 |
public void widgetSelected(SelectionEvent e) { |
| 260 |
DerbyEmbeddedDBProfileDetailsWizardPage.this.updateURLFromProps(); |
| 261 |
} |
| 262 |
}); |
| 263 |
|
| 264 |
this.mUpgradeDBCheckbox.addSelectionListener(new SelectionListener() { |
| 265 |
|
| 266 |
public void widgetDefaultSelected(SelectionEvent e) { |
| 267 |
DerbyEmbeddedDBProfileDetailsWizardPage.this.updateURLFromProps(); |
| 268 |
} |
| 269 |
|
| 270 |
public void widgetSelected(SelectionEvent e) { |
| 271 |
DerbyEmbeddedDBProfileDetailsWizardPage.this.updateURLFromProps(); |
| 272 |
} |
| 273 |
}); |
| 274 |
|
| 275 |
this.mBrowseFilePathButton.addSelectionListener( new SelectionListener() { |
| 276 |
|
| 277 |
public void widgetDefaultSelected(SelectionEvent e) { |
| 278 |
DerbyEmbeddedDBProfileDetailsWizardPage.this.browseForDBFolder(); |
| 279 |
} |
| 280 |
|
| 281 |
public void widgetSelected(SelectionEvent e) { |
| 282 |
DerbyEmbeddedDBProfileDetailsWizardPage.this.browseForDBFolder(); |
| 283 |
} |
| 284 |
}); |
| 285 |
|
| 286 |
this.combo.selectFirstItem(); |
| 287 |
// now set up the initial instance |
| 288 |
if (this.mDriverInstance == null) |
| 289 |
this.mDriverInstance = this.combo.getSelectedDriverInstance(); |
| 290 |
if (this.mDriverInstance != null) { |
| 291 |
this.mURLText.setText(getDriverURL()); |
| 292 |
} |
| 293 |
this.mURLText.setEnabled(false); |
| 294 |
|
| 295 |
} |
| 296 |
|
| 297 |
/** |
| 298 |
* Browse for the database folder |
| 299 |
*/ |
| 300 |
private void browseForDBFolder() { |
| 301 |
DirectoryDialog dialog = new DirectoryDialog(getShell()); |
| 302 |
dialog.setText(Messages |
| 303 |
.getString("DerbyEmbeddedDBProfileDetailsWizardPage.FileDialog.title.filebrowse")); //$NON-NLS-1$ |
| 304 |
dialog.setMessage(Messages |
| 305 |
.getString("DerbyEmbeddedDBProfileDetailsWizardPage.FileDialog.msg.filebrowse")); //$NON-NLS-1$ |
| 306 |
|
| 307 |
String dirName = mDBFilePathText.getText(); |
| 308 |
|
| 309 |
File path = new File(dirName); |
| 310 |
if (path.exists()) { |
| 311 |
dialog.setFilterPath(new Path(dirName).toOSString()); |
| 312 |
} |
| 313 |
|
| 314 |
String selectedDirectory = dialog.open(); |
| 315 |
if (selectedDirectory != null) { |
| 316 |
this.mDBFilePathText.setText(selectedDirectory); |
| 317 |
} |
| 318 |
} |
| 319 |
|
| 320 |
/** |
| 321 |
* Update the UI components from the URL |
| 322 |
*/ |
| 323 |
private void updatePropsFromURL() { |
| 324 |
if (this.mDBFilePathText != null && this.mURLText != null && this.mCreateDBCheckbox != null && this.mUpgradeDBCheckbox != null) { |
| 325 |
String url = this.mURLText.getText(); |
| 326 |
String[] chunks = parseString(url, ";"); //$NON-NLS-1$ |
| 327 |
if (chunks.length > 0) { |
| 328 |
String[] chunks2 = parseString(chunks[0], ":"); //$NON-NLS-1$ |
| 329 |
if (chunks2.length > 2) { |
| 330 |
String filepath = chunks2[2]; |
| 331 |
if (chunks2.length > 3) { |
| 332 |
filepath = filepath + ":" + chunks2[3]; //$NON-NLS-1$ |
| 333 |
} |
| 334 |
this.mDBFilePathText.setText(filepath); |
| 335 |
} |
| 336 |
} |
| 337 |
if (chunks.length > 1) { |
| 338 |
for (int i = 1; i < chunks.length; i++) { |
| 339 |
if (chunks[i].startsWith("create=")) //$NON-NLS-1$ |
| 340 |
this.mCreateDBCheckbox.setSelection(true); |
| 341 |
else if (chunks[i].startsWith("upgrade=")) //$NON-NLS-1$ |
| 342 |
this.mUpgradeDBCheckbox.setSelection(true); |
| 343 |
} |
| 344 |
} |
| 345 |
} |
| 346 |
} |
| 347 |
|
| 348 |
/** |
| 349 |
* Update the URL from the UI components |
| 350 |
*/ |
| 351 |
private void updateURLFromProps() { |
| 352 |
if (this.mDBFilePathText != null && this.mURLText != null && this.mCreateDBCheckbox != null && this.mUpgradeDBCheckbox != null) { |
| 353 |
String url = this.mURLText.getText(); |
| 354 |
String filePath = this.mDBFilePathText.getText(); |
| 355 |
boolean createDB = this.mCreateDBCheckbox.getSelection(); |
| 356 |
boolean upgradeDB = this.mUpgradeDBCheckbox.getSelection(); |
| 357 |
//jdbc:derby:C:\DerbyDatabases\MyDB;create=true |
| 358 |
String[] chunks = parseString(url, ";"); //$NON-NLS-1$ |
| 359 |
if (chunks.length > 0) { |
| 360 |
String[] chunks2 = parseString(chunks[0], ":"); //$NON-NLS-1$ |
| 361 |
if (chunks2.length > 2) { |
| 362 |
url = chunks2[0] + ":" + chunks2[1] + ":" + filePath; //$NON-NLS-1$ //$NON-NLS-2$ |
| 363 |
if (createDB) { |
| 364 |
url = url + ";" + "create=true"; //$NON-NLS-1$ //$NON-NLS-2$ |
| 365 |
} |
| 366 |
if (upgradeDB) { |
| 367 |
url = url + ";" + "upgrade=true"; //$NON-NLS-1$ //$NON-NLS-2$ |
| 368 |
} |
| 369 |
this.mURLText.setText(url); |
| 370 |
} |
| 371 |
} |
| 372 |
} |
| 373 |
} |
| 374 |
|
| 375 |
/** |
| 376 |
* Parse a string into a string array based on a token |
| 377 |
* @param str_list |
| 378 |
* @param token |
| 379 |
* @return |
| 380 |
*/ |
| 381 |
private String[] parseString(String str_list, String token) { |
| 382 |
StringTokenizer tk = new StringTokenizer(str_list, token); |
| 383 |
String[] pieces = new String[tk.countTokens()]; |
| 384 |
int index = 0; |
| 385 |
while (tk.hasMoreTokens()) |
| 386 |
pieces[index++] = tk.nextToken(); |
| 387 |
return pieces; |
| 388 |
} |
| 389 |
|
| 390 |
/** |
| 391 |
* @param propertyID |
| 392 |
* @return |
| 393 |
*/ |
| 394 |
private String getPropertyFromDriverInstance(String propertyID) { |
| 395 |
String returnStr = new String(); |
| 396 |
if (this.mDriverInstance != null |
| 397 |
&& this.mDriverInstance.getProperty(propertyID) != null) { |
| 398 |
returnStr = this.mDriverInstance.getProperty(propertyID); |
| 399 |
} |
| 400 |
return returnStr; |
| 401 |
} |
| 402 |
|
| 403 |
/** |
| 404 |
* Get the sample URL from the driver instance. |
| 405 |
* |
| 406 |
* @return |
| 407 |
*/ |
| 408 |
public String getDriverURL() { |
| 409 |
if (this.mDriverInstance != null |
| 410 |
&& this.mDriverInstance |
| 411 |
.getProperty(IDBDriverDefinitionConstants.URL_PROP_ID) != null) |
| 412 |
return this.mDriverInstance |
| 413 |
.getProperty(IDBDriverDefinitionConstants.URL_PROP_ID); |
| 414 |
return new String(); |
| 415 |
} |
| 416 |
|
| 417 |
/** |
| 418 |
* Get the sample database name from the driver instance. |
| 419 |
* |
| 420 |
* @return |
| 421 |
*/ |
| 422 |
public String getDriverDatabaseName() { |
| 423 |
if (this.mDriverInstance != null |
| 424 |
&& this.mDriverInstance |
| 425 |
.getProperty(IDBDriverDefinitionConstants.DATABASE_NAME_PROP_ID) != null) |
| 426 |
return this.mDriverInstance |
| 427 |
.getProperty(IDBDriverDefinitionConstants.DATABASE_NAME_PROP_ID); |
| 428 |
return new String(); |
| 429 |
} |
| 430 |
|
| 431 |
/** |
| 432 |
* Get the vendor |
| 433 |
* |
| 434 |
* @return |
| 435 |
*/ |
| 436 |
public String getVendor() { |
| 437 |
String vendor = ""; //$NON-NLS-1$ |
| 438 |
if (this.mDriverInstance != null) { |
| 439 |
vendor = this.mDriverInstance |
| 440 |
.getProperty(IDBDriverDefinitionConstants.DATABASE_VENDOR_PROP_ID); |
| 441 |
} |
| 442 |
return vendor; |
| 443 |
} |
| 444 |
|
| 445 |
/** |
| 446 |
* Get the version |
| 447 |
* |
| 448 |
* @return |
| 449 |
*/ |
| 450 |
public String getVersion() { |
| 451 |
String version = ""; //$NON-NLS-1$ |
| 452 |
if (this.mDriverInstance != null) { |
| 453 |
version = this.mDriverInstance |
| 454 |
.getProperty(IDBDriverDefinitionConstants.DATABASE_VERSION_PROP_ID); |
| 455 |
} |
| 456 |
return version; |
| 457 |
} |
| 458 |
|
| 459 |
/** |
| 460 |
* Get the driver class |
| 461 |
* |
| 462 |
* @return |
| 463 |
*/ |
| 464 |
public String getDriverClass() { |
| 465 |
String driverClass = ""; //$NON-NLS-1$ |
| 466 |
if (this.mDriverInstance != null) { |
| 467 |
driverClass = this.mDriverInstance |
| 468 |
.getProperty(IDBDriverDefinitionConstants.DRIVER_CLASS_PROP_ID); |
| 469 |
} |
| 470 |
return driverClass; |
| 471 |
} |
| 472 |
|
| 473 |
/** |
| 474 |
* Get the user name |
| 475 |
* |
| 476 |
* @return |
| 477 |
*/ |
| 478 |
public String getDBUID() { |
| 479 |
return this.mDBUIDText.getText(); |
| 480 |
} |
| 481 |
|
| 482 |
/** |
| 483 |
* Get the password |
| 484 |
* |
| 485 |
* @return |
| 486 |
*/ |
| 487 |
public String getDBPWD() { |
| 488 |
return this.mDBPWDText.getText(); |
| 489 |
} |
| 490 |
|
| 491 |
/** |
| 492 |
* Get the password |
| 493 |
* |
| 494 |
* @return |
| 495 |
*/ |
| 496 |
public boolean getSaveDBPWD() { |
| 497 |
return this.mSaveDBPWDCheckbox.getSelection(); |
| 498 |
} |
| 499 |
|
| 500 |
/** |
| 501 |
* Get the optional connection properties |
| 502 |
* |
| 503 |
* @return |
| 504 |
*/ |
| 505 |
public String getDBConnProps() { |
| 506 |
return this.mDBConnProps.getSelection(); |
| 507 |
} |
| 508 |
|
| 509 |
/** |
| 510 |
* Get the database name |
| 511 |
* |
| 512 |
* @return |
| 513 |
*/ |
| 514 |
public String getDatabaseName() { |
| 515 |
return this.mDatabaseNameText.getText(); |
| 516 |
} |
| 517 |
|
| 518 |
/** |
| 519 |
* Get the URL for the CP |
| 520 |
* |
| 521 |
* @return |
| 522 |
*/ |
| 523 |
public String getURL() { |
| 524 |
return this.mURLText.getText(); |
| 525 |
} |
| 526 |
|
| 527 |
/** |
| 528 |
* Get the driver ID |
| 529 |
* |
| 530 |
* @return |
| 531 |
*/ |
| 532 |
public String getDriverID() { |
| 533 |
return this.mDriverInstance.getId(); |
| 534 |
} |
| 535 |
|
| 536 |
/* |
| 537 |
* Create a label and a text box side by side. |
| 538 |
*/ |
| 539 |
private Control createLabelTextPair(Composite parent, String labelText, |
| 540 |
Control ctl, int style, int gData) { |
| 541 |
Label label = new Label(parent, SWT.NULL); |
| 542 |
label.setLayoutData(new GridData()); |
| 543 |
label.setText(labelText); |
| 544 |
|
| 545 |
ctl = new Text(parent, style); |
| 546 |
ctl.setLayoutData(new GridData(gData)); |
| 547 |
|
| 548 |
return ctl; |
| 549 |
} |
| 550 |
|
| 551 |
/* |
| 552 |
* (non-Javadoc) |
| 553 |
* |
| 554 |
* @see com.sybase.suade.common.ui.wizards.ISummaryDataSource#getSummaryData() |
| 555 |
*/ |
| 556 |
public List getSummaryData() { |
| 557 |
List data = new ArrayList(); |
| 558 |
|
| 559 |
data |
| 560 |
.add(new String[] { |
| 561 |
Messages.getString( |
| 562 |
"DerbyEmbeddedDBProfileDetailsWizardPage.summary.driverName.label"), //$NON-NLS-1$ |
| 563 |
mDriverInstance.getName() }); |
| 564 |
|
| 565 |
data |
| 566 |
.add(new String[] { |
| 567 |
Messages.getString( |
| 568 |
"DerbyEmbeddedDBProfileDetailsWizardPage.summary.connProps.label"), //$NON-NLS-1$ |
| 569 |
getDBConnProps() }); |
| 570 |
|
| 571 |
data |
| 572 |
.add(new String[] { |
| 573 |
Messages.getString( |
| 574 |
"DerbyEmbeddedDBProfileDetailsWizardPage.summary.userName.label"), //$NON-NLS-1$ |
| 575 |
getDBUID() }); |
| 576 |
|
| 577 |
StringBuffer pwdMask = new StringBuffer(); |
| 578 |
if (getDBPWD() != null && getDBPWD().length() > 0) { |
| 579 |
for (int i = 0, count = getDBPWD().length(); i < count; ++i) { |
| 580 |
pwdMask = pwdMask.append('*'); |
| 581 |
} |
| 582 |
} |
| 583 |
|
| 584 |
data |
| 585 |
.add(new String[] { |
| 586 |
Messages.getString( |
| 587 |
"DerbyEmbeddedDBProfileDetailsWizardPage.summary.password.label"), //$NON-NLS-1$ |
| 588 |
pwdMask.toString() }); |
| 589 |
|
| 590 |
data.add(new String[] { |
| 591 |
Messages.getString( |
| 592 |
"DerbyEmbeddedDBProfileDetailsWizardPage.summary.url.label"), //$NON-NLS-1$ |
| 593 |
getURL() }); |
| 594 |
|
| 595 |
return data; |
| 596 |
} |
| 597 |
|
| 598 |
private boolean isValid() { |
| 599 |
if (getErrorMessage() != null) { |
| 600 |
setPageComplete(false); |
| 601 |
return false; |
| 602 |
} |
| 603 |
|
| 604 |
return true; |
| 605 |
} |
| 606 |
|
| 607 |
/* |
| 608 |
* (non-Javadoc) |
| 609 |
* |
| 610 |
* @see org.eclipse.jface.dialogs.DialogPage#setErrorMessage(java.lang.String) |
| 611 |
*/ |
| 612 |
public void setErrorMessage(String newMessage) { |
| 613 |
super.setErrorMessage(newMessage); |
| 614 |
isValid(); |
| 615 |
} |
| 616 |
|
| 617 |
|
| 618 |
/** |
| 619 |
* @return |
| 620 |
*/ |
| 621 |
public String getDriverCategory() { |
| 622 |
return mDriverCategory; |
| 623 |
} |
| 624 |
|
| 625 |
|
| 626 |
/** |
| 627 |
* Sets the driver category that should be used for displaying available |
| 628 |
* driver defnitions. |
| 629 |
* |
| 630 |
* @param driverCategory |
| 631 |
*/ |
| 632 |
public void setDriverCategory(String driverCategory) { |
| 633 |
mDriverCategory = driverCategory; |
| 634 |
if (combo != null) { |
| 635 |
combo.setCategory(mDriverCategory); |
| 636 |
} |
| 637 |
} |
| 638 |
|
| 639 |
private ContextProviderDelegate contextProviderDelegate = |
| 640 |
new ContextProviderDelegate(DerbyUIPlugin.getDefault().getBundle().getSymbolicName()); |
| 641 |
|
| 642 |
public IContext getContext(Object target) { |
| 643 |
return contextProviderDelegate.getContext(target); |
| 644 |
} |
| 645 |
|
| 646 |
public int getContextChangeMask() { |
| 647 |
return contextProviderDelegate.getContextChangeMask(); |
| 648 |
} |
| 649 |
|
| 650 |
public String getSearchExpression(Object target) { |
| 651 |
return contextProviderDelegate.getSearchExpression(target); |
| 652 |
} |
| 653 |
|
| 654 |
public void createControl(Composite parent) { |
| 655 |
super.createControl(parent); |
| 656 |
getShell().setData( HelpUtil.CONTEXT_PROVIDER_KEY, this); |
| 657 |
HelpUtil.setHelp( getControl(), HelpUtil.getContextId(IHelpContextsDerbyProfile.DERBY_PROFILE_WIZARD_PAGE, DerbyUIPlugin.getDefault().getBundle().getSymbolicName())); |
| 658 |
} |
| 659 |
} |