예제 #1
0
 /**
  * Get node at indexed position.
  *
  * @param model
  * @param position
  * @return the node at position
  */
 static Node getNodeAt(IStructuredModel model, int position) {
   try {
     IndexedRegion region = model.getIndexedRegion(position);
     if (region instanceof Node) {
       return (Node) region;
     }
     return null;
   } catch (Exception e) {
     // "Error in region node creation"
     _log.error("Error.EditModelQuery.1", e); // $NON-NLS-1$
     return null;
   }
 }
예제 #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;
   }
 }