Package org.eclipse.wst.sse.core.internal.provisional.text

Examples of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion


    if (!node.isDataEditable()) {
      lockBoth(node);
      return;
    }

    IStructuredDocumentRegion flatNode;
    boolean canInsert = false;

    // end node (element)
    if (node.getNodeType() == Node.ELEMENT_NODE) {
      flatNode = node.getEndStructuredDocumentRegion();
      if (flatNode != null) {
        canInsert = node.isChildEditable();
        lock(flatNode, canInsert, false);
      }
    }
    // start node
    flatNode = node.getStartStructuredDocumentRegion();
    if (flatNode != null) {
      Span span = getDataSpan(node);
      if (0 <= span.length) {
        IStructuredDocument structuredDocument = flatNode.getParentDocument();
        int offset, length;
        offset = flatNode.getStart();
        length = span.offset;
        lock(structuredDocument, offset, length, false, false);
        offset = offset + span.offset + span.length;
        length = flatNode.getEnd() - offset;
        lock(structuredDocument, offset, length, false, canInsert);
      } else {
        lock(flatNode, false, canInsert);
      }
    }
View Full Code Here


  void unlockBoth(IDOMNode node) {
    if (node == null) {
      return;
    }

    IStructuredDocumentRegion flatNode;
    // start node
    flatNode = node.getStartStructuredDocumentRegion();
    if (flatNode != null) {
      unlock(flatNode);
    }
View Full Code Here

  void unlockNode(IDOMNode node) {
    if (node == null) {
      return;
    }

    IStructuredDocumentRegion flatNode;
    // end node
    if (node.getNodeType() == Node.ELEMENT_NODE) {
      flatNode = node.getEndStructuredDocumentRegion();
      if (flatNode != null) {
        unlock(flatNode);
      }
    }

    // start node
    flatNode = node.getStartStructuredDocumentRegion();
    if (flatNode != null) {
      if (node.isDataEditable()) {
        unlock(flatNode);
      } else {
        Span span = getDataSpan(node);
        if (span.length <= 0) {
          unlock(flatNode);
        } else {
          IStructuredDocument structuredDocument = flatNode.getParentDocument();
          int offset, length;
          offset = flatNode.getStart();
          length = span.offset - offset;
          unlock(structuredDocument, offset, length);
          offset = span.offset + span.length;
          length = flatNode.getEnd() - span.offset;
          unlock(structuredDocument, offset, length);
        }
      }
    }
  }
View Full Code Here

    Position retPos = null;
   
    //only want to fold regions of the valid type and with a valid range
    if(indexedRegion.getStartOffset() >= 0 && indexedRegion.getLength() >= 0) {
      IDOMNode node = (IDOMNode)indexedRegion;
      IStructuredDocumentRegion startRegion = node.getStartStructuredDocumentRegion();
      IStructuredDocumentRegion endRegion = node.getEndStructuredDocumentRegion();
     
      //if the node has an endRegion (end tag) then folding region is
      //  between the start and end tag
      //else if the region is a comment
      //else if the region is only an open tag or an open/close tag then don't fold it
      if(startRegion != null && endRegion != null) {
        if (endRegion.getEndOffset() >= startRegion.getStartOffset())
          retPos = new XMLElementFoldingPosition(startRegion, endRegion);
      } else if(startRegion != null && indexedRegion instanceof CommentImpl) {
        retPos = new XMLCommentFoldingPosition(startRegion);
      }
    }
View Full Code Here

  public final static int JSP_DIRECTIVE = 1003;
  public final static int XML = 1001;
  public final static int XML_BLOCK = 1002;

  public static IStructuredDocumentRegion createRegion(int type) {
    IStructuredDocumentRegion instance = null;
    switch (type) {
      case XML :
        instance = new XMLStructuredDocumentRegion();
        break;
      case XML_BLOCK :
View Full Code Here

  }

  /**
   */
  public boolean isClosed() {
    IStructuredDocumentRegion flatNode = getStructuredDocumentRegion();
    if (flatNode == null)
      return true; // will be generated
    String regionType = StructuredDocumentRegionUtil.getLastRegionType(flatNode);
    return (regionType == DOMRegionContext.XML_CDATA_CLOSE);
  }
View Full Code Here

    setFormattingPreferences(preferences);

    TextEdit edit = new MultiTextEdit();
    IStructuredDocument document = model.getStructuredDocument();
    // get initial document region
    IStructuredDocumentRegion currentRegion = document.getRegionAtCharacterOffset(start);
    if (currentRegion != null) {
      int startOffset = currentRegion.getStartOffset();

      // get initial dom node
      IndexedRegion currentIndexedRegion = model.getIndexedRegion(startOffset);
      if (currentIndexedRegion instanceof IDOMNode) {
        // set up domRegion which will contain current region to be
View Full Code Here

   * @param parentConstraints
   * @param currentDOMRegion
   * @param previousRegion
   */
  private void formatContent(TextEdit textEdit, Position formatRange, XMLFormattingConstraints parentConstraints, DOMRegion currentDOMRegion, IStructuredDocumentRegion previousRegion) {
    IStructuredDocumentRegion currentRegion = currentDOMRegion.documentRegion;
    String fullText = currentDOMRegion.domNode.getSource();

    // check if in preserve space mode, if so, don't touch anything but
    // make sure to update available line width
    String whitespaceMode = parentConstraints.getWhitespaceStrategy();
    if (XMLFormattingConstraints.PRESERVE.equals(whitespaceMode)) {
      int availableLineWidth = parentConstraints.getAvailableLineWidth();
      availableLineWidth = updateLineWidthWithLastLine(fullText, availableLineWidth);

      // update available line width in constraints
      parentConstraints.setAvailableLineWidth(availableLineWidth);
      // A text node can contain multiple structured document regions - sync the documentRegion
      // with the last region of the node since the text from all regions was formatted
      currentDOMRegion.documentRegion = currentDOMRegion.domNode.getLastStructuredDocumentRegion();
      return;
    }

    // if content is just whitespace and there's something after it
    // just skip over this region because region will take care of it
    boolean isAllWhitespace = ((IDOMText) currentDOMRegion.domNode).isElementContentWhitespace();
    IStructuredDocumentRegion nextDocumentRegion = null;
    if (isAllWhitespace) {
      parentConstraints.setAvailableLineWidth(fPreferences.getMaxLineWidth());
      nextDocumentRegion = currentRegion.getNext();
      if (nextDocumentRegion != null)
        return;
    }

    // special handling if text follows an entity or cdata region
    if (!XMLFormattingConstraints.COLLAPSE.equals(whitespaceMode) && previousRegion != null) {
      String previouRegionType = previousRegion.getType();
      if (DOMRegionContext.XML_ENTITY_REFERENCE.equals(previouRegionType) || DOMRegionContext.XML_CDATA_TEXT.equals(previouRegionType))
        whitespaceMode = XMLFormattingConstraints.COLLAPSE;
    }
    // also, special handling if text is before an entity or cdata region
    if (!XMLFormattingConstraints.COLLAPSE.equals(whitespaceMode)) {
      // get next document region if dont already have it
      if (nextDocumentRegion == null)
        nextDocumentRegion = currentRegion.getNext();
      if (nextDocumentRegion != null) {
        String nextRegionType = nextDocumentRegion.getType();
        if (DOMRegionContext.XML_ENTITY_REFERENCE.equals(nextRegionType) || DOMRegionContext.XML_CDATA_TEXT.equals(nextRegionType))
          whitespaceMode = XMLFormattingConstraints.COLLAPSE;
      }
    }
    final IStructuredDocumentRegion lastRegion = currentDOMRegion.domNode.getLastStructuredDocumentRegion();
    formatTextInContent(textEdit, parentConstraints, currentRegion, lastRegion != null ? lastRegion.getNext(): null, fullText, whitespaceMode);
    // A text node can contain multiple structured document regions - sync the documentRegion
    // with the last region of the node since the text from all regions was formatted
    currentDOMRegion.documentRegion = lastRegion;
  }
View Full Code Here

   * @param textEdit
   * @param currentRegion
   * @param textRegions
   */
  private void formatEndTag(TextEdit textEdit, Position formatRange, XMLFormattingConstraints constraints, DOMRegion currentDOMRegion, IStructuredDocumentRegion previousDocumentRegion) {
    IStructuredDocumentRegion currentDocumentRegion = currentDOMRegion.documentRegion;

    String whitespaceStrategy = constraints.getWhitespaceStrategy();
    String indentStrategy = constraints.getIndentStrategy();

    // do not format space before start tag if preserving spaces
    if (whitespaceStrategy != XMLFormattingConstraints.PRESERVE) {
      // format like indent strategy says
      if (XMLFormattingConstraints.INDENT.equals(indentStrategy) || XMLFormattingConstraints.NEW_LINE.equals(indentStrategy)) {
        int availableLineWidth = indentIfPossible(textEdit, constraints, currentDocumentRegion, previousDocumentRegion, whitespaceStrategy, indentStrategy, false);
        constraints.setAvailableLineWidth(availableLineWidth);
      }
      else if ( XMLFormattingConstraints.INLINE.equals(indentStrategy)){
        IStructuredDocument doc = currentDocumentRegion.getParentDocument();
        int currentLine = doc.getLineOfOffset(currentDocumentRegion.getStartOffset());
        int prevLine = doc.getLineOfOffset(previousDocumentRegion.getStartOffset());
        if ( currentLine != prevLine){
          int availableLineWidth = indentIfPossible(textEdit, constraints, currentDocumentRegion, previousDocumentRegion, whitespaceStrategy, indentStrategy, false);
          constraints.setAvailableLineWidth(availableLineWidth);
        }
View Full Code Here

   * @param previousRegion
   *            could be null
   * @return Returns the last region formatted
   */
  private DOMRegion formatRegion(TextEdit edit, Position formatRange, XMLFormattingConstraints parentConstraints, DOMRegion domRegion, IStructuredDocumentRegion previousRegion) {
    IStructuredDocumentRegion currentRegion = domRegion.documentRegion;
    String regionType = currentRegion.getType();
    if (DOMRegionContext.XML_TAG_NAME.equals(regionType)) {
      ITextRegion textRegion = currentRegion.getFirstRegion();
      String textRegionType = textRegion.getType();
      if (DOMRegionContext.XML_TAG_OPEN.equals(textRegionType)) {
        domRegion = formatStartTag(edit, formatRange, parentConstraints, domRegion, previousRegion);
      }
      else if (DOMRegionContext.XML_END_TAG_OPEN.equals(textRegionType)) {
        formatEndTag(edit, formatRange, parentConstraints, domRegion, previousRegion);
      }
    }
    else if (DOMRegionContext.XML_CONTENT.equals(regionType) || domRegion.domNode.getNodeType() == Node.TEXT_NODE) {
      formatContent(edit, formatRange, parentConstraints, domRegion, previousRegion);
    }
    else if (DOMRegionContext.XML_COMMENT_TEXT.equals(regionType)) {
      formatComment(edit, formatRange, parentConstraints, domRegion, previousRegion);
    }
    else {
      // unknown, so just leave alone for now but make sure to update
      // available line width
      String fullText = currentRegion.getFullText();
      int width = updateLineWidthWithLastLine(fullText, parentConstraints.getAvailableLineWidth());
      parentConstraints.setAvailableLineWidth(width);
    }
    return domRegion;
  }
View Full Code Here

TOP

Related Classes of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.