25b27d16e0ef920e6b887e1ed87a8c3af33bac72
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpeclipse / xml / ui / internal / preferences / ContentAssistPreference.java
1 package net.sourceforge.phpeclipse.xml.ui.internal.preferences;
2
3 import net.sourceforge.phpeclipse.ui.PreferenceConstants;
4 import net.sourceforge.phpeclipse.ui.templates.template.BasicCompletionProcessor;
5 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLPartitionScanner;
6
7 import org.eclipse.jface.preference.IPreferenceStore;
8 import org.eclipse.jface.text.contentassist.ContentAssistant;
9 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
10
11 public class ContentAssistPreference {
12         /** Preference key for html content assist auto activation triggers */
13         private final static String AUTOACTIVATION_TRIGGERS_HTML = PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_HTML;
14
15         /** Preference key for alphabetic ordering of proposals */
16         private final static String ORDER_PROPOSALS = PreferenceConstants.CODEASSIST_ORDER_PROPOSALS;
17
18         private static BasicCompletionProcessor getHTMLProcessor(
19                         ContentAssistant assistant) {
20                 IContentAssistProcessor p = assistant
21                                 .getContentAssistProcessor(XMLPartitionScanner.XML_TAG);
22                 if (p instanceof BasicCompletionProcessor)
23                         return (BasicCompletionProcessor) p;
24                 return null;
25         }
26
27         private static void configureHTMLProcessor(ContentAssistant assistant,
28                         IPreferenceStore store) {
29                 BasicCompletionProcessor hcp = getHTMLProcessor(assistant);
30                 if (hcp == null)
31                         return;
32
33                 String triggers = store.getString(AUTOACTIVATION_TRIGGERS_HTML);
34                 if (triggers != null)
35                         hcp.setCompletionProposalAutoActivationCharacters(triggers
36                                         .toCharArray());
37
38                 boolean enabled;
39                 // boolean enabled = store.getBoolean(CASE_SENSITIVITY);
40                 // jdcp.restrictProposalsToMatchingCases(enabled);
41
42                 enabled = store.getBoolean(ORDER_PROPOSALS);
43                 // hcp.orderProposalsAlphabetically(enabled);
44         }
45
46         private static void changeHTMLProcessor(ContentAssistant assistant,
47                         IPreferenceStore store, String key) {
48                 BasicCompletionProcessor jdcp = getHTMLProcessor(assistant);
49                 if (jdcp == null)
50                         return;
51
52                 if (AUTOACTIVATION_TRIGGERS_HTML.equals(key)) {
53                         String triggers = store.getString(AUTOACTIVATION_TRIGGERS_HTML);
54                         if (triggers != null)
55                                 jdcp.setCompletionProposalAutoActivationCharacters(triggers
56                                                 .toCharArray());
57                         // } else if (CASE_SENSITIVITY.equals(key)) {
58                         // boolean enabled = store.getBoolean(CASE_SENSITIVITY);
59                         // jdcp.restrictProposalsToMatchingCases(enabled);
60                 } else if (ORDER_PROPOSALS.equals(key)) {
61                         boolean enable = store.getBoolean(ORDER_PROPOSALS);
62                         // jdcp.orderProposalsAlphabetically(enable);
63                 }
64         }
65 }