use of org.jkiss.dbeaver.model.app.DBPDataSourceRegistry in project dbeaver by serge-rider.
the class NavigatorHandlerLocalFolderCreate method createFolder.
public static boolean createFolder(IWorkbenchWindow workbenchWindow, IWorkbenchPart activePart, DBNProjectDatabases databases, final DBNLocalFolder parentFolder, final Collection<DBNDataSource> nodes, String newName) {
if (newName == null) {
newName = EnterNameDialog.chooseName(workbenchWindow.getShell(), "Folder name");
}
if (CommonUtils.isEmpty(newName)) {
return false;
}
// Create folder and refresh databases root
// DS container will reload folders on refresh
final DBPDataSourceRegistry dsRegistry = databases.getDataSourceRegistry();
DBPDataSourceFolder folder = dsRegistry.addFolder(parentFolder == null ? null : parentFolder.getFolder(), newName);
for (DBNDataSource node : nodes) {
node.setFolder(folder);
}
if (parentFolder != null && activePart instanceof NavigatorViewBase) {
final TreeViewer viewer = ((NavigatorViewBase) activePart).getNavigatorViewer();
if (viewer != null) {
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
viewer.expandToLevel(parentFolder, 1);
}
});
}
}
DBNModel.updateConfigAndRefreshDatabases(databases);
return true;
}
use of org.jkiss.dbeaver.model.app.DBPDataSourceRegistry in project dbeaver by serge-rider.
the class DBNProject method readChildNodes.
@Override
protected DBNNode[] readChildNodes(DBRProgressMonitor monitor) throws DBException {
IProject project = getProject();
if (!project.isOpen()) {
try {
project.open(monitor.getNestedMonitor());
project.refreshLocal(IFile.DEPTH_ONE, monitor.getNestedMonitor());
} catch (CoreException e) {
throw new DBException("Can't open project '" + project.getName() + "'", e);
}
}
DBPDataSourceRegistry dataSourceRegistry = getModel().getPlatform().getProjectManager().getDataSourceRegistry(project);
DBNNode[] children = super.readChildNodes(monitor);
if (dataSourceRegistry != null) {
children = ArrayUtils.insertArea(DBNNode.class, children, 0, new Object[] { new DBNProjectDatabases(this, dataSourceRegistry) });
}
return children;
}
use of org.jkiss.dbeaver.model.app.DBPDataSourceRegistry in project dbeaver by serge-rider.
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;
}
use of org.jkiss.dbeaver.model.app.DBPDataSourceRegistry in project dbeaver by serge-rider.
the class DataSourceManagementToolbar method dispose.
private void dispose() {
DBeaverCore.getInstance().getNavigatorModel().removeListener(this);
IWorkbenchPage activePage = workbenchWindow.getActivePage();
if (activePage != null) {
pageListener.pageClosed(activePage);
}
DataSourceProviderRegistry.getInstance().removeDataSourceRegistryListener(this);
for (DBPDataSourceRegistry registry : handledRegistries) {
registry.removeDataSourceListener(this);
}
setActivePart(null);
this.workbenchWindow.removePageListener(pageListener);
}
use of org.jkiss.dbeaver.model.app.DBPDataSourceRegistry in project dbeaver by serge-rider.
the class NewConnectionWizard method performFinish.
/**
* This method is called when 'Finish' button is pressed in
* the wizard. We will create an operation and run it
* using wizard as execution context.
*/
@Override
public boolean performFinish() {
DriverDescriptor driver = getSelectedDriver();
ConnectionPageSettings pageSettings = getPageSettings();
DataSourceDescriptor dataSourceTpl = pageSettings == null ? getActiveDataSource() : pageSettings.getActiveDataSource();
DBPDataSourceRegistry dataSourceRegistry = getDataSourceRegistry();
DataSourceDescriptor dataSourceNew = new DataSourceDescriptor(dataSourceRegistry, dataSourceTpl.getId(), driver, dataSourceTpl.getConnectionConfiguration());
dataSourceNew.copyFrom(dataSourceTpl);
saveSettings(dataSourceNew);
dataSourceRegistry.addDataSource(dataSourceNew);
return true;
}
Aggregations