Search in sources :

Example 1 with CreateDriverDlg

use of net.sourceforge.sqlexplorer.dialogs.CreateDriverDlg 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 2 with CreateDriverDlg

use of net.sourceforge.sqlexplorer.dialogs.CreateDriverDlg 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)

Aggregations

ManagedDriver (net.sourceforge.sqlexplorer.dbproduct.ManagedDriver)2 CreateDriverDlg (net.sourceforge.sqlexplorer.dialogs.CreateDriverDlg)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 ExplorerException (net.sourceforge.sqlexplorer.ExplorerException)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 MouseAdapter (org.eclipse.swt.events.MouseAdapter)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Font (org.eclipse.swt.graphics.Font)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 Table (org.eclipse.swt.widgets.Table)1