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;
14 import net.sourceforge.phpeclipse.ui.WebUI;
16 import org.eclipse.jface.preference.IPreferenceStore;
17 import org.eclipse.jface.preference.PreferenceConverter;
18 import org.eclipse.jface.text.contentassist.ContentAssistant;
19 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
20 import org.eclipse.jface.util.PropertyChangeEvent;
21 import org.eclipse.swt.graphics.Color;
22 import org.eclipse.swt.graphics.RGB;
24 public class ContentAssistPreference {
26 /** Preference key for content assist auto activation */
27 private final static String AUTOACTIVATION = PreferenceConstants.CODEASSIST_AUTOACTIVATION;
29 /** Preference key for content assist auto activation delay */
30 private final static String AUTOACTIVATION_DELAY = PreferenceConstants.CODEASSIST_AUTOACTIVATION_DELAY;
32 /** Preference key for content assist proposal color */
33 private final static String PROPOSALS_FOREGROUND = PreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND;
35 /** Preference key for content assist proposal color */
36 private final static String PROPOSALS_BACKGROUND = PreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND;
38 /** Preference key for content assist parameters color */
39 private final static String PARAMETERS_FOREGROUND = PreferenceConstants.CODEASSIST_PARAMETERS_FOREGROUND;
41 /** Preference key for content assist parameters color */
42 private final static String PARAMETERS_BACKGROUND = PreferenceConstants.CODEASSIST_PARAMETERS_BACKGROUND;
44 /** Preference key for content assist completion replacement color */
45 private final static String COMPLETION_REPLACEMENT_FOREGROUND = PreferenceConstants.CODEASSIST_REPLACEMENT_FOREGROUND;
47 /** Preference key for content assist completion replacement color */
48 private final static String COMPLETION_REPLACEMENT_BACKGROUND = PreferenceConstants.CODEASSIST_REPLACEMENT_BACKGROUND;
50 /** Preference key for content assist auto insert */
51 private final static String AUTOINSERT = PreferenceConstants.CODEASSIST_AUTOINSERT;
53 /** Preference key for php content assist auto activation triggers */
54 private final static String AUTOACTIVATION_TRIGGERS_JAVA = PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA;
56 /** Preference key for phpdoc content assist auto activation triggers */
57 private final static String AUTOACTIVATION_TRIGGERS_JAVADOC = PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVADOC;
59 /** Preference key for html content assist auto activation triggers */
60 private final static String AUTOACTIVATION_TRIGGERS_HTML = PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_HTML;
62 /** Preference key for visibility of proposals */
63 private final static String SHOW_VISIBLE_PROPOSALS = PreferenceConstants.CODEASSIST_SHOW_VISIBLE_PROPOSALS;
65 /** Preference key for alphabetic ordering of proposals */
66 private final static String ORDER_PROPOSALS = PreferenceConstants.CODEASSIST_ORDER_PROPOSALS;
68 /** Preference key for case sensitivity of propsals */
69 private final static String CASE_SENSITIVITY = PreferenceConstants.CODEASSIST_CASE_SENSITIVITY;
71 /** Preference key for adding imports on code assist */
72 private final static String ADD_IMPORT = PreferenceConstants.CODEASSIST_ADDIMPORT;
74 /** Preference key for inserting content assist */
75 private static final String INSERT_COMPLETION = PreferenceConstants.CODEASSIST_INSERT_COMPLETION;
77 /** Preference key for filling argument names on method completion */
78 private static final String FILL_METHOD_ARGUMENTS = PreferenceConstants.CODEASSIST_FILL_ARGUMENT_NAMES;
80 /** Preference key for guessing argument names on method completion */
81 private static final String GUESS_METHOD_ARGUMENTS = PreferenceConstants.CODEASSIST_GUESS_METHOD_ARGUMENTS;
83 private static Color getColor(IPreferenceStore store, String key,
84 IColorManager manager) {
85 RGB rgb = PreferenceConverter.getColor(store, key);
86 return manager.getColor(rgb);
89 private static Color getColor(IPreferenceStore store, String key) {
90 JavaTextTools textTools = WebUI.getDefault()
92 return getColor(store, key, textTools.getColorManager());
95 private static PHPCompletionProcessor getJavaProcessor(
96 ContentAssistant assistant) {
97 IContentAssistProcessor p = assistant
98 .getContentAssistProcessor(IPHPPartitions.PHP_PARTITIONING);
99 if (p instanceof PHPCompletionProcessor)
100 return (PHPCompletionProcessor) p;
104 private static PHPDocCompletionProcessor getJavaDocProcessor(
105 ContentAssistant assistant) {
106 IContentAssistProcessor p = assistant
107 .getContentAssistProcessor(IPHPPartitions.PHP_PHPDOC_COMMENT);
108 if (p instanceof PHPDocCompletionProcessor)
109 return (PHPDocCompletionProcessor) p;
113 private static HTMLCompletionProcessor getHTMLProcessor(
114 ContentAssistant assistant) {
115 IContentAssistProcessor p = assistant
116 .getContentAssistProcessor(IPHPPartitions.HTML);
117 if (p instanceof HTMLCompletionProcessor)
118 return (HTMLCompletionProcessor) p;
122 private static void configureJavaProcessor(ContentAssistant assistant,
123 IPreferenceStore store) {
124 PHPCompletionProcessor pcp = getJavaProcessor(assistant);
128 String triggers = store.getString(AUTOACTIVATION_TRIGGERS_JAVA);
129 if (triggers != null)
130 pcp.setCompletionProposalAutoActivationCharacters(triggers
133 // boolean enabled= store.getBoolean(SHOW_VISIBLE_PROPOSALS);
134 // jcp.restrictProposalsToVisibility(enabled);
136 // enabled= store.getBoolean(CASE_SENSITIVITY);
137 // jcp.restrictProposalsToMatchingCases(enabled);
139 enabled = store.getBoolean(ORDER_PROPOSALS);
140 pcp.orderProposalsAlphabetically(enabled);
142 // enabled= store.getBoolean(ADD_IMPORT);
143 // jcp.allowAddingImports(enabled);
146 private static void configureJavaDocProcessor(ContentAssistant assistant,
147 IPreferenceStore store) {
148 PHPDocCompletionProcessor pdcp = getJavaDocProcessor(assistant);
152 String triggers = store.getString(AUTOACTIVATION_TRIGGERS_JAVADOC);
153 if (triggers != null)
154 pdcp.setCompletionProposalAutoActivationCharacters(triggers
157 boolean enabled = store.getBoolean(CASE_SENSITIVITY);
158 pdcp.restrictProposalsToMatchingCases(enabled);
160 enabled = store.getBoolean(ORDER_PROPOSALS);
161 pdcp.orderProposalsAlphabetically(enabled);
164 private static void configureHTMLProcessor(ContentAssistant assistant,
165 IPreferenceStore store) {
166 HTMLCompletionProcessor hcp = getHTMLProcessor(assistant);
170 String triggers = store.getString(AUTOACTIVATION_TRIGGERS_HTML);
171 if (triggers != null)
172 hcp.setCompletionProposalAutoActivationCharacters(triggers
176 // boolean enabled = store.getBoolean(CASE_SENSITIVITY);
177 // jdcp.restrictProposalsToMatchingCases(enabled);
179 enabled = store.getBoolean(ORDER_PROPOSALS);
180 hcp.orderProposalsAlphabetically(enabled);
184 * Configure the given content assistant from the given store.
186 public static void configure(ContentAssistant assistant,
187 IPreferenceStore store) {
189 JavaTextTools textTools = WebUI.getDefault()
191 IColorManager manager = textTools.getColorManager();
193 boolean enabled = store.getBoolean(AUTOACTIVATION);
194 assistant.enableAutoActivation(enabled);
196 int delay = store.getInt(AUTOACTIVATION_DELAY);
197 assistant.setAutoActivationDelay(delay);
199 Color c = getColor(store, PROPOSALS_FOREGROUND, manager);
200 assistant.setProposalSelectorForeground(c);
202 c = getColor(store, PROPOSALS_BACKGROUND, manager);
203 assistant.setProposalSelectorBackground(c);
205 c = getColor(store, PARAMETERS_FOREGROUND, manager);
206 assistant.setContextInformationPopupForeground(c);
207 assistant.setContextSelectorForeground(c);
209 c = getColor(store, PARAMETERS_BACKGROUND, manager);
210 assistant.setContextInformationPopupBackground(c);
211 assistant.setContextSelectorBackground(c);
213 enabled = store.getBoolean(AUTOINSERT);
214 assistant.enableAutoInsert(enabled);
216 configureJavaProcessor(assistant, store);
217 configureJavaDocProcessor(assistant, store);
218 configureHTMLProcessor(assistant, store);
221 private static void changeJavaProcessor(ContentAssistant assistant,
222 IPreferenceStore store, String key) {
223 PHPCompletionProcessor jcp = getJavaProcessor(assistant);
227 if (AUTOACTIVATION_TRIGGERS_JAVA.equals(key)) {
228 String triggers = store.getString(AUTOACTIVATION_TRIGGERS_JAVA);
229 if (triggers != null)
230 jcp.setCompletionProposalAutoActivationCharacters(triggers
233 // else if (SHOW_VISIBLE_PROPOSALS.equals(key)) {
234 // boolean enabled= store.getBoolean(SHOW_VISIBLE_PROPOSALS);
235 // jcp.restrictProposalsToVisibility(enabled);
236 // } else if (CASE_SENSITIVITY.equals(key)) {
237 // boolean enabled= store.getBoolean(CASE_SENSITIVITY);
238 // jcp.restrictProposalsToMatchingCases(enabled); }
239 else if (ORDER_PROPOSALS.equals(key)) {
240 boolean enable = store.getBoolean(ORDER_PROPOSALS);
241 jcp.orderProposalsAlphabetically(enable);
242 // } else if (ADD_IMPORT.equals(key)) {
243 // boolean enabled= store.getBoolean(ADD_IMPORT);
244 // jcp.allowAddingImports(enabled);
248 private static void changeJavaDocProcessor(ContentAssistant assistant,
249 IPreferenceStore store, String key) {
250 PHPDocCompletionProcessor jdcp = getJavaDocProcessor(assistant);
254 if (AUTOACTIVATION_TRIGGERS_JAVADOC.equals(key)) {
255 String triggers = store.getString(AUTOACTIVATION_TRIGGERS_JAVADOC);
256 if (triggers != null)
257 jdcp.setCompletionProposalAutoActivationCharacters(triggers
259 } else if (CASE_SENSITIVITY.equals(key)) {
260 boolean enabled = store.getBoolean(CASE_SENSITIVITY);
261 jdcp.restrictProposalsToMatchingCases(enabled);
262 } else if (ORDER_PROPOSALS.equals(key)) {
263 boolean enable = store.getBoolean(ORDER_PROPOSALS);
264 jdcp.orderProposalsAlphabetically(enable);
268 private static void changeHTMLProcessor(ContentAssistant assistant,
269 IPreferenceStore store, String key) {
270 HTMLCompletionProcessor jdcp = getHTMLProcessor(assistant);
274 if (AUTOACTIVATION_TRIGGERS_HTML.equals(key)) {
275 String triggers = store.getString(AUTOACTIVATION_TRIGGERS_HTML);
276 if (triggers != null)
277 jdcp.setCompletionProposalAutoActivationCharacters(triggers
279 // } else if (CASE_SENSITIVITY.equals(key)) {
280 // boolean enabled = store.getBoolean(CASE_SENSITIVITY);
281 // jdcp.restrictProposalsToMatchingCases(enabled);
282 } else if (ORDER_PROPOSALS.equals(key)) {
283 boolean enable = store.getBoolean(ORDER_PROPOSALS);
284 jdcp.orderProposalsAlphabetically(enable);
289 * Changes the configuration of the given content assistant according to the
290 * given property change event and the given preference store.
292 public static void changeConfiguration(ContentAssistant assistant,
293 IPreferenceStore store, PropertyChangeEvent event) {
295 String p = event.getProperty();
297 if (AUTOACTIVATION.equals(p)) {
298 boolean enabled = store.getBoolean(AUTOACTIVATION);
299 assistant.enableAutoActivation(enabled);
300 } else if (AUTOACTIVATION_DELAY.equals(p)) {
301 int delay = store.getInt(AUTOACTIVATION_DELAY);
302 assistant.setAutoActivationDelay(delay);
303 } else if (PROPOSALS_FOREGROUND.equals(p)) {
304 Color c = getColor(store, PROPOSALS_FOREGROUND);
305 assistant.setProposalSelectorForeground(c);
306 } else if (PROPOSALS_BACKGROUND.equals(p)) {
307 Color c = getColor(store, PROPOSALS_BACKGROUND);
308 assistant.setProposalSelectorBackground(c);
309 } else if (PARAMETERS_FOREGROUND.equals(p)) {
310 Color c = getColor(store, PARAMETERS_FOREGROUND);
311 assistant.setContextInformationPopupForeground(c);
312 assistant.setContextSelectorForeground(c);
313 } else if (PARAMETERS_BACKGROUND.equals(p)) {
314 Color c = getColor(store, PARAMETERS_BACKGROUND);
315 assistant.setContextInformationPopupBackground(c);
316 assistant.setContextSelectorBackground(c);
317 } else if (AUTOINSERT.equals(p)) {
318 boolean enabled = store.getBoolean(AUTOINSERT);
319 assistant.enableAutoInsert(enabled);
322 changeJavaProcessor(assistant, store, p);
323 changeJavaDocProcessor(assistant, store, p);
324 changeHTMLProcessor(assistant, store, p);
327 public static boolean fillArgumentsOnMethodCompletion(IPreferenceStore store) {
328 return store.getBoolean(FILL_METHOD_ARGUMENTS);