1 11 package org.eclipse.jdt.internal.debug.ui; 12 13 14 import java.util.Hashtable ; 15 16 import org.eclipse.jdt.core.JavaCore; 17 import org.eclipse.jdt.internal.debug.ui.contentassist.JavaDebugContentAssistProcessor; 18 import org.eclipse.jdt.internal.debug.ui.snippeteditor.JavaSnippetCompletionProcessor; 19 import org.eclipse.jdt.ui.PreferenceConstants; 20 import org.eclipse.jdt.ui.text.IColorManager; 21 import org.eclipse.jdt.ui.text.JavaTextTools; 22 import org.eclipse.jface.preference.IPreferenceStore; 23 import org.eclipse.jface.preference.PreferenceConverter; 24 import org.eclipse.jface.text.IDocument; 25 import org.eclipse.jface.text.contentassist.ContentAssistant; 26 import org.eclipse.jface.text.contentassist.IContentAssistProcessor; 27 import org.eclipse.jface.util.PropertyChangeEvent; 28 import org.eclipse.swt.graphics.Color; 29 import org.eclipse.swt.graphics.RGB; 30 31 32 public class JDIContentAssistPreference { 33 34 private final static String VISIBILITY= "org.eclipse.jdt.core.codeComplete.visibilityCheck"; private final static String ENABLED= "enabled"; private final static String DISABLED= "disabled"; 38 private static Color getColor(IPreferenceStore store, String key, IColorManager manager) { 39 RGB rgb= PreferenceConverter.getColor(store, key); 40 return manager.getColor(rgb); 41 } 42 43 private static Color getColor(IPreferenceStore store, String key) { 44 JavaTextTools textTools= JDIDebugUIPlugin.getDefault().getJavaTextTools(); 45 return getColor(store, key, textTools.getColorManager()); 46 } 47 48 private static JavaDebugContentAssistProcessor getDisplayProcessor(ContentAssistant assistant) { 49 IContentAssistProcessor p= assistant.getContentAssistProcessor(IDocument.DEFAULT_CONTENT_TYPE); 50 if (p instanceof JavaDebugContentAssistProcessor) 51 return (JavaDebugContentAssistProcessor) p; 52 return null; 53 } 54 55 private static JavaSnippetCompletionProcessor getJavaSnippetProcessor(ContentAssistant assistant) { 56 IContentAssistProcessor p= assistant.getContentAssistProcessor(IDocument.DEFAULT_CONTENT_TYPE); 57 if (p instanceof JavaSnippetCompletionProcessor) 58 return (JavaSnippetCompletionProcessor) p; 59 return null; 60 } 61 62 private static void configureDisplayProcessor(ContentAssistant assistant, IPreferenceStore store) { 63 JavaDebugContentAssistProcessor dcp= getDisplayProcessor(assistant); 64 if (dcp == null) { 65 return; 66 } 67 String triggers= store.getString(PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA); 68 if (triggers != null) { 69 dcp.setCompletionProposalAutoActivationCharacters(triggers.toCharArray()); 70 } 71 72 boolean enabled= store.getBoolean(PreferenceConstants.CODEASSIST_SHOW_VISIBLE_PROPOSALS); 73 restrictProposalsToVisibility(enabled); 74 75 enabled= store.getBoolean(PreferenceConstants.CODEASSIST_CASE_SENSITIVITY); 76 restrictProposalsToMatchingCases(enabled); 77 78 enabled= store.getBoolean(PreferenceConstants.CODEASSIST_SORTER); 79 dcp.orderProposalsAlphabetically(enabled); 80 } 81 82 private static void configureJavaSnippetProcessor(ContentAssistant assistant, IPreferenceStore store) { 83 JavaSnippetCompletionProcessor cp= getJavaSnippetProcessor(assistant); 84 if (cp == null) { 85 return; 86 } 87 88 String triggers= store.getString(PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA); 89 if (triggers != null) { 90 cp.setCompletionProposalAutoActivationCharacters(triggers.toCharArray()); 91 } 92 93 boolean enabled= store.getBoolean(PreferenceConstants.CODEASSIST_SHOW_VISIBLE_PROPOSALS); 94 restrictProposalsToVisibility(enabled); 95 96 enabled= store.getBoolean(PreferenceConstants.CODEASSIST_CASE_SENSITIVITY); 97 restrictProposalsToMatchingCases(enabled); 98 99 enabled= store.getBoolean(PreferenceConstants.CODEASSIST_SORTER); 100 cp.orderProposalsAlphabetically(enabled); 101 } 102 103 106 public static void configure(ContentAssistant assistant, IColorManager manager) { 107 108 IPreferenceStore store= getPreferenceStore(); 109 110 boolean enabled= store.getBoolean(PreferenceConstants.CODEASSIST_AUTOACTIVATION); 111 assistant.enableAutoActivation(enabled); 112 113 int delay= store.getInt(PreferenceConstants.CODEASSIST_AUTOACTIVATION_DELAY); 114 assistant.setAutoActivationDelay(delay); 115 116 Color c= getColor(store, PreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND, manager); 117 assistant.setProposalSelectorForeground(c); 118 119 c= getColor(store, PreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND, manager); 120 assistant.setProposalSelectorBackground(c); 121 122 c= getColor(store, PreferenceConstants.CODEASSIST_PARAMETERS_FOREGROUND, manager); 123 assistant.setContextInformationPopupForeground(c); 124 assistant.setContextSelectorForeground(c); 125 126 c= getColor(store, PreferenceConstants.CODEASSIST_PARAMETERS_BACKGROUND, manager); 127 assistant.setContextInformationPopupBackground(c); 128 assistant.setContextSelectorBackground(c); 129 130 enabled= store.getBoolean(PreferenceConstants.CODEASSIST_AUTOINSERT); 131 assistant.enableAutoInsert(enabled); 132 133 configureDisplayProcessor(assistant, store); 134 configureJavaSnippetProcessor(assistant, store); 135 } 136 137 138 private static void changeDisplayProcessor(ContentAssistant assistant, IPreferenceStore store, String key) { 139 JavaDebugContentAssistProcessor dcp= getDisplayProcessor(assistant); 140 if (dcp == null) { 141 return; 142 } 143 if (PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA.equals(key)) { 144 String triggers= store.getString(PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA); 145 if (triggers != null) { 146 dcp.setCompletionProposalAutoActivationCharacters(triggers.toCharArray()); 147 } 148 } else if (PreferenceConstants.CODEASSIST_SORTER.equals(key)) { 149 boolean enable= store.getBoolean(PreferenceConstants.CODEASSIST_SORTER); 150 dcp.orderProposalsAlphabetically(enable); 151 } 152 } 153 154 private static void changeJavaSnippetProcessor(ContentAssistant assistant, IPreferenceStore store, String key) { 155 JavaSnippetCompletionProcessor cp= getJavaSnippetProcessor(assistant); 156 if (cp == null) { 157 return; 158 } 159 if (PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA.equals(key)) { 160 String triggers= store.getString(PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA); 161 if (triggers != null) { 162 cp.setCompletionProposalAutoActivationCharacters(triggers.toCharArray()); 163 } 164 } else if (PreferenceConstants.CODEASSIST_SORTER.equals(key)) { 165 boolean enable= store.getBoolean(PreferenceConstants.CODEASSIST_SORTER); 166 cp.orderProposalsAlphabetically(enable); 167 } 168 } 169 170 171 175 public static void changeConfiguration(ContentAssistant assistant, PropertyChangeEvent event) { 176 177 IPreferenceStore store= getPreferenceStore(); 178 String p= event.getProperty(); 179 180 if (PreferenceConstants.CODEASSIST_AUTOACTIVATION.equals(p)) { 181 boolean enabled= store.getBoolean(PreferenceConstants.CODEASSIST_AUTOACTIVATION); 182 assistant.enableAutoActivation(enabled); 183 } else if (PreferenceConstants.CODEASSIST_AUTOACTIVATION_DELAY.equals(p)) { 184 int delay= store.getInt(PreferenceConstants.CODEASSIST_AUTOACTIVATION_DELAY); 185 assistant.setAutoActivationDelay(delay); 186 } else if (PreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND.equals(p)) { 187 Color c= getColor(store, PreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND); 188 assistant.setProposalSelectorForeground(c); 189 } else if (PreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND.equals(p)) { 190 Color c= getColor(store, PreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND); 191 assistant.setProposalSelectorBackground(c); 192 } else if (PreferenceConstants.CODEASSIST_PARAMETERS_FOREGROUND.equals(p)) { 193 Color c= getColor(store, PreferenceConstants.CODEASSIST_PARAMETERS_FOREGROUND); 194 assistant.setContextInformationPopupForeground(c); 195 assistant.setContextSelectorForeground(c); 196 } else if (PreferenceConstants.CODEASSIST_PARAMETERS_BACKGROUND.equals(p)) { 197 Color c= getColor(store, PreferenceConstants.CODEASSIST_PARAMETERS_BACKGROUND); 198 assistant.setContextInformationPopupBackground(c); 199 assistant.setContextSelectorBackground(c); 200 } else if (PreferenceConstants.CODEASSIST_AUTOINSERT.equals(p)) { 201 boolean enabled= store.getBoolean(PreferenceConstants.CODEASSIST_AUTOINSERT); 202 assistant.enableAutoInsert(enabled); 203 } 204 205 changeDisplayProcessor(assistant, store, p); 206 changeJavaSnippetProcessor(assistant, store, p); 207 } 208 209 215 private static void restrictProposalsToVisibility(boolean restrict) { 216 Hashtable options= JavaCore.getOptions(); 217 Object value= options.get(VISIBILITY); 218 if (value instanceof String ) { 219 String newValue= restrict ? ENABLED : DISABLED; 220 if (!newValue.equals(value)) { 221 options.put(VISIBILITY, newValue); 222 JavaCore.setOptions(options); 223 } 224 } 225 } 226 227 233 private static void restrictProposalsToMatchingCases(boolean restrict) { 234 } 236 237 private static IPreferenceStore getPreferenceStore() { 238 return PreferenceConstants.getPreferenceStore(); 239 } 240 } 241 | Popular Tags |