KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > text > java > ContentAssistProcessor


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.jdt.internal.ui.text.java;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Collections JavaDoc;
15 import java.util.Comparator JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.List JavaDoc;
18
19 import org.eclipse.core.runtime.Assert;
20 import org.eclipse.core.runtime.IProgressMonitor;
21 import org.eclipse.core.runtime.NullProgressMonitor;
22 import org.eclipse.core.runtime.Platform;
23 import org.eclipse.core.runtime.SubProgressMonitor;
24
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.events.SelectionAdapter;
27 import org.eclipse.swt.events.SelectionEvent;
28 import org.eclipse.swt.layout.GridData;
29 import org.eclipse.swt.layout.GridLayout;
30 import org.eclipse.swt.widgets.Button;
31 import org.eclipse.swt.widgets.Composite;
32 import org.eclipse.swt.widgets.Control;
33 import org.eclipse.swt.widgets.Link;
34 import org.eclipse.swt.widgets.Shell;
35
36 import org.eclipse.jface.action.LegacyActionTools;
37 import org.eclipse.jface.bindings.TriggerSequence;
38 import org.eclipse.jface.bindings.keys.KeySequence;
39 import org.eclipse.jface.dialogs.IDialogConstants;
40 import org.eclipse.jface.dialogs.MessageDialog;
41 import org.eclipse.jface.preference.IPreferenceStore;
42 import org.eclipse.jface.resource.JFaceResources;
43
44 import org.eclipse.jface.text.IDocument;
45 import org.eclipse.jface.text.ITextViewer;
46 import org.eclipse.jface.text.contentassist.ContentAssistEvent;
47 import org.eclipse.jface.text.contentassist.ContentAssistant;
48 import org.eclipse.jface.text.contentassist.ICompletionListener;
49 import org.eclipse.jface.text.contentassist.ICompletionProposal;
50 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
51 import org.eclipse.jface.text.contentassist.IContentAssistantExtension2;
52 import org.eclipse.jface.text.contentassist.IContentAssistantExtension3;
53 import org.eclipse.jface.text.contentassist.IContextInformation;
54 import org.eclipse.jface.text.contentassist.IContextInformationValidator;
55
56 import org.eclipse.ui.PlatformUI;
57 import org.eclipse.ui.dialogs.PreferencesUtil;
58 import org.eclipse.ui.keys.IBindingService;
59 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
60
61 import org.eclipse.jdt.internal.corext.util.Messages;
62
63 import org.eclipse.jdt.ui.PreferenceConstants;
64 import org.eclipse.jdt.ui.text.IJavaPartitions;
65 import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
66
67 import org.eclipse.jdt.internal.ui.JavaPlugin;
68 import org.eclipse.jdt.internal.ui.JavaUIMessages;
69 import org.eclipse.jdt.internal.ui.dialogs.OptionalMessageDialog;
70
71 /**
72  * A content assist processor that aggregates the proposals of the
73  * {@link org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer}s contributed via the
74  * <code>org.eclipse.jdt.ui.javaCompletionProposalComputer</code> extension point.
75  * <p>
76  * Subclasses may extend:
77  * <ul>
78  * <li><code>createContext</code> to provide the context object passed to the computers</li>
79  * <li><code>createProgressMonitor</code> to change the way progress is reported</li>
80  * <li><code>filterAndSort</code> to add sorting and filtering</li>
81  * <li><code>getContextInformationValidator</code> to add context validation (needed if any
82  * contexts are provided)</li>
83  * <li><code>getErrorMessage</code> to change error reporting</li>
84  * </ul>
85  * </p>
86  *
87  * @since 3.2
88  */

