Пример #1
0
 /**
  * Determine whether the position is at node's edge. When the offset is at edge, it is in the
  * leftmost or rightmost offset of node's region.
  *
  * @param position
  * @param forward
  * @return true if at edge
  */
 boolean atEdge(IDOMPosition position, boolean forward) {
   Node node = position.getContainerNode();
   int offset = position.getOffset();
   if (forward) {
     if (EditModelQuery.isText(node)) {
       return offset == node.getNodeValue().length();
     }
     return offset == node.getChildNodes().getLength();
   }
   return offset == 0;
 }
Пример #2
0
 /**
  * Create IDOMPosition based on Indexed 'position' in model. If node at position is text, use
  * position to calculate DOMPosition offset, otherwize, simply create position pointed to
  * container's children list's edge.
  *
  * @param model
  * @param position
  * @param adjust
  * @return the dom position
  */
 public IDOMPosition createDomposition1(IDOMModel model, int position, boolean adjust) {
   try {
     // get the container
     Object object = getPosNode(model, position);
     if (object == null && position > 0) {
       // The end of file?
       object = getPosNode(model, position - 1);
     }
     Node container = null;
     if (object == null) {
       // empty file?
       return new DOMPosition(model.getDocument(), 0);
     }
     container = (Node) object;
     Object oppNode = getPosNode(model, position - 1);
     if (oppNode != null
         && !EditModelQuery.isChild((Node) oppNode, container)
         && //
         !EditModelQuery.isInline(container)
         && EditModelQuery.isInline((Node) oppNode)) {
       container = (Node) oppNode;
     }
     int location = EditHelper.getInstance().getLocation(container, position, false);
     IDOMPosition result = null;
     switch (location) {
       case 1:
       case 2:
         result = new DOMRefPosition(container, false);
         break;
       case 4:
       case 5:
         result = new DOMRefPosition(container, true);
         break;
       case 3:
         if (EditModelQuery.isText(container)) {
           result =
               new DOMPosition(container, position - EditModelQuery.getNodeStartIndex(container));
         } else {
           result = new DOMPosition(container, container.getChildNodes().getLength());
         }
     }
     return result;
   } catch (Exception e) {
     // "Error in position creation"
     _log.error("Error.EditModelQuery.0" + e); // $NON-NLS-1$
     return null;
   }
 }