public void handleEvent(Event event) { Object changedObj = event.getProperty(UIEvents.EventTags.ELEMENT); if (!(changedObj instanceof MTrimmedWindow)) return; MTrimmedWindow window = (MTrimmedWindow) changedObj; if (window.getWidget() == null) return; String eventType = (String) event.getProperty(UIEvents.EventTags.TYPE); if (UIEvents.EventTypes.ADD.equals(eventType)) { MUIElement added = (MUIElement) event.getProperty(UIEvents.EventTags.NEW_VALUE); if (added.isToBeRendered()) createGui(added, window.getWidget(), window.getContext()); } else if (UIEvents.EventTypes.REMOVE.equals(eventType)) { MUIElement removed = (MUIElement) event.getProperty(UIEvents.EventTags.OLD_VALUE); if (removed.getRenderer() != null) removeGui(removed); } }
public void handleEvent(Event event) { MUIElement changedElement = (MUIElement) event.getProperty(UIEvents.EventTags.ELEMENT); MUIElement parent = changedElement.getParent(); if (parent == null) { parent = (MUIElement) ((EObject) changedElement).eContainer(); if (parent == null) { return; } } AbstractPartRenderer renderer = (AbstractPartRenderer) parent.getRenderer(); if (renderer == null || parent instanceof MToolBar) return; // Re-parent the control based on the visible state if (changedElement.isVisible()) { if (changedElement.isToBeRendered()) { if (changedElement.getWidget() instanceof Control) { // Ensure that the control is under its 'real' parent if // it's visible Composite realComp = (Composite) renderer.getUIContainer(changedElement); Control ctrl = (Control) changedElement.getWidget(); ctrl.setParent(realComp); fixZOrder(changedElement); } if (parent instanceof MElementContainer<?>) { renderer.childRendered((MElementContainer<MUIElement>) parent, changedElement); } } } else { // Put the control under the 'limbo' shell if (changedElement.getWidget() instanceof Control) { Control ctrl = (Control) changedElement.getWidget(); if (!(ctrl instanceof Shell)) { ctrl.getShell().layout(new Control[] {ctrl}, SWT.DEFER); } ctrl.setParent(getLimboShell()); } if (parent instanceof MElementContainer<?>) { renderer.hideChild((MElementContainer<MUIElement>) parent, changedElement); } } }
@Override public void hideChild(MElementContainer<MUIElement> parentElement, MUIElement child) { super.hideChild(parentElement, child); // only handle the disposal of this element if it was actually rendered // by the engine if (child.getRenderer() != null) { // Since there's no place to 'store' a child that's not in a menu // we'll blow it away and re-create on an add Widget widget = (Widget) child.getWidget(); if (widget != null && !widget.isDisposed()) { widget.dispose(); } ToolBar toolbar = (ToolBar) getUIContainer(child); if (toolbar != null && !toolbar.isDisposed()) { toolbar.pack(true); toolbar.getShell().layout(new Control[] {toolbar}, SWT.DEFER); } // disposeToolbarIfNecessary(parentElement); } }
protected AbstractPartRenderer getRendererFor(MUIElement element) { return (AbstractPartRenderer) element.getRenderer(); }