Package org.eclipse.wst.sse.ui.internal.contentassist

Examples of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal


      }
    }
  }

  protected void addPCDATAProposal(String nodeName, ContentAssistRequest contentAssistRequest) {
    CustomCompletionProposal proposal = new CustomCompletionProposal("<![CDATA[]]>", //$NON-NLS-1$
          contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), 9, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_CDATASECTION), "CDATA Section", //$NON-NLS-1$
          null, null, XMLRelevanceConstants.R_CDATA);
    contentAssistRequest.addProposal(proposal);

    proposal = new CustomCompletionProposal(nodeName, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), nodeName.length(), XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TXTEXT), "#PCDATA", //$NON-NLS-1$
          null, null, XMLRelevanceConstants.R_CDATA);
    contentAssistRequest.addProposal(proposal);
  }
View Full Code Here


        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
          CustomCompletionProposal proposal = new CustomCompletionProposal(getContentGenerator().getStartTagClose(node, elementDecl), contentAssistRequest.getReplacementBeginPosition(),
          // this is one of the few times to ignore the length --
                // always insert
                // contentAssistRequest.getReplacementLength(),
                0, getContentGenerator().getStartTagClose(node, elementDecl).length(), image, NLS.bind(XMLUIMessages.Close_with___, (new Object[]{getContentGenerator().getStartTagClose(node, elementDecl)})), null, proposedInfo, XMLRelevanceConstants.R_CLOSE_TAG);
          contentAssistRequest.addProposal(proposal);
        }
        else {
          // prompt with a close for the start tag
          CustomCompletionProposal proposal = new CustomCompletionProposal(">", //$NON-NLS-1$
                contentAssistRequest.getReplacementBeginPosition(),
                // this is one of the few times to ignore the
                // length -- always insert
                // contentAssistRequest.getReplacementLength(),
                0, 1, image, NLS.bind(XMLUIMessages.Close_with__, (new Object[]{" '>'"})), //$NON-NLS-1$
                null, proposedInfo, XMLRelevanceConstants.R_CLOSE_TAG);
          contentAssistRequest.addProposal(proposal);

          // prompt with the closer for the start tag and an end tag
          // if one is not present
          if (node.getEndStructuredDocumentRegion() == null) {
            // make sure tag name is actually what it thinks it
            // is...(eg. <%@ vs. <jsp:directive)
            IStructuredDocumentRegion sdr = contentAssistRequest.getDocumentRegion();
            String openingTagText = (sdr != null) ? sdr.getFullText() : ""; //$NON-NLS-1$
            if ((openingTagText != null) && (openingTagText.indexOf(node.getNodeName()) != -1)) {
              proposal = new CustomCompletionProposal("></" + node.getNodeName() + ">", //$NON-NLS-2$//$NON-NLS-1$
                    contentAssistRequest.getReplacementBeginPosition(),
                    // this is one of the few times to
                    // ignore the length -- always insert
                    // contentAssistRequest.getReplacementLength(),
                    0, 1, image, NLS.bind(XMLUIMessages.Close_with____, (new Object[]{node.getNodeName()})), null, proposedInfo, XMLRelevanceConstants.R_CLOSE_TAG);
              contentAssistRequest.addProposal(proposal);
            }
          }
          // prompt with slash bracket "/>" incase if it's a self
          // ending tag
          if (endWithSlashBracket) {
            proposal = new CustomCompletionProposal("/>", //$NON-NLS-1$
                  contentAssistRequest.getReplacementBeginPosition(),
                  // this is one of the few times to ignore
                  // the length -- always insert
                  // contentAssistRequest.getReplacementLength(),
                  0, 2, image, NLS.bind(XMLUIMessages.Close_with__, (new Object[]{" \"/>\""})), //$NON-NLS-1$
                  null, proposedInfo, XMLRelevanceConstants.R_CLOSE_TAG + 1); // +1
            // to
            // bring
            // to
            // top
            // of
            // list
            contentAssistRequest.addProposal(proposal);
          }
        }
      }
      else if ((contentAssistRequest.getDocumentRegion() == node.getLastStructuredDocumentRegion()) && !node.getLastStructuredDocumentRegion().isEnded()) {
        setErrorMessage(null);
        // prompt with a closing end character for the end tag
        CustomCompletionProposal proposal = new CustomCompletionProposal(">", //$NON-NLS-1$
              contentAssistRequest.getReplacementBeginPosition(),
              // this is one of the few times to ignore the
              // length -- always insert
              // contentAssistRequest.getReplacementLength(),
              0, 1, image, NLS.bind(XMLUIMessages.Close_with__, (new Object[]{" '>'"})), //$NON-NLS-1$
View Full Code Here

            }
            String proposedInfo = getAdditionalInfo(parentDecl, childType);
            for (int i = 0; i < childStrings.length; i++) {
              if(!childStrings[i].equals(defaultValue))
              {
                CustomCompletionProposal textProposal = new CustomCompletionProposal(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 CustomCompletionProposal(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);
      }
      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;

            Image image = CMImageUtil.getImage(elementDecl);

            if (image == null) {
              if (strictCMNodeSuggestions != null) {
                image = isStrictCMNodeSuggestion ? XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC_EMPHASIZED) : XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC_DEEMPHASIZED);
              }
              else {
                image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC);
              }

            }

            // int markupAdjustment =
            // getContentGenerator().getMinimalStartTagLength(parent,
            // elementDecl);
            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 CustomCompletionProposal(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()})));
            //$NON-NLS-1$ = "No known child tag names of <{0}> begin with \"{1}\"."
          }
          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 = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC);
            }
            String proposedText = getRequiredText(parent, ed);
            String tagname = getRequiredName(parent, ed);
            // account for the &lt; and &gt;
            int markupAdjustment = getContentGenerator().getMinimalStartTagLength(parent, ed);
            String proposedInfo = getAdditionalInfo(null, ed);
            CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), markupAdjustment, image, tagname, null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION);
            contentAssistRequest.addProposal(proposal);
          }
        }
      }
    }
