Search in sources :

Example 1 with IRendererFactory

use of org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory in project eclipse.platform.ui by eclipse-platform.

the class TrimBarRenderer method cleanUp.

/**
 * @param element
 *            the trimBar to be cleaned up
 */
protected void cleanUp(MTrimBar element) {
    IRendererFactory rendererFactory = context.get(IRendererFactory.class);
    for (MTrimElement child : element.getPendingCleanup()) {
        element.getChildren().remove(child);
        if (child instanceof ToolBarImpl) {
            ToolBarImpl tb = (ToolBarImpl) child;
            releaseToolbar(rendererFactory, tb);
        }
    }
    element.getPendingCleanup().clear();
    List<MTrimElement> children = element.getChildren();
    for (MTrimElement mTrimElement : children) {
        if (mTrimElement instanceof ToolBarImpl) {
            ToolBarImpl tb = (ToolBarImpl) mTrimElement;
            releaseToolbar(rendererFactory, tb);
        }
    }
}
Also used : ToolBarImpl(org.eclipse.e4.ui.model.application.ui.menu.impl.ToolBarImpl) IRendererFactory(org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory) MTrimElement(org.eclipse.e4.ui.model.application.ui.basic.MTrimElement)

Example 2 with IRendererFactory

use of org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory in project eclipse.platform.ui by eclipse-platform.

the class MenuService method registerMenu.

public static Menu registerMenu(final Control parentControl, final MPopupMenu mmenu, IEclipseContext context) {
    if (mmenu.getWidget() != null) {
        return (Menu) mmenu.getWidget();
    }
    // we need to delegate to the renderer so that it "processes" the
    // MenuManager correctly
    IRendererFactory rendererFactory = context.get(IRendererFactory.class);
    AbstractPartRenderer renderer = rendererFactory.getRenderer(mmenu, parentControl);
    mmenu.setRenderer(renderer);
    IEclipseContext popupContext = context.createChild("popup:" + mmenu.getElementId());
    mmenu.setContext(popupContext);
    if (mmenu.getParent() == null) {
        mmenu.getTransientData().put(IPresentationEngine.RENDERING_PARENT_KEY, parentControl);
    }
    Object widget = renderer.createWidget(mmenu, parentControl);
    if (!(widget instanceof Menu)) {
        mmenu.getTransientData().remove(IPresentationEngine.RENDERING_PARENT_KEY);
        return null;
    }
    renderer.bindWidget(mmenu, widget);
    renderer.hookControllerLogic(mmenu);
    // Process its internal structure through the renderer that created
    // it
    Object castObject = mmenu;
    @SuppressWarnings("unchecked") MElementContainer<MUIElement> container = (MElementContainer<MUIElement>) castObject;
    renderer.processContents(container);
    // Allow a final chance to set up
    renderer.postProcess(mmenu);
    // Now that we have a widget let the parent (if any) know
    MElementContainer<MUIElement> parentElement = mmenu.getParent();
    if (parentElement != null) {
        AbstractPartRenderer parentRenderer = rendererFactory.getRenderer(parentElement, null);
        if (parentRenderer != null) {
            parentRenderer.childRendered(parentElement, mmenu);
        }
    }
    return (Menu) widget;
}
Also used : IRendererFactory(org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) MPopupMenu(org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu) MMenu(org.eclipse.e4.ui.model.application.ui.menu.MMenu) Menu(org.eclipse.swt.widgets.Menu) MElementContainer(org.eclipse.e4.ui.model.application.ui.MElementContainer)

Example 3 with IRendererFactory

use of org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory in project eclipse.platform.ui by eclipse-platform.

the class CompatibilityView method disposeSite.