89 public class ContentAssistProcessor implements IContentAssistProcessor {
90     private static final boolean DEBUG= "true".equalsIgnoreCase(Platform.getDebugOption("org.eclipse.jdt.ui/debug/ResultCollector")); //$NON-NLS-1$//$NON-NLS-2$
91

92     /**
93      * Dialog settings key for the "all categories are disabled" warning dialog. See
94      * {@link OptionalMessageDialog}.
95      *
96      * @since 3.3
97      */

98     private static final String JavaDoc PREF_WARN_ABOUT_EMPTY_ASSIST_CATEGORY= "EmptyDefaultAssistCategory"; //$NON-NLS-1$
99

100     private static final Comparator JavaDoc ORDER_COMPARATOR= new Comparator JavaDoc() {
101
102         public int compare(Object JavaDoc o1, Object JavaDoc o2) {
103             CompletionProposalCategory d1= (CompletionProposalCategory) o1;
104             CompletionProposalCategory d2= (CompletionProposalCategory) o2;
105             
106             return d1.getSortOrder() - d2.getSortOrder();
107         }
108         
109     };
110     
111     private final List JavaDoc fCategories;
112     private final String JavaDoc fPartition;
113     private final ContentAssistant fAssistant;
114     
115     private char[] fCompletionAutoActivationCharacters;
116     
117     /* cycling stuff */
118     private int fRepetition= -1;
119     private List JavaDoc/*<List<CompletionProposalCategory>>*/ fCategoryIteration= null;
120     private String JavaDoc fIterationGesture= null;
121     private int fNumberOfComputedResults= 0;
122     private String JavaDoc fErrorMessage;
123     
124     public ContentAssistProcessor(ContentAssistant assistant, String JavaDoc partition) {
125         Assert.isNotNull(partition);
126         Assert.isNotNull(assistant);
127         fPartition= partition;
128         fCategories= CompletionProposalComputerRegistry.getDefault().getProposalCategories();
129         fAssistant= assistant;
130         fAssistant.addCompletionListener(new ICompletionListener() {
131             
132             /*
133              * @see org.eclipse.jface.text.contentassist.ICompletionListener#assistSessionStarted(org.eclipse.jface.text.contentassist.ContentAssistEvent)
134              */

135             public void assistSessionStarted(ContentAssistEvent event) {
136                 if (event.processor != ContentAssistProcessor.this)
137                     return;
138
139                 fIterationGesture= getIterationGesture();
140                 KeySequence binding= getIterationBinding();
141
142                 // this may show the warning dialog if all categories are disabled
143
fCategoryIteration= getCategoryIteration();
144                 for (Iterator JavaDoc it= fCategories.iterator(); it.hasNext();) {
145                     CompletionProposalCategory cat= (CompletionProposalCategory) it.next();
146                     cat.sessionStarted();
147                 }
148                 
149                 fRepetition= 0;
150                 if (event.assistant instanceof IContentAssistantExtension2) {
151                     IContentAssistantExtension2 extension= (IContentAssistantExtension2) event.assistant;
152
153                     if (fCategoryIteration.size() == 1) {
154                         extension.setRepeatedInvocationMode(false);
155                         extension.setShowEmptyList(false);
156                     } else {
157                         extension.setRepeatedInvocationMode(true);
158                         extension.setStatusLineVisible(true);
159                         extension.setStatusMessage(createIterationMessage());
160                         extension.setShowEmptyList(true);
161                         if (extension instanceof IContentAssistantExtension3) {
162                             IContentAssistantExtension3 ext3= (IContentAssistantExtension3) extension;
163                             ((ContentAssistant) ext3).setRepeatedInvocationTrigger(binding);
164                         }
165                     }
166                 
167                 }
168             }
169             
170             /*
171              * @see org.eclipse.jface.text.contentassist.ICompletionListener#assistSessionEnded(org.eclipse.jface.text.contentassist.ContentAssistEvent)
172              */

173             public void assistSessionEnded(ContentAssistEvent event) {
174                 if (event.processor != ContentAssistProcessor.this)
175                     return;
176
177                 for (Iterator JavaDoc it= fCategories.iterator(); it.hasNext();) {
178                     CompletionProposalCategory cat= (CompletionProposalCategory) it.next();
179                     cat.sessionEnded();
180                 }
181
182                 fCategoryIteration= null;
183                 fRepetition= -1;
184                 fIterationGesture= null;
185                 if (event.assistant instanceof IContentAssistantExtension2) {
186                     IContentAssistantExtension2 extension= (IContentAssistantExtension2) event.assistant;
187                     extension.setShowEmptyList(false);
188                     extension.setRepeatedInvocationMode(false);
189                     extension.setStatusLineVisible(false);
190                     if (extension instanceof IContentAssistantExtension3) {
191                         IContentAssistantExtension3 ext3= (IContentAssistantExtension3) extension;
192                         ((ContentAssistant) ext3).setRepeatedInvocationTrigger(null);
193                     }
194                 }
195             }
196
197             /*
198              * @see org.eclipse.jface.text.contentassist.ICompletionListener#selectionChanged(org.eclipse.jface.text.contentassist.ICompletionProposal, boolean)
199              */

200             public void selectionChanged(ICompletionProposal proposal, boolean smartToggle) {}
201             
202         });
203     }
204
205     /*
206      * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, int)
207      */

208     public final ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
209         long start= DEBUG ? System.currentTimeMillis() : 0;
210         
211         clearState();
212         
213         IProgressMonitor monitor= createProgressMonitor();
214         monitor.beginTask(JavaTextMessages.ContentAssistProcessor_computing_proposals, fCategories.size() + 1);
215
216         ContentAssistInvocationContext context= createContext(viewer, offset);
217         long setup= DEBUG ? System.currentTimeMillis() : 0;
218         
219         monitor.subTask(JavaTextMessages.ContentAssistProcessor_collecting_proposals);
220         List JavaDoc proposals= collectProposals(viewer, offset, monitor, context);
221         long collect= DEBUG ? System.currentTimeMillis() : 0;
222
223         monitor.subTask(JavaTextMessages.ContentAssistProcessor_sorting_proposals);
224         List JavaDoc filtered= filterAndSortProposals(proposals, monitor, context);
225         fNumberOfComputedResults= filtered.size();
226         long filter= DEBUG ? System.currentTimeMillis() : 0;
227         
228         ICompletionProposal[] result= (ICompletionProposal[]) filtered.toArray(new ICompletionProposal[filtered.size()]);
229         monitor.done();
230         
231         if (DEBUG) {
232             System.err.println("Code Assist Stats (" + result.length + " proposals)"); //$NON-NLS-1$ //$NON-NLS-2$
233
System.err.println("Code Assist (setup):\t" + (setup - start) ); //$NON-NLS-1$
234
System.err.println("Code Assist (collect):\t" + (collect - setup) ); //$NON-NLS-1$
235
System.err.println("Code Assist (sort):\t" + (filter - collect) ); //$NON-NLS-1$
236
}
237         
238         return result;
239     }
240
241     private void clearState() {
242         fErrorMessage=null;
243         fNumberOfComputedResults= 0;
244     }
245
246     private List JavaDoc collectProposals(ITextViewer viewer, int offset, IProgressMonitor monitor, ContentAssistInvocationContext context) {
247         List JavaDoc proposals= new ArrayList JavaDoc();
248         List JavaDoc providers= getCategories();
249         for (Iterator JavaDoc it= providers.iterator(); it.hasNext();) {
250             CompletionProposalCategory cat= (CompletionProposalCategory) it.next();
251             List JavaDoc computed= cat.computeCompletionProposals(context, fPartition, new SubProgressMonitor(monitor, 1));
252             proposals.addAll(computed);
253             if (fErrorMessage == null)
254                 fErrorMessage= cat.getErrorMessage();
255         }
256         
257         return proposals;
258     }
259
260     /**
261      * Filters and sorts the proposals. The passed list may be modified
262      * and returned, or a new list may be created and returned.
263      *
264      * @param proposals the list of collected proposals (element type:
265      * {@link ICompletionProposal})
266      * @param monitor a progress monitor
267      * @param context TODO
268      * @return the list of filtered and sorted proposals, ready for
269      * display (element type: {@link ICompletionProposal})
270      */

