Search in sources :

Example 6 with DBPExternalFileManager

use of org.jkiss.dbeaver.model.DBPExternalFileManager in project dbeaver by dbeaver.

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

DBPExternalFileManager (org.jkiss.dbeaver.model.DBPExternalFileManager)6 File (java.io.File)4 IFile (org.eclipse.core.resources.IFile)4 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)2 DBPProject (org.jkiss.dbeaver.model.app.DBPProject)2