@Override
        public void handleEvent(Event event) {
          Object element = event.getProperty(UIEvents.EventTags.ELEMENT);
          if (!(element instanceof MPartStack)) {
            return;
          }

          Object newValue = event.getProperty(UIEvents.EventTags.NEW_VALUE);
          Object oldValue = event.getProperty(UIEvents.EventTags.OLD_VALUE);

          boolean minimizedTagAdded =
              UIEvents.isADD(event) && IPresentationEngine.MINIMIZED.equals(newValue);
          boolean minimizedTagRemoved =
              UIEvents.isREMOVE(event) && IPresentationEngine.MINIMIZED.equals(oldValue);

          if (!(minimizedTagAdded || minimizedTagRemoved)) {
            return;
          }

          MPart part = toPart(((MPartStack) element).getSelectedElement());
          if (part != null && minimizedTagAdded) {
            firePartHidden(part);
          } else if (part != null) {
            firePartVisible(part);
          }
        }
        public void handleEvent(Event event) {
          if (psTB.isDisposed()) {
            return;
          }

          Object changedObj = event.getProperty(UIEvents.EventTags.ELEMENT);

          if (psME == null || !(changedObj instanceof MPerspectiveStack)) return;

          MWindow perspWin = modelService.getTopLevelWindowFor((MUIElement) changedObj);
          MWindow switcherWin = modelService.getTopLevelWindowFor(psME);
          if (perspWin != switcherWin) return;

          if (UIEvents.isADD(event)) {
            for (Object o : UIEvents.asIterable(event, UIEvents.EventTags.NEW_VALUE)) {
              MPerspective added = (MPerspective) o;
              // Adding invisible elements is a NO-OP
              if (!added.isToBeRendered()) continue;

              addPerspectiveItem(added);
            }
          } else if (UIEvents.isREMOVE(event)) {
            for (Object o : UIEvents.asIterable(event, UIEvents.EventTags.OLD_VALUE)) {
              MPerspective removed = (MPerspective) o;
              // Removing invisible elements is a NO-OP
              if (!removed.isToBeRendered()) continue;

              removePerspectiveItem(removed);
            }
          }
        }
 public void handleEvent(Event event) {
   // Ensure that this event is for a MMenuItem
   if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MToolBar)) return;
   MToolBar toolbarModel = (MToolBar) event.getProperty(UIEvents.EventTags.ELEMENT);
   if (UIEvents.isADD(event)) {
     Object obj = toolbarModel;
     processContents((MElementContainer<MUIElement>) obj);
   }
 }
  @Override
  public void bringToTop(MUIElement element) {
    if (element instanceof MApplication) {
      return;
    }

    MWindow window = getTopLevelWindowFor(element);
    if (window == element) {
      if (!element.isToBeRendered()) {
        element.setToBeRendered(true);
      }

      window.getParent().setSelectedElement(window);
    } else {
      showElementInWindow(window, element);
    }
    UIEvents.publishEvent(UIEvents.UILifeCycle.BRINGTOTOP, element);
  }
  private void activate(MPart part, boolean requiresFocus, boolean activateBranch) {
    if (part == null) {
      if (constructed && activePart != null) {
        firePartDeactivated(activePart);
      }
      activePart = part;
      return;
    }

    // Delegate activations to a CompositePart's inner part (if any)
    if (part instanceof MCompositePart) {
      if (part.getContext() != null) {
        IEclipseContext pContext = part.getContext();
        if (pContext.getActiveLeaf() != null) {
          MPart inner = pContext.getActiveLeaf().get(MPart.class);
          if (inner != null) {
            part = inner;
          }
        }
      }
    }

    // only activate parts that is under our control
    if (!isInContainer(part)) {
      return;
    }

    MWindow window = getWindow();
    IEclipseContext windowContext = window.getContext();
    // check if the active part has changed or if we are no longer the active window
    if (windowContext.getParent().getActiveChild() == windowContext && part == activePart) {
      // insert it in the beginning of the activation history, it may not have been inserted
      // pending when this service was instantiated
      partActivationHistory.prepend(part);
      UIEvents.publishEvent(UIEvents.UILifeCycle.ACTIVATE, part);
      return;
    }
    if (contextService != null) {
      contextService.deferUpdates(true);
    }
    if (contextManager != null) {
      contextManager.deferUpdates(true);
    }

    MPart lastActivePart = activePart;
    activePart = part;

    if (constructed && lastActivePart != null && lastActivePart != activePart) {
      firePartDeactivated(lastActivePart);
    }

    try {
      // record any sibling into the activation history if necessary, this will allow it to be
      // reselected again in the future as it will be an activation candidate in the future,
      // this
      // prevents other unrendered elements from being selected arbitrarily which would cause
      // unwanted bundle activation
      recordStackActivation(part);

      delegateBringToTop(part);
      window.getParent().setSelectedElement(window);

      partActivationHistory.activate(part, activateBranch);

      if (requiresFocus) {
        IPresentationEngine pe = part.getContext().get(IPresentationEngine.class);
        pe.focusGui(part);
      }

      firePartActivated(part);
      UIEvents.publishEvent(UIEvents.UILifeCycle.ACTIVATE, part);
    } finally {
      if (contextService != null) {
        contextService.deferUpdates(false);
      }
      if (contextManager != null) {
        contextManager.deferUpdates(false);
      }
    }
  }