2 * (c) Copyright IBM Corp. 2000, 2001.
5 package net.sourceforge.phpdt.internal.ui.text;
7 import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCompletionProcessor;
8 import net.sourceforge.phpdt.ui.PreferenceConstants;
9 import net.sourceforge.phpdt.ui.text.IColorManager;
10 import net.sourceforge.phpdt.ui.text.JavaTextTools;
11 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
12 import net.sourceforge.phpeclipse.phpeditor.php.HTMLCompletionProcessor;
13 import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor;
15 import org.eclipse.jface.preference.IPreferenceStore;
16 import org.eclipse.jface.preference.PreferenceConverter;
17 import org.eclipse.jface.text.contentassist.ContentAssistant;
18 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
19 import org.eclipse.jface.util.PropertyChangeEvent;
20 import org.eclipse.swt.graphics.Color;
21 import org.eclipse.swt.graphics.RGB;
23 public class ContentAssistPreference {
25 /** Preference key for content assist auto activation */
26 private final static String AUTOACTIVATION = PreferenceConstants.CODEASSIST_AUTOACTIVATION;
28 /** Preference key for content assist auto activation delay */
29 private final static String AUTOACTIVATION_DELAY = PreferenceConstants.CODEASSIST_AUTOACTIVATION_DELAY;
31 /** Preference key for content assist proposal color */
32 private final static String PROPOSALS_FOREGROUND = PreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND;
34 /** Preference key for content assist proposal color */
35 private final static String PROPOSALS_BACKGROUND = PreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND;
37 /** Preference key for content assist parameters color */
38 private final static String PARAMETERS_FOREGROUND = PreferenceConstants.CODEASSIST_PARAMETERS_FOREGROUND;
40 /** Preference key for content assist parameters color */
41 private final static String PARAMETERS_BACKGROUND = PreferenceConstants.CODEASSIST_PARAMETERS_BACKGROUND;
43 /** Preference key for content assist completion replacement color */
44 //private final static String COMPLETION_REPLACEMENT_FOREGROUND = PreferenceConstants.CODEASSIST_REPLACEMENT_FOREGROUND;
46 /** Preference key for content assist completion replacement color */
47 //private final static String COMPLETION_REPLACEMENT_BACKGROUND = PreferenceConstants.CODEASSIST_REPLACEMENT_BACKGROUND;
49 /** Preference key for content assist auto insert */
50 private final static String AUTOINSERT = PreferenceConstants.CODEASSIST_AUTOINSERT;
52 /** Preference key for php content assist auto activation triggers */
53 private final static String AUTOACTIVATION_TRIGGERS_JAVA = PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA;
55 /** Preference key for phpdoc content assist auto activation triggers */
56 private final static String AUTOACTIVATION_TRIGGERS_JAVADOC = PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVADOC;
58 /** Preference key for html content assist auto activation triggers */
59 private final static String AUTOACTIVATION_TRIGGERS_HTML = PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_HTML;
61 /** Preference key for visibility of proposals */
62 //private final static String SHOW_VISIBLE_PROPOSALS = PreferenceConstants.CODEASSIST_SHOW_VISIBLE_PROPOSALS;
64 /** Preference key for alphabetic ordering of proposals */
65 private final static String ORDER_PROPOSALS = PreferenceConstants.CODEASSIST_ORDER_PROPOSALS;
67 /** Preference key for case sensitivity of propsals */
68 private final static String CASE_SENSITIVITY = PreferenceConstants.CODEASSIST_CASE_SENSITIVITY;
70 /** Preference key for adding imports on code assist */
71 //private final static String ADD_IMPORT = PreferenceConstants.CODEASSIST_ADDIMPORT;
73 /** Preference key for inserting content assist */
74 //private static final String INSERT_COMPLETION = PreferenceConstants.CODEASSIST_INSERT_COMPLETION;
76 /** Preference key for filling argument names on method completion */
77 //private static final String FILL_METHOD_ARGUMENTS = PreferenceConstants.CODEASSIST_FILL_ARGUMENT_NAMES;
79 /** Preference key for guessing argument names on method completion */
80 //private static final String GUESS_METHOD_ARGUMENTS = PreferenceConstants.CODEASSIST_GUESS_METHOD_ARGUMENTS;
82 private static Color getColor(IPreferenceStore store, String key,
83 IColorManager manager) {
84 RGB rgb = PreferenceConverter.getColor(store, key);
85 return manager.getColor(rgb);
88 private static Color getColor(IPreferenceStore store, String key) {
89 JavaTextTools textTools = PHPeclipsePlugin.getDefault()
91 return getColor(store, key, textTools.getColorManager());
94 private static PHPCompletionProcessor getJavaProcessor(
95 ContentAssistant assistant) {
96 IContentAssistProcessor p = assistant
97 .getContentAssistProcessor(IPHPPartitions.PHP_PARTITIONING);
98 if (p instanceof PHPCompletionProcessor)
99 return (PHPCompletionProcessor) p;
103 private static PHPDocCompletionProcessor getJavaDocProcessor(
104 ContentAssistant assistant) {
105 IContentAssistProcessor p = assistant
106 .getContentAssistProcessor(IPHPPartitions.PHP_PHPDOC_COMMENT);
107 if (p instanceof PHPDocCompletionProcessor)
108 return (PHPDocCompletionProcessor) p;
112 private static HTMLCompletionProcessor getHTMLProcessor(
113 ContentAssistant assistant) {
114 IContentAssistProcessor p = assistant
115 .getContentAssistProcessor(IPHPPartitions.HTML);
116 if (p instanceof HTMLCompletionProcessor)
117 return (HTMLCompletionProcessor) p;
121 private static void configureJavaProcessor(ContentAssistant assistant,
122 IPreferenceStore store) {
123 PHPCompletionProcessor pcp = getJavaProcessor(assistant);
127 String triggers = store.getString(AUTOACTIVATION_TRIGGERS_JAVA);
128 if (triggers != null)
129 pcp.setCompletionProposalAutoActivationCharacters(triggers
132 // boolean enabled= store.getBoolean(SHOW_VISIBLE_PROPOSALS);
133 // jcp.restrictProposalsToVisibility(enabled);
135 // enabled= store.getBoolean(CASE_SENSITIVITY);
136 // jcp.restrictProposalsToMatchingCases(enabled);
138 enabled = store.getBoolean(ORDER_PROPOSALS);
139 pcp.orderProposalsAlphabetically(enabled);
141 // enabled= store.getBoolean(ADD_IMPORT);
142 // jcp.allowAddingImports(enabled);
145 private static void configureJavaDocProcessor(ContentAssistant assistant,
146 IPreferenceStore store) {
147 PHPDocCompletionProcessor pdcp = getJavaDocProcessor(assistant);
151 String triggers = store.getString(AUTOACTIVATION_TRIGGERS_JAVADOC);
152 if (triggers != null)
153 pdcp.setCompletionProposalAutoActivationCharacters(triggers
156 boolean enabled = store.getBoolean(CASE_SENSITIVITY);
157 pdcp.restrictProposalsToMatchingCases(enabled);
159 enabled = store.getBoolean(ORDER_PROPOSALS);
160 pdcp.orderProposalsAlphabetically(enabled);
163 private static void configureHTMLProcessor(ContentAssistant assistant,
164 IPreferenceStore store) {
165 HTMLCompletionProcessor hcp = getHTMLProcessor(assistant);
169 String triggers = store.getString(AUTOACTIVATION_TRIGGERS_HTML);
170 if (triggers != null)
171 hcp.setCompletionProposalAutoActivationCharacters(triggers
175 // boolean enabled = store.getBoolean(CASE_SENSITIVITY);
176 // jdcp.restrictProposalsToMatchingCases(enabled);
178 enabled = store.getBoolean(ORDER_PROPOSALS);
179 hcp.orderProposalsAlphabetically(enabled);
183 * Configure the given content assistant from the given store.
185 public static void configure(ContentAssistant assistant,
186 IPreferenceStore store) {
188 JavaTextTools textTools = PHPeclipsePlugin.getDefault()
190 IColorManager manager = textTools.getColorManager();
192 boolean enabled = store.getBoolean(AUTOACTIVATION);
193 assistant.enableAutoActivation(enabled);
195 int delay = store.getInt(AUTOACTIVATION_DELAY);
196 assistant.setAutoActivationDelay(delay);
198 Color c = getColor(store, PROPOSALS_FOREGROUND, manager);
199 assistant.setProposalSelectorForeground(c);
201 c = getColor(store, PROPOSALS_BACKGROUND, manager);
202 assistant.setProposalSelectorBackground(c);
204 c = getColor(store, PARAMETERS_FOREGROUND, manager);
205 assistant.setContextInformationPopupForeground(c);
206 assistant.setContextSelectorForeground(c);
208 c = getColor(store, PARAMETERS_BACKGROUND, manager);
209 assistant.setContextInformationPopupBackground(c);
210 assistant.setContextSelectorBackground(c);
212 enabled = store.getBoolean(AUTOINSERT);
213 assistant.enableAutoInsert(enabled);
215 configureJavaProcessor(assistant, store);
216 configureJavaDocProcessor(assistant, store);
217 configureHTMLProcessor(assistant, store);
220 private static void changeJavaProcessor(ContentAssistant assistant,
221 IPreferenceStore store, String key) {
222 PHPCompletionProcessor jcp = getJavaProcessor(assistant);
226 if (AUTOACTIVATION_TRIGGERS_JAVA.equals(key)) {
227 String triggers = store.getString(AUTOACTIVATION_TRIGGERS_JAVA);
228 if (triggers != null)
229 jcp.setCompletionProposalAutoActivationCharacters(triggers
232 // else if (SHOW_VISIBLE_PROPOSALS.equals(key)) {
233 // boolean enabled= store.getBoolean(SHOW_VISIBLE_PROPOSALS);
234 // jcp.restrictProposalsToVisibility(enabled);
235 // } else if (CASE_SENSITIVITY.equals(key)) {
236 // boolean enabled= store.getBoolean(CASE_SENSITIVITY);
237 // jcp.restrictProposalsToMatchingCases(enabled); }
238 else if (ORDER_PROPOSALS.equals(key)) {
239 boolean enable = store.getBoolean(ORDER_PROPOSALS);
240 jcp.orderProposalsAlphabetically(enable);
241 // } else if (ADD_IMPORT.equals(key)) {
242 // boolean enabled= store.getBoolean(ADD_IMPORT);
243 // jcp.allowAddingImports(enabled);
247 private static void changeJavaDocProcessor(ContentAssistant assistant,
248 IPreferenceStore store, String key) {
249 PHPDocCompletionProcessor jdcp = getJavaDocProcessor(assistant);
253 if (AUTOACTIVATION_TRIGGERS_JAVADOC.equals(key)) {
254 String triggers = store.getString(AUTOACTIVATION_TRIGGERS_JAVADOC);
255 if (triggers != null)
256 jdcp.setCompletionProposalAutoActivationCharacters(triggers
258 } else if (CASE_SENSITIVITY.equals(key)) {
259 boolean enabled = store.getBoolean(CASE_SENSITIVITY);
260 jdcp.restrictProposalsToMatchingCases(enabled);
261 } else if (ORDER_PROPOSALS.equals(key)) {
262 boolean enable = store.getBoolean(ORDER_PROPOSALS);
263 jdcp.orderProposalsAlphabetically(enable);
267 private static void changeHTMLProcessor(ContentAssistant assistant,
268 IPreferenceStore store, String key) {
269 HTMLCompletionProcessor jdcp = getHTMLProcessor(assistant);
273 if (AUTOACTIVATION_TRIGGERS_HTML.equals(key)) {
274 String triggers = store.getString(AUTOACTIVATION_TRIGGERS_HTML);
275 if (triggers != null)
276 jdcp.setCompletionProposalAutoActivationCharacters(triggers
278 // } else if (CASE_SENSITIVITY.equals(key)) {
279 // boolean enabled = store.getBoolean(CASE_SENSITIVITY);
280 // jdcp.restrictProposalsToMatchingCases(enabled);
281 } else if (ORDER_PROPOSALS.equals(key)) {
282 boolean enable = store.getBoolean(ORDER_PROPOSALS);
283 jdcp.orderProposalsAlphabetically(enable);
288 * Changes the configuration of the given content assistant according to the
289 * given property change event and the given preference store.
291 public static void changeConfiguration(ContentAssistant assistant,
292 IPreferenceStore store, PropertyChangeEvent event) {
294 String p = event.getProperty();
296 if (AUTOACTIVATION.equals(p)) {
297 boolean enabled = store.getBoolean(AUTOACTIVATION);
298 assistant.enableAutoActivation(enabled);
299 } else if (AUTOACTIVATION_DELAY.equals(p)) {
300 int delay = store.getInt(AUTOACTIVATION_DELAY);
301 assistant.setAutoActivationDelay(delay);
302 } else if (PROPOSALS_FOREGROUND.equals(p)) {
303 Color c = getColor(store, PROPOSALS_FOREGROUND);
304 assistant.setProposalSelectorForeground(c);
305 } else if (PROPOSALS_BACKGROUND.equals(p)) {
306 Color c = getColor(store, PROPOSALS_BACKGROUND);
307 assistant.setProposalSelectorBackground(c);
308 } else if (PARAMETERS_FOREGROUND.equals(p)) {
309 Color c = getColor(store, PARAMETERS_FOREGROUND);
310 assistant.setContextInformationPopupForeground(c);
311 assistant.setContextSelectorForeground(c);
312 } else if (PARAMETERS_BACKGROUND.equals(p)) {
313 Color c = getColor(store, PARAMETERS_BACKGROUND);
314 assistant.setContextInformationPopupBackground(c);
315 assistant.setContextSelectorBackground(c);
316 } else if (AUTOINSERT.equals(p)) {
317 boolean enabled = store.getBoolean(AUTOINSERT);
318 assistant.enableAutoInsert(enabled);
321 changeJavaProcessor(assistant, store, p);
322 changeJavaDocProcessor(assistant, store, p);
323 changeHTMLProcessor(assistant, store, p);
326 // public static boolean fillArgumentsOnMethodCompletion(IPreferenceStore store) {
327 // return store.getBoolean(FILL_METHOD_ARGUMENTS);