KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > refactoring > contentassist > ControlContentAssistHelper


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.refactoring.contentassist;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.widgets.Combo;
15 import org.eclipse.swt.widgets.Shell;
16 import org.eclipse.swt.widgets.Text;
17
18 import org.eclipse.jface.contentassist.SubjectControlContentAssistant;
19 import org.eclipse.jface.internal.text.html.HTMLTextPresenter;
20
21 import org.eclipse.jface.text.DefaultInformationControl;
22 import org.eclipse.jface.text.IDocument;
23 import org.eclipse.jface.text.IInformationControl;
24 import org.eclipse.jface.text.IInformationControlCreator;
25 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
26 import org.eclipse.jface.text.contentassist.IContentAssistant;
27
28 import org.eclipse.ui.contentassist.ContentAssistHandler;
29
30 import org.eclipse.jdt.internal.ui.JavaPlugin;
31 import org.eclipse.jdt.internal.ui.text.ContentAssistPreference;
32
33
34 /**
35  * @since 3.0
36  */

37 public class ControlContentAssistHelper {
38     
39     /**
40      * @param text the text field to install ContentAssist
41      * @param processor the <code>IContentAssistProcessor</code>
42      */

43     public static void createTextContentAssistant(final Text text, IContentAssistProcessor processor) {
44         ContentAssistHandler.createHandlerForText(text, createJavaContentAssistant(processor));
45     }
46
47     /**
48      * @param combo the text field to install ContentAssist
49      * @param processor the <code>IContentAssistProcessor</code>
50      */

51     public static void createComboContentAssistant(final Combo combo, IContentAssistProcessor processor) {
52         ContentAssistHandler.createHandlerForCombo(combo, createJavaContentAssistant(processor));
53     }
54
55     public static SubjectControlContentAssistant createJavaContentAssistant(IContentAssistProcessor processor) {
56         final SubjectControlContentAssistant contentAssistant= new SubjectControlContentAssistant();
57         
58         contentAssistant.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE);
59         
60         ContentAssistPreference.configure(contentAssistant, JavaPlugin.getDefault().getPreferenceStore());
61         contentAssistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
62         contentAssistant.setInformationControlCreator(new IInformationControlCreator() {
63             public IInformationControl createInformationControl(Shell parent) {
64                 return new DefaultInformationControl(parent, SWT.NONE, new HTMLTextPresenter(true));
65             }
66         });
67         
68         return contentAssistant;
69     }
70     
71 }
72
Popular Tags