Examples of CustomCompletionProposal


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

 
  protected void addPCDATAProposal(String nodeName,
      ContentAssistRequest contentAssistRequest,
      CompletionProposalInvocationContext context) {
   
    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

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

        // 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),
              contentAssistRequest.getReplacementBeginPosition(), 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 MarkupCompletionProposal(">", //$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 MarkupCompletionProposal("></" + 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 MarkupCompletionProposal("/>", //$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 MarkupCompletionProposal(">", //$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);
View Full Code Here

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

              }
            }
            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();
            }
            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 MarkupCompletionProposal(
                proposedText, contentAssistRequest.getReplacementBeginPosition(),
                contentAssistRequest.getReplacementLength(), markupAdjustment, image,
                tagname, null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION);
            contentAssistRequest.addProposal(proposal);
          }
View Full Code Here

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

                image = this.getGenericTagImage();
              }
            }
            int relevance = isStrictCMNodeSuggestion ? XMLRelevanceConstants.R_STRICTLY_VALID_TAG_NAME : XMLRelevanceConstants.R_TAG_NAME;
            String proposedInfo = getAdditionalInfo(getCMElementDeclaration(parent), elementDecl);
            CustomCompletionProposal proposal = new MarkupCompletionProposal(
                proposedText, contentAssistRequest.getReplacementBeginPosition(),
                contentAssistRequest.getReplacementLength(), cursorAdjustment, image,
                getRequiredName(parent, elementDecl), 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_names,
              (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) {
      List childElements = getAvailableRootChildren((Document) parent, childPosition);
      if ( childElements.size() == 0) {
        //No doctype available , treat it as empty document
        addEmptyDocumentProposals(contentAssistRequest, context);
      }
      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 = this.getGenericTagImage();
          }
          CustomCompletionProposal proposal = new MarkupCompletionProposal(
              proposedText, contentAssistRequest.getReplacementBeginPosition(),
              contentAssistRequest.getReplacementLength(), cursorAdjustment, image,
              getRequiredName(parent, ed), null, proposedInfo, XMLRelevanceConstants.R_TAG_NAME);
          contentAssistRequest.addProposal(proposal);
        }
View Full Code Here

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

    if (contentAssistRequest.getNode().getOwnerDocument().getDocumentElement() != null) {
      rootname = contentAssistRequest.getNode().getOwnerDocument().getDocumentElement().getNodeName();
    }

    String proposedText = "<!DOCTYPE " + rootname + " PUBLIC \"//UNKNOWN/\" \"unknown.dtd\">"; //$NON-NLS-1$ //$NON-NLS-2$
    ICompletionProposal proposal = new CustomCompletionProposal(
        proposedText, contentAssistRequest.getReplacementBeginPosition(),
        contentAssistRequest.getReplacementLength(), 10,
        XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_DOCTYPE),
        "<!DOCTYPE ... >", //$NON-NLS-1$
        null, null, XMLRelevanceConstants.R_DOCTYPE);
View Full Code Here

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

      e.printStackTrace();
    }

    for (int i = 0; i < propList.size(); i++) {
      String prop = propList.get(i);
      CustomCompletionProposal each = new CustomCompletionProposal(prefix + prop + suffix, offset,
          replacementLength, cursorPosition, image, prop, null, "Tapestry page property: " + prop, 1);
      completionList.add(each);
    }
    for (int i = 0; i < methodList.size(); i++) {
      String method = methodList.get(i);
      CustomCompletionProposal each = new CustomCompletionProposal(prefix + method + suffix, offset,
          replacementLength, cursorPosition, image, method, null, "method " + method, 1);
      completionList.add(each);
    }
    return completionList;
  }
