Package org.eclipse.jst.pagedesigner.dom

Examples of org.eclipse.jst.pagedesigner.dom.IDOMPosition


        root = jsfRoot;
      } else {
        root = document;
      }
    }
    IDOMPosition position1, position2;
    // if (root.hasChildNodes())
    // {
    // Node first = root.getFirstChild();
    // position1 = new DOMRefPosition(first, false);
    // Node last = root.getLastChild();
View Full Code Here


  /**
   * Delete one node or char at operation position.
   */
  private void deleteSingle() {
    IDOMPosition opPosition = getOperationPosition();
    opPosition = EditHelper.moveToNextEditPosition(getOperationPosition(),
        _forward, new InlineEditingNavigationMediator(new ActionData(
            ActionData.INLINE_EDIT, null)));
    // for inner debug
    if (INNER_DEBUG) {
View Full Code Here

    int location2 = EditHelper.getInstance().getLocation(currentNode,
        node.getPosOffsets()[1], true);
    // left index
    if (currentNode.getData().length() > 0) {
      if (location1 == EditHelper.IN_MIDDLE) {
        IDOMPosition position = new DOMPosition(currentNode, node
            .getPosOffsets()[0]);
        setOperationPosition(position);
        position = DOMPositionHelper.splitText(position);
        Node nnode = position.getNextSiblingNode();
        if (nnode instanceof Text) {
          currentNode = (Text) nnode;
          offsets[1] -= offsets[0] > 0 ? offsets[0] : 0;
        }
      } else {
        // setOperationPosition(new DOMRefPosition(currentNode, false));
        if (currentNode.getPreviousSibling() != null) {
          setOperationPosition(new DOMRefPosition(currentNode
              .getPreviousSibling(), true));
        } else {
          setOperationPosition(new DOMPosition(currentNode
              .getParentNode(), 0));
        }
      }
      // right index
      if (location2 >= EditHelper.IN_MIDDLE) {
        IDOMPosition position = new DOMPosition(currentNode, offsets[1]);
        position = DOMPositionHelper.splitText(position);
        second = position.getPreviousSiblingNode();
      }
      return second != null ? (Text) EditHelper.deleteNode(second) : null;
    }
        setOperationPosition(new DOMRefPosition(currentNode, false));
        return (Text) EditHelper.deleteNode(currentNode);
View Full Code Here

   * @see org.eclipse.jst.pagedesigner.commands.range.RangeModeCommand#doRangeExecute(org.eclipse.jst.pagedesigner.dom.DOMRange)
   */
  protected DOMRange doRangeExecute(DOMRange range) {
    if (range != null) {
      boolean ordered = range.isOrdered();
      IDOMPosition start = ordered ? range.getStartPosition() : range
          .getEndPosition();
      IDOMPosition end = ordered ? range.getEndPosition() : range
          .getStartPosition();
      Node common = null;
      Node container = null;
      if (EditModelQuery.isSame(range)) {
        container = start.getContainerNode();
        ParagraphFinder finder = new ParagraphFinder(start);
        Paragraph p = finder.getParagraph(start);
        start = p.getStart();
        end = p.getEnd();
        common = p.getLowestContainer();
      } else {
        common = EditModelQuery.getInstance().getCommonAncestor(start,
            end);
      }
      DOMRange rt;
      // This code is for h1-h6 only, it may need to be replaced.
      if ((rt = replaceExistingH(start, end)) != null) {
        return rt;
      }
      // replace existing p
      if (getTag().equalsIgnoreCase(IHTMLConstants.TAG_P)) {
        rt = replaceExistingP(start, end);
        if (rt != null) {
          return rt;
        }
      }
      if (start.getContainerNode() == end.getContainerNode()) {
        int offset1 = start.getOffset();
        int offset2 = end.getOffset();
        IDOMPosition old = start;
        start = split(start);
        // parent is splited
        if (start != old) {
          container = start.getNextSiblingNode();
          offset2 -= offset1;
View Full Code Here

    Node container = position.getContainerNode();
    String[] styleNodes = new String[EditModelQuery.HTML_STYLE_NODES.size()];
    EditModelQuery.HTML_STYLE_NODES.toArray(styleNodes);
    while (EditModelQuery.isText(container) || (container != common && //
        EditModelQuery.containItem(styleNodes, container, true))) {
      IDOMPosition old = position;
      position = EditHelper.splitNode(position);
      if (old == position) {
        int pos = EditHelper.getLocation(position);
        switch (pos) {
        case -1:
View Full Code Here

            .equals(
                ((Element) parentNode)
                    .getAttribute(IHTMLConstants.ATTR_ALIGN))) {
          ((Element) parentNode)
              .removeAttribute(IHTMLConstants.ATTR_ALIGN);
          IDOMPosition startPos = new DOMPosition(parentNode, 0);
          IDOMPosition endPos = new DOMRefPosition(endNode, true);
          return new DOMRange(startPos, endPos);
        }
        // else replace the align attribute
        /**
         * this._applyingNode.appendChild(startNode);
         * parentNode.getParentNode().replaceChild(this._applyingNode,
         * parentNode);
         */
        String align = this.getApplyingNode()
            .getAttribute(IHTMLConstants.ATTR_ALIGN);
        ((Element) parentNode).setAttribute(IHTMLConstants.ATTR_ALIGN,
            align);

        IDOMPosition startPos = new DOMPosition(parentNode, 0);
        IDOMPosition endPos = new DOMRefPosition(endNode, true);
        return new DOMRange(startPos, endPos);
      }
    } else {
      if (parentNode != null
          && parentNode.getNodeName().equalsIgnoreCase(
              IHTMLConstants.TAG_P)
          && parentNode.getChildNodes().getLength() == len) {
        if (this.getApplyingNode()
            .getAttribute(IHTMLConstants.ATTR_ALIGN)
            .equals(
                ((Element) parentNode)
                    .getAttribute(IHTMLConstants.ATTR_ALIGN))) {
          ((Element) parentNode)
              .removeAttribute(IHTMLConstants.ATTR_ALIGN);
          IDOMPosition startPos = new DOMPosition(parentNode, 0);
          IDOMPosition endPos = new DOMRefPosition(endNode, true);
          return new DOMRange(startPos, endPos);
        }

        /**
         * Node sibling = startNode.getNextSibling();
         * this._applyingNode.appendChild(startNode); Node
         * endNodeSibling = endNode.getNextSibling(); while (sibling !=
         * null && startNode != endNode && sibling != endNodeSibling) {
         * Node tempNode = sibling.getNextSibling();
         * this._applyingNode.appendChild(sibling); sibling = tempNode; }
         * parentNode.getParentNode().replaceChild(this._applyingNode,
         * parentNode);
         */
        String align = this.getApplyingNode()
            .getAttribute(IHTMLConstants.ATTR_ALIGN);
        ((Element) parentNode).setAttribute(IHTMLConstants.ATTR_ALIGN,
            align);

        IDOMPosition startPos = new DOMPosition(parentNode, 0);
        IDOMPosition endPos = new DOMRefPosition(endNode, true);
        return new DOMRange(startPos, endPos);
      }
    }
    return null;
  }
View Full Code Here

    if (range == null || range.isEmpty()) {
      return null;
    }

    boolean ordered = range.isOrdered();
    IDOMPosition start = ordered ? range.getStartPosition() : range
        .getEndPosition();
    IDOMPosition end = ordered ? range.getEndPosition() : range
        .getStartPosition();

    Node startContainer = start.getContainerNode();
    Node endContainer = end.getContainerNode();

    Node common = DOMUtil.findCommonAncester(start.getContainerNode(), end
        .getContainerNode());
    if (common == null) {
      // should not happen.
      return null;
    }
        if (startContainer instanceof Text) {
          // if the start offset is 0,then skip split the Text
          if (start.getOffset() > 0) {
            startContainer = ((Text) startContainer).splitText(start
                .getOffset());
            start = new DOMRefPosition(startContainer, false);
          }
        } else {
          startContainer = start.getNextSiblingNode();
        }
        if (endContainer instanceof Text) {
          if (end.getOffset() > 0) {
            endContainer = ((Text) endContainer).splitText(end
                .getOffset());
            endContainer = endContainer.getPreviousSibling();
          } else {
            endContainer = endContainer.getPreviousSibling();
          }
        } else {
          endContainer = end.getPreviousSiblingNode();
        }

        // now the startContainer and the endContainer should share the same
        // parent
        Element newNode = createStyleElement();
        startContainer.getParentNode()
            .insertBefore(newNode, startContainer);

        Node sibling = startContainer.getNextSibling();
        newNode.appendChild(startContainer);
        Node endNodeSibling = endContainer.getNextSibling();
        while (sibling != null && startContainer != endContainer
            && sibling != endNodeSibling) {
          Node tempNode = sibling.getNextSibling();
          newNode.appendChild(sibling);
          sibling = tempNode;
        }

        IDOMPosition startPos = new DOMPosition(newNode, 0);
        IDOMPosition endPos = new DOMRefPosition(endContainer, true);
        return new DOMRange(startPos, endPos);
  }
View Full Code Here

    ISelection selection = getViewer().getSelection();
    if (selection != null) {
      if (getViewer().isInRangeMode()) {
        DesignRange range = (DesignRange) selection;
        if (range.isValid()) {
          IDOMPosition domPos = DOMPositionHelper.toDOMPosition(range
              .getStartPosition());
          IDOMPosition domEnd = DOMPositionHelper.toDOMPosition(range
              .getEndPosition());
          if (EditValidateUtil.validPosition(domPos)
              && EditValidateUtil.validPosition(domEnd)) {
            position = EditModelQuery
                .getIndexedRegionLocation(domPos);
View Full Code Here

  protected ISelection toDesignRange(DOMRange range) {
    try {
      if (range == null) {
        return null;
      }
      IDOMPosition startPos = range.getStartPosition();
      DesignPosition start = DOMPositionHelper.toDesignPosition(startPos);
      if (range.isEmpty()) {
        return new DesignRange(start, start);
      }
            IDOMPosition endPos = range.getEndPosition();
            return new DesignRange(start, DOMPositionHelper
                .toDesignPosition(endPos));
    } catch (Exception e) {
      // "Selection error"
      _log.error("Error.RangeModeCommand.SetSelection"); //$NON-NLS-1$
View Full Code Here

     * @return position after necessary containers are created
     */
    public final IDOMPosition checkAndApplyNecessaryContainers(
            IDOMModel model, IDOMPosition domPosition)
    {
        IDOMPosition position = DOMPositionHelper.splitText(domPosition);

        position = BodyHelper.adjustInsertPosition
            (_creationData.getUri(), _creationData.getTagName(), position);
       
        //position = getContainerCreationCommands(position);
View Full Code Here

TOP

Related Classes of org.eclipse.jst.pagedesigner.dom.IDOMPosition

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.