use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class SelectDataSourceCombo method addProjectDataSources.
public void addProjectDataSources() {
addItem(null);
DBPProject activeProject = getActiveProject();
if (activeProject != null) {
for (DBPDataSourceContainer ds : activeProject.getDataSourceRegistry().getDataSources()) {
addItem(ds);
}
}
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class SelectActiveDataSourceHandler method getAvailableDataSources.
private static List<? extends DBPDataSourceContainer> getAvailableDataSources() {
// Get project from active editor
IWorkbenchWindow workbenchWindow = UIUtils.getActiveWorkbenchWindow();
if (workbenchWindow != null && workbenchWindow.getActivePage() != null) {
final IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
if (activeEditor != null) {
IFile curFile = EditorUtils.getFileFromInput(activeEditor.getEditorInput());
if (curFile != null) {
DBPDataSourceContainer fileDataSource = EditorUtils.getFileDataSource(curFile);
if (fileDataSource != null) {
return fileDataSource.getRegistry().getDataSources();
}
DBPProject projectMeta = DBWorkbench.getPlatform().getWorkspace().getProject(curFile.getProject());
if (projectMeta != null) {
return projectMeta.getDataSourceRegistry().getDataSources();
}
}
}
final DBPDataSourceContainer dataSourceContainer = getDataSourceContainerFromPart(workbenchWindow.getActivePage().getActivePart());
if (dataSourceContainer != null) {
return dataSourceContainer.getRegistry().getDataSources();
} else {
return DataSourceRegistry.getAllDataSources();
}
}
return Collections.emptyList();
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class SelectActiveDataSourceHandler method openDataSourceSelector.
public static void openDataSourceSelector(IWorkbenchWindow workbenchWindow, DBPDataSourceContainer dataSource) {
DBPProject activeProject = dataSource != null ? dataSource.getRegistry().getProject() : DBWorkbench.getPlatform().getWorkspace().getActiveProject();
IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
if (!(activeEditor instanceof IDataSourceContainerProviderEx)) {
return;
}
SelectDataSourceDialog dialog = new SelectDataSourceDialog(UIUtils.getActiveWorkbenchShell(), activeProject, dataSource);
dialog.setModeless(true);
if (dialog.open() == IDialogConstants.CANCEL_ID) {
return;
}
DBPDataSourceContainer newDataSource = dialog.getDataSource();
if (newDataSource == dataSource) {
return;
}
((IDataSourceContainerProviderEx) activeEditor).setDataSourceContainer(newDataSource);
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class SQLEditor method getDataSourceFromContent.
private DBPDataSourceContainer getDataSourceFromContent() {
DBPProject project = getProject();
IDocument document = getDocument();
if (document == null || document.getNumberOfLines() == 0) {
return null;
}
try {
IRegion region = document.getLineInformation(0);
String line = document.get(region.getOffset(), region.getLength());
Matcher matcher = EMBEDDED_BINDING_PREFIX_PATTERN.matcher(line);
if (matcher.matches()) {
String connSpec = matcher.group(1).trim();
if (!CommonUtils.isEmpty(connSpec)) {
final DBPDataSourceContainer dataSource = DataSourceUtils.getDataSourceBySpec(project, connSpec, null, true, false);
if (dataSource != null) {
return dataSource;
}
}
}
} catch (Throwable e) {
log.debug("Error extracting datasource info from script's content", e);
}
return null;
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class PrefPageProjectResourceSettings method performOk.
@Override
public boolean performOk() {
java.util.List<IResource> refreshedResources = new ArrayList<>();
// Save roots
DBPProject projectMeta = getProjectMeta();
if (projectMeta != null) {
for (TableItem item : resourceTable.getItems()) {
DBPResourceHandlerDescriptor descriptor = (DBPResourceHandlerDescriptor) item.getData();
String rootPath = item.getText(1);
if (!CommonUtils.equalObjects(descriptor.getDefaultRoot(projectMeta), rootPath)) {
IResource oldResource = project.findMember(descriptor.getDefaultRoot(projectMeta));
if (oldResource != null) {
refreshedResources.add(oldResource);
}
IResource newResource = project.findMember(rootPath);
if (newResource != null) {
refreshedResources.add(newResource);
}
descriptor.setDefaultRoot(projectMeta, rootPath);
}
}
if (!refreshedResources.isEmpty()) {
for (IResource resource : refreshedResources) {
DBNUtils.refreshNavigatorResource(resource, this);
}
}
}
return super.performOk();
}
Aggregations