@Override
        public void handleEvent(Event event) {
          // no need to do anything if we have no listeners
          if (!listeners.isEmpty()) {
            Object oldSelected = event.getProperty(UIEvents.EventTags.OLD_VALUE);
            if (oldSelected instanceof MPlaceholder) {
              oldSelected = ((MPlaceholder) oldSelected).getRef();
            }

            MPlaceholder placeholder = null;
            Object selected = event.getProperty(UIEvents.EventTags.NEW_VALUE);
            if (selected instanceof MPlaceholder) {
              placeholder = (MPlaceholder) selected;
              selected = placeholder.getRef();
            }

            MPart oldSelectedPart = oldSelected instanceof MPart ? (MPart) oldSelected : null;
            MPart selectedPart = selected instanceof MPart ? (MPart) selected : null;

            if (oldSelectedPart != null && getParts().contains(selectedPart)) {
              firePartHidden(oldSelectedPart);
            }

            if (selectedPart != null
                && selectedPart.isToBeRendered()
                && getParts().contains(selectedPart)) {
              // ask the renderer to create this part
              if (placeholder == null) {
                if (selectedPart.getParent().getRenderer() != null) {
                  engine.createGui(selectedPart);
                  firePartVisible(selectedPart);
                  firePartBroughtToTop(selectedPart);
                }
              } else if (placeholder.getParent().getRenderer() != null) {
                engine.createGui(placeholder);
                firePartVisible(selectedPart);
                firePartBroughtToTop(selectedPart);
              }
            }
          }
        }
 public static void addPartToAppropriateContainer(
     MPart part, MPartDescriptor descriptor, MApplication application, EModelService service) {
   // first try and find the container specified by the id in the "parent" persisted state
   MElementContainer<MUIElement> container = null;
   String parentId = descriptor.getPersistedState().get(PARENT_ID);
   if (parentId != null) {
     @SuppressWarnings("rawtypes")
     List<MElementContainer> containers =
         service.findElements(application, parentId, MElementContainer.class, null);
     if (!containers.isEmpty()) {
       @SuppressWarnings("unchecked")
       MElementContainer<MUIElement> uncheckedContainer = containers.get(0);
       container = uncheckedContainer;
     }
   }
   // next try and find a sibling, and use the sibling's container
   if (container == null) {
     List<MPart> siblings =
         service.findElements(application, descriptor.getElementId(), MPart.class, null);
     for (MPart sibling : siblings) {
       if (sibling == part) {
         continue;
       }
       container = sibling.getParent();
       if (sibling.isToBeRendered()) {
         // prefer visible siblings
         break;
       }
     }
   }
   if (container != null) {
     String position = descriptor.getPersistedState().get(POSITION_ID);
     int index = getPositionIndex(position, container);
     if (index < 0 || index > container.getChildren().size()) {
       container.getChildren().add(part);
     } else {
       container.getChildren().add(index, part);
     }
   }
 }
  @Override
  public boolean isPartOrPlaceholderInPerspective(String elementId, MPerspective perspective) {
    List<MPart> findElements = modelService.findElements(perspective, elementId, MPart.class, null);
    if (!findElements.isEmpty()) {
      MPart part = findElements.get(0);

      // if that is a shared part, check the placeholders
      if (workbenchWindow.getSharedElements().contains(part)) {
        List<MPlaceholder> placeholders =
            modelService.findElements(perspective, elementId, MPlaceholder.class, null);
        for (MPlaceholder mPlaceholder : placeholders) {
          if (mPlaceholder.isVisible() && mPlaceholder.isToBeRendered()) {
            return true;
          }
        }
        return false;
      }
      // not a shared part
      return part.isVisible() && part.isToBeRendered();
    }
    return false;
  }