Examples of CMElementDeclaration


Examples of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration

    }

    // the name region is REQUIRED to do anything useful
    if (nameRegion != null) {
      // Retrieve the declaration
      CMElementDeclaration elementDecl = getCMElementDeclaration(node);

      // String attributeName = nameRegion.getText();
      String attributeName = open.getText(nameRegion);

      CMAttributeDeclaration attrDecl = null;

      // No CMElementDeclaration means no attribute metadata, but retrieve the
      // declaration for the attribute otherwise
      if (elementDecl != null) {
        CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(elementDecl.getAttributes()) {
          private Map caseInsensitive;
         
          private Map getCaseInsensitiveMap() {
            if(caseInsensitive == null)
              caseInsensitive = new HashMap();
View Full Code Here

Examples of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration

      }
      while (aNode != null) {
        if (aNode.getNodeType() == Node.ELEMENT_NODE) {
          if (aNode.getNodeName().startsWith(matchString)) {
            IDOMNode aXMLNode = (IDOMNode) aNode;
            CMElementDeclaration ed = getCMElementDeclaration(aNode);
            //declaration must be valid for this computer to make proposal
            if ((aXMLNode.getEndStructuredDocumentRegion() == null) && (ed == null || (validModelQueryNode(ed) && ed.getContentType() != CMElementDeclaration.EMPTY))) {
              String replacementText = aNode.getNodeName();
              String displayText = replacementText;
              String proposedInfo = (ed != null) ? getAdditionalInfo(null, ed) : null;
              if(!contentAssistRequest.getDocumentRegion().isEnded()) {
                replacementText += ">"; //$NON-NLS-1$
View Full Code Here

Examples of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration

      CompletionProposalInvocationContext context) {
   
    IDOMNode node = (IDOMNode) contentAssistRequest.getParent();
    if (node.getNodeType() == Node.ELEMENT_NODE) {

      CMElementDeclaration elementDecl = getCMElementDeclaration(node);
      String proposedInfo = (elementDecl != null) ? getAdditionalInfo(null, elementDecl) : null;
      int contentType = (elementDecl != null) ? elementDecl.getContentType() : CMElementDeclaration.ANY;
      // if it's XML and content doesn't HAVE to be element, add "/>" proposal.
      boolean endWithSlashBracket = (isXMLNode(node) && (contentType != CMElementDeclaration.ELEMENT));

      //get the image
      Image image = CMImageUtil.getImage(elementDecl);
      if (image == null) {
        image = this.getGenericTagImage();
      }

      // is the start tag ended properly?
      if ((contentAssistRequest.getDocumentRegion() == node.getFirstStructuredDocumentRegion()) && !(node.getFirstStructuredDocumentRegion()).isEnded()) {
        setErrorMessage(null);
        // Is this supposed to be an empty tag? Note that if we can't
        // tell, we assume it's not.
        if ((elementDecl != null) && (elementDecl.getContentType() == CMElementDeclaration.EMPTY)) {
          // prompt with a self-closing end character if needed
          // this is one of the few times to ignore the length -- always insert
          // contentAssistRequest.getReplacementLength()
          CustomCompletionProposal proposal = new MarkupCompletionProposal(
              getContentGenerator().getStartTagClose(node, elementDecl),
View Full Code Here

Examples of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration

        parent = parent.getParentNode();
      }
    }

    if (parent.getNodeType() == Node.ELEMENT_NODE) {
      CMElementDeclaration parentDecl = getCMElementDeclaration(parent);
      if (parentDecl != null) {
        // XSD-specific ability - no filtering
        CMDataType childType = parentDecl.getDataType();
        if (childType != null) {
          String[] childStrings = childType.getEnumeratedValues();
          String defaultValue = childType.getImpliedValue();
          if (childStrings != null || defaultValue != null) {
            // the content string is the sole valid child...so replace the rest
            int begin = contentAssistRequest.getReplacementBeginPosition();
            int length = contentAssistRequest.getReplacementLength();
            if (parent instanceof IDOMNode) {
              if (((IDOMNode) parent).getLastStructuredDocumentRegion() != ((IDOMNode) parent).getFirstStructuredDocumentRegion()) {
                begin = ((IDOMNode) parent).getFirstStructuredDocumentRegion().getEndOffset();
                length = ((IDOMNode) parent).getLastStructuredDocumentRegion().getStartOffset() - begin;
              }
            }
            String proposedInfo = getAdditionalInfo(parentDecl, childType);
            for (int i = 0; i < childStrings.length; i++) {
              if(!childStrings[i].equals(defaultValue)) {
                CustomCompletionProposal textProposal = new MarkupCompletionProposal(
                    childStrings[i],begin, length, childStrings[i].length(),
                    XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ENUM),
                    childStrings[i], null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION);
                contentAssistRequest.addProposal(textProposal);
              }
            }
            if(defaultValue != null) {
              CustomCompletionProposal textProposal = new MarkupCompletionProposal(
                  defaultValue, begin, length, defaultValue.length(),
                  XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_DEFAULT),
                  defaultValue, null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION);
              contentAssistRequest.addProposal(textProposal);
            }
          }
        }
      }
      if ((parentDecl != null) && (parentDecl.getContentType() == CMElementDeclaration.PCDATA)) {
        addPCDATAProposal(parentDecl.getNodeName(), contentAssistRequest, context);
      }
      else {
        // retrieve the list of all possible children within this parent context
        cmnodes = getAvailableChildElementDeclarations((Element) parent, childPosition,ModelQueryAction.INSERT);

        // retrieve the list of the possible children within this
        // parent context and at this index
        List strictCMNodeSuggestions = null;
        if (XMLUIPreferenceNames.SUGGESTION_STRATEGY_VALUE_STRICT.equals(XMLUIPlugin.getInstance().getPreferenceStore().getString(XMLUIPreferenceNames.SUGGESTION_STRATEGY))) {
          strictCMNodeSuggestions = getValidChildElementDeclarations((Element) parent, childPosition, ModelQueryAction.INSERT);
        }
        Iterator nodeIterator = cmnodes.iterator();
        if (!nodeIterator.hasNext()) {
          if (getCMElementDeclaration(parent) != null) {
            error = NLS.bind(XMLUIMessages._Has_no_available_child, (new Object[]{parent.getNodeName()}));
          }
          else {
            error = NLS.bind(XMLUIMessages.Element__is_unknown, (new Object[]{parent.getNodeName()}));
          }
        }
        String matchString = contentAssistRequest.getMatchString();
        // chop off any leading <'s and whitespace from the matchstring
        while ((matchString.length() > 0) &&
            (Character.isWhitespace(matchString.charAt(0)) || beginsWith(matchString, "<"))) { //$NON-NLS-1$
         
          matchString = matchString.substring(1);
        }
        while (nodeIterator.hasNext()) {
          Object o = nodeIterator.next();
          if (o instanceof CMElementDeclaration) {
            CMElementDeclaration elementDecl =(CMElementDeclaration) o;
            // only add proposals for the child element's that
            // begin with the matchstring
            String tagname = getRequiredName(parent, elementDecl);
            boolean isStrictCMNodeSuggestion =
              strictCMNodeSuggestions != null ? strictCMNodeSuggestions.contains(elementDecl) : false;

            //get the proposal image
            Image image = CMImageUtil.getImage(elementDecl);
            if (image == null) {
              if (strictCMNodeSuggestions != null) {
                image = isStrictCMNodeSuggestion ? this.getEmphasizedTagImage() : this.getDeemphasizedTagImage();
              } else {
                image = this.getGenericTagImage();
              }
            }

            if (beginsWith(tagname, matchString)) {
              String proposedText = getRequiredText(parent, elementDecl);

              // https://bugs.eclipse.org/bugs/show_bug.cgi?id=89811
              // place cursor in first empty quotes
              int markupAdjustment = getCursorPositionForProposedText(proposedText);

              String proposedInfo = getAdditionalInfo(parentDecl, elementDecl);
              int relevance = isStrictCMNodeSuggestion ? XMLRelevanceConstants.R_STRICTLY_VALID_TAG_INSERTION : XMLRelevanceConstants.R_TAG_INSERTION;
              CustomCompletionProposal proposal = new MarkupCompletionProposal(
                  proposedText, contentAssistRequest.getReplacementBeginPosition(),
                  contentAssistRequest.getReplacementLength(), markupAdjustment,
                  image, tagname, null, proposedInfo, relevance);
              contentAssistRequest.addProposal(proposal);
            }
          }
        }
        if (contentAssistRequest.getProposals().size() == 0) {
          if (error != null) {
            setErrorMessage(error);
          }
          else if ((contentAssistRequest.getMatchString() != null) &&
              (contentAssistRequest.getMatchString().length() > 0)) {
           
            setErrorMessage(NLS.bind(
                XMLUIMessages.No_known_child_tag,
                (new Object[]{parent.getNodeName(), contentAssistRequest.getMatchString()})));
          }
          else {
            setErrorMessage(NLS.bind(
                XMLUIMessages.__Has_no_known_child,
                (new Object[]{parent.getNodeName()})));
          }
        }
      }
    }
    else if (parent.getNodeType() == Node.DOCUMENT_NODE) {
      // Can only prompt with elements if the cursor position is past
      // the XML processing
      // instruction and DOCTYPE declaration
      boolean xmlpiFound = false;
      boolean doctypeFound = false;
      int minimumOffset = -1;

      for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {

        boolean xmlpi = ((child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) && child.getNodeName().equals("xml")); //$NON-NLS-1$
        boolean doctype = child.getNodeType() == Node.DOCUMENT_TYPE_NODE;
        if (xmlpi || (doctype && (minimumOffset < 0))) {
          minimumOffset = ((IDOMNode) child).getFirstStructuredDocumentRegion().getStartOffset() + ((IDOMNode) child).getFirstStructuredDocumentRegion().getTextLength();
        }
        xmlpiFound = xmlpiFound || xmlpi;
        doctypeFound = doctypeFound || doctype;
      }

      if (contentAssistRequest.getReplacementBeginPosition() >= minimumOffset) {
        List childDecls = getAvailableRootChildren((Document) parent, childPosition);
        for (int i = 0; i < childDecls.size(); i++) {
          CMElementDeclaration ed = (CMElementDeclaration) childDecls.get(i);
          if (ed != null) {
            Image image = CMImageUtil.getImage(ed);
            if (image == null) {
              image = this.getGenericTagImage();
            }
View Full Code Here

Examples of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration

          else {
            proposedText = getRequiredName(parent, elementDecl);
           
            cursorAdjustment = proposedText.length();
            if (elementDecl instanceof CMElementDeclaration) {
              CMElementDeclaration ed = (CMElementDeclaration) elementDecl;
              // https://bugs.eclipse.org/bugs/show_bug.cgi?id=89811
              StringBuffer sb = new StringBuffer();
              getContentGenerator().generateTag(parent, ed, sb);
              // since it's a name proposal, assume '<' is already there
              // only return the rest of the tag
View Full Code Here

Examples of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration

    ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
    if (modelQuery != null) {
      CMDocument cmdoc = modelQuery.getCorrespondingCMDocument(document);
      if (cmdoc != null) {
        if (rootName != null) {
          CMElementDeclaration rootDecl = (CMElementDeclaration) cmdoc.getElements().getNamedItem(rootName);
          if (rootDecl != null) {
            list.add(rootDecl);
          }
          else {
            // supply the given document name anyway, even if it
View Full Code Here

Examples of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration

   * @param validityChecking
   * @return
   */
  private List getAvailableModelQueryActionsAtIndex(Element parent, int index, int validityChecking) {
    List list = new ArrayList();
    CMElementDeclaration parentDecl = getCMElementDeclaration(parent);
    if (parentDecl != null) {
      ModelQuery modelQuery = ModelQueryUtil.getModelQuery(parent.getOwnerDocument());
      // taken from ActionManagers
      // int editMode = modelQuery.getEditMode();
      int editMode = ModelQuery.EDIT_MODE_UNCONSTRAINED;
View Full Code Here

Examples of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration

    // TODO provide special documentation on doc type
    contentAssistRequest.addProposal(proposal);
  }
 
  public static CMElementDeclaration getCMElementDeclaration(Node node) {
    CMElementDeclaration result = null;
    if (node.getNodeType() == Node.ELEMENT_NODE) {
      ModelQuery modelQuery = ModelQueryUtil.getModelQuery(node.getOwnerDocument());
      if (modelQuery != null) {
        result = modelQuery.getCMElementDeclaration((Element) node);
      }
View Full Code Here

Examples of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration

   */
  protected CMAttributeDeclaration getDeclaration() {
    ElementImpl element = (ElementImpl) getOwnerElement();
    if (element == null)
      return null;
    CMElementDeclaration elementDecl = element.getDeclaration();
    if (elementDecl == null)
      return null;

    List nodes = ModelQueryUtil.getModelQuery(getOwnerDocument()).getAvailableContent(getOwnerElement(), elementDecl, ModelQuery.INCLUDE_ATTRIBUTES);
    String name = getName();
View Full Code Here

Examples of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration

        }
        r = r.getNext();
      }
      return new DOMRefPosition(node, true);
    } else if (node instanceof Element) {
      CMElementDeclaration cm = CMUtil
          .getElementDeclaration((Element) node);
      if (cm != null && cm.getContentType() == CMElementDeclaration.EMPTY) {
        // this node can't have children.
        return new DOMRefPosition(node, true);
      }
      IStructuredDocumentRegion startRegion = node
          .getStartStructuredDocumentRegion();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.