View Full Code Here

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

    if (completionRegion.getType() == DOMRegionContext.XML_COMMENT_TEXT && !isXMLFormat(doc)) {
      if (request == null) {
        request = new ContentAssistRequest(treeNode, xmlnode, sdRegion,
            completionRegion, documentPosition, 0, ""); //$NON-NLS-1$
      }
      request.addProposal(new CustomCompletionProposal("<%=  %>",//$NON-NLS-1$
          documentPosition, 0, 4,
          JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_JSP),
          "jsp:expression", null, "&lt;%= %&gt;", XMLRelevanceConstants.R_JSP)); //$NON-NLS-1$ //$NON-NLS-2$
    }
    /* handle proposals in and around JSP_DIRECTIVE_OPEN,
     * JSP_DIRECTIVE_CLOSE (preceded by OPEN) and JSP_DIRECTIVE_NAME
     */
    else if ((completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN &&
        documentPosition >= sdRegion.getTextEndOffset(completionRegion)) ||
        (completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME &&
            documentPosition <= sdRegion.getTextEndOffset(completionRegion)) ||
        (completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_CLOSE &&
            prevTextRegion != null &&
            prevTextRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN &&
            documentPosition <= sdRegion.getTextEndOffset(completionRegion))) {

      if (completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN ||
          completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_CLOSE) {
       
        if (request == null) {
          request = new ContentAssistRequest(xmlnode, xmlnode, sdRegion,
              completionRegion, documentPosition, 0, matchString);
        }
       
        //determine if there is any part of a directive name already existing
        Iterator regions = sdRegion.getRegions().iterator();
        String nameString = null;
        int begin = request.getReplacementBeginPosition();
        int length = request.getReplacementLength();
        while (regions.hasNext()) {
          ITextRegion region = (ITextRegion) regions.next();
          if (region.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) {
            nameString = sdRegion.getText(region);
            begin = sdRegion.getStartOffset(region);
            length = region.getTextLength();
            break;
          }
        }
        if (nameString == null) {
          nameString = ""; //$NON-NLS-1$
        }
       
        /* Suggest the directive names that have been determined to be
         * appropriate based on existing content
         */
        for (int i = 0; i < directiveNames.length; i++) {
          if (directiveNames[i].startsWith(nameString) || documentPosition <= begin) {
            request.addProposal(new CustomCompletionProposal(directiveNames[i], begin,
                length, directiveNames[i].length(),
                JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_JSP),
                directiveNames[i], null, null, XMLRelevanceConstants.R_JSP));
          }
        }
      }
      // by default, JSP_DIRECTIVE_NAME
      else {
        if (request == null) {
          request = new ContentAssistRequest(xmlnode, xmlnode, sdRegion,
              completionRegion, sdRegion.getStartOffset(completionRegion),
              completionRegion.getTextLength(), matchString);
        }
        //add each of the directive names as a proposal
        for (int i = 0; i < directiveNames.length; i++) {
          if (directiveNames[i].startsWith(matchString)) {
            request.addProposal(new CustomCompletionProposal(
                directiveNames[i], request.getReplacementBeginPosition(),
                request.getReplacementLength(), directiveNames[i].length(),
                JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_JSP),
                directiveNames[i], null, null, XMLRelevanceConstants.R_JSP));
          }
        }
      }
    }
    else if ((completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME &&
        documentPosition > sdRegion.getTextEndOffset(completionRegion)) ||
        (completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_CLOSE &&
            documentPosition <= sdRegion.getStartOffset(completionRegion))) {
     
      if (request == null) {
        request = computeAttributeProposals(matchString, completionRegion,
            treeNode, xmlnode, context);
      }
    }
    // no name?: <%@ %>
    else if (completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_CLOSE &&
        documentPosition <= sdRegion.getStartOffset(completionRegion)) {
      if (request != null) {
        request = computeAttributeProposals(matchString, completionRegion, treeNode,
            xmlnode, context);
      }
      Iterator regions = sdRegion.getRegions().iterator();
      String nameString = null;
      while (regions.hasNext()) {
        ITextRegion region = (ITextRegion) regions.next();
        if (region.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) {
          nameString = sdRegion.getText(region);
          break;
        }
      }
      if (nameString == null) {
        for (int i = 0; i < directiveNames.length; i++) {
          request.addProposal(new CustomCompletionProposal(
              directiveNames[i], request.getReplacementBeginPosition(),
              request.getReplacementLength(), directiveNames[i].length(),
              JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_JSP),
              directiveNames[i], null, null, XMLRelevanceConstants.R_JSP));
        }
View Full Code Here

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

   *         display (element type: {@link ICompletionProposal})
   */
  protected List filterAndSortProposals(List proposals, IProgressMonitor monitor, CompletionProposalInvocationContext context) {
    for(int i=0; i<proposals.size(); i++){
      if(proposals.get(i) instanceof CustomCompletionProposal){
        CustomCompletionProposal ccp = (CustomCompletionProposal) proposals.get(i);
        if(ccp.getDisplayString().startsWith("t:"))
          ccp.setImage(tapestryImage);
      }
    }
    return proposals;
  }
View Full Code Here

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

                  Logger.logException(e);
                }
                if (image == null) {
                  image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
                }
                CustomCompletionProposal proposal = new CustomCompletionProposal(
                    "\"" + uri + "\"", start, length, uri.length() + 2, //$NON-NLS-1$ //$NON-NLS-2$
                    image, uri, null, additionalInfo, IRelevanceConstants.R_NONE);
                contentAssistRequest.addProposal(proposal);
              }
            }
          }
          else if (attributeName.equals(JSP20Namespace.ATTR_NAME_TAGDIR)) {
            ITaglibRecord[] availableTaglibRecords = TaglibIndex.getAvailableTaglibRecords(basePath);
            /*
             * a simple enough way to remove duplicates (resolution at
             * runtime would be nondeterministic anyway)
             */
            Map uriToRecords = new HashMap();
            IPath localContextRoot = FacetModuleCoreSupport.computeWebContentRootPath(basePath);
            for (int taglibRecordNumber = 0; taglibRecordNumber < availableTaglibRecords.length; taglibRecordNumber++) {
              ITaglibRecord taglibRecord = availableTaglibRecords[taglibRecordNumber];
              String uri = null;
              if (taglibRecord.getRecordType() == ITaglibRecord.TAGDIR) {
                IPath path = ((ITagDirRecord) taglibRecord).getPath();
                if (localContextRoot.isPrefixOf(path)) {
                  uri = IPath.SEPARATOR + path.removeFirstSegments(localContextRoot.segmentCount()).toString();
                  uriToRecords.put(uri, taglibRecord);
                }
              }
            }
            /*
             * use the records and their descriptors to construct
             * proposals
             */
            Object[] uris = uriToRecords.keySet().toArray();
            for (int uriNumber = 0; uriNumber < uris.length; uriNumber++) {
              String uri = uris[uriNumber].toString();
              ITaglibRecord taglibRecord = (ITaglibRecord) uriToRecords.get(uri);
              ITaglibDescriptor descriptor = (taglibRecord).getDescriptor();
              if (uri != null && uri.length() > 0 && (matchString.length() == 0 ||
                  uri.toLowerCase(Locale.US).startsWith(lowerCaseMatch))) {
               
                String url = getSmallImageURL(taglibRecord);
                ImageDescriptor imageDescriptor = null;
                if (url != null) {
                  imageDescriptor = JSPUIPlugin.getInstance().getImageRegistry().getDescriptor(url);
                }
                if (imageDescriptor == null && url != null) {
                  URL imageURL;
                  try {
                    imageURL = new URL(url);
                    imageDescriptor = ImageDescriptor.createFromURL(imageURL);
                    JSPUIPlugin.getInstance().getImageRegistry().put(url, imageDescriptor);
                  }
                  catch (MalformedURLException e) {
                    Logger.logException(e);
                  }
                }
                String additionalInfo = descriptor.getDescription() + "<br/>" + descriptor.getTlibVersion(); //$NON-NLS-1$
                Image image = null;
                try {
                  image = JSPUIPlugin.getInstance().getImageRegistry().get(url);
                }
                catch (Exception e) {
                  Logger.logException(e);
                }
                if (image == null) {
                  image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
                }
                CustomCompletionProposal proposal = new CustomCompletionProposal(
                    "\"" + uri + "\"", start, length, uri.length() + 2, image, uri, //$NON-NLS-1$ //$NON-NLS-2$
                    null, additionalInfo, IRelevanceConstants.R_NONE);
                contentAssistRequest.addProposal(proposal);
              }
            }
          }
          else if (attributeName.equals(JSP11Namespace.ATTR_NAME_PREFIX)) {
            Node uriAttr = node.getAttributes().getNamedItem(JSP11Namespace.ATTR_NAME_URI);
            String uri = null;
            if (uriAttr != null) {
              uri = uriAttr.getNodeValue();
              ITaglibRecord[] availableTaglibRecords = TaglibIndex.getAvailableTaglibRecords(basePath);
              Map prefixMap = new HashMap();
              for (int taglibrecordNumber = 0; taglibrecordNumber < availableTaglibRecords.length; taglibrecordNumber++) {
                ITaglibDescriptor descriptor = availableTaglibRecords[taglibrecordNumber].getDescriptor();
                if (descriptor != null && descriptor.getURI() != null &&
                    descriptor.getURI().toLowerCase(Locale.US).equals(uri.toLowerCase(Locale.US))) {
                  String shortName = descriptor.getShortName().trim();
                  if (shortName.length() > 0) {
                    boolean valid = true;
                    for (int character = 0; character < shortName.length(); character++) {
                      valid = valid && !Character.isWhitespace(shortName.charAt(character));
                    }
                    if (valid) {
                      prefixMap.put(shortName, descriptor);
                    }
                  }
                }
              }
              Object prefixes[] = prefixMap.keySet().toArray();
              for (int j = 0; j < prefixes.length; j++) {
                String prefix = (String) prefixes[j];
                ITaglibDescriptor descriptor = (ITaglibDescriptor) prefixMap.get(prefix);
                Image image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
                CustomCompletionProposal proposal = new CustomCompletionProposal(
                    "\"" + prefix + "\"", start, length, prefix.length() + 2, image, //$NON-NLS-1$ //$NON-NLS-2$
                    prefix, null, descriptor.getDescription(), IRelevanceConstants.R_NONE);
                contentAssistRequest.addProposal(proposal);
              }
            }
            else {
              Node dirAttr = node.getAttributes().getNamedItem(JSP20Namespace.ATTR_NAME_TAGDIR);
              if (dirAttr != null) {
                String dir = dirAttr.getNodeValue();
                if (dir != null) {
                  ITaglibRecord record = TaglibIndex.resolve(basePath.toString(), dir, false);
                  if (record != null) {
                    ITaglibDescriptor descriptor = record.getDescriptor();
                    if (descriptor != null) {
                      String shortName = descriptor.getShortName();
   
                      Image image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
                      CustomCompletionProposal proposal = new CustomCompletionProposal(
                          "\"" + shortName + "\"", start, length, shortName.length() + 2, //$NON-NLS-1$ //$NON-NLS-2$
                          image, shortName, null, descriptor.getDescription(),
                          IRelevanceConstants.R_NONE);
                      contentAssistRequest.addProposal(proposal);
                    }
                    else {
                      if (dir.startsWith("/WEB-INF/")) { //$NON-NLS-1$
                        dir = dir.substring(9);
                      }
                      String prefix = StringUtils.replace(dir, "/", "-"); //$NON-NLS-1$ //$NON-NLS-2$
   
                      Image image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
                      CustomCompletionProposal proposal = new CustomCompletionProposal(
                          "\"" + prefix + "\"", start, length, prefix.length() + 2, //$NON-NLS-1$ //$NON-NLS-2$
                          image, prefix, null, null, IRelevanceConstants.R_NONE);
                      contentAssistRequest.addProposal(proposal);
                    }
                  }
View Full Code Here

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

                //create the proposal
                int cursorAdjustment = getCursorPositionForProposedText(proposedText);
                String proposedInfo = AbstractXMLModelQueryCompletionProposalComputer.getAdditionalInfo(
                    AbstractXMLModelQueryCompletionProposalComputer.getCMElementDeclaration(parent), elementDecl);
                String tagname = getContentGenerator().getRequiredName(node, ed);
                CustomCompletionProposal proposal = new CustomCompletionProposal(
                    proposedText, contentAssistRequest.getReplacementBeginPosition(),
                    contentAssistRequest.getReplacementLength(), cursorAdjustment, image, tagname, null, proposedInfo,
                    XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
                contentAssistRequest.addProposal(proposal);
              }
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.