@Override
  public void hidePart(MPart part, boolean force) {
    if (isInContainer(part)) {
      MPlaceholder sharedRef = part.getCurSharedRef();
      MUIElement toBeRemoved = getRemoveTarget(part);
      MElementContainer<MUIElement> parent = getParent(toBeRemoved);
      List<MUIElement> children = parent.getChildren();

      // check if we're a placeholder but not actually the shared ref of the part
      if (toBeRemoved != part && toBeRemoved instanceof MPlaceholder && sharedRef != toBeRemoved) {
        toBeRemoved.setToBeRendered(false);

        // if so, not much to do, remove ourselves if necessary but that's it
        if (force || part.getTags().contains(REMOVE_ON_HIDE_TAG)) {
          parent.getChildren().remove(toBeRemoved);
        }
        return;
      }

      boolean isActiveChild = isActiveChild(part);
      MPart activationCandidate = null;
      // check if we're the active child
      if (isActiveChild) {
        // get the activation candidate if we are
        activationCandidate = partActivationHistory.getNextActivationCandidate(getParts(), part);
      }

      MPerspective thePersp = modelService.getPerspectiveFor(toBeRemoved);
      boolean needNewSel =
          thePersp == null || !thePersp.getTags().contains("PerspClosing"); // $NON-NLS-1$
      if (needNewSel) {
        if (parent.getSelectedElement() == toBeRemoved) {
          // if we're the selected element and we're going to be hidden, need to select
          // something else
          MUIElement candidate = partActivationHistory.getSiblingSelectionCandidate(part);
          candidate =
              candidate == null
                  ? null
                  : candidate.getCurSharedRef() == null ? candidate : candidate.getCurSharedRef();
          if (candidate != null && children.contains(candidate)) {
            parent.setSelectedElement(candidate);
          } else {
            for (MUIElement child : children) {
              if (child != toBeRemoved && child.isToBeRendered()) {
                parent.setSelectedElement(child);
                break;
              }
            }
          }
        }

        if (activationCandidate == null) {
          // nothing else to activate and we're the active child, deactivate
          if (isActiveChild) {
            part.getContext().deactivate();
          }
        } else {
          // activate our candidate
          activate(activationCandidate);
        }
      }

      if (toBeRemoved != null) {
        toBeRemoved.setToBeRendered(false);
      } else {
        part.setToBeRendered(false);
      }

      if (parent.getSelectedElement() == toBeRemoved) {
        parent.setSelectedElement(null);
      }

      if (force || part.getTags().contains(REMOVE_ON_HIDE_TAG)) {
        children.remove(toBeRemoved);
      }
      // remove ourselves from the activation history also since we're being hidden
      partActivationHistory.forget(getWindow(), part, toBeRemoved == part);
    }
  }