/** * @param menuModel * @param manager * @param menuContribution * @return true if the menuContribution was processed */ private boolean processAddition(MMenu menuModel, final MenuManager manager, MMenuContribution menuContribution, final HashSet<String> existingMenuIds, HashSet<String> existingSeparatorNames, boolean menuBar) { final ContributionRecord record = new ContributionRecord(menuModel, menuContribution, this); if (!record.mergeIntoModel()) { return false; } if (menuBar || isPartMenu(menuModel)) { final IEclipseContext parentContext = getContext(menuModel); parentContext.runAndTrack(new RunAndTrack() { @Override public boolean changed(IEclipseContext context) { record.updateVisibility(parentContext.getActiveLeaf()); scheduleManagerUpdate(manager); return true; } }); } return true; }
updateIsVisible(exprContext); HashSet<ContributionRecord> recentlyUpdated = new HashSet<>(); recentlyUpdated.add(this); boolean changed = false; for (MMenuElement item : generatedElements) { boolean currentVisibility = computeVisibility(recentlyUpdated, item, exprContext); if (item.isVisible() != currentVisibility) { boolean currentVisibility = computeVisibility(recentlyUpdated, item, exprContext); if (item.isVisible() != currentVisibility) { MenuManager manager = getManagerForModel(); if (manager != null) { manager.markDirty();
for (ContributionRecord record : vals.toArray(new ContributionRecord[vals.size()])) { if (record.menuModel == menuModel) { record.dispose(); for (MMenuElement copy : record.getGeneratedElements()) { cleanUpCopy(record, copy); for (MMenuElement copy : record.getSharedElements()) { cleanUpCopy(record, copy); record.getGeneratedElements().clear(); record.getSharedElements().clear(); disposedRecords.add(record);
public boolean mergeIntoModel() { int idx = getIndex(menuModel, menuContribution.getPositionInParent()); if (idx == -1) { return false; copyElements = mergeFactoryIntoModel(); } else { copyElements = new ArrayList<MMenuElement>(); MMenu shared = findExistingMenu(copy.getElementId()); if (shared == null) { shared = (MMenu) copy; menuModel.getChildren().add(idx++, copy); } else { shared.setVisibleWhen(merge(copy.getVisibleWhen(), shared.getVisibleWhen())); copy = shared; MMenuSeparator shared = findExistingSeparator(copy .getElementId()); if (shared == null) {
/** * @return */ private List<MMenuElement> mergeFactoryIntoModel() { Object obj = menuContribution.getTransientData().get(FACTORY); if (!(obj instanceof IContextFunction)) { return Collections.EMPTY_LIST; } IEclipseContext staticContext = getStaticContext(); staticContext.remove(List.class); factoryDispose = (Runnable) ((IContextFunction) obj).compute( staticContext, null); return staticContext.get(List.class); }
private MExpression merge(MExpression expressionA, MExpression expressionB) { Expression coreExpressionA = getExpression(expressionA); Expression coreExpressionB = getExpression(expressionB); if (coreExpressionA == null || coreExpressionB == null) { // implied to always be visible return null; } if (coreExpressionA.equals(coreExpressionB)) { return expressionA; } // combine the two expressions OrExpression expression = new OrExpression(); expression.add(coreExpressionA); expression.add(coreExpressionB); MCoreExpression exp = UiFactoryImpl.eINSTANCE.createCoreExpression(); exp.setCoreExpressionId("programmatic.value"); //$NON-NLS-1$ exp.setCoreExpression(expression); return exp; }
public void cleanUpCopy(ContributionRecord record, MMenuElement copy) { modelContributionToRecord.remove(copy); if (copy instanceof MMenu) { MMenu menuCopy = (MMenu) copy; cleanUp(menuCopy); MenuManager copyManager = getManager(menuCopy); clearModelToManager(menuCopy, copyManager); if (copyManager != null) { record.getManagerForModel().remove(copyManager); copyManager.dispose(); } } else { IContributionItem ici = getContribution(copy); clearModelToContribution(copy, ici); if (ici != null) { record.getManagerForModel().remove(ici); } } }
/** * @param info * @param menuModel * @param renderer * @param evalContext * @param recurse */ public static void collectInfo(ExpressionInfo info, final MMenu menuModel, final MenuManagerRenderer renderer, final IEclipseContext evalContext, boolean recurse) { HashSet<ContributionRecord> records = new HashSet<>(); for (MMenuElement element : menuModel.getChildren()) { ContributionRecord record = renderer.getContributionRecord(element); if (record != null) { if (records.add(record)) { record.collectInfo(info); } } else { ContributionsAnalyzer.collectInfo(info, element.getVisibleWhen()); } if (recurse && element instanceof MMenu) { MMenu childMenu = (MMenu) element; collectInfo(info, childMenu, renderer, evalContext, false); } } }
.toArray(new ContributionRecord[vals.size()])) { if (record.menuModel == menuModel) { record.dispose(); for (MMenuElement copy : record.generatedElements) { cleanUpCopy(record, copy);
public boolean mergeIntoModel() { int idx = getIndex(menuModel, menuContribution.getPositionInParent()); if (idx == -1) { return false; copyElements = mergeFactoryIntoModel(); } else { copyElements = new ArrayList<>(); MMenu shared = findExistingMenu(copy.getElementId()); if (shared == null) { shared = (MMenu) copy; menuModel.getChildren().add(idx++, copy); } else { shared.setVisibleWhen(merge(copy.getVisibleWhen(), shared.getVisibleWhen())); copy = shared; MMenuSeparator shared = findExistingSeparator(copy .getElementId()); if (shared == null) {
/** * @return */ private List<MMenuElement> mergeFactoryIntoModel() { Object obj = menuContribution.getTransientData().get(FACTORY); if (!(obj instanceof IContextFunction)) { return Collections.EMPTY_LIST; } IEclipseContext staticContext = getStaticContext(); staticContext.remove(List.class); factoryDispose = (Runnable) ((IContextFunction) obj) .compute(staticContext, null); return staticContext.get(List.class); }
private MExpression merge(MExpression expressionA, MExpression expressionB) { Expression coreExpressionA = getExpression(expressionA); Expression coreExpressionB = getExpression(expressionB); if (coreExpressionA == null || coreExpressionB == null) { // implied to always be visible return null; } // combine the two expressions OrExpression expression = new OrExpression(); expression.add(coreExpressionA); expression.add(coreExpressionB); MCoreExpression exp = UiFactoryImpl.eINSTANCE.createCoreExpression(); exp.setCoreExpressionId("programmatic.value"); //$NON-NLS-1$ exp.setCoreExpression(expression); return exp; }
public void cleanUpCopy(ContributionRecord record, MMenuElement copy) { modelContributionToRecord.remove(copy); if (copy instanceof MMenu) { MMenu menuCopy = (MMenu) copy; cleanUp(menuCopy); MenuManager copyManager = getManager(menuCopy); clearModelToManager(menuCopy, copyManager); if (copyManager != null) { record.getManagerForModel().remove(copyManager); copyManager.dispose(); } } else { IContributionItem ici = getContribution(copy); clearModelToContribution(copy, ici); if (ici != null) { record.getManagerForModel().remove(ici); } } }
/** * @param info * @param menuModel * @param renderer * @param evalContext * @param recurse */ public static void collectInfo(ExpressionInfo info, final MMenu menuModel, final MenuManagerRenderer renderer, final IEclipseContext evalContext, boolean recurse) { HashSet<ContributionRecord> records = new HashSet<ContributionRecord>(); for (MMenuElement element : menuModel.getChildren()) { ContributionRecord record = renderer.getContributionRecord(element); if (record != null) { if (records.add(record)) { record.collectInfo(info); } } else { ContributionsAnalyzer.collectInfo(info, element.getVisibleWhen()); } if (recurse && element instanceof MMenu) { MMenu childMenu = (MMenu) element; collectInfo(info, childMenu, renderer, evalContext, false); } } }
updateIsVisible(exprContext); HashSet<ContributionRecord> recentlyUpdated = new HashSet<ContributionRecord>(); recentlyUpdated.add(this); boolean changed = false; for (MMenuElement item : generatedElements) { boolean currentVisibility = computeVisibility(recentlyUpdated, item, exprContext); if (item.isVisible() != currentVisibility) { boolean currentVisibility = computeVisibility(recentlyUpdated, item, exprContext); if (item.isVisible() != currentVisibility) { MenuManager manager = getManagerForModel(); if (manager != null) { manager.markDirty();
/** * @param menuModel * @param manager * @param menuContribution * @return true if the menuContribution was processed */ private boolean processAddition(MMenu menuModel, final MenuManager manager, MMenuContribution menuContribution, final HashSet<String> existingMenuIds, HashSet<String> existingSeparatorNames, boolean menuBar) { final ContributionRecord record = new ContributionRecord(menuModel, menuContribution, this); if (!record.mergeIntoModel()) { return false; } if (menuBar || isPartMenu(menuModel)) { final IEclipseContext parentContext = getContext(menuModel); parentContext.runAndTrack(new RunAndTrack() { @Override public boolean changed(IEclipseContext context) { record.updateVisibility(parentContext.getActiveLeaf()); manager.update(false); return true; } }); } return true; }