1 11 package org.eclipse.jdt.internal.ui.text; 12 13 import org.eclipse.swt.graphics.Color; 14 import org.eclipse.swt.graphics.RGB; 15 16 import org.eclipse.jface.preference.IPreferenceStore; 17 import org.eclipse.jface.preference.PreferenceConverter; 18 import org.eclipse.jface.text.IDocument; 19 import org.eclipse.jface.text.contentassist.ContentAssistant; 20 import org.eclipse.jface.text.contentassist.IContentAssistProcessor; 21 import org.eclipse.jface.util.PropertyChangeEvent; 22 23 import org.eclipse.jdt.ui.PreferenceConstants; 24 import org.eclipse.jdt.ui.text.IColorManager; 25 import org.eclipse.jdt.ui.text.IJavaPartitions; 26 import org.eclipse.jdt.ui.text.JavaTextTools; 27 28 import org.eclipse.jdt.internal.ui.JavaPlugin; 29 import org.eclipse.jdt.internal.ui.text.java.JavaCompletionProcessor; 30 import org.eclipse.jdt.internal.ui.text.javadoc.JavadocCompletionProcessor; 31 32 33 public class ContentAssistPreference { 34 35 36 private final static String AUTOACTIVATION= PreferenceConstants.CODEASSIST_AUTOACTIVATION; 37 38 private final static String AUTOACTIVATION_DELAY= PreferenceConstants.CODEASSIST_AUTOACTIVATION_DELAY; 39 40 private final static String PROPOSALS_FOREGROUND= PreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND; 41 42 private final static String PROPOSALS_BACKGROUND= PreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND; 43 44 private final static String PARAMETERS_FOREGROUND= PreferenceConstants.CODEASSIST_PARAMETERS_FOREGROUND; 45 46 private final static String PARAMETERS_BACKGROUND= PreferenceConstants.CODEASSIST_PARAMETERS_BACKGROUND; 47 48 private final static String AUTOINSERT= PreferenceConstants.CODEASSIST_AUTOINSERT; 49 50 51 private final static String AUTOACTIVATION_TRIGGERS_JAVA= PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA; 52 53 private final static String AUTOACTIVATION_TRIGGERS_JAVADOC= PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVADOC; 54 55 56 private final static String SHOW_VISIBLE_PROPOSALS= PreferenceConstants.CODEASSIST_SHOW_VISIBLE_PROPOSALS; 57 58 private final static String CASE_SENSITIVITY= PreferenceConstants.CODEASSIST_CASE_SENSITIVITY; 59 60 61 private static final String FILL_METHOD_ARGUMENTS= PreferenceConstants.CODEASSIST_FILL_ARGUMENT_NAMES; 62 63 private static final String PREFIX_COMPLETION= PreferenceConstants.CODEASSIST_PREFIX_COMPLETION; 64 65 66 private static Color getColor(IPreferenceStore store, String key, IColorManager manager) { 67 RGB rgb= PreferenceConverter.getColor(store, key); 68 return manager.getColor(rgb); 69 } 70 71 private static Color getColor(IPreferenceStore store, String key) { 72 JavaTextTools textTools= JavaPlugin.getDefault().getJavaTextTools(); 73 return getColor(store, key, textTools.getColorManager()); 74 } 75 76 private static JavaCompletionProcessor getJavaProcessor(ContentAssistant assistant) { 77 IContentAssistProcessor p= assistant.getContentAssistProcessor(IDocument.DEFAULT_CONTENT_TYPE); 78 if (p instanceof JavaCompletionProcessor) 79 return (JavaCompletionProcessor) p; 80 return null; 81 } 82 83 private static JavadocCompletionProcessor getJavaDocProcessor(ContentAssistant assistant) { 84 IContentAssistProcessor p= assistant.getContentAssistProcessor(IJavaPartitions.JAVA_DOC); 85 if (p instanceof JavadocCompletionProcessor) 86 return (JavadocCompletionProcessor) p; 87 return null; 88 } 89 90 private static void configureJavaProcessor(ContentAssistant assistant, IPreferenceStore store) { 91 JavaCompletionProcessor jcp= getJavaProcessor(assistant); 92 if (jcp == null) 93 return; 94 95 String triggers= store.getString(AUTOACTIVATION_TRIGGERS_JAVA); 96 if (triggers != null) 97 jcp.setCompletionProposalAutoActivationCharacters(triggers.toCharArray()); 98 99 boolean enabled= store.getBoolean(SHOW_VISIBLE_PROPOSALS); 100 jcp.restrictProposalsToVisibility(enabled); 101 102 enabled= store.getBoolean(CASE_SENSITIVITY); 103 jcp.restrictProposalsToMatchingCases(enabled); 104 } 105 106 private static void configureJavaDocProcessor(ContentAssistant assistant, IPreferenceStore store) { 107 JavadocCompletionProcessor jdcp= getJavaDocProcessor(assistant); 108 if (jdcp == null) 109 return; 110 111 String triggers= store.getString(AUTOACTIVATION_TRIGGERS_JAVADOC); 112 if (triggers != null) 113 jdcp.setCompletionProposalAutoActivationCharacters(triggers.toCharArray()); 114 115 boolean enabled= store.getBoolean(CASE_SENSITIVITY); 116 jdcp.restrictProposalsToMatchingCases(enabled); 117 } 118 119 122 public static void configure(ContentAssistant assistant, IPreferenceStore store) { 123 124 JavaTextTools textTools= JavaPlugin.getDefault().getJavaTextTools(); 125 IColorManager manager= textTools.getColorManager(); 126 127 128 boolean enabled= store.getBoolean(AUTOACTIVATION); 129 assistant.enableAutoActivation(enabled); 130 131 int delay= store.getInt(AUTOACTIVATION_DELAY); 132 assistant.setAutoActivationDelay(delay); 133 134 Color c= getColor(store, PROPOSALS_FOREGROUND, manager); 135 assistant.setProposalSelectorForeground(c); 136 137 c= getColor(store, PROPOSALS_BACKGROUND, manager); 138 assistant.setProposalSelectorBackground(c); 139 140 c= getColor(store, PARAMETERS_FOREGROUND, manager); 141 assistant.setContextInformationPopupForeground(c); 142 assistant.setContextSelectorForeground(c); 143 144 c= getColor(store, PARAMETERS_BACKGROUND, manager); 145 assistant.setContextInformationPopupBackground(c); 146 assistant.setContextSelectorBackground(c); 147 148 enabled= store.getBoolean(AUTOINSERT); 149 assistant.enableAutoInsert(enabled); 150 151 enabled= store.getBoolean(PREFIX_COMPLETION); 152 assistant.enablePrefixCompletion(enabled); 153 154 configureJavaProcessor(assistant, store); 155 configureJavaDocProcessor(assistant, store); 156 } 157 158 159 private static void changeJavaProcessor(ContentAssistant assistant, IPreferenceStore store, String key) { 160 JavaCompletionProcessor jcp= getJavaProcessor(assistant); 161 if (jcp == null) 162 return; 163 164 if (AUTOACTIVATION_TRIGGERS_JAVA.equals(key)) { 165 String triggers= store.getString(AUTOACTIVATION_TRIGGERS_JAVA); 166 if (triggers != null) 167 jcp.setCompletionProposalAutoActivationCharacters(triggers.toCharArray()); 168 } else if (SHOW_VISIBLE_PROPOSALS.equals(key)) { 169 boolean enabled= store.getBoolean(SHOW_VISIBLE_PROPOSALS); 170 jcp.restrictProposalsToVisibility(enabled); 171 } else if (CASE_SENSITIVITY.equals(key)) { 172 boolean enabled= store.getBoolean(CASE_SENSITIVITY); 173 jcp.restrictProposalsToMatchingCases(enabled); 174 } 175 } 176 177 private static void changeJavaDocProcessor(ContentAssistant assistant, IPreferenceStore store, String key) { 178 JavadocCompletionProcessor jdcp= getJavaDocProcessor(assistant); 179 if (jdcp == null) 180 return; 181 182 if (AUTOACTIVATION_TRIGGERS_JAVADOC.equals(key)) { 183 String triggers= store.getString(AUTOACTIVATION_TRIGGERS_JAVADOC); 184 if (triggers != null) 185 jdcp.setCompletionProposalAutoActivationCharacters(triggers.toCharArray()); 186 } else if (CASE_SENSITIVITY.equals(key)) { 187 boolean enabled= store.getBoolean(CASE_SENSITIVITY); 188 jdcp.restrictProposalsToMatchingCases(enabled); 189 } 190 } 191 192 196 public static void changeConfiguration(ContentAssistant assistant, IPreferenceStore store, PropertyChangeEvent event) { 197 198 String p= event.getProperty(); 199 200 if (AUTOACTIVATION.equals(p)) { 201 boolean enabled= store.getBoolean(AUTOACTIVATION); 202 assistant.enableAutoActivation(enabled); 203 } else if (AUTOACTIVATION_DELAY.equals(p)) { 204 int delay= store.getInt(AUTOACTIVATION_DELAY); 205 assistant.setAutoActivationDelay(delay); 206 } else if (PROPOSALS_FOREGROUND.equals(p)) { 207 Color c= getColor(store, PROPOSALS_FOREGROUND); 208 assistant.setProposalSelectorForeground(c); 209 } else if (PROPOSALS_BACKGROUND.equals(p)) { 210 Color c= getColor(store, PROPOSALS_BACKGROUND); 211 assistant.setProposalSelectorBackground(c); 212 } else if (PARAMETERS_FOREGROUND.equals(p)) { 213 Color c= getColor(store, PARAMETERS_FOREGROUND); 214 assistant.setContextInformationPopupForeground(c); 215 assistant.setContextSelectorForeground(c); 216 } else if (PARAMETERS_BACKGROUND.equals(p)) { 217 Color c= getColor(store, PARAMETERS_BACKGROUND); 218 assistant.setContextInformationPopupBackground(c); 219 assistant.setContextSelectorBackground(c); 220 } else if (AUTOINSERT.equals(p)) { 221 boolean enabled= store.getBoolean(AUTOINSERT); 222 assistant.enableAutoInsert(enabled); 223 } else if (PREFIX_COMPLETION.equals(p)) { 224 boolean enabled= store.getBoolean(PREFIX_COMPLETION); 225 assistant.enablePrefixCompletion(enabled); 226 } 227 228 changeJavaProcessor(assistant, store, p); 229 changeJavaDocProcessor(assistant, store, p); 230 } 231 232 public static boolean fillArgumentsOnMethodCompletion(IPreferenceStore store) { 233 return store.getBoolean(FILL_METHOD_ARGUMENTS); 234 } 235 } 236 237 | Popular Tags |