271     protected List JavaDoc filterAndSortProposals(List JavaDoc proposals, IProgressMonitor monitor, ContentAssistInvocationContext context) {
272         return proposals;
273     }
274
275     /*
276      * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int)
277      */

278     public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
279         clearState();
280
281         IProgressMonitor monitor= createProgressMonitor();
282         monitor.beginTask(JavaTextMessages.ContentAssistProcessor_computing_contexts, fCategories.size() + 1);
283         
284         monitor.subTask(JavaTextMessages.ContentAssistProcessor_collecting_contexts);
285         List JavaDoc proposals= collectContextInformation(viewer, offset, monitor);
286
287         monitor.subTask(JavaTextMessages.ContentAssistProcessor_sorting_contexts);
288         List JavaDoc filtered= filterAndSortContextInformation(proposals, monitor);
289         fNumberOfComputedResults= filtered.size();
290         
291         IContextInformation[] result= (IContextInformation[]) filtered.toArray(new IContextInformation[filtered.size()]);
292         monitor.done();
293         return result;
294     }
295
296     private List JavaDoc collectContextInformation(ITextViewer viewer, int offset, IProgressMonitor monitor) {
297         List JavaDoc proposals= new ArrayList JavaDoc();
298         ContentAssistInvocationContext context= createContext(viewer, offset);
299         
300         List JavaDoc providers= getCategories();
301         for (Iterator JavaDoc it= providers.iterator(); it.hasNext();) {
302             CompletionProposalCategory cat= (CompletionProposalCategory) it.next();
303             List JavaDoc computed= cat.computeContextInformation(context, fPartition, new SubProgressMonitor(monitor, 1));
304             proposals.addAll(computed);
305             if (fErrorMessage == null)
306                 fErrorMessage= cat.getErrorMessage();
307         }
308         
309         return proposals;
310     }
311
312     /**
313      * Filters and sorts the context information objects. The passed
314      * list may be modified and returned, or a new list may be created
315      * and returned.
316      *
317      * @param contexts the list of collected proposals (element type:
318      * {@link IContextInformation})
319      * @param monitor a progress monitor
320      * @return the list of filtered and sorted proposals, ready for
321      * display (element type: {@link IContextInformation})
322      */

