use of net.sourceforge.sqlexplorer.dbproduct.ManagedDriver in project tdq-studio-se by Talend.
the class CreateAliasDlg method createDialogArea.
protected Control createDialogArea(Composite parent) {
// top level composite
Composite parentComposite = (Composite) super.createDialogArea(parent);
// create a composite with standard margins and spacing
Composite composite = new Composite(parentComposite, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
composite.setLayout(layout);
final GridData gd_composite = new GridData(SWT.FILL, SWT.FILL, true, true);
gd_composite.heightHint = 238;
composite.setLayoutData(gd_composite);
composite.setFont(parentComposite.getFont());
Composite nameGroup = new Composite(composite, SWT.NONE);
layout = new GridLayout();
layout.numColumns = 3;
layout.marginWidth = 10;
nameGroup.setLayout(layout);
GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
data.heightHint = 211;
nameGroup.setLayoutData(data);
Label label = new Label(nameGroup, SWT.WRAP);
// $NON-NLS-1$
label.setText("Name");
nameField = new Text(nameGroup, SWT.BORDER);
if (type != Type.CREATE)
nameField.setText(alias.getName());
data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
data.horizontalSpan = 2;
data.widthHint = SIZING_TEXT_FIELD_WIDTH;
nameField.setLayoutData(data);
nameField.addKeyListener(new KeyListener() {
public void keyPressed(org.eclipse.swt.events.KeyEvent e) {
CreateAliasDlg.this.validate();
}
public void keyReleased(org.eclipse.swt.events.KeyEvent e) {
CreateAliasDlg.this.validate();
}
});
Label label2 = new Label(nameGroup, SWT.WRAP);
// $NON-NLS-1$
label2.setText("Driver");
cboDriver = new Combo(nameGroup, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
final GridData gd_driver = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
gd_driver.widthHint = SIZING_TEXT_FIELD_WIDTH;
cboDriver.setLayoutData(gd_driver);
String defaultDriverName = SQLExplorerPlugin.getDefault().getPluginPreferences().getString(IConstants.DEFAULT_DRIVER);
ManagedDriver defaultDriver = null;
int defaultDriverIndex = 0;
populateCombo();
for (Entry<Integer, ManagedDriver> entry : comboDriverIndexes.entrySet()) {
ManagedDriver driver = entry.getValue();
if (driver.getName().startsWith(defaultDriverName)) {
defaultDriver = driver;
defaultDriverIndex = entry.getKey();
break;
}
}
Button btnListDrivers = new Button(nameGroup, SWT.NULL);
// $NON-NLS-1$
btnListDrivers.setText(Messages.getString("AliasDialog.EditDrivers"));
final GridData gd_btnListDrivers = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
btnListDrivers.setLayoutData(gd_btnListDrivers);
btnListDrivers.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
PreferenceDialog dlg = PreferencesUtil.createPreferenceDialogOn(getShell(), null, new String[] { DriverPreferencePage.class.getName() }, null);
if (dlg.open() == IDialogConstants.OK_ID)
populateCombo();
}
});
Label label3 = new Label(nameGroup, SWT.WRAP);
// $NON-NLS-1$
label3.setText("URL");
urlField = new Text(nameGroup, SWT.BORDER);
data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
data.horizontalSpan = 2;
data.widthHint = SIZING_TEXT_FIELD_WIDTH;
urlField.setLayoutData(data);
urlField.addKeyListener(new KeyListener() {
public void keyPressed(org.eclipse.swt.events.KeyEvent e) {
CreateAliasDlg.this.validate();
}
public void keyReleased(org.eclipse.swt.events.KeyEvent e) {
CreateAliasDlg.this.validate();
}
});
new Label(nameGroup, SWT.NONE);
noUsernameRequired = new Button(nameGroup, SWT.CHECK);
noUsernameRequired.setText("Username is not required for this database");
new Label(nameGroup, SWT.NONE);
Label label4 = new Label(nameGroup, SWT.WRAP);
// $NON-NLS-1$
label4.setText("User Name");
userField = new Text(nameGroup, SWT.BORDER);
data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
data.horizontalSpan = 2;
data.widthHint = SIZING_TEXT_FIELD_WIDTH;
userField.setLayoutData(data);
userField.addKeyListener(new KeyListener() {
public void keyPressed(org.eclipse.swt.events.KeyEvent e) {
CreateAliasDlg.this.validate();
}
public void keyReleased(org.eclipse.swt.events.KeyEvent e) {
CreateAliasDlg.this.validate();
}
});
Label label5 = new Label(nameGroup, SWT.WRAP);
// $NON-NLS-1$
label5.setText("Password");
passwordField = new Text(nameGroup, SWT.BORDER);
passwordField.setEchoChar('*');
data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
data.horizontalSpan = 2;
data.widthHint = SIZING_TEXT_FIELD_WIDTH;
passwordField.setLayoutData(data);
cboDriver.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
int selIndex = cboDriver.getSelectionIndex();
ManagedDriver driver = comboDriverIndexes.get(selIndex);
urlField.setText(driver.getUrl());
CreateAliasDlg.this.validate();
}
});
if (!comboDriverIndexes.isEmpty() && defaultDriver != null) {
cboDriver.select(defaultDriverIndex);
urlField.setText(defaultDriver.getUrl());
}
new Label(nameGroup, SWT.NONE);
final Composite connectionPropertiesComposite = new Composite(nameGroup, SWT.NONE);
connectionPropertiesComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
connectionPropertiesComposite.setLayout(gridLayout);
new Label(nameGroup, SWT.NONE);
new Label(nameGroup, SWT.NONE);
/* final Button */
autoLogonButton = new Button(connectionPropertiesComposite, SWT.CHECK);
autoLogonButton.setToolTipText("If set, SQLExplorer will try to logon without prompting");
final GridData gd_autoLogonButton = new GridData(158, SWT.DEFAULT);
autoLogonButton.setLayoutData(gd_autoLogonButton);
autoLogonButton.setText("Auto logon");
/* final Button */
autoCommitButton = new Button(connectionPropertiesComposite, SWT.CHECK);
autoCommitButton.setToolTipText("Sets the default for new SQL Editors");
autoCommitButton.setText("Auto Commit");
/* final Button */
logonAtStartupButton = new Button(connectionPropertiesComposite, SWT.CHECK);
logonAtStartupButton.setToolTipText("If set, SQLExplorer will establish a connection during startup");
logonAtStartupButton.setText("Logon during startup");
/* final Button */
commitOnCloseButton = new Button(connectionPropertiesComposite, SWT.CHECK);
commitOnCloseButton.setToolTipText("Sets the default for new SQL editors");
commitOnCloseButton.setText("Commit on close");
new Label(nameGroup, SWT.NONE);
autoLogonButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
boolean checked = autoLogonButton.getSelection();
logonAtStartupButton.setEnabled(checked);
if (!checked)
logonAtStartupButton.setSelection(false);
}
});
logonAtStartupButton.setEnabled(alias.isConnectAtStartup());
logonAtStartupButton.setSelection(alias.isConnectAtStartup());
autoLogonButton.setSelection(alias.isConnectAtStartup());
autoCommitButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
commitOnCloseButton.setEnabled(!autoCommitButton.getSelection());
}
});
User user = alias.getDefaultUser();
if (user != null) {
autoCommitButton.setSelection(user.isAutoCommit());
commitOnCloseButton.setEnabled(!user.isAutoCommit());
commitOnCloseButton.setSelection(user.isCommitOnClose());
}
noUsernameRequired.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
userField.setEnabled(!noUsernameRequired.getSelection());
passwordField.setEnabled(!noUsernameRequired.getSelection());
}
});
if (alias.hasNoUserName()) {
noUsernameRequired.setSelection(true);
userField.setEnabled(false);
passwordField.setEnabled(false);
} else {
noUsernameRequired.setSelection(false);
userField.setEnabled(true);
passwordField.setEnabled(true);
if (alias.getDefaultUser() != null) {
userField.setText(alias.getDefaultUser().getUserName());
passwordField.setText(alias.getDefaultUser().getPassword());
}
}
if (type != Type.CREATE) {
if (alias.getDriver() != null)
cboDriver.setText(alias.getDriver().getName());
urlField.setText(alias.getUrl());
}
return parentComposite;
}
use of net.sourceforge.sqlexplorer.dbproduct.ManagedDriver in project tdq-studio-se by Talend.
the class DriverLabelProvider method selectDefault.
// Bold the default driver element
void selectDefault(Table table) {
String defaultDriver = _prefs.getString(IConstants.DEFAULT_DRIVER);
if (defaultDriver == null) {
return;
}
int index = 0;
for (ManagedDriver driver : _driverModel.getDrivers()) {
if (driver.getName().toLowerCase().startsWith(defaultDriver.toLowerCase())) {
_boldfont = new Font(_tableViewer.getTable().getDisplay(), table.getFont().toString(), table.getFont().getFontData()[0].getHeight(), SWT.BOLD);
_tableViewer.getTable().getItem(index).setFont(0, _boldfont);
_tableViewer.getTable().pack(true);
break;
}
index++;
}
}
use of net.sourceforge.sqlexplorer.dbproduct.ManagedDriver in project tdq-studio-se by Talend.
the class DriverLabelProvider method selectFirst.
void selectFirst() {
Iterator<ManagedDriver> iter = _driverModel.getDrivers().iterator();
if (iter.hasNext()) {
StructuredSelection sel = new StructuredSelection(iter.next());
_tableViewer.setSelection(sel);
}
}
use of net.sourceforge.sqlexplorer.dbproduct.ManagedDriver in project tdq-studio-se by Talend.
the class SqlexplorerService method updateDriverIfClassNotLoad.
/**
* if the sqlexplorer driver is unRegisted,load the driver jar by lib manage system.
*
* @param sqlPlugin
* @param connection
* @param databaseConnection
*/
public void updateDriverIfClassNotLoad(DatabaseConnection databaseConnection) {
SQLExplorerPlugin sqlPlugin = SQLExplorerPlugin.getDefault();
DriverManager driverManager = sqlPlugin.getDriverModel();
String driverClassName = JavaSqlFactory.getDriverClass(databaseConnection);
if (driverClassName != null) {
String id = AliasAndManaDriverHelper.getInstance().joinManagedDriverId(databaseConnection);
ManagedDriver manDr = driverManager.getDriver(id);
if (manDr != null && !manDr.isDriverClassLoaded()) {
loadDriverByLibManageSystem(databaseConnection);
}
}
}
use of net.sourceforge.sqlexplorer.dbproduct.ManagedDriver in project tdq-studio-se by Talend.
the class SqlexplorerService method loadManagedDriver.
/**
* Load the driver by lib management system , which will configure the SQL Explorer driver classpath from xml.
*
* @param dbType
* @param dbVersion
* @param driverClassName
* @param userName. the userName is used a special case :it MSSQL with empty userName.
*/
private void loadManagedDriver(DatabaseConnection dbConn) {
String dbType = dbConn.getDatabaseType();
String dbVersion = dbConn.getDbVersionString();
String driverClassName = JavaSqlFactory.getDriverClass(dbConn);
if (dbType == null || driverClassName == null) {
return;
}
DriverManager driverManager = SQLExplorerPlugin.getDefault().getDriverModel();
AliasAndManaDriverHelper aliasManaHelper = AliasAndManaDriverHelper.getInstance();
String manaDriverId = aliasManaHelper.joinManagedDriverId(dbType, driverClassName, dbVersion);
ManagedDriver manDr = driverManager.getDriver(manaDriverId);
if (manDr != null && !manDr.isDriverClassLoaded()) {
// "librariesIndex.xml".
try {
List<String> jarNames = EDatabaseVersion4Drivers.getDrivers(dbType, dbVersion);
if (jarNames.isEmpty() && "JDBC".equals(dbType)) {
jarNames.add(dbConn.getDriverJarPath());
}
LinkedList<String> driverJarRealPaths = aliasManaHelper.getDriverJarRealPaths(jarNames);
if (!driverJarRealPaths.isEmpty()) {
manDr.getJars().clear();
manDr.getJars().addAll(driverJarRealPaths);
}
manDr.registerSQLDriver(dbConn);
} catch (Exception e) {
log.error(e);
}
}
}
Aggregations