Beispiel #1
0
  /**
   * Returns true if the given fragment can be inserted at the current caret position.
   *
   * @param frag DocumentFragment to be inserted.
   */
  public boolean canInsertFragment(VEXDocumentFragment frag) {

    VEXDocument doc = this.getDocument();
    if (doc == null) {
      return false;
    }

    Validator validator = doc.getValidator();
    if (validator == null) {
      return true;
    }

    int startOffset = this.getCaretOffset();
    int endOffset = this.getCaretOffset();
    if (this.hasSelection()) {
      startOffset = this.getSelectionStart();
      endOffset = this.getSelectionEnd();
    }

    VEXElement parent = this.getDocument().getElementAt(startOffset);
    EList<String> seq1 = doc.getNodeNames(parent.getStartOffset() + 1, startOffset);

    EList<String> seq2 = frag.getNodeNames();

    EList<String> seq3 = doc.getNodeNames(endOffset, parent.getEndOffset());

    return validator.isValidSequence(parent.getName(), seq1, seq2, seq3, true);
  }
Beispiel #2
0
  public void insertFragment(VEXDocumentFragment frag) throws DocumentValidationException {

    if (this.hasSelection()) {
      this.deleteSelection();
    }

    this.document.insertFragment(this.getCaretOffset(), frag);
    this.moveTo(this.getCaretOffset() + frag.getLength());
  }