Search in sources :

Example 61 with DBPProject

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

the class AbstractNativeToolSettings method loadSettings.

public void loadSettings(DBRRunnableContext runnableContext, DBPPreferenceStore preferenceStore) throws DBException {
    if (dataSourceContainer == null && !CommonUtils.isEmpty(databaseObjects)) {
        BASE_OBJECT baseObject = databaseObjects.get(0);
        dataSourceContainer = baseObject instanceof DBPDataSourceContainer ? (DBPDataSourceContainer) baseObject : baseObject.getDataSource().getContainer();
    }
    if (dataSourceContainer == null) {
        String dsID = preferenceStore.getString("dataSource");
        if (!CommonUtils.isEmpty(dsID)) {
            String projectName = preferenceStore.getString("project");
            DBPProject project = CommonUtils.isEmpty(projectName) ? null : DBWorkbench.getPlatform().getWorkspace().getProject(projectName);
            if (project == null) {
                if (!CommonUtils.isEmpty(projectName)) {
                    log.error("Can't find project '" + projectName + "' for tool configuration");
                }
                project = DBWorkbench.getPlatform().getWorkspace().getActiveProject();
            }
            dataSourceContainer = project.getDataSourceRegistry().getDataSource(dsID);
            if (dataSourceContainer == null) {
                log.error("Can't find datasource '" + dsID + "' in project '" + project.getName() + "' for tool configuration");
            }
        }
    }
    if (preferenceStore instanceof DBPPreferenceMap && dataSourceContainer != null) {
        List<String> databaseObjectList = ((DBPPreferenceMap) preferenceStore).getObject("databaseObjects");
        if (!CommonUtils.isEmpty(databaseObjectList)) {
            DBPProject finalProject = dataSourceContainer.getProject();
            try {
                runnableContext.run(true, true, monitor -> {
                    monitor.beginTask("Load database object list", databaseObjectList.size());
                    try {
                        for (String objectId : databaseObjectList) {
                            monitor.subTask("Load " + objectId);
                            try {
                                DBSObject object = DBUtils.findObjectById(monitor, finalProject, objectId);
                                if (object != null) {
                                    databaseObjects.add((BASE_OBJECT) object);
                                    dataSourceContainer = object instanceof DBPDataSourceContainer ? (DBPDataSourceContainer) object : object.getDataSource().getContainer();
                                }
                            } catch (Throwable e) {
                                throw new DBException("Can't find database object '" + objectId + "' in project '" + finalProject.getName() + "' for task configuration", e);
                            }
                            monitor.worked(1);
                        }
                    } catch (Exception e) {
                        throw new InvocationTargetException(e);
                    } finally {
                        monitor.done();
                    }
                });
            } catch (InvocationTargetException e) {
                throw new DBException("Error loading objects configuration", e.getTargetException());
            } catch (InterruptedException e) {
            // Ignore
            }
        }
    }
    extraCommandArgs = preferenceStore.getString(PROP_NAME_EXTRA_ARGS);
    clientHomeName = preferenceStore.getString("clientHomeName");
    if (preferenceStore instanceof DBPPreferenceMap) {
        toolUserName = preferenceStore.getString("tool.user");
        toolUserPassword = preferenceStore.getString("tool.password");
        try {
            final SecuredPasswordEncrypter encrypter = new SecuredPasswordEncrypter();
            if (!CommonUtils.isEmpty(toolUserName))
                toolUserName = encrypter.decrypt(toolUserName);
            if (!CommonUtils.isEmpty(toolUserPassword))
                toolUserPassword = encrypter.decrypt(toolUserPassword);
        } catch (Exception e) {
            throw new DBException("Error decrypting user credentials", e);
        }
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPPreferenceMap(org.jkiss.dbeaver.model.preferences.DBPPreferenceMap) SecuredPasswordEncrypter(org.jkiss.dbeaver.runtime.encode.SecuredPasswordEncrypter) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 62 with DBPProject

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

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 63 with DBPProject

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

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 64 with DBPProject

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

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 65 with DBPProject

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

the class EditorUtils method getInputContextDefaults.

/**
 * String[2] = { defaultCatalogName, defaultSchema }
 */
public static String[] getInputContextDefaults(DBPDataSourceContainer dataSource, IEditorInput editorInput) {
    String defaultDatasource = null;
    String defaultCatalogName = null;
    String defaultSchema = null;
    if (editorInput instanceof INonPersistentEditorInput) {
        defaultDatasource = (String) ((INonPersistentEditorInput) editorInput).getProperty(PROP_CONTEXT_DEFAULT_DATASOURCE);
        defaultCatalogName = (String) ((INonPersistentEditorInput) editorInput).getProperty(PROP_CONTEXT_DEFAULT_CATALOG);
        defaultSchema = (String) ((INonPersistentEditorInput) editorInput).getProperty(PROP_CONTEXT_DEFAULT_SCHEMA);
    } else {
        IFile file = getFileFromInput(editorInput);
        if (file != null) {
            DBPProject projectMeta = DBWorkbench.getPlatform().getWorkspace().getProject(file.getProject());
            if (projectMeta != null) {
                defaultDatasource = (String) projectMeta.getResourceProperty(file, PROP_CONTEXT_DEFAULT_DATASOURCE);
                defaultCatalogName = (String) projectMeta.getResourceProperty(file, PROP_CONTEXT_DEFAULT_CATALOG);
                defaultSchema = (String) projectMeta.getResourceProperty(file, PROP_CONTEXT_DEFAULT_SCHEMA);
            }
        } else {
            File localFile = getLocalFileFromInput(editorInput);
            if (localFile != null) {
                final DBPExternalFileManager efManager = DBWorkbench.getPlatform().getExternalFileManager();
                defaultDatasource = (String) efManager.getFileProperty(localFile, PROP_CONTEXT_DEFAULT_DATASOURCE);
                defaultCatalogName = (String) efManager.getFileProperty(localFile, PROP_CONTEXT_DEFAULT_CATALOG);
                defaultSchema = (String) efManager.getFileProperty(localFile, PROP_CONTEXT_DEFAULT_SCHEMA);
            }
        }
    }
    if (!CommonUtils.isEmpty(defaultDatasource) && !defaultDatasource.equals(dataSource.getId())) {
        // Wrong datasource
        return new String[] { null, null };
    }
    return new String[] { defaultCatalogName, defaultSchema };
}
Also used : IFile(org.eclipse.core.resources.IFile) DBPExternalFileManager(org.jkiss.dbeaver.model.DBPExternalFileManager) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

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