129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 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.text.source.ContentAssistantFacade;
|
|
14
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17
|
|
18
|
|
19 import dwtx.core.commands.IHandler;
|
|
20 import dwtx.core.runtime.Assert;
|
|
21 import dwtx.jface.text.contentassist.ICompletionListener;
|
|
22 import dwtx.jface.text.contentassist.IContentAssistant;
|
|
23 import dwtx.jface.text.contentassist.IContentAssistantExtension2;
|
|
24 import dwtx.jface.text.contentassist.IContentAssistantExtension4;
|
|
25
|
|
26
|
|
27 /**
|
|
28 * Facade to allow minimal access to the given content assistant.
|
|
29 * <p>
|
|
30 * The offered API access can grow over time.
|
|
31 * </p>
|
|
32 *
|
|
33 * @since 3.4
|
|
34 */
|
|
35 public final class ContentAssistantFacade {
|
|
36
|
|
37 private IContentAssistant fContentAssistant;
|
|
38
|
|
39 /**
|
|
40 * Creates a new facade.
|
|
41 *
|
|
42 * @param contentAssistant the content assistant which implements {@link IContentAssistantExtension2} and {@link IContentAssistantExtension4}
|
|
43 */
|
|
44 public ContentAssistantFacade(IContentAssistant contentAssistant) {
|
|
45 Assert.isLegal(contentAssistant instanceof IContentAssistantExtension4 && contentAssistant instanceof IContentAssistantExtension4);
|
|
46 fContentAssistant= contentAssistant;
|
|
47 }
|
|
48
|
|
49 /**
|
|
50 * Returns the handler for the given command identifier.
|
|
51 * <p>
|
|
52 * The same handler instance will be returned when called a more than once
|
|
53 * with the same command identifier.
|
|
54 * </p>
|
|
55 *
|
|
56 * @param commandId the command identifier
|
|
57 * @return the handler for the given command identifier
|
|
58 * @throws IllegalArgumentException if the command is not supported by this
|
|
59 * content assistant
|
|
60 * @throws IllegalStateException if called when the content assistant is
|
|
61 * uninstalled
|
|
62 */
|
|
63 public IHandler getHandler(String commandId) {
|
|
64 if (fContentAssistant is null)
|
|
65 throw new IllegalStateException();
|
|
66 return ((IContentAssistantExtension4)fContentAssistant).getHandler(commandId);
|
|
67 }
|
|
68
|
|
69 /**
|
|
70 * Adds a completion listener that will be informed before proposals are
|
|
71 * computed.
|
|
72 *
|
|
73 * @param listener the listener
|
|
74 * @throws IllegalStateException if called when the content assistant is
|
|
75 * uninstalled
|
|
76 */
|
|
77 public void addCompletionListener(ICompletionListener listener) {
|
|
78 if (fContentAssistant is null)
|
|
79 throw new IllegalStateException();
|
|
80 ((IContentAssistantExtension2)fContentAssistant).addCompletionListener(listener);
|
|
81 }
|
|
82
|
|
83 /**
|
|
84 * Removes a completion listener.
|
|
85 *
|
|
86 * @param listener the listener to remove
|
|
87 * @throws IllegalStateException if called when the content assistant is
|
|
88 * uninstalled
|
|
89 */
|
|
90 public void removeCompletionListener(ICompletionListener listener) {
|
|
91 ((IContentAssistantExtension2)fContentAssistant).removeCompletionListener(listener);
|
|
92 }
|
|
93
|
|
94 }
|