use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by serge-rider.
the class EditorUtils method setFileDataSource.
public static void setFileDataSource(@NotNull IFile file, @NotNull DatabaseEditorContext context) {
DBPProject projectMeta = DBWorkbench.getPlatform().getWorkspace().getProject(file.getProject());
if (projectMeta == null) {
return;
}
DBPDataSourceContainer dataSourceContainer = context.getDataSourceContainer();
String dataSourceId = dataSourceContainer == null ? null : dataSourceContainer.getId();
projectMeta.setResourceProperty(file, PROP_SQL_DATA_SOURCE_ID, dataSourceId);
if (!isDefaultContextSettings(context)) {
projectMeta.setResourceProperty(file, PROP_CONTEXT_DEFAULT_DATASOURCE, dataSourceId);
String catalogName = getDefaultCatalogName(context);
if (catalogName != null)
projectMeta.setResourceProperty(file, PROP_CONTEXT_DEFAULT_CATALOG, catalogName);
String schemaName = getDefaultSchemaName(context);
if (catalogName != null || schemaName != null)
projectMeta.setResourceProperty(file, PROP_CONTEXT_DEFAULT_SCHEMA, schemaName);
}
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class DataSourceDescriptorManager method createNewObject.
@Override
public DataSourceDescriptor createNewObject(DBRProgressMonitor monitor, DBECommandContext commandContext, Object container, Object copyFrom, Map<String, Object> options) {
if (copyFrom != null) {
DataSourceDescriptor dsTpl = (DataSourceDescriptor) copyFrom;
DBPDataSourceRegistry registry;
DBPDataSourceFolder folder = null;
if (container instanceof DataSourceRegistry) {
registry = (DBPDataSourceRegistry) container;
} else if (container instanceof DBPProject) {
registry = ((DBPProject) container).getDataSourceRegistry();
} else if (container instanceof DBPDataSourceFolder) {
folder = (DBPDataSourceFolder) container;
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);
} else if (dsTpl.getRegistry() == registry) {
// Copy folder only if we copy in the same project
dataSource.setFolder(dsTpl.getFolder());
}
// 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 {
UIUtils.asyncExec(() -> NewConnectionDialog.openNewConnectionDialog(UIUtils.getActiveWorkbenchWindow()));
}
return null;
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class DiagramLoader method load.
public static void load(DBRProgressMonitor monitor, IProject project, DiagramPart diagramPart, InputStream in) throws XMLException, DBException {
monitor.beginTask("Parse diagram", 1);
final EntityDiagram diagram = diagramPart.getDiagram();
DBPProject projectMeta = DBWorkbench.getPlatform().getWorkspace().getProject(project);
if (projectMeta == null) {
throw new DBException("Cannot find datasource registry for project '" + project.getName() + "'");
}
final Document document = XMLUtils.parseDocument(in);
monitor.done();
loadDiagram(monitor, document, projectMeta, diagram);
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class DiagramLoader method extractContainers.
public static List<DBPDataSourceContainer> extractContainers(IFile resource) throws IOException, XMLException, DBException {
List<DBPDataSourceContainer> containers = new ArrayList<>();
DBPProject projectMeta = DBWorkbench.getPlatform().getWorkspace().getProject(resource.getProject());
if (projectMeta == null) {
return containers;
}
try (InputStream is = resource.getContents()) {
final Document document = XMLUtils.parseDocument(is);
final Element diagramElem = document.getDocumentElement();
final Element entitiesElem = XMLUtils.getChildElement(diagramElem, TAG_ENTITIES);
if (entitiesElem != null) {
// Parse data source
for (Element dsElem : XMLUtils.getChildElementList(entitiesElem, TAG_DATA_SOURCE)) {
String dsId = dsElem.getAttribute(ATTR_ID);
if (!CommonUtils.isEmpty(dsId)) {
// Get connected datasource
final DBPDataSourceContainer dataSourceContainer = projectMeta.getDataSourceRegistry().getDataSource(dsId);
if (dataSourceContainer != null) {
containers.add(dataSourceContainer);
}
}
}
}
} catch (CoreException e) {
throw new DBException("Error reading resource contents", e);
}
return containers;
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class ProjectHandlerImpl method openResource.
@Override
public void openResource(@NotNull IResource resource) {
DBPProject project = DBWorkbench.getPlatform().getWorkspace().getProject((IProject) resource);
if (project == null) {
DBWorkbench.getPlatformUI().showError("No project", "Can't get project metadata for resource " + resource.getName());
return;
}
MultiPageWizardDialog dialog = new MultiPageWizardDialog(UIUtils.getActiveWorkbenchWindow(), new EditProjectWizard(project));
dialog.open();
}
Aggregations