@Override
void disposeSite(PartSite site) {
    IEclipseContext context = getModel().getContext();
    IRendererFactory rendererFactory = context.get(IRendererFactory.class);
    IActionBars actionBars = site.getActionBars();
    for (MMenu menu : part.getMenus()) {
        if (menu.getTags().contains(StackRenderer.TAG_VIEW_MENU)) {
            AbstractPartRenderer apr = rendererFactory.getRenderer(menu, null);
            if (apr instanceof MenuManagerRenderer) {
                MenuManagerRenderer renderer = (MenuManagerRenderer) apr;
                MenuManager mm = (MenuManager) actionBars.getMenuManager();
                renderer.clearModelToManager(menu, mm);
                clearOpaqueMenuItems(renderer, menu);
            }
            break;
        }
    }
    MToolBar toolbar = part.getToolbar();
    if (toolbar != null) {
        AbstractPartRenderer apr = rendererFactory.getRenderer(toolbar, null);
        if (apr instanceof ToolBarManagerRenderer) {
            ToolBarManager tbm = (ToolBarManager) actionBars.getToolBarManager();
            ToolBarManagerRenderer tbmr = (ToolBarManagerRenderer) apr;
            tbmr.clearModelToManager(toolbar, tbm);
            clearOpaqueToolBarItems(tbmr, toolbar);
        }
        toolbar.getTransientData().remove(ToolBarManagerRenderer.POST_PROCESSING_FUNCTION);
    }
    clearMenuServiceContributions(site, part);
    super.disposeSite(site);
}
Also used : MToolBar(org.eclipse.e4.ui.model.application.ui.menu.MToolBar) AbstractPartRenderer(org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer) ToolBarManagerRenderer(org.eclipse.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer) IRendererFactory(org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) MenuManager(org.eclipse.jface.action.MenuManager) MMenu(org.eclipse.e4.ui.model.application.ui.menu.MMenu) MenuManagerRenderer(org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer) IActionBars(org.eclipse.ui.IActionBars) ToolBarManager(org.eclipse.jface.action.ToolBarManager)

Example 4 with IRendererFactory

use of org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory in project eclipse.platform.ui by eclipse-platform.

the class CompatibilityView method createPartControl.

