public static void addToolBarContributions( final MToolBar toolbarModel, ArrayList<MToolBarContribution> toContribute, IEclipseContext ctx, final ExpressionContext eContext, HashMap<MToolBar, ArrayList<ArrayList<MToolBarElement>>> pendingCleanup) { HashSet<String> existingSeparatorNames = new HashSet<String>(); for (MToolBarElement child : toolbarModel.getChildren()) { String elementId = child.getElementId(); if (child instanceof MToolBarSeparator && elementId != null) { existingSeparatorNames.add(elementId); } } boolean done = toContribute.size() == 0; while (!done) { ArrayList<MToolBarContribution> curList = new ArrayList<MToolBarContribution>(toContribute); int retryCount = toContribute.size(); toContribute.clear(); for (final MToolBarContribution contribution : curList) { final ArrayList<MToolBarElement> toRemove = new ArrayList<MToolBarElement>(); if (!ContributionsAnalyzer.processAddition( toolbarModel, contribution, toRemove, existingSeparatorNames)) { toContribute.add(contribution); } else { if (contribution.getVisibleWhen() != null) { ctx.runAndTrack( new RunAndTrack() { @Override public boolean changed(IEclipseContext context) { if (!toolbarModel.isToBeRendered() || !toolbarModel.isVisible() || toolbarModel.getWidget() == null) { return false; } boolean rc = ContributionsAnalyzer.isVisible(contribution, eContext); for (MToolBarElement child : toRemove) { child.setToBeRendered(rc); } return true; } }); } ArrayList<ArrayList<MToolBarElement>> lists = pendingCleanup.get(toolbarModel); if (lists == null) { lists = new ArrayList<ArrayList<MToolBarElement>>(); pendingCleanup.put(toolbarModel, lists); } lists.add(toRemove); } } // We're done if the retryList is now empty (everything done) or // if the list hasn't changed at all (no hope) done = (toContribute.size() == 0) || (toContribute.size() == retryCount); } }
/** * @param menuManager * @param element * @param evalContext */ public static void updateVisibility( MenuManager menuManager, MMenuElement element, ExpressionContext evalContext) { if (!(element.getVisibleWhen() instanceof MCoreExpression)) { return; } boolean val = ContributionsAnalyzer.isVisible((MCoreExpression) element.getVisibleWhen(), evalContext); if (val != element.isVisible()) { element.setVisible(val); menuManager.markDirty(); } }
public boolean computeVisibility( HashSet<ToolBarContributionRecord> recentlyUpdated, MToolBarElement item, ExpressionContext exprContext) { boolean currentVisibility = isVisible; if (currentVisibility && item.getVisibleWhen() instanceof MCoreExpression) { boolean val = ContributionsAnalyzer.isVisible((MCoreExpression) item.getVisibleWhen(), exprContext); currentVisibility = val; } return currentVisibility; }
private IEclipseContext getStaticContext() { if (infoContext == null) { IEclipseContext parentContext = renderer.getContext(toolbarModel); if (parentContext != null) { infoContext = parentContext.createChild(STATIC_CONTEXT); } else { infoContext = EclipseContextFactory.create(STATIC_CONTEXT); } ContributionsAnalyzer.populateModelInterfaces( toolbarModel, infoContext, toolbarModel.getClass().getInterfaces()); infoContext.set(ToolBarRenderer.class, renderer); } return infoContext; }
@Override public void processContents(MElementContainer<MUIElement> container) { super.processContents(container); IEclipseContext ctx = getContext(container); ExpressionContext eContext = new ExpressionContext(ctx); ArrayList<MToolBarContribution> toContribute = new ArrayList<MToolBarContribution>(); MElementContainer<?> toolbarObj = container; MToolBar toolbarModel = (MToolBar) toolbarObj; ContributionsAnalyzer.gatherToolBarContributions( toolbarModel, application.getToolBarContributions(), toolbarModel.getElementId(), toContribute, eContext); addToolBarContributions(toolbarModel, toContribute, ctx, eContext, pendingCleanup); }
private void setEnabled(MHandledMenuItem itemModel, MenuItem newItem) { ParameterizedCommand cmd = itemModel.getWbCommand(); if (cmd == null) { return; } final IEclipseContext lclContext = getContext(itemModel); EHandlerService service = lclContext.get(EHandlerService.class); final IEclipseContext staticContext = EclipseContextFactory.create(HMI_STATIC_CONTEXT); ContributionsAnalyzer.populateModelInterfaces( itemModel, staticContext, itemModel.getClass().getInterfaces()); try { itemModel.setEnabled(service.canExecute(cmd, staticContext)); } finally { staticContext.dispose(); } newItem.setEnabled(itemModel.isEnabled()); }
/** * @param menuModel * @param isMenuBar * @param isPopup */ public void processContributions(MMenu menuModel, boolean isMenuBar, boolean isPopup) { if (menuModel.getElementId() == null) { return; } final ArrayList<MMenuContribution> toContribute = new ArrayList<MMenuContribution>(); ContributionsAnalyzer.XXXgatherMenuContributions( menuModel, application.getMenuContributions(), menuModel.getElementId(), toContribute, null, isPopup); generateContributions(menuModel, toContribute, isMenuBar); for (MMenuElement element : menuModel.getChildren()) { if (element instanceof MMenu) { processContributions((MMenu) element, false, isPopup); } } }
/* * (non-Javadoc) * * @see * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#processContents * (org.eclipse.e4.ui.model.application.ui.MElementContainer) */ @Override public void processContents(MElementContainer<MUIElement> container) { if (container.getChildren().size() == 0) { Object obj = container.getWidget(); if (obj instanceof MenuItem) { MenuItem mi = (MenuItem) obj; if (mi.getMenu() == null) { mi.setMenu(new Menu(mi)); } Menu menu = mi.getMenu(); MenuItem menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText(MenuManagerRendererFilter.NUL_MENU_ITEM); menuItem.setEnabled(false); } } super.processContents(container); Object obj = container.getWidget(); Object menuObj = container; if ((obj instanceof Menu) && (((Menu) obj).getStyle() & SWT.BAR) != 0 && (menuObj instanceof MMenu)) { MMenu menuModel = (MMenu) menuObj; IEclipseContext ctx = getContext(container); ExpressionContext eContext = new ExpressionContext(ctx); ArrayList<MMenuContribution> toContribute = new ArrayList<MMenuContribution>(); ContributionsAnalyzer.gatherMenuContributions( menuModel, application.getMenuContributions(), menuModel.getElementId(), toContribute, eContext, false); addMenuBarContributions(menuModel, toContribute, ctx, eContext); } }
public void updateIsVisible(ExpressionContext exprContext) { isVisible = ContributionsAnalyzer.isVisible(toolbarContribution, exprContext); }
/** @param element */ public void processContribution(MToolBar toolbarModel, String elementId) { final ArrayList<MToolBarContribution> toContribute = new ArrayList<MToolBarContribution>(); ContributionsAnalyzer.XXXgatherToolBarContributions( toolbarModel, application.getToolBarContributions(), elementId, toContribute); generateContributions(toolbarModel, toContribute); }