Search in sources :

Example 86 with DBPProject

use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.

the class SelectDataSourceCombo method addProjectDataSources.

public void addProjectDataSources() {
    addItem(null);
    DBPProject activeProject = getActiveProject();
    if (activeProject != null) {
        for (DBPDataSourceContainer ds : activeProject.getDataSourceRegistry().getDataSources()) {
            addItem(ds);
        }
    }
}
Also used : DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 87 with DBPProject

use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.

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();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) IEditorPart(org.eclipse.ui.IEditorPart)

Example 88 with DBPProject

use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.

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);
}
Also used : DBPProject(org.jkiss.dbeaver.model.app.DBPProject) IEditorPart(org.eclipse.ui.IEditorPart) SelectDataSourceDialog(org.jkiss.dbeaver.ui.navigator.dialogs.SelectDataSourceDialog)

Example 89 with DBPProject

use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.

the class SQLEditor method getDataSourceFromContent.

private DBPDataSourceContainer getDataSourceFromContent() {
    DBPProject project = getProject();
    IDocument document = getDocument();
    if (document == null || document.getNumberOfLines() == 0) {
        return null;
    }
    try {
        IRegion region = document.getLineInformation(0);
        String line = document.get(region.getOffset(), region.getLength());
        Matcher matcher = EMBEDDED_BINDING_PREFIX_PATTERN.matcher(line);
        if (matcher.matches()) {
            String connSpec = matcher.group(1).trim();
            if (!CommonUtils.isEmpty(connSpec)) {
                final DBPDataSourceContainer dataSource = DataSourceUtils.getDataSourceBySpec(project, connSpec, null, true, false);
                if (dataSource != null) {
                    return dataSource;
                }
            }
        }
    } catch (Throwable e) {
        log.debug("Error extracting datasource info from script's content", e);
    }
    return null;
}
Also used : Matcher(java.util.regex.Matcher) DBPProject(org.jkiss.dbeaver.model.app.DBPProject)

Example 90 with DBPProject

use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.

the class PrefPageProjectResourceSettings method performOk.

@Override
public boolean performOk() {
    java.util.List<IResource> refreshedResources = new ArrayList<>();
    // Save roots
    DBPProject projectMeta = getProjectMeta();
    if (projectMeta != null) {
        for (TableItem item : resourceTable.getItems()) {
            DBPResourceHandlerDescriptor descriptor = (DBPResourceHandlerDescriptor) item.getData();
            String rootPath = item.getText(1);
            if (!CommonUtils.equalObjects(descriptor.getDefaultRoot(projectMeta), rootPath)) {
                IResource oldResource = project.findMember(descriptor.getDefaultRoot(projectMeta));
                if (oldResource != null) {
                    refreshedResources.add(oldResource);
                }
                IResource newResource = project.findMember(rootPath);
                if (newResource != null) {
                    refreshedResources.add(newResource);
                }
                descriptor.setDefaultRoot(projectMeta, rootPath);
            }
        }
        if (!refreshedResources.isEmpty()) {
            for (IResource resource : refreshedResources) {
                DBNUtils.refreshNavigatorResource(resource, this);
            }
        }
    }
    return super.performOk();
}
Also used : DBPResourceHandlerDescriptor(org.jkiss.dbeaver.model.app.DBPResourceHandlerDescriptor) ArrayList(java.util.ArrayList) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) IResource(org.eclipse.core.resources.IResource)

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