Search in sources :

Example 51 with DBPProject

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");
}
Also used : DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 52 with DBPProject

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));
// }
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) IFile(org.eclipse.core.resources.IFile) SQLScriptExecuteSettings(org.jkiss.dbeaver.tools.sql.SQLScriptExecuteSettings) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 53 with DBPProject

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;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) IFolder(org.eclipse.core.resources.IFolder)

Example 54 with DBPProject

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);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) Combo(org.eclipse.swt.widgets.Combo) DriverSelectViewer(org.jkiss.dbeaver.ui.dialogs.driver.DriverSelectViewer) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 55 with DBPProject

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;
}
Also used : DBException(org.jkiss.dbeaver.DBException) CoreException(org.eclipse.core.runtime.CoreException) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) Document(org.w3c.dom.Document)

Aggregations

DBPProject (org.jkiss.dbeaver.model.app.DBPProject)90 IFile (org.eclipse.core.resources.IFile)20 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)18 DBException (org.jkiss.dbeaver.DBException)14 DBPDataSourceRegistry (org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)14 IFolder (org.eclipse.core.resources.IFolder)8 DBPWorkspace (org.jkiss.dbeaver.model.app.DBPWorkspace)8 IResource (org.eclipse.core.resources.IResource)6 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6 SelectionEvent (org.eclipse.swt.events.SelectionEvent)6 IEditorPart (org.eclipse.ui.IEditorPart)6 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)6 GridData (org.eclipse.swt.layout.GridData)5 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 ArrayList (java.util.ArrayList)4 CoreException (org.eclipse.core.runtime.CoreException)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 DBPImage (org.jkiss.dbeaver.model.DBPImage)4 Document (org.w3c.dom.Document)4