323     protected List JavaDoc filterAndSortContextInformation(List JavaDoc contexts, IProgressMonitor monitor) {
324         return contexts;
325     }
326
327     /**
328      * Sets this processor's set of characters triggering the activation of the
329      * completion proposal computation.
330      *
331      * @param activationSet the activation set
332      */

333     public final void setCompletionProposalAutoActivationCharacters(char[] activationSet) {
334         fCompletionAutoActivationCharacters= activationSet;
335     }
336
337
338     /*
339      * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
340      */

341     public final char[] getCompletionProposalAutoActivationCharacters() {
342         return fCompletionAutoActivationCharacters;
343     }
344
345     /*
346      * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters()
347      */

348     public char[] getContextInformationAutoActivationCharacters() {
349         return null;
350     }
351
352     /*
353      * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage()
354      */

355     public String JavaDoc getErrorMessage() {
356         if (fNumberOfComputedResults > 0)
357             return null;
358         if (fErrorMessage != null)
359             return fErrorMessage;
360         return JavaUIMessages.JavaEditor_codeassist_noCompletions;
361     }
362
363     /*
364      * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator()
365      */

366     public IContextInformationValidator getContextInformationValidator() {
367         return null;
368     }
369
370     /**
371      * Creates a progress monitor.
372      * <p>
373      * The default implementation creates a
374      * <code>NullProgressMonitor</code>.
375      * </p>
376      *
377      * @return a progress monitor
378      */

379     protected IProgressMonitor createProgressMonitor() {
380         return new NullProgressMonitor();
381     }
382
383     /**
384      * Creates the context that is passed to the completion proposal
385      * computers.
386      *
387      * @param viewer the viewer that content assist is invoked on
388      * @param offset the content assist offset
389      * @return the context to be passed to the computers
390      */