@Override
protected boolean createPartControl(IWorkbenchPart legacyPart, Composite parent) {
    clearMenuItems();
    part.getContext().set(IViewPart.class, (IViewPart) legacyPart);
    final IEclipseContext partContext = getModel().getContext();
    IRendererFactory rendererFactory = partContext.get(IRendererFactory.class);
    // Some views (i.e. Console) require that the actual ToolBar be
    // instantiated before they are
    final IActionBars actionBars = ((IViewPart) legacyPart).getViewSite().getActionBars();
    ToolBarManager tbm = (ToolBarManager) actionBars.getToolBarManager();
    Composite toolBarParent = new Composite(parent, SWT.NONE);
    tbm.createControl(toolBarParent);
    MenuManager mm = (MenuManager) actionBars.getMenuManager();
    MMenu menu = getViewMenu();
    if (menu == null) {
        menu = modelService.createModelElement(MMenu.class);
        // If the id contains a ':' use the part before it as the descriptor
        // id
        String partId = part.getElementId();
        int colonIndex = partId.indexOf(':');
        String descId = colonIndex == -1 ? partId : partId.substring(0, colonIndex);
        menu.setElementId(descId);
        menu.getTags().add(StackRenderer.TAG_VIEW_MENU);
        menu.getTags().add(ContributionsAnalyzer.MC_MENU);
        part.getMenus().add(menu);
    }
    AbstractPartRenderer apr = rendererFactory.getRenderer(menu, parent);
    if (apr instanceof MenuManagerRenderer) {
        MenuManagerRenderer renderer = (MenuManagerRenderer) apr;
        renderer.linkModelToManager(menu, mm);
    }
    // Construct the toolbar (if necessary)
    MToolBar toolbar = part.getToolbar();
    if (toolbar == null) {
        toolbar = modelService.createModelElement(MToolBar.class);
        // If the id contains a ':' use the part before it as the descriptor
        // id
        String partId = part.getElementId();
        int colonIndex = partId.indexOf(':');
        String descId = colonIndex == -1 ? partId : partId.substring(0, colonIndex);
        toolbar.setElementId(descId);
        part.setToolbar(toolbar);
    } else {
        // clear out the model entries so they can be re-created by
        // contributions
        // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=402561
        toolbar.getChildren().clear();
    }
    apr = rendererFactory.getRenderer(toolbar, parent);
    if (apr instanceof ToolBarManagerRenderer) {
        ((ToolBarManagerRenderer) apr).linkModelToManager(toolbar, tbm);
    }
    super.createPartControl(legacyPart, parent);
    ViewDescriptor desc = reference.getDescriptor();
    if (desc != null && desc.getPluginId() != null) {
        parent.setData(new ContributionInfo(desc.getPluginId(), ContributionInfoMessages.ContributionInfo_View, null));
    }
    // dispose the tb, it will be re-created when the tab is shown
    toolBarParent.dispose();
    apr = rendererFactory.getRenderer(menu, parent);
    if (apr instanceof MenuManagerRenderer) {
        MenuManagerRenderer renderer = (MenuManagerRenderer) apr;
        // create opaque items for any contribution items that were added
        // directly to the manager
        renderer.reconcileManagerToModel(mm, menu);
    }
    apr = rendererFactory.getRenderer(toolbar, parent);
    if (apr instanceof ToolBarManagerRenderer) {
        // create opaque items for any contribution items that were added
        // directly to the manager
        ((ToolBarManagerRenderer) apr).reconcileManagerToModel(tbm, toolbar);
    }
    final AtomicBoolean toolbarContributed = new AtomicBoolean();
    final IContextFunction func = new ContextFunction() {

        @Override
        public Object compute(IEclipseContext context, String contextKey) {
            if (toolbarContributed.getAndSet(true)) {
                // fix for bug 448873: don't contribute to the toolbar twice
                return null;
            }
            final ViewActionBuilder actionBuilder = new ViewActionBuilder();
            actionBuilder.readActionExtensions(getView());
            ActionDescriptor[] actionDescriptors = actionBuilder.getExtendedActions();
            if (actionDescriptors != null) {
                IHandlerService hs = partContext.get(IHandlerService.class);
                for (ActionDescriptor actionDescriptor : actionDescriptors) {
                    if (actionDescriptor != null) {
                        IAction action = actionDescriptor.getAction();
                        if (action != null && action.getActionDefinitionId() != null) {
                            hs.activateHandler(action.getActionDefinitionId(), new ActionHandler(action));
                        }
                    }
                }
            }
            actionBars.updateActionBars();
            Runnable dispose = actionBuilder::dispose;
            return dispose;
        }
    };
    if (toolbar.getWidget() == null) {
        toolbar.getTransientData().put(ToolBarManagerRenderer.POST_PROCESSING_FUNCTION, func);
    } else {
        toolbar.getTransientData().put(ToolBarManagerRenderer.POST_PROCESSING_DISPOSE, func.compute(partContext, null));
    }
    return true;
}
Also used : ActionDescriptor(org.eclipse.ui.internal.ActionDescriptor) ToolBarManager(org.eclipse.jface.action.ToolBarManager) ViewDescriptor(org.eclipse.ui.internal.registry.ViewDescriptor) IContextFunction(org.eclipse.e4.core.contexts.IContextFunction) IRendererFactory(org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory) IActionBars(org.eclipse.ui.IActionBars) Composite(org.eclipse.swt.widgets.Composite) ContributionInfo(org.eclipse.ui.testing.ContributionInfo) IAction(org.eclipse.jface.action.IAction) MMenu(org.eclipse.e4.ui.model.application.ui.menu.MMenu) MToolBar(org.eclipse.e4.ui.model.application.ui.menu.MToolBar) ViewActionBuilder(org.eclipse.ui.internal.ViewActionBuilder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ContextFunction(org.eclipse.e4.core.contexts.ContextFunction) IContextFunction(org.eclipse.e4.core.contexts.IContextFunction) AbstractPartRenderer(org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer) ToolBarManagerRenderer(org.eclipse.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer) IHandlerService(org.eclipse.ui.handlers.IHandlerService) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) MenuManager(org.eclipse.jface.action.MenuManager) MenuManagerRenderer(org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer) ActionHandler(org.eclipse.jface.commands.ActionHandler)

Example 5 with IRendererFactory

use of org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory in project eclipse.platform.ui by eclipse-platform.

the class WorkbenchMenuService method clearContributions.

