Search in sources :

Example 1 with MTrimElement

use of org.eclipse.e4.ui.model.application.ui.basic.MTrimElement in project dbeaver by dbeaver.

the class DataSourceToolbarUtils method refreshSelectorToolbar.

public static void refreshSelectorToolbar(IWorkbenchWindow window) {
    if (window instanceof WorkbenchWindow) {
        MTrimBar topTrim = ((WorkbenchWindow) window).getTopTrim();
        for (MTrimElement element : topTrim.getChildren()) {
            if (CONNECTION_SELECTOR_TOOLBAR_ID.equals(element.getElementId())) {
                boolean showConnectionSelector = false;
                IEditorPart activeEditor = window.getActivePage().getActiveEditor();
                DBPDataSourceContainer dataSourceContainer = null;
                if (activeEditor instanceof IDataSourceContainerProvider) {
                    showConnectionSelector = true;
                    dataSourceContainer = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
                }
                if (element instanceof MElementContainer) {
                    Object widget = element.getWidget();
                    if (widget instanceof Composite) {
                        Composite controlsPanel = (Composite) widget;
                        Color bgColor = dataSourceContainer == null ? null : UIUtils.getConnectionTypeColor(dataSourceContainer.getConnectionConfiguration().getConnectionType());
                        Control[] childControl = controlsPanel.getChildren();
                        for (Control cc : childControl) {
                            // if (bgColor != null) {
                            // Color oldBackground = cc.getBackground();
                            // if (oldBackground != null) {
                            // RGB newBackground = UIUtils.blend(oldBackground.getRGB(), bgColor.getRGB(), 50);
                            // cc.setBackground(UIUtils.getSharedColor(newBackground));
                            // continue;
                            // }
                            // }
                            cc.setBackground(bgColor);
                        }
                    }
                    MElementContainer<? extends MUIElement> container = (MElementContainer<? extends MUIElement>) element;
                    for (MUIElement tbItem : container.getChildren()) {
                        // So we need to hide/show it to force text update
                        if (showConnectionSelector) {
                            tbItem.setVisible(false);
                        }
                        tbItem.setVisible(showConnectionSelector);
                    }
                }
                return;
            }
        }
    }
    // By some reason we can't locate the toolbar (#5712?). Let's just refresh elements then - its better than nothing
    updateCommandsUI();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) WorkbenchWindow(org.eclipse.ui.internal.WorkbenchWindow) IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) Composite(org.eclipse.swt.widgets.Composite) Color(org.eclipse.swt.graphics.Color) IEditorPart(org.eclipse.ui.IEditorPart) MElementContainer(org.eclipse.e4.ui.model.application.ui.MElementContainer) MTrimBar(org.eclipse.e4.ui.model.application.ui.basic.MTrimBar) Control(org.eclipse.swt.widgets.Control) MTrimElement(org.eclipse.e4.ui.model.application.ui.basic.MTrimElement) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 2 with MTrimElement

use of org.eclipse.e4.ui.model.application.ui.basic.MTrimElement in project dbeaver by serge-rider.

the class DataSourceToolbarUtils method refreshSelectorToolbar.

public static void refreshSelectorToolbar(IWorkbenchWindow window) {
    if (window instanceof WorkbenchWindow) {
        MTrimBar topTrim = ((WorkbenchWindow) window).getTopTrim();
        for (MTrimElement element : topTrim.getChildren()) {
            if (CONNECTION_SELECTOR_TOOLBAR_ID.equals(element.getElementId())) {
                boolean showConnectionSelector = false;
                IEditorPart activeEditor = window.getActivePage().getActiveEditor();
                DBPDataSourceContainer dataSourceContainer = null;
                if (activeEditor instanceof IDataSourceContainerProvider) {
                    showConnectionSelector = true;
                    dataSourceContainer = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
                }
                if (element instanceof MElementContainer) {
                    Object widget = element.getWidget();
                    if (widget instanceof Composite) {
                        Composite controlsPanel = (Composite) widget;
                        Color bgColor = dataSourceContainer == null ? null : UIUtils.getConnectionTypeColor(dataSourceContainer.getConnectionConfiguration().getConnectionType());
                        Control[] childControl = controlsPanel.getChildren();
                        for (Control cc : childControl) {
                            // if (bgColor != null) {
                            // Color oldBackground = cc.getBackground();
                            // if (oldBackground != null) {
                            // RGB newBackground = UIUtils.blend(oldBackground.getRGB(), bgColor.getRGB(), 50);
                            // cc.setBackground(UIUtils.getSharedColor(newBackground));
                            // continue;
                            // }
                            // }
                            cc.setBackground(bgColor);
                        }
                    }
                    MElementContainer<? extends MUIElement> container = (MElementContainer<? extends MUIElement>) element;
                    for (MUIElement tbItem : container.getChildren()) {
                        // So we need to hide/show it to force text update
                        if (showConnectionSelector) {
                            tbItem.setVisible(false);
                        }
                        tbItem.setVisible(showConnectionSelector);
                    }
                }
                return;
            }
        }
    }
    // By some reason we can't locate the toolbar (#5712?). Let's just refresh elements then - its better than nothing
    updateCommandsUI();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) WorkbenchWindow(org.eclipse.ui.internal.WorkbenchWindow) IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) Composite(org.eclipse.swt.widgets.Composite) Color(org.eclipse.swt.graphics.Color) IEditorPart(org.eclipse.ui.IEditorPart) MElementContainer(org.eclipse.e4.ui.model.application.ui.MElementContainer) MTrimBar(org.eclipse.e4.ui.model.application.ui.basic.MTrimBar) Control(org.eclipse.swt.widgets.Control) MTrimElement(org.eclipse.e4.ui.model.application.ui.basic.MTrimElement) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Aggregations

MElementContainer (org.eclipse.e4.ui.model.application.ui.MElementContainer)2 MUIElement (org.eclipse.e4.ui.model.application.ui.MUIElement)2 MTrimBar (org.eclipse.e4.ui.model.application.ui.basic.MTrimBar)2 MTrimElement (org.eclipse.e4.ui.model.application.ui.basic.MTrimElement)2 Color (org.eclipse.swt.graphics.Color)2 Composite (org.eclipse.swt.widgets.Composite)2 Control (org.eclipse.swt.widgets.Control)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 WorkbenchWindow (org.eclipse.ui.internal.WorkbenchWindow)2 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)2 IDataSourceContainerProvider (org.jkiss.dbeaver.model.IDataSourceContainerProvider)2