Search in sources :

Example 11 with ManagedDriver

use of net.sourceforge.sqlexplorer.dbproduct.ManagedDriver in project tdq-studio-se by Talend.

the class AliasAndManaDriverHelper method createNewManagerDriver.

/**
 * create a New ManagerDriver. id is like as "dbType:driverClassName:dbVersion",name is like as "dbType:dbVersion".
 * then regist jdbc driver.
 *
 * @param dbConn
 * @param id
 * @return
 * @throws IllegalAccessException
 * @throws InstantiationException
 * @throws ClassNotFoundException
 */
public ManagedDriver createNewManagerDriver(DatabaseConnection dbConn) throws Exception {
    String id = this.joinManagedDriverId(dbConn);
    ManagedDriver manaDriver = new ManagedDriver(id);
    String dbType = dbConn.getDatabaseType();
    String dbVersion = dbConn.getDbVersionString();
    manaDriver.setName(dbVersion == null ? dbType : dbType + ":" + dbVersion);
    manaDriver.setDriverClassName(JavaSqlFactory.getDriverClass(dbConn));
    manaDriver.setUrl(JavaSqlFactory.getURL(dbConn));
    // set jar path
    addJars(dbConn, manaDriver);
    // register jdbc driver for Object ManagedDriver when its jars are not empty.
    if (!manaDriver.getJars().isEmpty()) {
        manaDriver.registerSQLDriver(dbConn);
    }
    return manaDriver;
}
Also used : ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver)

Example 12 with ManagedDriver

use of net.sourceforge.sqlexplorer.dbproduct.ManagedDriver in project tdq-studio-se by Talend.

the class DriverLabelProvider method getColumnText.

public String getColumnText(Object element, int i) {
    ManagedDriver dv = (ManagedDriver) element;
    // MOD qiongli,display different name for different vertica driver version.
    String name = dv.getName();
    if ("Vertica".equalsIgnoreCase(name) && EDriverName.VERTICA2.getSqlEid().equals(dv.getId())) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        name = "Vertica 6/7";
    }
    return name;
}
Also used : ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver)

Example 13 with ManagedDriver

use of net.sourceforge.sqlexplorer.dbproduct.ManagedDriver in project tdq-studio-se by Talend.

the class DriverLabelProvider method createContents.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) The UI is
     * defined in the DriverContainerGroup class. Note: The [Restore Default] and [Apply] buttons have been removed
     * using the noDefaultandApplyButton method as these don't apply since all updates are made in the corresponding
     * dialogs.
     */
