Search in sources :

Example 1 with DatabaseLazyEditorInput

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);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DBCExecutionContextDefaults(org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults) DatabaseLazyEditorInput(org.jkiss.dbeaver.ui.editors.DatabaseLazyEditorInput) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBSCatalog(org.jkiss.dbeaver.model.struct.rdb.DBSCatalog) IEditorPart(org.eclipse.ui.IEditorPart) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) IPropertyListener(org.eclipse.ui.IPropertyListener) IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) DBSSchema(org.jkiss.dbeaver.model.struct.rdb.DBSSchema) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) DBIcon(org.jkiss.dbeaver.model.DBIcon) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IEditorInput(org.eclipse.ui.IEditorInput)

Example 2 with DatabaseLazyEditorInput

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);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DBCExecutionContextDefaults(org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults) DatabaseLazyEditorInput(org.jkiss.dbeaver.ui.editors.DatabaseLazyEditorInput) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBSCatalog(org.jkiss.dbeaver.model.struct.rdb.DBSCatalog) IEditorPart(org.eclipse.ui.IEditorPart) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) IPropertyListener(org.eclipse.ui.IPropertyListener) IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) DBSSchema(org.jkiss.dbeaver.model.struct.rdb.DBSSchema) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) DBIcon(org.jkiss.dbeaver.model.DBIcon) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

IEditorInput (org.eclipse.ui.IEditorInput)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IPropertyListener (org.eclipse.ui.IPropertyListener)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 DBIcon (org.jkiss.dbeaver.model.DBIcon)2 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)2 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)2 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)2 DBCExecutionContextDefaults (org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults)2 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)2 DBSObjectContainer (org.jkiss.dbeaver.model.struct.DBSObjectContainer)2 DBSCatalog (org.jkiss.dbeaver.model.struct.rdb.DBSCatalog)2 DBSSchema (org.jkiss.dbeaver.model.struct.rdb.DBSSchema)2 DatabaseLazyEditorInput (org.jkiss.dbeaver.ui.editors.DatabaseLazyEditorInput)2 IDatabaseEditorInput (org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput)2