Search in sources :

Example 1 with BaseDialog

use of org.jkiss.dbeaver.ui.dialogs.BaseDialog in project dbeaver by dbeaver.

the class DriverManagerDialog method undeleteDrivers.

private boolean undeleteDrivers() {
    List<DriverDescriptor> drivers = new ArrayList<>();
    BaseDialog dialog = new BaseDialog(getShell(), "Restore deleted driver(s)", null) {

        @Override
        protected Composite createDialogArea(Composite parent) {
            final Composite composite = super.createDialogArea(parent);
            Table driverTable = new Table(composite, SWT.CHECK | SWT.FULL_SELECTION | SWT.BORDER);
            driverTable.setLayoutData(new GridData(GridData.FILL_BOTH));
            for (DBPDataSourceProviderDescriptor dspd : DataSourceProviderRegistry.getInstance().getEnabledDataSourceProviders()) {
                for (DBPDriver dd : dspd.getDrivers()) {
                    if (dd.isDisabled()) {
                        TableItem item = new TableItem(driverTable, SWT.NONE);
                        item.setImage(DBeaverIcons.getImage(dd.getIcon()));
                        item.setText(dd.getName());
                        item.setData(dd);
                    }
                }
            }
            driverTable.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    if (((TableItem) e.item).getChecked()) {
                        drivers.add((DriverDescriptor) e.item.getData());
                    } else {
                        drivers.remove((DriverDescriptor) e.item.getData());
                    }
                }
            });
            return super.createDialogArea(parent);
        }
    };
    if (dialog.open() == IDialogConstants.OK_ID) {
        for (DriverDescriptor dd : drivers) {
            dd.setDisabled(false);
            dd.getProviderDescriptor().getRegistry().saveDrivers();
        }
        return true;
    }
    return false;
}
Also used : BaseDialog(org.jkiss.dbeaver.ui.dialogs.BaseDialog) DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArrayList(java.util.ArrayList) DBPDriver(org.jkiss.dbeaver.model.connection.DBPDriver) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBPDataSourceProviderDescriptor(org.jkiss.dbeaver.model.connection.DBPDataSourceProviderDescriptor)

Example 2 with BaseDialog

use of org.jkiss.dbeaver.ui.dialogs.BaseDialog in project dbeaver by serge-rider.

the class DriverManagerDialog method undeleteDrivers.

private boolean undeleteDrivers() {
    List<DriverDescriptor> drivers = new ArrayList<>();
    BaseDialog dialog = new BaseDialog(getShell(), "Restore deleted driver(s)", null) {

        @Override
        protected Composite createDialogArea(Composite parent) {
            final Composite composite = super.createDialogArea(parent);
            Table driverTable = new Table(composite, SWT.CHECK | SWT.FULL_SELECTION | SWT.BORDER);
            driverTable.setLayoutData(new GridData(GridData.FILL_BOTH));
            for (DBPDataSourceProviderDescriptor dspd : DataSourceProviderRegistry.getInstance().getEnabledDataSourceProviders()) {
                for (DBPDriver dd : dspd.getDrivers()) {
                    if (dd.isDisabled()) {
                        TableItem item = new TableItem(driverTable, SWT.NONE);
                        item.setImage(DBeaverIcons.getImage(dd.getIcon()));
                        item.setText(dd.getName());
                        item.setData(dd);
                    }
                }
            }
            driverTable.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    if (((TableItem) e.item).getChecked()) {
                        drivers.add((DriverDescriptor) e.item.getData());
                    } else {
                        drivers.remove((DriverDescriptor) e.item.getData());
                    }
                }
            });
            return super.createDialogArea(parent);
        }
    };
    if (dialog.open() == IDialogConstants.OK_ID) {
        for (DriverDescriptor dd : drivers) {
            dd.setDisabled(false);
            dd.getProviderDescriptor().getRegistry().saveDrivers();
        }
        return true;
    }
    return false;
}
Also used : BaseDialog(org.jkiss.dbeaver.ui.dialogs.BaseDialog) DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArrayList(java.util.ArrayList) DBPDriver(org.jkiss.dbeaver.model.connection.DBPDriver) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBPDataSourceProviderDescriptor(org.jkiss.dbeaver.model.connection.DBPDataSourceProviderDescriptor)

Aggregations

ArrayList (java.util.ArrayList)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 DBPDataSourceProviderDescriptor (org.jkiss.dbeaver.model.connection.DBPDataSourceProviderDescriptor)2 DBPDriver (org.jkiss.dbeaver.model.connection.DBPDriver)2 DriverDescriptor (org.jkiss.dbeaver.registry.driver.DriverDescriptor)2 BaseDialog (org.jkiss.dbeaver.ui.dialogs.BaseDialog)2