1 11 package org.eclipse.jdt.internal.ui.text.folding; 12 13 import java.util.ArrayList ; 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 import java.util.Map ; 17 18 import org.eclipse.swt.SWT; 19 import org.eclipse.swt.events.SelectionEvent; 20 import org.eclipse.swt.events.SelectionListener; 21 import org.eclipse.swt.layout.GridData; 22 import org.eclipse.swt.layout.GridLayout; 23 import org.eclipse.swt.widgets.Button; 24 import org.eclipse.swt.widgets.Composite; 25 import org.eclipse.swt.widgets.Control; 26 import org.eclipse.swt.widgets.Label; 27 28 import org.eclipse.jface.preference.IPreferenceStore; 29 30 import org.eclipse.jdt.ui.PreferenceConstants; 31 import org.eclipse.jdt.ui.text.folding.IJavaFoldingPreferenceBlock; 32 33 import org.eclipse.jdt.internal.ui.JavaPlugin; 34 import org.eclipse.jdt.internal.ui.preferences.OverlayPreferenceStore; 35 import org.eclipse.jdt.internal.ui.preferences.OverlayPreferenceStore.OverlayKey; 36 37 38 43 public class DefaultJavaFoldingPreferenceBlock implements IJavaFoldingPreferenceBlock { 44 45 private IPreferenceStore fStore; 46 private OverlayPreferenceStore fOverlayStore; 47 private OverlayKey[] fKeys; 48 private Map fCheckBoxes= new HashMap (); 49 private SelectionListener fCheckBoxListener= new SelectionListener() { 50 public void widgetDefaultSelected(SelectionEvent e) { 51 } 52 public void widgetSelected(SelectionEvent e) { 53 Button button= (Button) e.widget; 54 fOverlayStore.setValue((String ) fCheckBoxes.get(button), button.getSelection()); 55 } 56 }; 57 58 59 public DefaultJavaFoldingPreferenceBlock() { 60 fStore= JavaPlugin.getDefault().getPreferenceStore(); 61 fKeys= createKeys(); 62 fOverlayStore= new OverlayPreferenceStore(fStore, fKeys); 63 } 64 65 private OverlayKey[] createKeys() { 66 ArrayList overlayKeys= new ArrayList (); 67 68 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_JAVADOC)); 69 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_INNERTYPES)); 70 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_METHODS)); 71 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_IMPORTS)); 72 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_HEADERS)); 73 74 return (OverlayKey[]) overlayKeys.toArray(new OverlayKey[overlayKeys.size()]); 75 } 76 77 80 public Control createControl(Composite composite) { 81 fOverlayStore.load(); 82 fOverlayStore.start(); 83 84 Composite inner= new Composite(composite, SWT.NONE); 85 GridLayout layout= new GridLayout(1, true); 86 layout.verticalSpacing= 3; 87 layout.marginWidth= 0; 88 inner.setLayout(layout); 89 90 Label label= new Label(inner, SWT.LEFT); 91 label.setText(FoldingMessages.DefaultJavaFoldingPreferenceBlock_title); 92 93 addCheckBox(inner, FoldingMessages.DefaultJavaFoldingPreferenceBlock_comments, PreferenceConstants.EDITOR_FOLDING_JAVADOC, 0); 94 addCheckBox(inner, FoldingMessages.DefaultJavaFoldingPreferenceBlock_headers, PreferenceConstants.EDITOR_FOLDING_HEADERS, 0); 95 addCheckBox(inner, FoldingMessages.DefaultJavaFoldingPreferenceBlock_innerTypes, PreferenceConstants.EDITOR_FOLDING_INNERTYPES, 0); 96 addCheckBox(inner, FoldingMessages.DefaultJavaFoldingPreferenceBlock_methods, PreferenceConstants.EDITOR_FOLDING_METHODS, 0); 97 addCheckBox(inner, FoldingMessages.DefaultJavaFoldingPreferenceBlock_imports, PreferenceConstants.EDITOR_FOLDING_IMPORTS, 0); 98 99 return inner; 100 } 101 102 private Button addCheckBox(Composite parent, String label, String key, int indentation) { 103 Button checkBox= new Button(parent, SWT.CHECK); 104 checkBox.setText(label); 105 106 GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); 107 gd.horizontalIndent= indentation; 108 gd.horizontalSpan= 1; 109 gd.grabExcessVerticalSpace= false; 110 checkBox.setLayoutData(gd); 111 checkBox.addSelectionListener(fCheckBoxListener); 112 113 fCheckBoxes.put(checkBox, key); 114 115 return checkBox; 116 } 117 118 private void initializeFields() { 119 Iterator it= fCheckBoxes.keySet().iterator(); 120 while (it.hasNext()) { 121 Button b= (Button) it.next(); 122 String key= (String ) fCheckBoxes.get(b); 123 b.setSelection(fOverlayStore.getBoolean(key)); 124 } 125 } 126 127 130 public void performOk() { 131 fOverlayStore.propagate(); 132 } 133 134 135 138 public void initialize() { 139 initializeFields(); 140 } 141 142 145 public void performDefaults() { 146 fOverlayStore.loadDefaults(); 147 initializeFields(); 148 } 149 150 153 public void dispose() { 154 fOverlayStore.stop(); 155 } 156 } 157 | Popular Tags |