1 12 13 package org.eclipse.jdt.internal.ui.preferences; 14 15 import java.util.ArrayList ; 16 import java.util.HashMap ; 17 import java.util.Iterator ; 18 import java.util.Map ; 19 20 import org.eclipse.core.runtime.Assert; 21 import org.eclipse.core.runtime.IStatus; 22 23 import org.eclipse.swt.SWT; 24 import org.eclipse.swt.events.SelectionAdapter; 25 import org.eclipse.swt.events.SelectionEvent; 26 import org.eclipse.swt.events.SelectionListener; 27 import org.eclipse.swt.layout.GridData; 28 import org.eclipse.swt.layout.GridLayout; 29 import org.eclipse.swt.widgets.Button; 30 import org.eclipse.swt.widgets.Composite; 31 import org.eclipse.swt.widgets.Control; 32 import org.eclipse.swt.widgets.Label; 33 import org.eclipse.swt.widgets.Link; 34 35 import org.eclipse.ui.dialogs.PreferencesUtil; 36 37 38 import org.eclipse.jdt.ui.PreferenceConstants; 39 40 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; 41 import org.eclipse.jdt.internal.ui.util.PixelConverter; 42 43 48 class MarkOccurrencesConfigurationBlock implements IPreferenceConfigurationBlock { 49 50 private OverlayPreferenceStore fStore; 51 52 53 private Map fCheckBoxes= new HashMap (); 54 private SelectionListener fCheckBoxListener= new SelectionListener() { 55 public void widgetDefaultSelected(SelectionEvent e) { 56 } 57 public void widgetSelected(SelectionEvent e) { 58 Button button= (Button) e.widget; 59 fStore.setValue((String ) fCheckBoxes.get(button), button.getSelection()); 60 } 61 }; 62 63 69 private ArrayList fMasterSlaveListeners= new ArrayList (); 70 71 private StatusInfo fStatus; 72 73 public MarkOccurrencesConfigurationBlock(OverlayPreferenceStore store) { 74 Assert.isNotNull(store); 75 fStore= store; 76 77 fStore.addKeys(createOverlayStoreKeys()); 78 } 79 80 private OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys() { 81 82 ArrayList overlayKeys= new ArrayList (); 83 84 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_OCCURRENCES)); 85 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES)); 86 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES)); 87 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES)); 88 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES)); 89 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES)); 90 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES)); 91 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS)); 92 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_IMPLEMENTORS)); 93 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_BREAK_CONTINUE_TARGETS)); 94 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_STICKY_OCCURRENCES)); 95 96 OverlayPreferenceStore.OverlayKey[] keys= new OverlayPreferenceStore.OverlayKey[overlayKeys.size()]; 97 overlayKeys.toArray(keys); 98 return keys; 99 } 100 101 107 public Control createControl(final Composite parent) { 108 109 Composite composite= new Composite(parent, SWT.NONE); 110 GridLayout layout= new GridLayout(); 111 layout.numColumns= 1; 112 layout.marginHeight= 0; 113 layout.marginWidth= 0; 114 composite.setLayout(layout); 115 116 Link link= new Link(composite, SWT.NONE); 117 link.setText(PreferencesMessages.MarkOccurrencesConfigurationBlock_link); 118 link.addSelectionListener(new SelectionAdapter() { 119 public void widgetSelected(SelectionEvent e) { 120 PreferencesUtil.createPreferenceDialogOn(parent.getShell(), e.text, null, null); 121 } 122 }); 123 link.setToolTipText(PreferencesMessages.MarkOccurrencesConfigurationBlock_link_tooltip); 126 127 addFiller(composite); 128 129 String label; 130 131 label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markOccurrences; 132 Button master= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_OCCURRENCES, 0); 133 134 addFiller(composite); 135 136 label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markTypeOccurrences; 137 Button slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES, 0); 138 createDependency(master, PreferenceConstants.EDITOR_STICKY_OCCURRENCES, slave); 139 140 label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markMethodOccurrences; 141 slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES, 0); 142 createDependency(master, PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES, slave); 143 144 label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markConstantOccurrences; 145 slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES, 0); 146 createDependency(master, PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES, slave); 147 148 label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markFieldOccurrences; 149 slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES, 0); 150 createDependency(master, PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES, slave); 151 152 label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markLocalVariableOccurrences; 153 slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES, 0); 154 createDependency(master, PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES, slave); 155 156 label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markExceptionOccurrences; 157 slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES, 0); 158 createDependency(master, PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES, slave); 159 160 label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markMethodExitPoints; 161 slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS, 0); 162 createDependency(master, PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS, slave); 163 164 label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markImplementors; 165 slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_IMPLEMENTORS, 0); 166 createDependency(master, PreferenceConstants.EDITOR_MARK_IMPLEMENTORS, slave); 167 168 label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markBreakContinueTargets; 169 slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_BREAK_CONTINUE_TARGETS, 0); 170 createDependency(master, PreferenceConstants.EDITOR_MARK_BREAK_CONTINUE_TARGETS, slave); 171 172 addFiller(composite); 173 174 label= PreferencesMessages.MarkOccurrencesConfigurationBlock_stickyOccurrences; 175 slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_STICKY_OCCURRENCES, 0); 176 createDependency(master, PreferenceConstants.EDITOR_STICKY_OCCURRENCES, slave); 177 178 return composite; 179 } 180 181 private void addFiller(Composite composite) { 182 PixelConverter pixelConverter= new PixelConverter(composite); 183 184 Label filler= new Label(composite, SWT.LEFT ); 185 GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); 186 gd.horizontalSpan= 2; 187 gd.heightHint= pixelConverter.convertHeightInCharsToPixels(1) / 2; 188 filler.setLayoutData(gd); 189 } 190 191 private Button addCheckBox(Composite parent, String label, String key, int indentation) { 192 Button checkBox= new Button(parent, SWT.CHECK); 193 checkBox.setText(label); 194 195 GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); 196 gd.horizontalIndent= indentation; 197 gd.horizontalSpan= 2; 198 checkBox.setLayoutData(gd); 199 checkBox.addSelectionListener(fCheckBoxListener); 200 201 fCheckBoxes.put(checkBox, key); 202 203 return checkBox; 204 } 205 206 private void createDependency(final Button master, String masterKey, final Control slave) { 207 indent(slave); 208 boolean masterState= fStore.getBoolean(masterKey); 209 slave.setEnabled(masterState); 210 SelectionListener listener= new SelectionListener() { 211 public void widgetSelected(SelectionEvent e) { 212 slave.setEnabled(master.getSelection()); 213 } 214 215 public void widgetDefaultSelected(SelectionEvent e) {} 216 }; 217 master.addSelectionListener(listener); 218 fMasterSlaveListeners.add(listener); 219 } 220 221 private static void indent(Control control) { 222 GridData gridData= new GridData(); 223 gridData.horizontalIndent= 10; 224 control.setLayoutData(gridData); 225 } 226 227 public void initialize() { 228 initializeFields(); 229 } 230 231 void initializeFields() { 232 233 Iterator iter= fCheckBoxes.keySet().iterator(); 234 while (iter.hasNext()) { 235 Button b= (Button) iter.next(); 236 String key= (String ) fCheckBoxes.get(b); 237 b.setSelection(fStore.getBoolean(key)); 238 } 239 240 iter= fMasterSlaveListeners.iterator(); 242 while (iter.hasNext()) { 243 SelectionListener listener= (SelectionListener)iter.next(); 244 listener.widgetSelected(null); 245 } 246 247 } 248 249 public void performOk() { 250 } 251 252 public void performDefaults() { 253 restoreFromPreferences(); 254 initializeFields(); 255 } 256 257 private void restoreFromPreferences() { 258 259 } 260 261 IStatus getStatus() { 262 if (fStatus == null) 263 fStatus= new StatusInfo(); 264 return fStatus; 265 } 266 267 271 public void dispose() { 272 } 273 } 274 | Popular Tags |