Search in sources :

Example 6 with CreateConnectionDialog

use of org.jkiss.dbeaver.ui.dialogs.connection.CreateConnectionDialog in project dbeaver by dbeaver.

the class DataSourceDescriptorManager method createNewObject.

@Override
public DataSourceDescriptor createNewObject(DBRProgressMonitor monitor, DBECommandContext commandContext, DBPObject parent, Object copyFrom) {
    if (copyFrom != null) {
        DataSourceDescriptor dsTpl = (DataSourceDescriptor) copyFrom;
        DBPDataSourceRegistry registry;
        DBPDataSourceFolder folder = null;
        if (parent instanceof DataSourceRegistry) {
            registry = (DBPDataSourceRegistry) parent;
        } else if (parent instanceof DBPDataSourceFolder) {
            folder = (DBPDataSourceFolder) parent;
            registry = folder.getDataSourceRegistry();
        } else {
            registry = dsTpl.getRegistry();
        }
        DataSourceDescriptor dataSource = new DataSourceDescriptor(registry, DataSourceDescriptor.generateNewId(dsTpl.getDriver()), dsTpl.getDriver(), new DBPConnectionConfiguration(dsTpl.getConnectionConfiguration()));
        dataSource.copyFrom(dsTpl);
        if (folder != null) {
            dataSource.setFolder(folder);
        }
        // Generate new name
        String origName = dsTpl.getName();
        String newName = origName;
        for (int i = 0; ; i++) {
            if (registry.findDataSourceByName(newName) == null) {
                break;
            }
            newName = origName + " " + (i + 1);
        }
        dataSource.setName(newName);
        registry.addDataSource(dataSource);
    } else {
        DBeaverUI.asyncExec(new Runnable() {

            @Override
            public void run() {
                CreateConnectionDialog dialog = new CreateConnectionDialog(DBeaverUI.getActiveWorkbenchWindow(), new NewConnectionWizard());
                dialog.open();
            }
        });
    }
    return null;
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry) DBPDataSourceFolder(org.jkiss.dbeaver.model.DBPDataSourceFolder) NewConnectionWizard(org.jkiss.dbeaver.ui.dialogs.connection.NewConnectionWizard) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry) CreateConnectionDialog(org.jkiss.dbeaver.ui.dialogs.connection.CreateConnectionDialog)

Aggregations

CreateConnectionDialog (org.jkiss.dbeaver.ui.dialogs.connection.CreateConnectionDialog)6 NewConnectionWizard (org.jkiss.dbeaver.ui.dialogs.connection.NewConnectionWizard)6 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)3 DBPDataSourceFolder (org.jkiss.dbeaver.model.DBPDataSourceFolder)2 DBPDataSourceRegistry (org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)2 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)2