use of org.talend.repository.ui.wizards.metadata.connection.database.SelectDatabaseJarDialog in project tdq-studio-se by Talend.
the class SetJDBCDriverPreferencePage method createContents.
@Override
protected Control createContents(Composite parent) {
mainComposite = new Composite(parent, SWT.NONE);
mainComposite.setLayout(new GridLayout(3, false));
mainComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
GridLayout layout2 = (GridLayout) mainComposite.getLayout();
layout2.marginHeight = 0;
layout2.marginTop = 0;
layout2.marginBottom = 0;
GridData gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.horizontalSpan = 3;
header = new Label(mainComposite, SWT.WRAP);
header.setLayoutData(gridData);
// $NON-NLS-1$
header.setText(DefaultMessagesImpl.getString("SetJDBCDriverPreferencePage.heard"));
dbTypeLabel = new Label(mainComposite, SWT.WRAP);
// $NON-NLS-1$
dbTypeLabel.setText(DefaultMessagesImpl.getString("SetJDBCDriverPreferencePage.dbType") + dbType_jdbc);
dbTypeLabel.setLayoutData(gridData);
generalJdbcUrlText = new LabelledText(mainComposite, DefaultMessagesImpl.getString("SetJDBCDriverPreferencePage.general.url"), // $NON-NLS-1$
2);
String url = getPreferenceStore().getString(URL_KEY);
generalJdbcUrlText.setText(url != null ? url : PluginConstant.EMPTY_STRING);
generalJdbcDriverjarText = new LabelledText(mainComposite, // $NON-NLS-1$
DefaultMessagesImpl.getString("SetJDBCDriverPreferencePage.general.jarfile"), 1);
String driver = getPreferenceStore().getString(DRIVER_KEY);
generalJdbcDriverjarText.setText(driver != null ? driver : PluginConstant.EMPTY_STRING);
browseJarFilesButton = new Button(mainComposite, SWT.NONE);
// $NON-NLS-1$
browseJarFilesButton.setText("...");
generalJdbcClassNameText = new LabelledCombo(mainComposite, DefaultMessagesImpl.getString("SetJDBCDriverPreferencePage.general.classname"), "", null, 1, true, // $NON-NLS-1$
SWT.NONE);
String className = getPreferenceStore().getString(CLASSNAME_KEY);
generalJdbcClassNameText.setText(className != null ? className : PluginConstant.EMPTY_STRING);
browseClassButton = new Button(mainComposite, SWT.NONE);
// $NON-NLS-1$
browseClassButton.setText("...");
generalJdbcUserText = new LabelledText(mainComposite, DefaultMessagesImpl.getString("SetJDBCDriverPreferencePage.general.user"), // $NON-NLS-1$
2);
String userName = getPreferenceStore().getString(USERNAME_KEY);
generalJdbcUserText.setText(userName != null ? userName : PluginConstant.EMPTY_STRING);
generalJdbcPasswordText = new LabelledText(mainComposite, DefaultMessagesImpl.getString("SetJDBCDriverPreferencePage.general.password"), // $NON-NLS-1$
2);
// see
generalJdbcPasswordText.getTextControl().setEchoChar('*');
String password = getPreferenceStore().getString(PASSWORD_KEY);
generalJdbcPasswordText.setText(password != null ? password : PluginConstant.EMPTY_STRING);
generalMappingFileText = new LabelledText(mainComposite, DefaultMessagesImpl.getString("SetJDBCDriverPreferencePage.general.mapping"), // $NON-NLS-1$
1);
String mapFile = getPreferenceStore().getString(MAPFILE_KEY);
generalMappingFileText.setText(mapFile != null ? mapFile : PluginConstant.EMPTY_STRING);
generalMappingSelectButton = new Button(mainComposite, SWT.NONE);
// $NON-NLS-1$
generalMappingSelectButton.setText("...");
applyButton = new Button(mainComposite, SWT.CENTER | SWT.BOTTOM);
// $NON-NLS-1$
applyButton.setText(DefaultMessagesImpl.getString("SetJDBCDriverPreferencePage.selectConnectionButton"));
GridData gd = new GridData();
gd.horizontalAlignment = GridData.CENTER;
gd.horizontalSpan = 3;
applyButton.setLayoutData(gd);
applyButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
CheckedTreeSelectionDialog dialog = createConnSelectDialog();
dialog.create();
if (dialog.open() == Window.OK) {
Object[] selects = dialog.getResult();
if (selects != null && selects.length > 0) {
boolean isConfirm = MessageDialog.openConfirm(dialog.getShell(), // $NON-NLS-1$
DefaultMessagesImpl.getString("SetJDBCDriverPreferencePage.confirmTitle"), // $NON-NLS-1$
DefaultMessagesImpl.getString("SetJDBCDriverPreferencePage.confirmContent"));
if (!isConfirm) {
return;
}
saveDatabases(selects);
}
}
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
browseJarFilesButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
SelectDatabaseJarDialog dialog = new SelectDatabaseJarDialog(getShell(), generalJdbcDriverjarText.getText());
if (dialog.open() == Window.OK) {
generalJdbcDriverjarText.setText(dialog.getJarsString());
}
}
});
browseClassButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
generalJdbcClassNameText.removeAll();
for (String stringToFile : generalJdbcDriverjarText.getText().trim().split(";")) {
// $NON-NLS-1$
File file = new File(stringToFile);
if (file != null) {
try {
MyURLClassLoader cl = new MyURLClassLoader(file.toURL());
Class[] classes = cl.getAssignableClasses(Driver.class);
for (Class classe : classes) {
generalJdbcClassNameText.add(classe.getName());
}
} catch (Exception ex) {
ExceptionHandler.process(ex);
}
}
}
if (generalJdbcClassNameText.getItemCount() > 0) {
String driverClassName = generalJdbcClassNameText.getItem(0);
generalJdbcClassNameText.setText(driverClassName);
}
}
});
generalMappingSelectButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
MappingFileSelectDialog dialog = new MappingFileSelectDialog(getShell());
dialog.open();
generalMappingFileText.setText(dialog.getSelectId());
}
});
return mainComposite;
}
Aggregations