use of org.jkiss.dbeaver.ui.editors.DatabaseLazyEditorInput in project dbeaver by serge-rider.
the class SelectActiveSchemaHandler method updateElement.
@Override
public void updateElement(UIElement element, Map parameters) {
if ("true".equals(parameters.get("noCustomLabel"))) {
return;
}
IWorkbenchWindow workbenchWindow = element.getServiceLocator().getService(IWorkbenchWindow.class);
if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
return;
}
IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
if (activeEditor == null) {
return;
}
String schemaName = "< N/A >";
DBIcon schemaIcon = DBIcon.TREE_SCHEMA;
String schemaTooltip = UINavigatorMessages.toolbar_datasource_selector_combo_database_tooltip;
DBPDataSourceContainer dataSource = DataSourceToolbarUtils.getCurrentDataSource(workbenchWindow);
if (dataSource != null && dataSource.isConnected()) {
// schemaName = "<no schema>";
IEditorInput editorInput = activeEditor.getEditorInput();
if (editorInput instanceof IDatabaseEditorInput) {
if (editorInput instanceof DatabaseLazyEditorInput) {
activeEditor.addPropertyListener(new IPropertyListener() {
@Override
public void propertyChanged(Object source, int propId) {
if (EntityEditor.PROP_TITLE == propId) {
DataSourceToolbarUtils.updateCommandsUI();
activeEditor.removePropertyListener(this);
}
}
});
}
DBCExecutionContext executionContext = ((IDatabaseEditorInput) editorInput).getExecutionContext();
if (executionContext != null) {
DBSObject schemaObject = DBUtils.getSelectedObject(executionContext);
if (schemaObject != null && DBUtils.getPublicObjectContainer(schemaObject) != dataSource) {
DBSObject schemaParent = schemaObject.getParentObject();
if (schemaParent instanceof DBSObjectContainer && !(schemaParent instanceof DBPDataSource)) {
schemaName = schemaObject.getName() + "@" + schemaParent.getName();
} else {
schemaName = schemaObject.getName();
}
}
}
} else {
DBCExecutionContext executionContext = getExecutionContextFromPart(activeEditor);
DBCExecutionContextDefaults contextDefaults = null;
if (executionContext != null) {
contextDefaults = executionContext.getContextDefaults();
}
if (contextDefaults != null) {
DBSCatalog defaultCatalog = contextDefaults.getDefaultCatalog();
DBSSchema defaultSchema = contextDefaults.getDefaultSchema();
if (defaultCatalog != null && (defaultSchema != null || contextDefaults.supportsSchemaChange())) {
schemaName = defaultSchema == null ? "?" : defaultSchema.getName() + "@" + defaultCatalog.getName();
schemaIcon = DBIcon.TREE_SCHEMA;
} else if (defaultCatalog != null) {
schemaName = defaultCatalog.getName();
schemaIcon = DBIcon.TREE_DATABASE;
} else if (defaultSchema != null) {
schemaName = defaultSchema.getName();
schemaIcon = DBIcon.TREE_SCHEMA;
}
}
}
}
element.setText(schemaName);
element.setIcon(DBeaverIcons.getImageDescriptor(schemaIcon));
element.setTooltip(schemaTooltip);
}
use of org.jkiss.dbeaver.ui.editors.DatabaseLazyEditorInput in project dbeaver by dbeaver.
the class SelectActiveSchemaHandler method updateElement.
@Override
public void updateElement(UIElement element, Map parameters) {
if ("true".equals(parameters.get("noCustomLabel"))) {
return;
}
IWorkbenchWindow workbenchWindow = element.getServiceLocator().getService(IWorkbenchWindow.class);
if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
return;
}
IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
if (activeEditor == null) {
return;
}
String schemaName = "< N/A >";
DBIcon schemaIcon = DBIcon.TREE_SCHEMA;
String schemaTooltip = UINavigatorMessages.toolbar_datasource_selector_combo_database_tooltip;
DBPDataSourceContainer dataSource = DataSourceToolbarUtils.getCurrentDataSource(workbenchWindow);
if (dataSource != null && dataSource.isConnected()) {
// schemaName = "<no schema>";
IEditorInput editorInput = activeEditor.getEditorInput();
if (editorInput instanceof IDatabaseEditorInput) {
if (editorInput instanceof DatabaseLazyEditorInput) {
activeEditor.addPropertyListener(new IPropertyListener() {
@Override
public void propertyChanged(Object source, int propId) {
if (EntityEditor.PROP_TITLE == propId) {
DataSourceToolbarUtils.updateCommandsUI();
activeEditor.removePropertyListener(this);
}
}
});
}
DBCExecutionContext executionContext = ((IDatabaseEditorInput) editorInput).getExecutionContext();
if (executionContext != null) {
DBSObject schemaObject = DBUtils.getSelectedObject(executionContext);
if (schemaObject != null && DBUtils.getPublicObjectContainer(schemaObject) != dataSource) {
DBSObject schemaParent = schemaObject.getParentObject();
if (schemaParent instanceof DBSObjectContainer && !(schemaParent instanceof DBPDataSource)) {
schemaName = schemaObject.getName() + "@" + schemaParent.getName();
} else {
schemaName = schemaObject.getName();
}
}
}
} else {
DBCExecutionContext executionContext = getExecutionContextFromPart(activeEditor);
DBCExecutionContextDefaults contextDefaults = null;
if (executionContext != null) {
contextDefaults = executionContext.getContextDefaults();
}
if (contextDefaults != null) {
DBSCatalog defaultCatalog = contextDefaults.getDefaultCatalog();
DBSSchema defaultSchema = contextDefaults.getDefaultSchema();
if (defaultCatalog != null && (defaultSchema != null || contextDefaults.supportsSchemaChange())) {
schemaName = defaultSchema == null ? "?" : defaultSchema.getName() + "@" + defaultCatalog.getName();
schemaIcon = DBIcon.TREE_SCHEMA;
} else if (defaultCatalog != null) {
schemaName = defaultCatalog.getName();
schemaIcon = DBIcon.TREE_DATABASE;
} else if (defaultSchema != null) {
schemaName = defaultSchema.getName();
schemaIcon = DBIcon.TREE_SCHEMA;
}
}
}
}
element.setText(schemaName);
element.setIcon(DBeaverIcons.getImageDescriptor(schemaIcon));
element.setTooltip(schemaTooltip);
}
Aggregations