1 package org.apache.directory.ldapstudio.browser.common.widgets; 2 3 4 import java.util.ArrayList ; 5 import java.util.Arrays ; 6 import java.util.Collections ; 7 import java.util.List ; 8 9 import org.eclipse.jface.fieldassist.IContentProposal; 10 import org.eclipse.jface.fieldassist.IContentProposalProvider; 11 12 13 20 public class ListContentProposalProvider implements IContentProposalProvider 21 { 22 23 24 private List <String > proposals; 25 26 27 32 public ListContentProposalProvider( List <String > proposals ) 33 { 34 setProposals( proposals ); 35 } 36 37 38 43 public ListContentProposalProvider( String [] proposals ) 44 { 45 setProposals( new ArrayList <String >( Arrays.asList( proposals ) ) ); 46 } 47 48 49 52 public IContentProposal[] getProposals( String contents, int position ) 53 { 54 String string = contents.substring( 0, position ); 55 56 Collections.sort( proposals ); 57 58 List <IContentProposal> proposalList = new ArrayList <IContentProposal>(); 59 for ( int k = 0; k < proposals.size(); k++ ) 60 { 61 final String proposal = proposals.get( k ); 62 if ( proposal.toUpperCase().startsWith( string.toUpperCase() ) && !proposal.equalsIgnoreCase( string ) 63 && !"".equals( string ) ) 64 { 65 IContentProposal p = new IContentProposal() 66 { 67 public String getContent() 68 { 69 return proposal; 70 } 71 72 73 public String getDescription() 74 { 75 return proposal; 76 } 77 78 79 public String getLabel() 80 { 81 return proposal; 82 } 83 84 85 public int getCursorPosition() 86 { 87 return proposal.length(); 88 } 89 }; 90 proposalList.add( p ); 91 } 92 } 93 return proposalList.toArray( new IContentProposal[proposalList.size()] ); 94 } 95 96 97 102 public void setProposals( List <String > proposals ) 103 { 104 if ( proposals == null ) 105 { 106 proposals = new ArrayList <String >(); 107 } 108 109 this.proposals = proposals; 110 } 111 112 } 113 | Popular Tags |