@Override
protected Control createContents(Composite parent) {
    noDefaultAndApplyButton();
    _driverModel = SQLExplorerPlugin.getDefault().getDriverModel();
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, SQLExplorerPlugin.PLUGIN_ID + ".DriverContainerGroup");
    _prefs = SQLExplorerPlugin.getDefault().getPreferenceStore();
    GridLayout parentLayout = new GridLayout(1, false);
    parentLayout.marginTop = parentLayout.marginBottom = 0;
    parentLayout.marginHeight = 0;
    parentLayout.verticalSpacing = 10;
    parent.setLayout(parentLayout);
    GridLayout layout;
    Composite myComposite = new Composite(parent, SWT.NONE);
    // Define layout.
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginWidth = layout.marginHeight = 0;
    layout.horizontalSpacing = 20;
    layout.verticalSpacing = 10;
    myComposite.setLayout(layout);
    myComposite.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, true));
    GridData gid = new GridData(GridData.FILL_BOTH);
    gid.grabExcessHorizontalSpace = gid.grabExcessVerticalSpace = true;
    gid.horizontalAlignment = gid.verticalAlignment = GridData.FILL;
    gid.verticalSpan = 6;
    _tableViewer = new TableViewer(myComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    _tableViewer.getControl().setLayoutData(gid);
    _tableViewer.setContentProvider(new DriverContentProvider());
    final DriverLabelProvider dlp = new DriverLabelProvider();
    _tableViewer.setLabelProvider(dlp);
    _tableViewer.getTable().addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            dlp.dispose();
            if (_boldfont != null) {
                _boldfont.dispose();
            }
        }
    });
    _tableViewer.getTable().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            changeDriver();
        }
    });
    _tableViewer.setInput(_driverModel);
    selectFirst();
    final Table table = _tableViewer.getTable();
    myComposite.layout();
    parent.layout();
    // Add Buttons
    gid = new GridData(GridData.FILL);
    gid.widthHint = 75;
    Button add = new Button(myComposite, SWT.PUSH);
    add.setText(Messages.getString("Preferences.Drivers.Button.Add"));
    add.setLayoutData(gid);
    add.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            CreateDriverDlg dlg = new CreateDriverDlg(getShell(), CreateDriverDlg.Type.CREATE, null);
            dlg.open();
            _tableViewer.refresh();
            selectFirst();
        }
    });
    gid = new GridData(GridData.FILL);
    gid.widthHint = 75;
    Button edit = new Button(myComposite, SWT.PUSH);
    edit.setText(Messages.getString("Preferences.Drivers.Button.Edit"));
    edit.setLayoutData(gid);
    edit.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            changeDriver();
            _tableViewer.refresh();
        }
    });
    gid = new GridData(GridData.FILL);
    gid.widthHint = 75;
    Button copy = new Button(myComposite, SWT.PUSH);
    copy.setText(Messages.getString("Preferences.Drivers.Button.Copy"));
    copy.setLayoutData(gid);
    copy.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            StructuredSelection sel = (StructuredSelection) _tableViewer.getSelection();
            ManagedDriver dv = (ManagedDriver) sel.getFirstElement();
            if (dv != null) {
                CreateDriverDlg dlg = new CreateDriverDlg(getShell(), CreateDriverDlg.Type.COPY, dv);
                dlg.open();
                _tableViewer.refresh();
            }
        }
    });
    gid = new GridData(GridData.FILL);
    gid.widthHint = 75;
    Button remove = new Button(myComposite, SWT.PUSH);
    remove.setText(Messages.getString("Preferences.Drivers.Button.Remove"));
    remove.setLayoutData(gid);
    remove.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            StructuredSelection sel = (StructuredSelection) _tableViewer.getSelection();
            ManagedDriver managedDriver = (ManagedDriver) sel.getFirstElement();
            if (managedDriver != null) {
                // when the driver is used by other Aliases, give a warning to user
                if (managedDriver.isUsedByAliases()) {
                    MessageDialog.openWarning(getShell(), Messages.getString("Preferences.Drivers.ConfirmDelete.Title"), Messages.getString("Preferences.Drivers.ConfirmDelete.Warning"));
                } else {
                    boolean okToDelete = MessageDialog.openConfirm(getShell(), Messages.getString("Preferences.Drivers.ConfirmDelete.Title"), Messages.getString("Preferences.Drivers.ConfirmDelete.Prefix") + _tableViewer.getTable().getSelection()[0].getText() + Messages.getString("Preferences.Drivers.ConfirmDelete.Postfix"));
                    if (okToDelete) {
                        _driverModel.removeDriver(managedDriver);
                        _tableViewer.refresh();
                        selectFirst();
                    }
                }
            }
        }
    });
    gid = new GridData(GridData.FILL);
    gid.widthHint = 73;
    Button bdefault = new Button(myComposite, SWT.PUSH);
    bdefault.setText(Messages.getString("Preferences.Drivers.Button.Default"));
    bdefault.setLayoutData(gid);
    // Remove bold font on all elements, and make selected element bold
    bdefault.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            for (int i = 0; i < _tableViewer.getTable().getItemCount(); i++) {
                _tableViewer.getTable().getItem(i).setFont(0, table.getFont());
            }
            _boldfont = new Font(_tableViewer.getTable().getDisplay(), table.getFont().toString(), table.getFont().getFontData()[0].getHeight(), SWT.BOLD);
            _tableViewer.getTable().getSelection()[0].setFont(0, _boldfont);
            _prefs.setValue(IConstants.DEFAULT_DRIVER, _tableViewer.getTable().getSelection()[0].getText());
        }
    });
    // add button to restore default drivers
    Button bRestore = new Button(parent, SWT.PUSH);
    bRestore.setText(Messages.getString("Preferences.Drivers.Button.RestoreDefault"));
    bRestore.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            try {
                _driverModel.restoreDrivers();
                _tableViewer.refresh();
                selectFirst();
            } catch (ExplorerException ex) {
                SQLExplorerPlugin.error("Cannot restore default driver configuration", ex);
            }
        }
    });
    bRestore.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, false, false));
    selectDefault(table);
    return parent;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) MouseEvent(org.eclipse.swt.events.MouseEvent) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ExplorerException(net.sourceforge.sqlexplorer.ExplorerException) ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Font(org.eclipse.swt.graphics.Font) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) CreateDriverDlg(net.sourceforge.sqlexplorer.dialogs.CreateDriverDlg) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 14 with ManagedDriver

