use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class SQLScriptExecuteSettings method loadConfiguration.
public void loadConfiguration(DBRRunnableContext runnableContext, Map<String, Object> config) {
// Legacy config support (single datasource
String projectName = JSONUtils.getString(config, "project");
DBPProject project = CommonUtils.isEmpty(projectName) ? null : DBWorkbench.getPlatform().getWorkspace().getProject(projectName);
if (project != null) {
String dataSourceContainerId = JSONUtils.getString(config, "dataSourceContainer");
if (!CommonUtils.isEmpty(dataSourceContainerId)) {
DBPDataSourceContainer dataSource = project.getDataSourceRegistry().getDataSource(dataSourceContainerId);
if (dataSource != null) {
dataSources.add(dataSource);
}
}
} else {
// Modern config (datasource list)
List<Map<String, Object>> dsConfig = JSONUtils.getObjectList(config, "dataSources");
for (Map<String, Object> dsInfo : dsConfig) {
projectName = JSONUtils.getString(dsInfo, "project");
project = CommonUtils.isEmpty(projectName) ? null : DBWorkbench.getPlatform().getWorkspace().getProject(projectName);
if (project != null) {
String dataSourceContainerId = JSONUtils.getString(dsInfo, "dataSource");
if (!CommonUtils.isEmpty(dataSourceContainerId)) {
DBPDataSourceContainer dataSource = project.getDataSourceRegistry().getDataSource(dataSourceContainerId);
if (dataSource != null) {
dataSources.add(dataSource);
}
}
}
}
}
scriptFiles = JSONUtils.deserializeStringList(config, "scriptFiles");
ignoreErrors = JSONUtils.getBoolean(config, "ignoreErrors");
dumpQueryResultsToLog = JSONUtils.getBoolean(config, "dumpQueryResultsToLog");
autoCommit = JSONUtils.getBoolean(config, "autoCommit");
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class SQLScriptTaskPageSettings method loadSettings.
public void loadSettings() {
SQLScriptExecuteSettings settings = sqlWizard.getSettings();
List<String> scriptFiles = settings.getScriptFiles();
for (String filePath : scriptFiles) {
IFile file = SQLScriptExecuteSettings.getWorkspaceFile(filePath);
if (file == null) {
log.debug("Script file '" + filePath + "' not found");
continue;
}
DBPProject currentProject = DBWorkbench.getPlatform().getWorkspace().getProject(file.getProject());
if (currentProject == null) {
log.debug("Project '" + file.getProject().getName() + "' not found");
continue;
}
DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(currentProject);
if (projectNode != null) {
DBNResource resource = projectNode.findResource(file);
if (resource != null) {
selectedScripts.add(resource);
}
}
}
scriptsViewer.setInput(selectedScripts);
for (DBPDataSourceContainer dataSource : settings.getDataSources()) {
DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(dataSource.getProject());
DBNDataSource dsNode = projectNode.getDatabases().getDataSource(dataSource);
if (dsNode != null) {
selectedDataSources.add(dsNode);
}
}
dataSourceViewer.setInput(selectedDataSources);
// if (!selectedDataSources.isEmpty()) {
// dataSourceTree.getCheckboxViewer().setCheckedElements(selectedDataSources.toArray());
// dataSourceTree.getCheckboxViewer().reveal(selectedDataSources.get(0));
// }
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class DiagramCreateWizard method init.
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
setWindowTitle(ERDUIMessages.wizard_diagram_create_title);
setNeedsProgressMonitor(true);
IFolder diagramFolder = null;
if (selection != null) {
Object element = selection.getFirstElement();
if (element != null) {
diagramFolder = Platform.getAdapterManager().getAdapter(element, IFolder.class);
}
}
if (diagramFolder == null) {
DBPProject activeProject = DBWorkbench.getPlatform().getWorkspace().getActiveProject();
if (activeProject == null) {
errorMessage = "Can't create diagram without active project";
} else {
try {
diagramFolder = ERDResourceHandler.getDiagramsFolder(activeProject, true);
} catch (CoreException e) {
errorMessage = e.getMessage();
}
}
// Check for entity selection
if (selection != null && !selection.isEmpty()) {
if (Platform.getAdapterManager().getAdapter(selection.getFirstElement(), DBSEntity.class) != null) {
entitySelection = selection;
}
}
}
this.folder = diagramFolder;
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by serge-rider.
the class ConnectionPageDriver method createControl.
@Override
public void createControl(Composite parent) {
Composite placeholder = UIUtils.createComposite(parent, 1);
{
driverSelectViewer = new DriverSelectViewer(placeholder, this, wizard.getAvailableProvides(), true);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 200;
driverSelectViewer.getControl().setLayoutData(gd);
}
setControl(placeholder);
Composite controlsGroup = UIUtils.createComposite(placeholder, 5);
controlsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// Navigator view preset
{
Composite presetComposite = new Composite(controlsGroup, SWT.NONE);
presetComposite.setLayout(new RowLayout());
new Label(presetComposite, SWT.NONE).setImage(DBeaverIcons.getImage(UIIcon.CONFIGURATION));
new Label(presetComposite, SWT.NONE).setText("Connection view: ");
for (DataSourceNavigatorSettings.Preset p : DataSourceNavigatorSettings.PRESETS.values()) {
if (p != DataSourceNavigatorSettings.PRESET_CUSTOM) {
Button pButton = new Button(presetComposite, SWT.RADIO);
pButton.setText(p.getName());
pButton.setToolTipText(p.getDescription());
if (p == navigatorPreset) {
pButton.setSelection(true);
}
pButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (pButton.getSelection()) {
navigatorPreset = p;
DBeaverActivator.getInstance().getPreferences().setValue(DEFAULT_NAVIGATOR_SETTINGS_RESET, navigatorPreset.getId());
}
}
});
}
}
}
{
// Spacer
new Label(controlsGroup, SWT.NONE).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
{
// Sorter
Composite orderGroup = new Composite(controlsGroup, SWT.NONE);
orderGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
orderGroup.setLayout(new RowLayout());
new Label(orderGroup, SWT.NONE).setImage(DBeaverIcons.getImage(UIIcon.SORT));
new Label(orderGroup, SWT.NONE).setText("Sort by: ");
for (DriverSelectViewer.OrderBy ob : DriverSelectViewer.OrderBy.values()) {
Button obScoreButton = new Button(orderGroup, SWT.RADIO);
obScoreButton.setText(ob.getLabel());
obScoreButton.setToolTipText(ob.getDescription());
obScoreButton.setData(ob);
if (ob == driverSelectViewer.getOrderBy()) {
obScoreButton.setSelection(true);
}
obScoreButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
driverSelectViewer.setOrderBy((DriverSelectViewer.OrderBy) obScoreButton.getData());
}
});
}
}
{
// Spacer
new Label(controlsGroup, SWT.NONE).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
final List<DBPProject> projects = DBWorkbench.getPlatform().getWorkspace().getProjects();
if (projects.size() == 1) {
if (connectionProject == null) {
connectionProject = projects.get(0);
}
} else if (projects.size() > 1) {
Composite projectGroup = UIUtils.createComposite(controlsGroup, 3);
projectGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
new Label(projectGroup, SWT.NONE).setImage(DBeaverIcons.getImage(DBIcon.PROJECT));
UIUtils.createControlLabel(projectGroup, CoreMessages.dialog_connection_driver_project);
final Combo projectCombo = new Combo(projectGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
projectCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
for (DBPProject project : projects) {
projectCombo.add(project.getName());
}
if (connectionProject == null) {
projectCombo.select(0);
connectionProject = projects.get(0);
} else {
projectCombo.setText(connectionProject.getName());
}
projectCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
connectionProject = projects.get(projectCombo.getSelectionIndex());
}
});
if (projects.size() < 2) {
// projectCombo.setEnabled(false);
}
} else {
setErrorMessage("You need to create a project first");
}
UIUtils.setHelp(placeholder, IHelpContextIds.CTX_CON_WIZARD_DRIVER);
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by serge-rider.
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;
}
Aggregations