391     protected ContentAssistInvocationContext createContext(ITextViewer viewer, int offset) {
392         return new ContentAssistInvocationContext(viewer, offset);
393     }
394
395     private List JavaDoc getCategories() {
396         if (fCategoryIteration == null)
397             return fCategories;
398         
399         int iteration= fRepetition % fCategoryIteration.size();
400         fAssistant.setStatusMessage(createIterationMessage());
401         fAssistant.setEmptyMessage(createEmptyMessage());
402         fRepetition++;
403         
404 // fAssistant.setShowMessage(fRepetition % 2 != 0);
405
//
406
return (List JavaDoc) fCategoryIteration.get(iteration);
407     }
408
409     private List JavaDoc getCategoryIteration() {
410         List JavaDoc sequence= new ArrayList JavaDoc();
411         sequence.add(getDefaultCategories());
412         for (Iterator JavaDoc it= getSeparateCategories().iterator(); it.hasNext();) {
413             CompletionProposalCategory cat= (CompletionProposalCategory) it.next();
414             sequence.add(Collections.singletonList(cat));
415         }
416         return sequence;
417     }
418
419     private List JavaDoc getDefaultCategories() {
420         // default mix - enable all included computers
421
List JavaDoc included= getDefaultCategoriesUnchecked();
422
423         if ((IJavaPartitions.JAVA_DOC.equals(fPartition) || IDocument.DEFAULT_CONTENT_TYPE.equals(fPartition)) && included.isEmpty() && !fCategories.isEmpty())
424             if (informUserAboutEmptyDefaultCategory())
425                 // preferences were restored - recompute the default categories
426
included= getDefaultCategoriesUnchecked();
427
428         return included;
429     }
430
431     private List JavaDoc getDefaultCategoriesUnchecked() {
432         List JavaDoc included= new ArrayList JavaDoc();
433         for (Iterator JavaDoc it= fCategories.iterator(); it.hasNext();) {
434             CompletionProposalCategory category= (CompletionProposalCategory) it.next();
435             if (category.isIncluded() && category.hasComputers(fPartition))
436                 included.add(category);
437         }
438         return included;
439     }
440
441     /**
442      * Informs the user about the fact that there are no enabled categories in the default content
443      * assist set and shows a link to the preferences.
444      *
445      * @since 3.3
446      */