use of net.sourceforge.sqlexplorer.dbproduct.ManagedDriver in project tdq-studio-se by Talend.

the class DriverLabelProvider method changeDriver.

private void changeDriver() {
    StructuredSelection sel = (StructuredSelection) _tableViewer.getSelection();
    ManagedDriver dv = (ManagedDriver) sel.getFirstElement();
    if (dv != null) {
        CreateDriverDlg dlg = new CreateDriverDlg(getShell(), CreateDriverDlg.Type.MODIFY, dv);
        dlg.open();
        _tableViewer.refresh();
        selectFirst();
    }
}
Also used : CreateDriverDlg(net.sourceforge.sqlexplorer.dialogs.CreateDriverDlg) ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 15 with ManagedDriver

use of net.sourceforge.sqlexplorer.dbproduct.ManagedDriver in project tdq-studio-se by Talend.

the class CreateAliasDlg method okPressed.

protected void okPressed() {
    try {
        User previousUser = alias.getDefaultUser();
        alias.setName(nameField.getText().trim());
        int selIndex = cboDriver.getSelectionIndex();
        ManagedDriver driver = comboDriverIndexes.get(selIndex);
        alias.setDriver(driver);
        alias.setUrl(urlField.getText().trim());
        if (noUsernameRequired.getSelection())
            alias.setHasNoUserName(true);
        else {
            alias.setHasNoUserName(false);
            if (userField.getText().trim().length() > 0)
                alias.setDefaultUser(new User(userField.getText().trim(), passwordField.getText().trim()));
        }
        alias.setName(this.nameField.getText().trim());
        alias.setSchemaFilterExpression("");
        alias.setNameFilterExpression("");
        alias.setFolderFilterExpression("");
        alias.setConnectAtStartup(logonAtStartupButton.getSelection());
        alias.setAutoLogon(autoLogonButton.getSelection());
        if (type != Type.CHANGE)
            SQLExplorerPlugin.getDefault().getAliasManager().addAlias(alias);
        else // objects even though we have explicitly created a new instance of User above)
        if (alias.getDefaultUser() != previousUser) {
            if (!previousUser.isInUse())
                alias.removeUser(previousUser);
        }
        User user = alias.getDefaultUser();
        if (user != null) {
            user.setAutoCommit(autoCommitButton.getSelection());
            user.setCommitOnClose(commitOnCloseButton.getSelection());
        }
    } catch (ExplorerException excp) {
        // $NON-NLS-1$
        SQLExplorerPlugin.error("Validation Exception", excp);
    // System.out.println(Messages.getString("Error_Validation_Exception_4"));//$NON-NLS-1$
    }
    // Notify that ther has been changes
    SQLExplorerPlugin.getDefault().getAliasManager().modelChanged();
    close();
}
Also used : User(net.sourceforge.sqlexplorer.dbproduct.User) ExplorerException(net.sourceforge.sqlexplorer.ExplorerException) ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver)

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