/**
   * Traverses to the closest EditPart in the given list that is also in the given direction.
   *
   * @param event the KeyEvent for the keys that were pressed to trigger this traversal
   * @param direction PositionConstants.* indicating the direction in which to traverse
   */
  boolean navigateNextSibling(KeyEvent event, int direction, List<?> list) {
    IEntityPart epStart = getFocusEntityPart();
    if (epStart instanceof ITextualEntityPart) {
      ITextualEntityPart textualEntityPart = (ITextualEntityPart) epStart;
      ITextualFigure textualFigure = textualEntityPart.getTextualFigure();
      String text = textualFigure.getText();
      int line = CaretUtils.getLineFromPosition(text, textualEntityPart.getCaretPosition());
      int lines = CaretUtils.getCaretLines(text);
      if ((direction == PositionConstants.WEST && textualEntityPart.getCaretPosition() > 0)
          || (direction == PositionConstants.EAST
              && textualEntityPart.getCaretPosition() < textualEntityPart.getCaretPositions())) {
        int position =
            textualEntityPart.getCaretPosition() + (direction == PositionConstants.WEST ? -1 : 1);
        CaretUpdater.sheduleSyncUpdate(
            getViewer(), textualEntityPart.getModelEntity(), position, true);
        return true;
      } else if ((direction == PositionConstants.NORTH && line > 0)
          || (direction == PositionConstants.SOUTH && line < lines)) {
        int dy =
            FigureUtilities.getFontMetrics(textualFigure.getFont()).getHeight()
                * (direction == PositionConstants.NORTH ? -1 : 1);
        Point location = textualFigure.getCaretBounds().getCenter().translate(0, dy);
        CaretUpdater.sheduleSyncUpdate(
            getViewer(), textualEntityPart.getModelEntity(), location, true);
        textualEntityPart.updateCaret(location);
        return true;
      }
    }
    if (!(epStart instanceof IGraphicalEntityPart)) return false;
    IFigure figure = ((IGraphicalEntityPart) epStart).getFigure();
    Point pStart = getNavigationPoint(figure);
    figure.translateToAbsolute(pStart);
    EditPart next =
        findSibling(
            list, pStart, direction, epStart); // parent.findSibling(pStart, direction, epStart);
    while (next == null) {
      if (!(epStart.getParent() instanceof IGraphicalEntityPart)) return false;

      epStart = (IGraphicalEntityPart) epStart.getParent();
      if (epStart == getViewer().getContents()
          || epStart.getParent() == getViewer().getContents()
          || epStart.getParent() == null) return false;

      list = epStart.getParent().getChildren();
      next = findSibling(list, pStart, direction, epStart);
    }

    // next = next.enter(pStart, direction, epStart);1+2
    navigateTo(next, event);
    return true;
  }
  public boolean navigateModel(KeyEvent event, int direction) {
    EditPoint focusPoint = getEditPoint();

    if (!(focusPoint.focus.getParent() instanceof IEntityPart)) return false;

    switch (direction) {
      case NORTH:
        IEntityPart parentPart = (IEntityPart) focusPoint.focus.getParent();
        if (isRootPart(parentPart)) return false;

        editPoint.focus = parentPart;
        break;
      case SOUTH:
        List<?> children = focusPoint.focus.getChildren();
        if (children.isEmpty()) return false;

        editPoint.focus = (IEntityPart) children.get(0);
        break;
      case EAST:
        parentPart = (IEntityPart) focusPoint.focus.getParent();
        if (isRootPart(parentPart)) return false;

        List<?> siblings = parentPart.getChildren();
        int index = siblings.indexOf(editPoint.focus);
        if (index < siblings.size() - 1)
          editPoint.focus = findModelFirstChild((IEntityPart) siblings.get(index + 1));
        else editPoint.focus = parentPart;
        break;
      case WEST:
        parentPart = (IEntityPart) focusPoint.focus.getParent();
        if (isRootPart(parentPart)) return false;

        siblings = parentPart.getChildren();
        index = siblings.indexOf(editPoint.focus);
        if (index > 0) editPoint.focus = findModelLastChild((IEntityPart) siblings.get(index - 1));
        else editPoint.focus = parentPart;
        break;
    }
    editPoint.caret = 0;

    navigateTo(editPoint.focus, event);
    return true;
  }
 public IEntityPart findModelLastChild(IEntityPart parent) {
   List<?> children = parent.getChildren();
   if (children.isEmpty()) return parent;
   return findModelLastChild((IEntityPart) children.get(children.size() - 1));
 }