29
|
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 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.fieldassist.AutoCompleteField;
|
|
14
|
|
15 import dwtx.jface.fieldassist.IControlContentAdapter;
|
|
16 import dwtx.jface.fieldassist.SimpleContentProposalProvider;
|
|
17 import dwtx.jface.fieldassist.ContentProposalAdapter;
|
|
18
|
|
19 import dwt.widgets.Control;
|
|
20
|
|
21 import dwt.dwthelper.utils;
|
|
22
|
|
23 /**
|
|
24 * AutoCompleteField is a class which attempts to auto-complete a user's
|
|
25 * keystrokes by activating a popup that filters a list of proposals according
|
|
26 * to the content typed by the user.
|
|
27 *
|
|
28 * @see ContentProposalAdapter
|
|
29 * @see SimpleContentProposalProvider
|
|
30 *
|
|
31 * @since 3.3
|
|
32 */
|
|
33 public class AutoCompleteField {
|
|
34
|
|
35 private SimpleContentProposalProvider proposalProvider;
|
|
36 private ContentProposalAdapter adapter;
|
|
37
|
|
38 /**
|
|
39 * Construct an AutoComplete field on the specified control, whose
|
|
40 * completions are characterized by the specified array of Strings.
|
|
41 *
|
|
42 * @param control
|
|
43 * the control for which autocomplete is desired. May not be
|
|
44 * <code>null</code>.
|
|
45 * @param controlContentAdapter
|
|
46 * the <code>IControlContentAdapter</code> used to obtain and
|
|
47 * update the control's contents. May not be <code>null</code>.
|
|
48 * @param proposals
|
|
49 * the array of Strings representing valid content proposals for
|
|
50 * the field.
|
|
51 */
|
|
52 public this(Control control,
|
|
53 IControlContentAdapter controlContentAdapter, String[] proposals) {
|
|
54 proposalProvider = new SimpleContentProposalProvider(proposals);
|
|
55 proposalProvider.setFiltering(true);
|
|
56 adapter = new ContentProposalAdapter(control, controlContentAdapter,
|
|
57 proposalProvider, null, null);
|
|
58 adapter.setPropagateKeys(true);
|
|
59 adapter
|
|
60 .setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
|
|
61 }
|
|
62
|
|
63 /**
|
|
64 * Set the Strings to be used as content proposals.
|
|
65 *
|
|
66 * @param proposals
|
|
67 * the array of Strings to be used as proposals.
|
|
68 */
|
|
69 public void setProposals(String[] proposals) {
|
|
70 proposalProvider.setProposals(proposals);
|
|
71 }
|
|
72 }
|