KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > fieldassist > AutoCompleteField


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jface.fieldassist;
12
13 import org.eclipse.swt.widgets.Control;
14
15 /**
16  * AutoCompleteField is a class which attempts to auto-complete a user's
17  * keystrokes by activating a popup that filters a list of proposals according
18  * to the content typed by the user.
19  *
20  * @see ContentProposalAdapter
21  * @see SimpleContentProposalProvider
22  *
23  * @since 3.3
24  */

25 public class AutoCompleteField {
26
27     private SimpleContentProposalProvider proposalProvider;
28     private ContentProposalAdapter adapter;
29
30     /**
31      * Construct an AutoComplete field on the specified control, whose
32      * completions are characterized by the specified array of Strings.
33      *
34      * @param control
35      * the control for which autocomplete is desired. May not be
36      * <code>null</code>.
37      * @param controlContentAdapter
38      * the <code>IControlContentAdapter</code> used to obtain and
39      * update the control's contents. May not be <code>null</code>.
40      * @param proposals
41      * the array of Strings representing valid content proposals for
42      * the field.
43      */

44     public AutoCompleteField(Control control,
45             IControlContentAdapter controlContentAdapter, String JavaDoc[] proposals) {
46         proposalProvider = new SimpleContentProposalProvider(proposals);
47         proposalProvider.setFiltering(true);
48         adapter = new ContentProposalAdapter(control, controlContentAdapter,
49                 proposalProvider, null, null);
50         adapter.setPropagateKeys(true);
51         adapter
52                 .setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
53     }
54
55     /**
56      * Set the Strings to be used as content proposals.
57      *
58      * @param proposals
59      * the array of Strings to be used as proposals.
60      */

61     public void setProposals(String JavaDoc[] proposals) {
62         proposalProvider.setProposals(proposals);
63     }
64 }
65
Popular Tags