Search in sources :

Example 1 with MElementContainer

use of org.eclipse.e4.ui.model.application.ui.MElementContainer in project nebula.widgets.nattable by eclipse.

the class LifecycleManager method preSave.

@PreSave
void preSave(EModelService modelService, MApplication app) {
    List<String> tags = new ArrayList<>();
    tags.add(CLOSE_ON_SHUTDOWN_TAG);
    List<MPart> elementsWithTags = modelService.findElements(app, null, MPart.class, tags);
    for (MPart part : elementsWithTags) {
        try {
            part.setToBeRendered(false);
            part.setVisible(false);
            MElementContainer<MUIElement> parent = part.getParent();
            parent.getChildren().remove(part);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) ArrayList(java.util.ArrayList) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) PreSave(org.eclipse.e4.ui.workbench.lifecycle.PreSave)

Example 2 with MElementContainer

use of org.eclipse.e4.ui.model.application.ui.MElementContainer in project portfolio by buchen.

the class LifeCycleManager method removePortfolioPartsWithoutPersistedFile.

private void removePortfolioPartsWithoutPersistedFile(MApplication app, EPartService partService, EModelService modelService) {
    List<MPart> parts = modelService.findElements(app, MPart.class, EModelService.IN_ACTIVE_PERSPECTIVE, new Selector() {

        @Override
        public boolean select(MApplicationElement element) {
            if (// $NON-NLS-1$
            !"name.abuchen.portfolio.ui.part.portfolio".equals(element.getElementId()))
                return false;
            // $NON-NLS-1$
            return element.getPersistedState().get("file") == null;
        }
    });
    for (MPart part : parts) {
        MElementContainer<MUIElement> parent = part.getParent();
        if (parent.getSelectedElement().equals(part))
            parent.setSelectedElement(null);
        parent.getChildren().remove(part);
    }
}
Also used : MApplicationElement(org.eclipse.e4.ui.model.application.MApplicationElement) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) Selector(org.eclipse.e4.ui.workbench.Selector)

Example 3 with MElementContainer

use of org.eclipse.e4.ui.model.application.ui.MElementContainer 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 4 with MElementContainer

use of org.eclipse.e4.ui.model.application.ui.MElementContainer 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

MUIElement (org.eclipse.e4.ui.model.application.ui.MUIElement)4 MElementContainer (org.eclipse.e4.ui.model.application.ui.MElementContainer)2 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)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 ArrayList (java.util.ArrayList)1 MApplicationElement (org.eclipse.e4.ui.model.application.MApplicationElement)1 Selector (org.eclipse.e4.ui.workbench.Selector)1 PreSave (org.eclipse.e4.ui.workbench.lifecycle.PreSave)1