Examples of CustomCompletionProposal


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

                  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();
            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();
                IPath localContextRoot = TaglibIndex.getContextRoot(basePath);
                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

        CMDocumentImpl doc = (CMDocumentImpl) tracker.getDocument();

        List functions = doc.getFunctions();
        for (Iterator it = functions.iterator(); it.hasNext();) {
          TLDFunction function = (TLDFunction) it.next();
          CustomCompletionProposal proposal = new CustomCompletionProposal(
              function.getName() + "()", //$NON-NLS-1$
              offset,
              0,
              function.getName().length() + 1,
              null,
View Full Code Here

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

    }
    sortList(propList);
    sortList(methodList);
    for(int i=0; i<propList.size(); i++){
      String prop = propList.get(i);
      CustomCompletionProposal each = new CustomCompletionProposal( "prop:"+prop, offset, replacementLength,replacementLength, image, prop, null,
          "variable "+prop, 1);
      completionList.add(each);
    }
    for(int i=0; i<methodList.size(); i++){
      String method = methodList.get(i);
      CustomCompletionProposal each = new CustomCompletionProposal( "prop:"+method, offset, replacementLength,replacementLength, 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

                //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

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

          String proposedText = getRequiredText(document, ed);
          String tagname = getRequiredName(document, ed);
          // account for the &lt; and &gt;
          int markupAdjustment = getContentGenerator().getMinimalStartTagLength(document, 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

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

          if (typeName != null && typeName.length() > 0) {
            // find the class/type/beanName definition and obtain the list of properties
            IBeanInfoProvider provider = new BeanInfoProvider();
            IResource resource = JSPContentAssistHelper.getResource(contentAssistRequest);
            IJavaPropertyDescriptor[] descriptors = provider.getRuntimeProperties(resource, typeName);
            CustomCompletionProposal proposal = null;
            String displayString = ""; //$NON-NLS-1$
            for (int j = 0; j < descriptors.length; j++) {
              IJavaPropertyDescriptor pd = descriptors[j];
              // check whether it's get or set kinda property
              if (pd.getReadable() && isGetProperty || pd.getWriteable() && !isGetProperty) {
                // filter attr value name
                if (matchString.length() == 0 || pd.getName().toLowerCase().startsWith(matchString.toLowerCase())) {
                  displayString = pd.getDisplayName();
                  if (pd.getDeclaredType() != null && pd.getDeclaredType().length() > 0)
                    displayString += " - " + pd.getDeclaredType(); //$NON-NLS-1$
                  proposal = new CustomCompletionProposal("\"" + pd.getName() + "\"", //$NON-NLS-1$ //$NON-NLS-2$
                        contentAssistRequest.getReplacementBeginPosition(),
                        contentAssistRequest.getReplacementLength(),
                        pd.getName().length() + 2,
                        SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_ATTRIBUTE),
                        displayString, null, pd.getDeclaredType(), XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
View Full Code Here

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

          // https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=2341
          if(id != null) {
              // filter
            if (matchString.length() == 0 || id.startsWith(matchString)) {
              CustomCompletionProposal proposal = new CustomCompletionProposal("\"" + id + "\"", //$NON-NLS-1$ //$NON-NLS-2$
                    contentAssistRequest.getReplacementBeginPosition(),
                                        contentAssistRequest.getReplacementLength(),
                                        id.length() + 2,
                                        JSPEditorPluginImageHelper.getInstance().getImage(imageName),
                                        displayString, null, null,
View Full Code Here

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

        CMDocumentImpl doc = (CMDocumentImpl) tracker.getDocument();

        List functions = doc.getFunctions();
        for (Iterator it = functions.iterator(); it.hasNext();) {
          TLDFunction function = (TLDFunction) it.next();
          CustomCompletionProposal proposal = new CustomCompletionProposal(function.getName() + "()", //$NON-NLS-1$
                offset, 0, function.getName().length() + 1, null, function.getName() + " - " + function.getSignature(), null, null, 1); //$NON-NLS-1$

          completionList.add(proposal);
        }
      }
View Full Code Here

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

    for (int i = 0; i < resources.size(); i++) {
      memberResource = (IResource) resources.get(i);
      if (memberResource.getType() == IResource.FILE && memberResource.getName().endsWith(".ser")) { //$NON-NLS-1$
        String path = URIHelper.normalize(memberResource.getFullPath().toString(), resource.getFullPath().toString(), resource.getProject().getFullPath().toString());
        if (path != null) {
          names.add(new CustomCompletionProposal("\"" + path + "\"", //$NON-NLS-1$ //$NON-NLS-2$
                replacementStart, replacementLength, path.length() + 2, null, path, null, null, IRelevanceConstants.R_NONE));
        }
      }
    }
    return (ICompletionProposal[]) names.toArray(new ICompletionProposal[names.size()]);
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.