Search in sources :

Example 1 with DBPExternalFileManager

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

the class EditorUtils method setFileDataSource.

public static void setFileDataSource(@NotNull File localFile, @NotNull DatabaseEditorContext context) {
    final DBPExternalFileManager efManager = DBWorkbench.getPlatform().getExternalFileManager();
    DBPDataSourceContainer dataSourceContainer = context.getDataSourceContainer();
    efManager.setFileProperty(localFile, PROP_SQL_PROJECT_ID, dataSourceContainer == null ? null : dataSourceContainer.getRegistry().getProject().getName());
    String dataSourceId = dataSourceContainer == null ? null : dataSourceContainer.getId();
    efManager.setFileProperty(localFile, PROP_SQL_DATA_SOURCE_ID, dataSourceId);
    if (!isDefaultContextSettings(context)) {
        efManager.setFileProperty(localFile, PROP_CONTEXT_DEFAULT_DATASOURCE, dataSourceId);
        String catalogName = getDefaultCatalogName(context);
        if (catalogName != null)
            efManager.setFileProperty(localFile, PROP_CONTEXT_DEFAULT_CATALOG, getDefaultCatalogName(context));
        String schemaName = getDefaultSchemaName(context);
        if (catalogName != null || schemaName != null)
            efManager.setFileProperty(localFile, PROP_CONTEXT_DEFAULT_SCHEMA, getDefaultCatalogName(context));
    }
}
Also used : DBPExternalFileManager(org.jkiss.dbeaver.model.DBPExternalFileManager) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 2 with DBPExternalFileManager

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

the class EditorUtils method setInputDataSource.

public static void setInputDataSource(@NotNull IEditorInput editorInput, @Nullable DBPDataSourceContainer dataSourceContainer, boolean notify) {
    if (editorInput instanceof INonPersistentEditorInput) {
        ((INonPersistentEditorInput) editorInput).setProperty(PROP_SQL_DATA_SOURCE, dataSourceContainer);
        return;
    }
    IFile file = getFileFromInput(editorInput);
    if (file != null) {
        setFileDataSource(file, dataSourceContainer, notify);
    } else {
        File localFile = getLocalFileFromInput(editorInput);
        if (localFile != null) {
            final DBPExternalFileManager efManager = DBeaverCore.getInstance().getExternalFileManager();
            efManager.setFileProperty(localFile, PROP_SQL_PROJECT, dataSourceContainer == null ? null : dataSourceContainer.getRegistry().getProject().getName());
            efManager.setFileProperty(localFile, PROP_SQL_DATA_SOURCE, dataSourceContainer == null ? null : dataSourceContainer.getId());
        } else {
            log.error("Can't set datasource for input " + editorInput);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) DBPExternalFileManager(org.jkiss.dbeaver.model.DBPExternalFileManager) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 3 with DBPExternalFileManager

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

the class EditorUtils method setInputDataSource.

public static void setInputDataSource(@NotNull IEditorInput editorInput, @Nullable DBPDataSourceContainer dataSourceContainer, boolean notify) {
    if (editorInput instanceof INonPersistentEditorInput) {
        ((INonPersistentEditorInput) editorInput).setProperty(PROP_SQL_DATA_SOURCE, dataSourceContainer);
        return;
    }
    IFile file = getFileFromInput(editorInput);
    if (file != null) {
        setFileDataSource(file, dataSourceContainer, notify);
    } else {
        File localFile = getLocalFileFromInput(editorInput);
        if (localFile != null) {
            final DBPExternalFileManager efManager = DBeaverCore.getInstance().getExternalFileManager();
            efManager.setFileProperty(localFile, PROP_SQL_PROJECT, dataSourceContainer == null ? null : dataSourceContainer.getRegistry().getProject().getName());
            efManager.setFileProperty(localFile, PROP_SQL_DATA_SOURCE, dataSourceContainer == null ? null : dataSourceContainer.getId());
        } else {
            log.error("Can't set datasource for input " + editorInput);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) DBPExternalFileManager(org.jkiss.dbeaver.model.DBPExternalFileManager) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 4 with DBPExternalFileManager

use of org.jkiss.dbeaver.model.DBPExternalFileManager 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)

Example 5 with DBPExternalFileManager

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

the class EditorUtils method setFileDataSource.

public static void setFileDataSource(@NotNull File localFile, @NotNull DatabaseEditorContext context) {
    final DBPExternalFileManager efManager = DBWorkbench.getPlatform().getExternalFileManager();
    DBPDataSourceContainer dataSourceContainer = context.getDataSourceContainer();
    efManager.setFileProperty(localFile, PROP_SQL_PROJECT_ID, dataSourceContainer == null ? null : dataSourceContainer.getRegistry().getProject().getName());
    String dataSourceId = dataSourceContainer == null ? null : dataSourceContainer.getId();
    efManager.setFileProperty(localFile, PROP_SQL_DATA_SOURCE_ID, dataSourceId);
    if (!isDefaultContextSettings(context)) {
        efManager.setFileProperty(localFile, PROP_CONTEXT_DEFAULT_DATASOURCE, dataSourceId);
        String catalogName = getDefaultCatalogName(context);
        if (catalogName != null)
            efManager.setFileProperty(localFile, PROP_CONTEXT_DEFAULT_CATALOG, getDefaultCatalogName(context));
        String schemaName = getDefaultSchemaName(context);
        if (catalogName != null || schemaName != null)
            efManager.setFileProperty(localFile, PROP_CONTEXT_DEFAULT_SCHEMA, getDefaultCatalogName(context));
    }
}
Also used : DBPExternalFileManager(org.jkiss.dbeaver.model.DBPExternalFileManager) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

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