示例#1
0
  protected final void rawInsertAfterMeWithoutNotifications(TreeElement firstNew) {
    firstNew.rawRemoveUpToWithoutNotifications(null, false);
    final CompositeElement p = getTreeParent();
    final TreeElement treeNext = getTreeNext();
    firstNew.setTreePrev(this);
    setTreeNext(firstNew);
    while (true) {
      final TreeElement n = firstNew.getTreeNext();
      assert n != this : "Attempt to create cycle";
      firstNew.setTreeParent(p);
      if (n == null) break;
      firstNew = n;
    }

    if (treeNext == null) {
      if (p != null) {
        firstNew.setTreeParent(p);
        p.setLastChildNode(firstNew);
      }
    } else {
      firstNew.setTreeNext(treeNext);
      treeNext.setTreePrev(firstNew);
    }
    DebugUtil.checkTreeStructure(this);
  }
示例#2
0
  protected void invalidate() {
    CompositeElement parent = getTreeParent();
    if (parent != null) {
      parent.subtreeChanged();
    }

    // invalidate replaced element
    setTreeNext(null);
    setTreePrev(null);
    setTreeParent(null);
    onInvalidated();
  }
示例#3
0
  // remove nodes from this[including] to end[excluding] from the parent
  protected final void rawRemoveUpToWithoutNotifications(TreeElement end, boolean invalidate) {
    if (this == end) return;

    final CompositeElement parent = getTreeParent();
    final TreeElement startPrev = getTreePrev();
    final TreeElement endPrev = end != null ? end.getTreePrev() : null;

    assert end == null || end.getTreeParent() == parent : "Trying to remove non-child";

    if (end != null) {
      TreeElement element;
      for (element = this; element != end && element != null; element = element.getTreeNext()) ;
      assert element == end : end + " is not successor of " + this + " in the .getTreeNext() chain";
    }
    if (parent != null) {
      if (this == parent.getFirstChildNode()) {
        parent.setFirstChildNode(end);
      }
      if (end == null) {
        parent.setLastChildNode(startPrev);
      }
    }
    if (startPrev != null) {
      startPrev.setTreeNext(end);
    }
    if (end != null) {
      end.setTreePrev(startPrev);
    }

    setTreePrev(null);
    if (endPrev != null) {
      endPrev.setTreeNext(null);
    }

    if (parent != null) {
      for (TreeElement element = this; element != null; element = element.getTreeNext()) {
        element.setTreeParent(null);
        if (invalidate) {
          element.onInvalidated();
        }
      }
    }

    DebugUtil.checkTreeStructure(parent);
    DebugUtil.checkTreeStructure(this);
  }
示例#4
0
  public void rawInsertBeforeMe(@NotNull TreeElement firstNew) {
    final TreeElement anchorPrev = getTreePrev();
    if (anchorPrev == null) {
      firstNew.rawRemoveUpToLast();
      final CompositeElement p = getTreeParent();
      if (p != null) p.setFirstChildNode(firstNew);
      while (true) {
        final TreeElement treeNext = firstNew.getTreeNext();
        assert treeNext != this : "Attempt to create cycle";
        firstNew.setTreeParent(p);
        if (treeNext == null) break;
        firstNew = treeNext;
      }
      setTreePrev(firstNew);
      firstNew.setTreeNext(this);
      if (p != null) {
        p.subtreeChanged();
      }
    } else anchorPrev.rawInsertAfterMe(firstNew);

    DebugUtil.checkTreeStructure(this);
  }