Search in sources :

Example 1 with ManagedDriver

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;
}
Also used : User(net.sourceforge.sqlexplorer.dbproduct.User) Composite(org.eclipse.swt.widgets.Composite) ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) GridLayout(org.eclipse.swt.layout.GridLayout) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) KeyListener(org.eclipse.swt.events.KeyListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 2 with ManagedDriver

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++;
    }
}
Also used : ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver) Font(org.eclipse.swt.graphics.Font)

Example 3 with ManagedDriver

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);
    }
}
Also used : ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 4 with ManagedDriver

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);
        }
    }
}
Also used : ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver) DriverManager(net.sourceforge.sqlexplorer.dbproduct.DriverManager) SQLExplorerPlugin(net.sourceforge.sqlexplorer.plugin.SQLExplorerPlugin)

Example 5 with ManagedDriver

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);
        }
    }
}
Also used : ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver) AliasAndManaDriverHelper(net.sourceforge.sqlexplorer.util.AliasAndManaDriverHelper) DriverManager(net.sourceforge.sqlexplorer.dbproduct.DriverManager) PartInitException(org.eclipse.ui.PartInitException) MalformedURLException(java.net.MalformedURLException)

Aggregations

ManagedDriver (net.sourceforge.sqlexplorer.dbproduct.ManagedDriver)16 DriverManager (net.sourceforge.sqlexplorer.dbproduct.DriverManager)8 User (net.sourceforge.sqlexplorer.dbproduct.User)3 SQLExplorerPlugin (net.sourceforge.sqlexplorer.plugin.SQLExplorerPlugin)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 File (java.io.File)2 MalformedURLException (java.net.MalformedURLException)2 ArrayList (java.util.ArrayList)2 ExplorerException (net.sourceforge.sqlexplorer.ExplorerException)2 CreateDriverDlg (net.sourceforge.sqlexplorer.dialogs.CreateDriverDlg)2 AliasAndManaDriverHelper (net.sourceforge.sqlexplorer.util.AliasAndManaDriverHelper)2 MyURLClassLoader (net.sourceforge.sqlexplorer.util.MyURLClassLoader)2 IFile (org.eclipse.core.resources.IFile)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Font (org.eclipse.swt.graphics.Font)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Button (org.eclipse.swt.widgets.Button)2 Composite (org.eclipse.swt.widgets.Composite)2