use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.
the class EntityEditor method refreshPart.
@Override
public void refreshPart(final Object source, boolean force) {
if (getContainer() == null || getContainer().isDisposed() || isSaveInProgress()) {
return;
}
if (force && isDirty()) {
if (ConfirmationDialog.showConfirmDialog(ResourceBundle.getBundle(UINavigatorMessages.BUNDLE_NAME), null, NavigatorPreferences.CONFIRM_ENTITY_REVERT, ConfirmationDialog.QUESTION, getTitle()) != IDialogConstants.YES_ID) {
return;
}
}
if (source instanceof DBNEvent && ((DBNEvent) source).getNodeChange() == DBNEvent.NodeChange.REFRESH) {
// This may happen if editor was refreshed indirectly (it is a child of refreshed node)
// force = true;
}
if (force && getDatabaseObject().isPersisted()) {
// Lists and commands should be refreshed only if we make real refresh from remote storage
// Otherwise just update object's properties
DBECommandContext commandContext = getCommandContext();
if (commandContext != null && commandContext.isDirty()) {
// Just clear command context. Do not undo because object state was already refreshed
commandContext.resetChanges(true);
}
}
DBSObject databaseObject = getEditorInput().getDatabaseObject();
if (databaseObject != null) {
// Refresh visual content in parts
for (IEditorPart editor : editorMap.values()) {
if (editor instanceof IRefreshablePart) {
((IRefreshablePart) editor).refreshPart(source, force);
}
}
}
setPartName(getEditorInput().getName());
setTitleImage(getEditorInput().getImageDescriptor());
if (hasPropertiesEditor) {
// Update main editor image
setPageImage(0, DBeaverIcons.getImage(getEditorInput().getNavigatorNode().getNodeIconDefault()));
}
}
use of org.jkiss.dbeaver.model.struct.DBSObject 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.model.struct.DBSObject in project dbeaver by serge-rider.
the class AbstractDataSourceHandler method getActiveExecutionContext.
/**
* Get execution context from active editor or active selection
*/
public static DBCExecutionContext getActiveExecutionContext(ExecutionEvent event, boolean useEditor) {
if (useEditor) {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof DBPContextProvider) {
return ((DBPContextProvider) editor).getExecutionContext();
}
return null;
}
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
if (activePart instanceof DBPContextProvider) {
return ((DBPContextProvider) activePart).getExecutionContext();
}
ISelection selection = HandlerUtil.getCurrentSelection(event);
DBSObject selectedObject = NavigatorUtils.getSelectedObject(selection);
if (selectedObject != null) {
return DBUtils.getDefaultContext(selectedObject, false);
}
return null;
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.
the class AbstractDataSourceHandler method getActiveDataSourceContainer.
public static DBPDataSourceContainer getActiveDataSourceContainer(ExecutionEvent event, boolean useEditor) {
if (useEditor) {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor != null) {
DBPDataSourceContainer container = getDataSourceContainerFromPart(editor);
if (container != null) {
return container;
}
}
return null;
}
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
DBPDataSourceContainer container = getDataSourceContainerFromPart(activePart);
if (container != null) {
return container;
}
ISelection selection = HandlerUtil.getCurrentSelection(event);
DBSObject selectedObject = NavigatorUtils.getSelectedObject(selection);
if (selectedObject instanceof DBPDataSourceContainer) {
return (DBPDataSourceContainer) selectedObject;
} else if (selectedObject != null) {
DBPDataSource dataSource = selectedObject.getDataSource();
return dataSource == null ? null : dataSource.getContainer();
}
return null;
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.
the class EntityEditor method updateEditorDefaults.
private void updateEditorDefaults(String pageId, @Nullable String folderId) {
IDatabaseEditorInput editorInput = getEditorInput();
if (editorInput instanceof DatabaseEditorInput) {
((DatabaseEditorInput) editorInput).setDefaultPageId(pageId);
((DatabaseEditorInput) editorInput).setDefaultFolderId(folderId);
}
DBSObject object = editorInput.getDatabaseObject();
if (object != null) {
synchronized (defaultPageMap) {
EditorDefaults editorDefaults = defaultPageMap.get(object.getClass().getName());
if (editorDefaults == null) {
editorDefaults = new EditorDefaults(pageId, folderId);
defaultPageMap.put(object.getClass().getName(), editorDefaults);
} else {
if (pageId != null) {
editorDefaults.pageId = pageId;
}
if (folderId != null) {
editorDefaults.folderId = folderId;
}
}
}
}
}
Aggregations