Package org.eclipse.jface.text.contentassist

Examples of org.eclipse.jface.text.contentassist.CompletionProposal


                    // writing
                    String replacementString = wordProposal;
                    int replacementOffset = documentOffset - guessedMethodWord.length();
                    int replacementLength = guessedMethodWord.length();
                    int cursorPosition = wordProposal.length();
                    CompletionProposal completionProposal = new CompletionProposal(replacementString, replacementOffset,
                            replacementLength, cursorPosition);
                    props.add(completionProposal);
                } else if (wordProposal.toLowerCase().contains(guessedMethodWord.toLowerCase())) {
                    // propose then those words that contain the letters the user is writing
                    String replacementString = wordProposal;
                    int replacementOffset = documentOffset - guessedMethodWord.length();
                    int replacementLength = guessedMethodWord.length();
                    int cursorPosition = wordProposal.length();
                    CompletionProposal completionProposal = new CompletionProposal(replacementString, replacementOffset,
                            replacementLength, cursorPosition);
                    tmp.add(completionProposal);
                }
            }
            // add second choice
            props.addAll(tmp);
        } else {
            if (readWord.endsWith(".")) {
                // after the dot, propose methods
                for( int i = 0; i < methodWordsProposals.length; i++ ) {
                    String replacementString = methodWordsProposals[i];
                    int replacementOffset = documentOffset;
                    int replacementLength = 0;
                    int cursorPosition = methodWordsProposals[i].length();
                    CompletionProposal completionProposal = new CompletionProposal(replacementString, replacementOffset,
                            replacementLength, cursorPosition);
                    props.add(completionProposal);
                }
            } else {
                List<ICompletionProposal> tmp = new ArrayList<ICompletionProposal>();
                // propose classes and other words
                for( int i = 0; i < singleWordsProposals.length; i++ ) {
                    String wordProposal = singleWordsProposals[i];
                    if (guessedModelWord != null && wordProposal.toLowerCase().startsWith(guessedModelWord.toLowerCase())) {
                        String replacementString = wordProposal;
                        int replacementOffset = documentOffset - guessedModelWord.length();
                        int replacementLength = guessedModelWord.length();
                        int cursorPosition = wordProposal.length();
                        CompletionProposal completionProposal = new CompletionProposal(replacementString, replacementOffset,
                                replacementLength, cursorPosition);
                        props.add(completionProposal);
                    } else if (wordProposal.toLowerCase().contains(guessedModelWord.toLowerCase())) {
                        // propose then those words that contain the letters the user is writing
                        String replacementString = wordProposal;
                        int replacementOffset = documentOffset - guessedModelWord.length();
                        int replacementLength = guessedModelWord.length();
                        int cursorPosition = wordProposal.length();
                        CompletionProposal completionProposal = new CompletionProposal(replacementString, replacementOffset,
                                replacementLength, cursorPosition);
                        tmp.add(completionProposal);
                    }
                }
                props.addAll(tmp);
View Full Code Here


                                append('>');

                            replace = sb.toString();

                            proposals[0] =
                                new CompletionProposal(
                                    replace,
                                    documentOffset - ic.getMatchName().length(),
                                    ic.getMatchName().length(),
                                    replace.length(),
                                    null,
View Full Code Here

            // Create the proposal using the replacement string and cursor position
            // calculated above. The list always shows the "unqualified" names for
            // attributes and elements.
            proposals[i] =
                new CompletionProposal(
                    replace,
                    replaceOffset,
                    replaceLength,
                    cursorPos,
                    null,
View Full Code Here

        // convert code completion proposal into eclipse ICompletionProposal
        ICompletionProposal[] ret = new ICompletionProposal[proposals.length];
        for (int i = 0; i < proposals.length; i++) {
            CodeCompletionProposal prop = proposals[i];
            ret[i] = new CompletionProposal(prop.getReplacementString(), prop
                    .getReplacementOffset(), prop.getReplacementLength(), prop.getCursorPosition(),
                    null, prop.getDisplayString(), null, prop.getDoc());
        }

        return ret;
View Full Code Here

    ICompletionProposal[] prop = (ICompletionProposal[])list.toArray(new ICompletionProposal[list.size()]);
    return prop;
  }
 
  private static CompletionProposal createProposal(String text, String display, String word, int offset, int position, String image){
    return new CompletionProposal(
        text, offset - word.length(), word.length(), position,
        HTMLPlugin.getDefault().getImageRegistry().get(image), display,
        null, null);
  }
View Full Code Here

        AttributeInfo attrInfo = tagInfo.getAttributeInfo(attr);
        if(attrInfo!=null){
          AssistInfo[] keywords = getAttributeValues(last,dim[0].substring(1),attrInfo);
          for(int i=0;i<keywords.length;i++){
            if(keywords[i].getReplaceString().toLowerCase().startsWith(value.toLowerCase())){
              list.add(new CompletionProposal(
                  keywords[i].getReplaceString(),
                  documentOffset - value.length(), value.length(),
                  keywords[i].getReplaceString().length(),
                  keywords[i].getImage()==null ? valueImage : keywords[i].getImage(),
                  keywords[i].getDisplayString(), null, null));
            }
          }
        }
      }
    // tag
    } else if(word.startsWith("<") && !word.equals("</")) {
      if(supportTagRelation()){
        TagInfo parent = getTagInfo(last);
        tagList = new ArrayList();
        if(parent!=null){
          String[] childNames = parent.getChildTagNames();
          for(int i=0;i<childNames.length;i++){
            tagList.add(getTagInfo(childNames[i]));
          }
        }
      }
      for(int i=0;i<tagList.size();i++){
        TagInfo tagInfo = (TagInfo)tagList.get(i);
        if(tagInfo instanceof TextInfo){
          TextInfo textInfo = (TextInfo)tagInfo;
          if ((textInfo.getText().toLowerCase()).indexOf(word) == 0) {
            list.add(new CompletionProposal(
                textInfo.getText(), documentOffset - word.length(),
                word.length(), textInfo.getPosition(), tagImage,
                textInfo.getDisplayString(), null, tagInfo.getDescription()));
          }
          continue;
        }
        String tagName = tagInfo.getTagName();
        if (("<" + tagInfo.getTagName().toLowerCase()).indexOf(word) == 0) {
          String assistKeyword = tagName;
          int position = 0;
          // required attributes
          AttributeInfo[] requierAttrs = tagInfo.getRequiredAttributeInfo();
          for(int j=0;j<requierAttrs.length;j++){
            assistKeyword = assistKeyword + " " + requierAttrs[j].getAttributeName();
            if(requierAttrs[j].hasValue()){
              assistKeyword = assistKeyword + "=\"\"";
              if(j==0){
                position = tagName.length() + requierAttrs[j].getAttributeName().length() + 3;
              }
            }
          }
          if(tagInfo.hasBody()){
            assistKeyword = assistKeyword + ">";
            if(assistCloseTag){
              if(position==0){
                position = assistKeyword.length();
              }
              assistKeyword = assistKeyword + "</" + tagName + ">";
            }
          } else {
            if(tagInfo.isEmptyTag() && xhtmlMode == false){
              assistKeyword = assistKeyword + ">";
            } else {
              assistKeyword = assistKeyword + "/>";
            }
          }
          if(position==0){
            position = assistKeyword.length();
          }
          try {
          list.add(new CompletionProposal(
                assistKeyword, documentOffset - word.length() + 1,
                word.length() - 1, position, tagImage, tagName, null, tagInfo.getDescription()));
          } catch(Exception ex){
          }
        }
      }
      // custom elements
      for(int i=0;i<customElems.size();i++){
        CustomElement element = (CustomElement)customElems.get(i);
        if ((element.getAssistString().toLowerCase()).indexOf(word) == 0) {
          int position = element.getAssistString().indexOf('"');
          if(position==-1){
            position = element.getAssistString().indexOf("><");
          }
          if(position==-1){
            position = element.getAssistString().length();
          }
          list.add(new CompletionProposal(
              element.getAssistString(), documentOffset - word.length(),
              word.length(), position + 1, tagImage, element.getDisplayName(),
              null, null));
        }
      }
    // attribute
    } else if(!prev.equals("")){
      String tagName = prev;
      TagInfo tagInfo = getTagInfo(tagName);
      if(tagInfo!=null){
        AttributeInfo[] attrList = tagInfo.getAttributeInfo();
        for(int j=0;j<attrList.length;j++){
          if (attrList[j].getAttributeName().toLowerCase().indexOf(word) == 0) {
            String assistKeyword = null;
            int position = 0;
            if(attrList[j].hasValue()){
              assistKeyword = attrList[j].getAttributeName() + "=\"\"";
              position = 2;
            } else {
              assistKeyword = attrList[j].getAttributeName();
              position = 0;
            }
            list.add(new CompletionProposal(
                assistKeyword, documentOffset - word.length(), word.length(),
                attrList[j].getAttributeName().length() + position,
                attrImage, attrList[j].getAttributeName(), null, attrList[j].getDescription()));
          }
        }
      }
      // custom attributes
      for(int i=0;i<customAttrs.size();i++){
        CustomAttribute attrInfo = (CustomAttribute)customAttrs.get(i);
        if(attrInfo.getTargetTag().equals("*") || attrInfo.getTargetTag().equals(tagName)){
          if(tagName.indexOf(":")<0 || customElemNames.contains(tagName)){
            list.add(new CompletionProposal(
                attrInfo.getAttributeName() + "=\"\"",
                documentOffset - word.length(), word.length(),
                attrInfo.getAttributeName().length() + 2,
                attrImage, attrInfo.getAttributeName(), null, null));
          }
        }
      }
    // close tag
    } else if(!last.equals("")){
      TagInfo info = getTagInfo(last);
      if(info==null || xhtmlMode==true || info.hasBody() || !info.isEmptyTag()){
        String assistKeyword = "</" + last + ">";
        int length = 0;
        if(word.equals("</")){
          length = 2;
        }
        list.add(new CompletionProposal(
            assistKeyword, documentOffset - length, length,
            assistKeyword.length(), tagImage, assistKeyword, null, null));
      }
    }
   
View Full Code Here

   
    ArrayList list = new ArrayList();
    if(word!=null){
      for(int i=0;i<CSSDefinition.CSS_KEYWORDS.length;i++){
        if(CSSDefinition.CSS_KEYWORDS[i].getReplaceString().startsWith(word)){
          list.add(new CompletionProposal(
              CSSDefinition.CSS_KEYWORDS[i].getReplaceString(),
              offset - word.length(),
              word.length(),
              CSSDefinition.CSS_KEYWORDS[i].getReplaceString().length(),
              HTMLPlugin.getDefault().getImageRegistry().get(HTMLPlugin.ICON_CSS_PROP),
View Full Code Here

              type = VARIABLE;
              replace = children[i].getName();
              position = replace.length();
            }
           
            proposal.add(new CompletionProposal(
                replace, offset - word.length(), word.length(),
                position, getImageFromType(type),
                children[i].toString(), null, null));
          }
        }
View Full Code Here

      this.replaceString = replaceString;
      this.position = position;
    }
   
    public CompletionProposal createCompletionProposal(int offset, String word){
      return new CompletionProposal(
          replaceString, offset - word.length(), word.length(),
          position, getImageFromType(type),
          displayString, null, null);
    }
View Full Code Here

    List assistInfos = new ArrayList();
   
    for(int i=0;i<values.size();i++){
      String value = (String)values.get(i);
      if(value.startsWith(lastWord)){
        assistInfos.add(new CompletionProposal(
            value,
            offset-lastWord.length(),
            lastWord.length(),
            value.length(),
            valueImage,
View Full Code Here

TOP

Related Classes of org.eclipse.jface.text.contentassist.CompletionProposal

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.