use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by serge-rider.
the class AbstractNativeToolSettings method loadSettings.
public void loadSettings(DBRRunnableContext runnableContext, DBPPreferenceStore preferenceStore) throws DBException {
if (dataSourceContainer == null && !CommonUtils.isEmpty(databaseObjects)) {
BASE_OBJECT baseObject = databaseObjects.get(0);
dataSourceContainer = baseObject instanceof DBPDataSourceContainer ? (DBPDataSourceContainer) baseObject : baseObject.getDataSource().getContainer();
}
if (dataSourceContainer == null) {
String dsID = preferenceStore.getString("dataSource");
if (!CommonUtils.isEmpty(dsID)) {
String projectName = preferenceStore.getString("project");
DBPProject project = CommonUtils.isEmpty(projectName) ? null : DBWorkbench.getPlatform().getWorkspace().getProject(projectName);
if (project == null) {
if (!CommonUtils.isEmpty(projectName)) {
log.error("Can't find project '" + projectName + "' for tool configuration");
}
project = DBWorkbench.getPlatform().getWorkspace().getActiveProject();
}
dataSourceContainer = project.getDataSourceRegistry().getDataSource(dsID);
if (dataSourceContainer == null) {
log.error("Can't find datasource '" + dsID + "' in project '" + project.getName() + "' for tool configuration");
}
}
}
if (preferenceStore instanceof DBPPreferenceMap && dataSourceContainer != null) {
List<String> databaseObjectList = ((DBPPreferenceMap) preferenceStore).getObject("databaseObjects");
if (!CommonUtils.isEmpty(databaseObjectList)) {
DBPProject finalProject = dataSourceContainer.getProject();
try {
runnableContext.run(true, true, monitor -> {
monitor.beginTask("Load database object list", databaseObjectList.size());
try {
for (String objectId : databaseObjectList) {
monitor.subTask("Load " + objectId);
try {
DBSObject object = DBUtils.findObjectById(monitor, finalProject, objectId);
if (object != null) {
databaseObjects.add((BASE_OBJECT) object);
dataSourceContainer = object instanceof DBPDataSourceContainer ? (DBPDataSourceContainer) object : object.getDataSource().getContainer();
}
} catch (Throwable e) {
throw new DBException("Can't find database object '" + objectId + "' in project '" + finalProject.getName() + "' for task configuration", e);
}
monitor.worked(1);
}
} catch (Exception e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
});
} catch (InvocationTargetException e) {
throw new DBException("Error loading objects configuration", e.getTargetException());
} catch (InterruptedException e) {
// Ignore
}
}
}
extraCommandArgs = preferenceStore.getString(PROP_NAME_EXTRA_ARGS);
clientHomeName = preferenceStore.getString("clientHomeName");
if (preferenceStore instanceof DBPPreferenceMap) {
toolUserName = preferenceStore.getString("tool.user");
toolUserPassword = preferenceStore.getString("tool.password");
try {
final SecuredPasswordEncrypter encrypter = new SecuredPasswordEncrypter();
if (!CommonUtils.isEmpty(toolUserName))
toolUserName = encrypter.decrypt(toolUserName);
if (!CommonUtils.isEmpty(toolUserPassword))
toolUserPassword = encrypter.decrypt(toolUserPassword);
} catch (Exception e) {
throw new DBException("Error decrypting user credentials", e);
}
}
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by serge-rider.
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 serge-rider.
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 serge-rider.
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 serge-rider.
the class EditorUtils method getInputContextDefaults.
/**
* String[2] = { defaultCatalogName, defaultSchema }
*/
public static String[] getInputContextDefaults(DBPDataSourceContainer dataSource, IEditorInput editorInput) {
String defaultDatasource = null;
String defaultCatalogName = null;
String defaultSchema = null;
if (editorInput instanceof INonPersistentEditorInput) {
defaultDatasource = (String) ((INonPersistentEditorInput) editorInput).getProperty(PROP_CONTEXT_DEFAULT_DATASOURCE);
defaultCatalogName = (String) ((INonPersistentEditorInput) editorInput).getProperty(PROP_CONTEXT_DEFAULT_CATALOG);
defaultSchema = (String) ((INonPersistentEditorInput) editorInput).getProperty(PROP_CONTEXT_DEFAULT_SCHEMA);
} else {
IFile file = getFileFromInput(editorInput);
if (file != null) {
DBPProject projectMeta = DBWorkbench.getPlatform().getWorkspace().getProject(file.getProject());
if (projectMeta != null) {
defaultDatasource = (String) projectMeta.getResourceProperty(file, PROP_CONTEXT_DEFAULT_DATASOURCE);
defaultCatalogName = (String) projectMeta.getResourceProperty(file, PROP_CONTEXT_DEFAULT_CATALOG);
defaultSchema = (String) projectMeta.getResourceProperty(file, PROP_CONTEXT_DEFAULT_SCHEMA);
}
} else {
File localFile = getLocalFileFromInput(editorInput);
if (localFile != null) {
final DBPExternalFileManager efManager = DBWorkbench.getPlatform().getExternalFileManager();
defaultDatasource = (String) efManager.getFileProperty(localFile, PROP_CONTEXT_DEFAULT_DATASOURCE);
defaultCatalogName = (String) efManager.getFileProperty(localFile, PROP_CONTEXT_DEFAULT_CATALOG);
defaultSchema = (String) efManager.getFileProperty(localFile, PROP_CONTEXT_DEFAULT_SCHEMA);
}
}
}
if (!CommonUtils.isEmpty(defaultDatasource) && !defaultDatasource.equals(dataSource.getId())) {
// Wrong datasource
return new String[] { null, null };
}
return new String[] { defaultCatalogName, defaultSchema };
}
Aggregations