Search in sources :

Example 1 with SelectDatabaseJarDialog

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;
}
Also used : LabelledText(org.talend.commons.ui.swt.formtools.LabelledText) LabelledCombo(org.talend.commons.ui.swt.formtools.LabelledCombo) Composite(org.eclipse.swt.widgets.Composite) CheckedTreeSelectionDialog(org.eclipse.ui.dialogs.CheckedTreeSelectionDialog) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) MyURLClassLoader(org.talend.commons.ui.utils.loader.MyURLClassLoader) Driver(java.sql.Driver) PersistenceException(org.talend.commons.exception.PersistenceException) SelectDatabaseJarDialog(org.talend.repository.ui.wizards.metadata.connection.database.SelectDatabaseJarDialog) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MappingFileSelectDialog(org.talend.metadata.managment.ui.dialog.MappingFileSelectDialog) File(java.io.File) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

File (java.io.File)1 Driver (java.sql.Driver)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 CheckedTreeSelectionDialog (org.eclipse.ui.dialogs.CheckedTreeSelectionDialog)1 PersistenceException (org.talend.commons.exception.PersistenceException)1 LabelledCombo (org.talend.commons.ui.swt.formtools.LabelledCombo)1 LabelledText (org.talend.commons.ui.swt.formtools.LabelledText)1 MyURLClassLoader (org.talend.commons.ui.utils.loader.MyURLClassLoader)1 MappingFileSelectDialog (org.talend.metadata.managment.ui.dialog.MappingFileSelectDialog)1 SelectDatabaseJarDialog (org.talend.repository.ui.wizards.metadata.connection.database.SelectDatabaseJarDialog)1