KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > quickassist > QuickAssistAssistant


1 /*******************************************************************************
2  * Copyright (c) 2006 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.text.quickassist;
12
13 import org.eclipse.swt.graphics.Color;
14
15
16 import org.eclipse.jface.text.IDocument;
17 import org.eclipse.jface.text.IInformationControlCreator;
18 import org.eclipse.jface.text.ITextViewer;
19 import org.eclipse.jface.text.contentassist.ContentAssistant;
20 import org.eclipse.jface.text.contentassist.ICompletionListener;
21 import org.eclipse.jface.text.contentassist.ICompletionProposal;
22 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
23 import org.eclipse.jface.text.contentassist.IContextInformation;
24 import org.eclipse.jface.text.contentassist.IContextInformationValidator;
25 import org.eclipse.jface.text.source.Annotation;
26 import org.eclipse.jface.text.source.ISourceViewer;
27 import org.eclipse.jface.text.source.TextInvocationContext;
28
29
30 /**
31  * Default implementation of <code>IQuickAssistAssistant</code>.
32  *
33  * @since 3.2
34  */

35 public class QuickAssistAssistant implements IQuickAssistAssistant {
36     
37     
38     private static final class QuickAssistAssistantImpl extends ContentAssistant {
39         /*
40          * @see org.eclipse.jface.text.contentassist.ContentAssistant#possibleCompletionsClosed()
41          */

42         public void possibleCompletionsClosed() {
43             super.possibleCompletionsClosed();
44         }
45     }
46
47     
48     private static final class ContentAssistProcessor implements IContentAssistProcessor {
49
50         private IQuickAssistProcessor fQuickAssistProcessor;
51
52         ContentAssistProcessor(IQuickAssistProcessor processor) {
53             fQuickAssistProcessor= processor;
54         }
55         
56         /*
57          * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, int)
58          */

59         public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
60             // panic code - should not happen
61
if (!(viewer instanceof ISourceViewer))
62                 return null;
63             
64             return fQuickAssistProcessor.computeQuickAssistProposals(new TextInvocationContext((ISourceViewer)viewer, offset, -1));
65         }
66
67         /*
68          * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int)
69          */

70         public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
71             return null;
72         }
73
74         /*
75          * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
76          */

77         public char[] getCompletionProposalAutoActivationCharacters() {
78             return null;
79         }
80
81         /*
82          * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters()
83          */

84         public char[] getContextInformationAutoActivationCharacters() {
85             return null;
86         }
87
88         /*
89          * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage()
90          */

91         public String JavaDoc getErrorMessage() {
92             return null;
93         }
94
95         /*
96          * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator()
97          */

98         public IContextInformationValidator getContextInformationValidator() {
99             return null;
100         }
101         
102     }
103     
104     private QuickAssistAssistantImpl fQuickAssistAssistantImpl;
105     private IQuickAssistProcessor fQuickAssistProcessor;
106     
107     public QuickAssistAssistant() {
108         fQuickAssistAssistantImpl= new QuickAssistAssistantImpl();
109         fQuickAssistAssistantImpl.enableAutoActivation(false);
110         fQuickAssistAssistantImpl.enableAutoInsert(false);
111     }
112
113     /*
114      * @see org.eclipse.jface.text.quickassist.IQuickAssistAssistant#showPossibleQuickAssists()
115      */

116     public String JavaDoc showPossibleQuickAssists() {
117         return fQuickAssistAssistantImpl.showPossibleCompletions();
118     }
119
120     /*
121      * @see org.eclipse.jface.text.quickassist.IQuickAssistAssistant#getQuickAssistProcessor(java.lang.String)
122      */

123     public IQuickAssistProcessor getQuickAssistProcessor() {
124         return fQuickAssistProcessor;
125     }
126
127     /*
128      * @see org.eclipse.jface.text.quickassist.IQuickAssistAssistant#setQuickAssistProcessor(org.eclipse.jface.text.quickassist.IQuickAssistProcessor)
129      */

