View | Details | Raw Unified | Return to bug 374568 | Differences between
and this patch

Collapse All | Expand All

(-)a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java (+71 lines)
Lines 48-53 Link Here
48
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl;
48
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl;
49
import org.eclipse.e4.ui.workbench.IResourceUtilities;
49
import org.eclipse.e4.ui.workbench.IResourceUtilities;
50
import org.eclipse.e4.ui.workbench.UIEvents;
50
import org.eclipse.e4.ui.workbench.UIEvents;
51
import org.eclipse.e4.ui.workbench.UIEvents.ElementContainer;
51
import org.eclipse.e4.ui.workbench.modeling.ExpressionContext;
52
import org.eclipse.e4.ui.workbench.modeling.ExpressionContext;
52
import org.eclipse.e4.ui.workbench.swt.util.ISWTResourceUtilities;
53
import org.eclipse.e4.ui.workbench.swt.util.ISWTResourceUtilities;
53
import org.eclipse.emf.common.util.URI;
54
import org.eclipse.emf.common.util.URI;
Lines 204-209 Link Here
204
		}
205
		}
205
	};
206
	};
206
207
208
	private EventHandler childUpdater = new EventHandler() {
209
		public void handleEvent(Event event) {
210
			// Ensure that this event is for a MMenuItem
211
			if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MMenu))
212
				return;
213
214
			Object menuModel = event.getProperty(UIEvents.EventTags.ELEMENT);
215
216
			if (UIEvents.isADD(event)) {
217
				processContents((MElementContainer<MUIElement>) menuModel);
218
			} else if (UIEvents.isREMOVE(event)) {
219
				MenuManager parentManager = getManager((MMenu) menuModel);
220
				if (parentManager == null) {
221
					return;
222
				}
223
				Object oldValue = event
224
						.getProperty(UIEvents.EventTags.OLD_VALUE);
225
				if (oldValue instanceof MMenu) {
226
					disposeMenuManager(getManager((MMenu) oldValue),
227
							parentManager, (MMenu) oldValue);
228
				} else if (oldValue instanceof MMenuElement) {
229
					disposeContributionItem(
230
							getContribution((MMenuElement) oldValue),
231
							parentManager, (MMenuElement) oldValue);
232
					parentManager.update(false);
233
				} else if (oldValue instanceof List) {
234
					for (Object object : (List) oldValue) {
235
						if (object instanceof MMenu) {
236
							disposeMenuManager(getManager((MMenu) object),
237
									parentManager, (MMenu) object);
238
						} else if (object instanceof MMenuElement) {
239
							disposeContributionItem(
240
									getContribution((MMenuElement) object),
241
									parentManager, (MMenuElement) object);
242
						}
243
					}
244
					parentManager.update(false);
245
				}
246
			}
247
		}
248
	};
249
207
	private MenuManagerRendererFilter rendererFilter;
250
	private MenuManagerRendererFilter rendererFilter;
208
251
209
	@PostConstruct
252
	@PostConstruct
Lines 213-218 Link Here
213
		eventBroker.subscribe(UIEvents.Item.TOPIC_ENABLED, enabledUpdater);
256
		eventBroker.subscribe(UIEvents.Item.TOPIC_ENABLED, enabledUpdater);
214
		eventBroker
257
		eventBroker
215
				.subscribe(UIEvents.UIElement.TOPIC_ALL, toBeRenderedUpdater);
258
				.subscribe(UIEvents.UIElement.TOPIC_ALL, toBeRenderedUpdater);
259
		eventBroker.subscribe(ElementContainer.TOPIC_CHILDREN, childUpdater);
216
260
217
		context.set(MenuManagerRenderer.class, this);
261
		context.set(MenuManagerRenderer.class, this);
218
		Display display = context.get(Display.class);
262
		Display display = context.get(Display.class);
Lines 235-240 Link Here
235
		eventBroker.unsubscribe(selectionUpdater);
279
		eventBroker.unsubscribe(selectionUpdater);
236
		eventBroker.unsubscribe(enabledUpdater);
280
		eventBroker.unsubscribe(enabledUpdater);
237
		eventBroker.unsubscribe(toBeRenderedUpdater);
281
		eventBroker.unsubscribe(toBeRenderedUpdater);
282
		eventBroker.unsubscribe(childUpdater);
238
283
239
		ContextInjectionFactory.uninject(MenuManagerEventHelper.showHelper,
284
		ContextInjectionFactory.uninject(MenuManagerEventHelper.showHelper,
240
				context);
285
				context);
Lines 520-525 Link Here
520
		parentManager.update(false);
565
		parentManager.update(false);
521
	}
566
	}
522
567
568
	// Disposes the menuManager and its children
569
	private void disposeMenuManager(MenuManager menuManager,
570
			MenuManager parentManager, MMenu menuModel) {
571
		// Cleanup all contributions in menuManager since the parent is being
572
		// disposed.
573
		for (IContributionItem contributionItem : menuManager.getItems()) {
574
			if (contributionItem instanceof MenuManager) {
575
				disposeMenuManager((MenuManager) contributionItem, menuManager,
576
						getMenuModel((MenuManager) contributionItem));
577
			} else {
578
				disposeContributionItem(contributionItem, parentManager,
579
						getMenuElement(contributionItem));
580
			}
581
		}
582
		clearModelToManager(menuModel, menuManager);
583
		parentManager.remove(menuManager);
584
		menuManager.dispose();
585
	}
586
587
	private void disposeContributionItem(IContributionItem contributionItem,
588
			MenuManager parentManager, MMenuElement menuElement) {
589
		parentManager.remove(contributionItem);
590
		contributionItem.dispose();
591
		clearModelToContribution(menuElement, contributionItem);
592
	}
593
523
	private void addToManager(MenuManager parentManager, MMenuElement model,
594
	private void addToManager(MenuManager parentManager, MMenuElement model,
524
			IContributionItem menuManager) {
595
			IContributionItem menuManager) {
525
		MElementContainer<MUIElement> parent = model.getParent();
596
		MElementContainer<MUIElement> parent = model.getParent();

Return to bug 374568