1 11 package org.eclipse.jface.fieldassist; 12 13 import java.util.ArrayList ; 14 15 23 public class SimpleContentProposalProvider implements IContentProposalProvider { 24 25 28 private String [] proposals; 29 30 34 private IContentProposal[] contentProposals; 35 36 39 private boolean filterProposals = false; 40 41 49 public SimpleContentProposalProvider(String [] proposals) { 50 super(); 51 this.proposals = proposals; 52 } 53 54 66 public IContentProposal[] getProposals(String contents, int position) { 67 if (filterProposals) { 68 ArrayList list = new ArrayList (); 69 for (int i = 0; i < proposals.length; i++) { 70 if (proposals[i].length() > contents.length() 71 && proposals[i].substring(0, contents.length()) 72 .equalsIgnoreCase(contents)) { 73 list.add(makeContentProposal(proposals[i])); 74 } 75 } 76 return (IContentProposal[]) list.toArray(new IContentProposal[list 77 .size()]); 78 } 79 if (contentProposals == null) { 80 contentProposals = new IContentProposal[proposals.length]; 81 for (int i = 0; i < proposals.length; i++) { 82 contentProposals[i] = makeContentProposal(proposals[i]); 83 } 84 } 85 return contentProposals; 86 } 87 88 94 public void setProposals(String [] items) { 95 this.proposals = items; 96 contentProposals = null; 97 } 98 99 110 public void setFiltering(boolean filterProposals) { 111 this.filterProposals = filterProposals; 112 contentProposals = null; 114 } 115 116 119 private IContentProposal makeContentProposal(final String proposal) { 120 return new IContentProposal() { 121 public String getContent() { 122 return proposal; 123 } 124 125 public String getDescription() { 126 return null; 127 } 128 129 public String getLabel() { 130 return null; 131 } 132 133 public int getCursorPosition() { 134 return proposal.length(); 135 } 136 }; 137 } 138 } 139 | Popular Tags |