130     public void setQuickAssistProcessor(IQuickAssistProcessor processor) {
131         fQuickAssistProcessor= processor;
132         fQuickAssistAssistantImpl.setDocumentPartitioning("__" + getClass().getName() + "_partitioning"); //$NON-NLS-1$ //$NON-NLS-2$
133
fQuickAssistAssistantImpl.setContentAssistProcessor(new ContentAssistProcessor(processor), IDocument.DEFAULT_CONTENT_TYPE);
134     }
135
136     /*
137      * @see org.eclipse.jface.text.quickassist.IQuickAssistAssistant#canFix(org.eclipse.jface.text.source.Annotation)
138      */

139     public boolean canFix(Annotation annotation) {
140         return fQuickAssistProcessor != null && fQuickAssistProcessor.canFix(annotation);
141     }
142
143     /*
144      * @see org.eclipse.jface.text.quickassist.IQuickAssistAssistant#canAssist(org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext)
145      */

146     public boolean canAssist(IQuickAssistInvocationContext invocationContext) {
147         return fQuickAssistProcessor != null && fQuickAssistProcessor.canAssist(invocationContext);
148     }
149
150     /*
151      * @see org.eclipse.jface.text.quickassist.IQuickAssistAssistant#install(org.eclipse.jface.text.ITextViewer)
152      */

153     public void install(ISourceViewer sourceViewer) {
154         fQuickAssistAssistantImpl.install(sourceViewer);
155     }
156
157     /*
158      * @see org.eclipse.jface.text.quickassist.IQuickAssistAssistant#setInformationControlCreator(org.eclipse.jface.text.IInformationControlCreator)
159      */

160     public void setInformationControlCreator(IInformationControlCreator creator) {
161         fQuickAssistAssistantImpl.setInformationControlCreator(creator);
162     }
163     
164     /*
165      * @see org.eclipse.jface.text.quickassist.IQuickAssistAssistant#uninstall()
166      */

167     public void uninstall() {
168         fQuickAssistAssistantImpl.uninstall();
169     }
170     /**
171      * Sets the proposal selector's background color.
172      *
173      * @param background the background color
174      */

175     public void setProposalSelectorBackground(Color background) {
176         fQuickAssistAssistantImpl.setProposalSelectorBackground(background);
177     }
178     
179     /*
180      * @see org.eclipse.jface.text.quickassist.IQuickAssistAssistant#setProposalSelectorForeground(org.eclipse.swt.graphics.Color)
181      */

182     public void setProposalSelectorForeground(Color foreground) {
183         fQuickAssistAssistantImpl.setProposalSelectorForeground(foreground);
184     }
185
186     /**
187      * Callback to signal this quick assist assistant that the presentation of the
188      * possible completions has been stopped.
189      */

190     protected void possibleCompletionsClosed() {
191         fQuickAssistAssistantImpl.possibleCompletionsClosed();
192     }
193
194     /*
195      * @see org.eclipse.jface.text.quickassist.IQuickAssistAssistant#addCompletionListener(org.eclipse.jface.text.contentassist.ICompletionListener)
196      */

197     public void addCompletionListener(ICompletionListener listener) {
198         fQuickAssistAssistantImpl.addCompletionListener(listener);
199     }
200
201     /*
202      * @see org.eclipse.jface.text.quickassist.IQuickAssistAssistant#removeCompletionListener(org.eclipse.jface.text.contentassist.ICompletionListener)
203      */

204     public void removeCompletionListener(ICompletionListener listener) {
205         fQuickAssistAssistantImpl.removeCompletionListener(listener);
206     }
207
208     /*
209      * @see org.eclipse.jface.text.quickassist.IQuickAssistAssistant#setStatusLineVisible(boolean)
210      */

211     public void setStatusLineVisible(boolean show) {
212         fQuickAssistAssistantImpl.setStatusLineVisible(show);
213         
214     }
215
216     /*
217      * @see org.eclipse.jface.text.quickassist.IQuickAssistAssistant#setStatusMessage(java.lang.String)
218      */

219     public void setStatusMessage(String JavaDoc message) {
220         fQuickAssistAssistantImpl.setStatusMessage(message);
221     }
222 }
223
Popular Tags