View Full Code Here

            Image image = CMImageUtil.getImage(elementDecl);
            if (image == null) {
              image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC);
            }
            String proposedInfo = getAdditionalInfo(getCMElementDeclaration(parent), elementDecl);
            CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), cursorAdjustment, image, getRequiredName(parent, elementDecl), null, proposedInfo, XMLRelevanceConstants.R_TAG_NAME);
            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_names, (new Object[]{parent.getNodeName(), contentAssistRequest.getMatchString()})));
          //$NON-NLS-1$ = "No known child tag names of <{0}> begin with \"{1}\""
        }
        else {
          setErrorMessage(NLS.bind(XMLUIMessages.__Has_no_known_child, (new Object[]{parent.getNodeName()})));
        }
      }
    }
    else if (parent.getNodeType() == Node.DOCUMENT_NODE) {
      List childElements = getAvailableRootChildren((Document) parent, childPosition);
      for (int i = 0; i < childElements.size(); i++) {
        CMNode ed = (CMNode) childElements.get(i);
        if (ed == null) {
          continue;
        }
        String proposedText = null;
        int cursorAdjustment = 0;
        if (ed instanceof CMElementDeclaration) {
          // proposedText = getRequiredName(parent, ed);
          StringBuffer sb = new StringBuffer();
          getContentGenerator().generateTag(parent, (CMElementDeclaration) ed, sb);
          // tag starts w/ '<', but we want to compare to name
          proposedText = sb.toString().substring(1);

          if (!beginsWith(proposedText, matchString)) {
            continue;
          }

          cursorAdjustment = getCursorPositionForProposedText(proposedText);

          String proposedInfo = getAdditionalInfo(null, ed);
          Image image = CMImageUtil.getImage(ed);
          if (image == null) {
            image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC);
          }
          CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), cursorAdjustment, image, getRequiredName(parent, ed), null, proposedInfo, XMLRelevanceConstants.R_TAG_NAME);
          contentAssistRequest.addProposal(proposal);
        }
      }
    }
  }
View Full Code Here

  @Override
  protected String getCompletion(ICompletionProposal proposal)
  {
    if (proposal instanceof CustomCompletionProposal){
      CustomCompletionProposal completion = (CustomCompletionProposal)proposal;
      String replacement = completion.getReplacementString();
      // strip off trailing " on attribute completions
      if (replacement.endsWith("\"")){
        return replacement.substring(0, replacement.length() - 1);
      }
      // strip off closing tag so the user doesn't have to then move back to the
View Full Code Here

            cursor = replaceText.length() - 1;
          } else {
            cursor = replaceText.length() + 2;
          }

          CustomCompletionProposal proposal1 = new CustomCompletionProposal(
              replaceText, request.getReplacementBeginPosition(),
              request.getReplacementLength(), cursor, image,
              namespacePrefix + name + displayText, null, null,
              CONSTRUCTOR_RELEVANCE);

          if (!attrAtLocationHasValue) {
            refReplaceText += "=\"\"";
            cursor = refReplaceText.length() - 1;
          } else {
            cursor = refReplaceText.length() + 2;
          }
          image = BeansModelImages.getDecoratedImage(image,
              BeansModelImages.FLAG_EXTERNAL);
          CustomCompletionProposal proposal2 = new CustomCompletionProposal(
              refReplaceText,
              request.getReplacementBeginPosition(),
              request.getReplacementLength(), cursor, image,
              namespacePrefix + name + "-ref" + displayText,
              null, null, CONSTRUCTOR_RELEVANCE);
View Full Code Here

        }
        else {
          cursor = replaceText.length() + 2;
        }

        CustomCompletionProposal proposal1 = new CustomCompletionProposal(
            replaceText, request.getReplacementBeginPosition(),
            request.getReplacementLength(), cursor, image,
            namespacePrefix + propertyName + displayText, null,
            null, PROPERTY_RELEVANCE);

        if (!attrAtLocationHasValue) {
          refReplaceText += "=\"\"";
          cursor = refReplaceText.length() - 1;
        }
        else {
          cursor = refReplaceText.length() + 2;
        }
        image = BeansModelImages.getDecoratedImage(image,
            BeansModelImages.FLAG_EXTERNAL);
        CustomCompletionProposal proposal2 = new CustomCompletionProposal(
            refReplaceText, request.getReplacementBeginPosition(),
            request.getReplacementLength(), cursor, image,
            namespacePrefix + propertyName + "-ref" + displayText,
            null, null, PROPERTY_RELEVANCE);
View Full Code Here

TOP

Related Classes of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal

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.