/**
 * Disposes contributions created by service for given part. See bug 537046.
 *
 * @param site
 * @param part
 */
@Override
public void clearContributions(PartSite site, MPart part) {
    List<MToolBar> toolbars = getContributedToolbars(part);
    IEclipseContext context = part.getContext();
    IRendererFactory rendererFactory = context.get(IRendererFactory.class);
    IActionBars actionBars = site.getActionBars();
    if (toolbars != null) {
        for (MToolBar mToolBar : toolbars) {
            ((Notifier) mToolBar).eAdapters().clear();
            AbstractPartRenderer apr = rendererFactory.getRenderer(mToolBar, null);
            if (apr instanceof ToolBarManagerRenderer) {
                ToolBarManager tbm = (ToolBarManager) actionBars.getToolBarManager();
                ToolBarManagerRenderer tbmr = (ToolBarManagerRenderer) apr;
                tbmr.clearModelToManager(mToolBar, tbm);
                CompatibilityView.clearOpaqueToolBarItems(tbmr, mToolBar);
            }
            mToolBar.getTransientData().remove(ToolBarManagerRenderer.POST_PROCESSING_FUNCTION);
            final IPresentationEngine engine = context.get(IPresentationEngine.class);
            engine.removeGui(mToolBar);
            mToolBar.getTransientData().remove(ModelUtils.CONTAINING_PARENT);
        }
    }
    List<MMenu> menus = getContributedMenus(part);
    if (menus != null) {
        for (MMenu mMenu : menus) {
            ((Notifier) mMenu).eAdapters().clear();
            AbstractPartRenderer apr = rendererFactory.getRenderer(mMenu, null);
            if (apr instanceof MenuManagerRenderer) {
                MenuManager tbm = (MenuManager) actionBars.getMenuManager();
                MenuManagerRenderer tbmr = (MenuManagerRenderer) apr;
                tbmr.clearModelToManager(mMenu, tbm);
                CompatibilityView.clearOpaqueMenuItems(tbmr, mMenu);
            }
            final IPresentationEngine engine = context.get(IPresentationEngine.class);
            engine.removeGui(mMenu);
            mMenu.getTransientData().remove(ModelUtils.CONTAINING_PARENT);
        }
    }
}
Also used : IPresentationEngine(org.eclipse.e4.ui.workbench.IPresentationEngine) MMenu(org.eclipse.e4.ui.model.application.ui.menu.MMenu) ToolBarManager(org.eclipse.jface.action.ToolBarManager) MToolBar(org.eclipse.e4.ui.model.application.ui.menu.MToolBar) AbstractPartRenderer(org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer) ToolBarManagerRenderer(org.eclipse.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer) IRendererFactory(org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) MenuManager(org.eclipse.jface.action.MenuManager) MenuManagerRenderer(org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer) IActionBars(org.eclipse.ui.IActionBars)

Aggregations

IRendererFactory (org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory)19 AbstractPartRenderer (org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer)16 MenuManagerRenderer (org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer)13 MMenu (org.eclipse.e4.ui.model.application.ui.menu.MMenu)9 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)7 MToolBar (org.eclipse.e4.ui.model.application.ui.menu.MToolBar)7 ToolBarManagerRenderer (org.eclipse.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer)6 MenuManager (org.eclipse.jface.action.MenuManager)5 ToolBarManager (org.eclipse.jface.action.ToolBarManager)5 MUIElement (org.eclipse.e4.ui.model.application.ui.MUIElement)4 IPresentationEngine (org.eclipse.e4.ui.workbench.IPresentationEngine)3 IActionBars (org.eclipse.ui.IActionBars)3 ArrayList (java.util.ArrayList)2 IContributionFactory (org.eclipse.e4.core.services.contributions.IContributionFactory)2 MApplicationElement (org.eclipse.e4.ui.model.application.MApplicationElement)2 MElementContainer (org.eclipse.e4.ui.model.application.ui.MElementContainer)2 MPopupMenu (org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu)2 Composite (org.eclipse.swt.widgets.Composite)2 Menu (org.eclipse.swt.widgets.Menu)2 ToolBar (org.eclipse.swt.widgets.ToolBar)2