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);
}
}
}
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;
}
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);
}
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;
}
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);
}
}
}
Aggregations