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; |
Link Here
|
203 |
} |
204 |
} |
204 |
}; |
205 |
}; |
205 |
|
206 |
|
|
|
207 |
private EventHandler childUpdater = new EventHandler() { |
208 |
public void handleEvent(Event event) { |
209 |
// Ensure that this event is for a MMenuItem |
210 |
if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MMenu)) |
211 |
return; |
212 |
|
213 |
MMenu menuModel = (MMenu) event |
214 |
.getProperty(UIEvents.EventTags.ELEMENT); |
215 |
String eventType = (String) event |
216 |
.getProperty(UIEvents.EventTags.TYPE); |
217 |
if (UIEvents.EventTypes.ADD.equals(eventType) |
218 |
|| UIEvents.EventTypes.REMOVE.equals(eventType)) { |
219 |
Object obj = menuModel; |
220 |
processContents((MElementContainer<MUIElement>) obj); |
221 |
} |
222 |
} |
223 |
}; |
224 |
|
206 |
private MenuManagerRendererFilter rendererFilter; |
225 |
private MenuManagerRendererFilter rendererFilter; |
207 |
|
226 |
|
208 |
@PostConstruct |
227 |
@PostConstruct |
Link Here
|
212 |
eventBroker.subscribe(UIEvents.Item.TOPIC_ENABLED, enabledUpdater); |
231 |
eventBroker.subscribe(UIEvents.Item.TOPIC_ENABLED, enabledUpdater); |
213 |
eventBroker |
232 |
eventBroker |
214 |
.subscribe(UIEvents.UIElement.TOPIC_ALL, toBeRenderedUpdater); |
233 |
.subscribe(UIEvents.UIElement.TOPIC_ALL, toBeRenderedUpdater); |
|
|
234 |
eventBroker.subscribe(ElementContainer.TOPIC_CHILDREN, childUpdater); |
215 |
|
235 |
|
216 |
context.set(MenuManagerRenderer.class, this); |
236 |
context.set(MenuManagerRenderer.class, this); |
217 |
Display display = context.get(Display.class); |
237 |
Display display = context.get(Display.class); |
Link Here
|
230 |
eventBroker.unsubscribe(selectionUpdater); |
250 |
eventBroker.unsubscribe(selectionUpdater); |
231 |
eventBroker.unsubscribe(enabledUpdater); |
251 |
eventBroker.unsubscribe(enabledUpdater); |
232 |
eventBroker.unsubscribe(toBeRenderedUpdater); |
252 |
eventBroker.unsubscribe(toBeRenderedUpdater); |
|
|
253 |
eventBroker.unsubscribe(childUpdater); |
233 |
|
254 |
|
234 |
context.remove(MenuManagerRendererFilter.class); |
255 |
context.remove(MenuManagerRendererFilter.class); |
235 |
Display display = context.get(Display.class); |
256 |
Display display = context.get(Display.class); |
Link Here
|
505 |
modelProcessSwitch(parentManager, (MMenuElement) childME); |
526 |
modelProcessSwitch(parentManager, (MMenuElement) childME); |
506 |
} |
527 |
} |
507 |
} |
528 |
} |
|
|
529 |
|
530 |
// Determine if there are any items in the parentManager that are not in |
531 |
// the model. If there is then remove the contributionItem since it is |
532 |
// no longer in the model. This fix is for when a menu items are removed |
533 |
// from the MMenu model. |
534 |
for (IContributionItem contributionItem : parentManager.getItems()) { |
535 |
processContributionItem(contributionItem, parentManager); |
536 |
} |
508 |
parentManager.update(false); |
537 |
parentManager.update(false); |
509 |
} |
538 |
} |
510 |
|
539 |
|
|
|
540 |
private void processContributionItem(IContributionItem contributionItem, |
541 |
MenuManager parentManager) { |
542 |
if (contributionItem instanceof MenuManager) { |
543 |
processMenuManager((MenuManager) contributionItem, parentManager); |
544 |
} else { |
545 |
MMenuElement menuElement = getMenuElement(contributionItem); |
546 |
if (menuElement == null || menuElement.getParent() == null) { |
547 |
// Contribution is no longer in the model |
548 |
parentManager.remove(contributionItem); |
549 |
contributionItem.dispose(); |
550 |
clearModelToContribution(menuElement, contributionItem); |
551 |
} |
552 |
} |
553 |
} |
554 |
|
555 |
private void processMenuManager(MenuManager menuManager, |
556 |
MenuManager parentManager) { |
557 |
MMenu menuModel = getMenuModel(menuManager); |
558 |
if (menuModel == null || menuModel.getParent() == null) { |
559 |
// Menu is no longer in the model |
560 |
disposeMenuManager(menuManager, parentManager, menuModel); |
561 |
} else { |
562 |
// SubMenu is still alive process its items |
563 |
for (IContributionItem contributionItem : menuManager.getItems()) { |
564 |
processContributionItem(contributionItem, menuManager); |
565 |
} |
566 |
} |
567 |
} |
568 |
|
569 |
// Disposes the menuManager and its children |
570 |
private void disposeMenuManager(MenuManager menuManager, |
571 |
MenuManager parentManager, MMenu menuModel) { |
572 |
// Cleanup all contributions in menuManager since the parent is being |
573 |
// disposed. |
574 |
for (IContributionItem contributionItem : menuManager.getItems()) { |
575 |
if (contributionItem instanceof MenuManager) { |
576 |
disposeMenuManager((MenuManager) contributionItem, menuManager, |
577 |
getMenuModel((MenuManager) contributionItem)); |
578 |
} else { |
579 |
parentManager.remove(contributionItem); |
580 |
contributionItem.dispose(); |
581 |
clearModelToContribution(getMenuElement(contributionItem), |
582 |
contributionItem); |
583 |
} |
584 |
} |
585 |
clearModelToManager(menuModel, menuManager); |
586 |
parentManager.remove(menuManager); |
587 |
menuManager.dispose(); |
588 |
} |
589 |
|
511 |
private void addToManager(MenuManager parentManager, MMenuElement model, |
590 |
private void addToManager(MenuManager parentManager, MMenuElement model, |
512 |
IContributionItem menuManager) { |
591 |
IContributionItem menuManager) { |
513 |
MElementContainer<MUIElement> parent = model.getParent(); |
592 |
MElementContainer<MUIElement> parent = model.getParent(); |