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 };
}
Aggregations