use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by serge-rider.
the class SQLToolExecuteSettings method loadConfiguration.
public void loadConfiguration(DBRRunnableContext runnableContext, Map<String, Object> config) {
try {
runnableContext.run(true, true, monitor -> {
List<OBJECT_TYPE> objList = new ArrayList<>();
for (Map<String, Object> objectConfig : JSONUtils.getObjectList(config, "objects")) {
String projectName = CommonUtils.toString(objectConfig.get("project"));
DBPProject project = CommonUtils.isEmpty(projectName) ? null : DBWorkbench.getPlatform().getWorkspace().getProject(projectName);
if (project == null) {
log.error("Project '" + projectName + "' not found");
continue;
}
String objectId = CommonUtils.toString(objectConfig.get("objectId"));
try {
OBJECT_TYPE object = (OBJECT_TYPE) DBUtils.findObjectById(monitor, project, objectId);
if (object != null) {
objList.add(object);
}
} catch (DBException e) {
log.error("Can't find object '" + objectId + "' in project '" + project.getName() + "'");
warnings.add(e);
}
}
objectList.addAll(objList);
});
} catch (InvocationTargetException e) {
log.error(e.getTargetException());
} catch (InterruptedException e) {
// ignore
}
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by serge-rider.
the class DataSourceRegistry method getAllDataSources.
public static List<DBPDataSourceContainer> getAllDataSources() {
List<DBPDataSourceContainer> result = new ArrayList<>();
DBPWorkspace workspace = DBWorkbench.getPlatform().getWorkspace();
for (DBPProject project : workspace.getProjects()) {
if (project.isOpen() && project.isRegistryLoaded()) {
result.addAll(project.getDataSourceRegistry().getDataSources());
}
}
return result;
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class WorkbenchInitializerCreateSampleDatabase method initializeWorkbenchWindow.
@Override
public void initializeWorkbenchWindow(IWorkbenchWindow window) {
if (DBWorkbench.getPlatform().getPreferenceStore().getBoolean(PROP_SAMPLE_DB_CANCELED)) {
// Create was canceled
return;
}
if (DataSourceRegistry.getAllDataSources().size() > 1) {
// Seems to be experienced user - no need in sampel db
return;
}
DBPProject activeProject = DBWorkbench.getPlatform().getWorkspace().getActiveProject();
if (activeProject == null || !activeProject.isRegistryLoaded()) {
// No active project
return;
}
DBPDataSourceRegistry registry = activeProject.getDataSourceRegistry();
if (isSampleDatabaseExists(registry)) {
// Already exist
return;
}
if (!showCreateSampleDatabasePrompt(window.getShell())) {
DBWorkbench.getPlatform().getPreferenceStore().setValue(PROP_SAMPLE_DB_CANCELED, true);
return;
}
createSampleDatabase(registry);
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class DBUtils method getAllRegistries.
public static List<DBPDataSourceRegistry> getAllRegistries(boolean forceLoad) {
List<DBPDataSourceRegistry> result = new ArrayList<>();
for (DBPProject project : DBWorkbench.getPlatform().getWorkspace().getProjects()) {
if (forceLoad || (project.isOpen() && project.isRegistryLoaded())) {
project.ensureOpen();
DBPDataSourceRegistry registry = project.getDataSourceRegistry();
if (registry != null) {
result.add(registry);
}
}
}
return result;
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class DBNModel method resourceChanged.
@Override
public void resourceChanged(IResourceChangeEvent event) {
if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
IResourceDelta delta = event.getDelta();
for (IResourceDelta childDelta : delta.getAffectedChildren()) {
if (childDelta.getResource() instanceof IProject) {
IProject project = (IProject) childDelta.getResource();
DBNProject projectNode = getRoot().getProjectNode(project);
if (projectNode == null) {
if (childDelta.getKind() == IResourceDelta.ADDED) {
// New projectNode
DBPProject projectMeta = platform.getWorkspace().getProject(project);
if (projectMeta == null) {
log.error("Can't find project '" + project.getName() + "' metadata");
} else {
getRoot().addProject(projectMeta, true);
}
} else if (childDelta.getKind() != IResourceDelta.REMOVED) {
// Project not found - report an error
log.error("Project '" + childDelta.getResource().getName() + "' not found in navigator");
}
} else {
if (childDelta.getKind() == IResourceDelta.REMOVED) {
// Project deleted
DBPProject projectMeta = platform.getWorkspace().getProject(project);
if (projectMeta == null) {
log.error("Can't find project '" + project.getName() + "' metadata");
} else {
getRoot().removeProject(projectMeta);
}
} else {
// Some resource changed within the projectNode
// Let it handle this event itself
projectNode.handleResourceChange(childDelta);
}
}
}
}
}
}
Aggregations