447     private boolean informUserAboutEmptyDefaultCategory() {
448         if (OptionalMessageDialog.isDialogEnabled(PREF_WARN_ABOUT_EMPTY_ASSIST_CATEGORY)) {
449             final Shell shell= JavaPlugin.getActiveWorkbenchShell();
450             String JavaDoc title= JavaTextMessages.ContentAssistProcessor_all_disabled_title;
451             String JavaDoc message= JavaTextMessages.ContentAssistProcessor_all_disabled_message;
452             // see PreferencePage#createControl for the 'defaults' label
453
final String JavaDoc restoreButtonLabel= JFaceResources.getString("defaults"); //$NON-NLS-1$
454
final String JavaDoc linkMessage= Messages.format(JavaTextMessages.ContentAssistProcessor_all_disabled_preference_link, LegacyActionTools.removeMnemonics(restoreButtonLabel));
455             final int restoreId= IDialogConstants.CLIENT_ID + 10;
456             final int settingsId= IDialogConstants.CLIENT_ID + 11;
457             final OptionalMessageDialog dialog= new OptionalMessageDialog(PREF_WARN_ABOUT_EMPTY_ASSIST_CATEGORY, shell, title, null /* default image */, message, MessageDialog.WARNING, new String JavaDoc[] { restoreButtonLabel, IDialogConstants.CLOSE_LABEL }, 1) {
458                 /*
459                  * @see org.eclipse.jdt.internal.ui.dialogs.OptionalMessageDialog#createCustomArea(org.eclipse.swt.widgets.Composite)
460                  */

461                 protected Control createCustomArea(Composite composite) {
462                     // wrap link and checkbox in one composite without space
463
Composite parent= new Composite(composite, SWT.NONE);
464                     GridLayout layout= new GridLayout();
465                     layout.marginHeight= 0;
466                     layout.marginWidth= 0;
467                     layout.verticalSpacing= 0;
468                     parent.setLayout(layout);
469                     
470                     Composite linkComposite= new Composite(parent, SWT.NONE);
471                     layout= new GridLayout();
472                     layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
473                     layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
474                     layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
475                     linkComposite.setLayout(layout);
476
477                     Link link= new Link(linkComposite, SWT.NONE);
478                     link.setText(linkMessage);
479                     link.addSelectionListener(new SelectionAdapter() {
480                         public void widgetSelected(SelectionEvent e) {
481                             setReturnCode(settingsId);
482                             close();
483                         }
484                     });
485                     GridData gridData= new GridData(SWT.FILL, SWT.BEGINNING, true, false);
486                     gridData.widthHint= this.getMinimumMessageWidth();
487                     link.setLayoutData(gridData);
488
489                     // create checkbox and "don't show this message" prompt
490
super.createCustomArea(parent);
491                     
492                     return parent;
493                 }
494                 
495                 /*
496                  * @see org.eclipse.jface.dialogs.MessageDialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
497                  */

498                 protected void createButtonsForButtonBar(Composite parent) {
499                     Button[] buttons= new Button[2];
500                     buttons[0]= createButton(parent, restoreId, restoreButtonLabel, false);
501                     buttons[1]= createButton(parent, IDialogConstants.CLOSE_ID, IDialogConstants.CLOSE_LABEL, true);
502                     setButtons(buttons);
503                 }
504             };
505             int returnValue= dialog.open();
506             if (restoreId == returnValue || settingsId == returnValue) {
507                 if (restoreId == returnValue) {
508                     IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore();
509                     store.setToDefault(PreferenceConstants.CODEASSIST_CATEGORY_ORDER);
510                     store.setToDefault(PreferenceConstants.CODEASSIST_EXCLUDED_CATEGORIES);
511                 }
512                 if (settingsId == returnValue)
513                     PreferencesUtil.createPreferenceDialogOn(shell, "org.eclipse.jdt.ui.preferences.CodeAssistPreferenceAdvanced", null, null).open(); //$NON-NLS-1$
514
CompletionProposalComputerRegistry registry= CompletionProposalComputerRegistry.getDefault();
515                 registry.reload();
516                 return true;
517             }
518         }
519         return false;
520     }
521
522     private List JavaDoc getSeparateCategories() {
523         ArrayList JavaDoc sorted= new ArrayList JavaDoc();
524         for (Iterator JavaDoc it= fCategories.iterator(); it.hasNext();) {
525             CompletionProposalCategory category= (CompletionProposalCategory) it.next();
526             if (category.isSeparateCommand() && category.hasComputers(fPartition))
527                 sorted.add(category);
528         }
529         Collections.sort(sorted, ORDER_COMPARATOR);
530         return sorted;
531     }
532     
533     private String JavaDoc createEmptyMessage() {
534         return Messages.format(JavaTextMessages.ContentAssistProcessor_empty_message, new String JavaDoc[]{getCategoryLabel(fRepetition)});
535     }
536     
537     private String JavaDoc createIterationMessage() {
538         return Messages.format(JavaTextMessages.ContentAssistProcessor_toggle_affordance_update_message, new String JavaDoc[]{ getCategoryLabel(fRepetition), fIterationGesture, getCategoryLabel(fRepetition + 1) });
539     }
540     
541     private String JavaDoc getCategoryLabel(int repetition) {
542         int iteration= repetition % fCategoryIteration.size();
543         if (iteration == 0)
544             return JavaTextMessages.ContentAssistProcessor_defaultProposalCategory;
545         return toString((CompletionProposalCategory) ((List JavaDoc) fCategoryIteration.get(iteration)).get(0));
546     }
547     
548     private String JavaDoc toString(CompletionProposalCategory category) {
549         return category.getDisplayName();
550     }
551
552     private String JavaDoc getIterationGesture() {
553         TriggerSequence binding= getIterationBinding();
554         return binding != null ?
555                   Messages.format(JavaTextMessages.ContentAssistProcessor_toggle_affordance_press_gesture, new Object JavaDoc[] { binding.format() })
556                 : JavaTextMessages.ContentAssistProcessor_toggle_affordance_click_gesture;
557     }
558
559     private KeySequence getIterationBinding() {
560         final IBindingService bindingSvc= (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class);
561         TriggerSequence binding= bindingSvc.getBestActiveBindingFor(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
562         if (binding instanceof KeySequence)
563             return (KeySequence) binding;
564         return null;
565     }
566 }
567
Popular Tags