1 11 package org.eclipse.jdt.internal.ui.preferences; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.events.SelectionEvent; 17 import org.eclipse.swt.events.SelectionListener; 18 import org.eclipse.swt.layout.GridData; 19 import org.eclipse.swt.layout.GridLayout; 20 import org.eclipse.swt.widgets.Button; 21 import org.eclipse.swt.widgets.Composite; 22 import org.eclipse.swt.widgets.Control; 23 import org.eclipse.swt.widgets.Group; 24 import org.eclipse.swt.widgets.Label; 25 import org.eclipse.swt.widgets.Text; 26 27 import org.eclipse.jface.dialogs.Dialog; 28 import org.eclipse.jface.dialogs.IDialogConstants; 29 import org.eclipse.jface.dialogs.MessageDialog; 30 import org.eclipse.jface.preference.IPreferenceStore; 31 import org.eclipse.jface.preference.PreferencePage; 32 33 import org.eclipse.ui.IWorkbench; 34 import org.eclipse.ui.IWorkbenchPreferencePage; 35 import org.eclipse.ui.PlatformUI; 36 37 import org.eclipse.jdt.ui.PreferenceConstants; 38 39 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 40 import org.eclipse.jdt.internal.ui.JavaPlugin; 41 import org.eclipse.jdt.internal.ui.dialogs.OptionalMessageDialog; 42 import org.eclipse.jdt.internal.ui.refactoring.RefactoringSavePreferences; 43 import org.eclipse.jdt.internal.ui.util.SWTUtil; 44 45 49 public class JavaBasePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { 50 51 public static final String JAVA_BASE_PREF_PAGE_ID= "org.eclipse.jdt.ui.preferences.JavaBasePreferencePage"; 53 private static final String OPEN_TYPE_HIERARCHY= PreferenceConstants.OPEN_TYPE_HIERARCHY; 54 private static final String OPEN_TYPE_HIERARCHY_IN_PERSPECTIVE= PreferenceConstants.OPEN_TYPE_HIERARCHY_IN_PERSPECTIVE; 55 private static final String OPEN_TYPE_HIERARCHY_IN_VIEW_PART= PreferenceConstants.OPEN_TYPE_HIERARCHY_IN_VIEW_PART; 56 57 private static final String DOUBLE_CLICK= PreferenceConstants.DOUBLE_CLICK; 58 private static final String DOUBLE_CLICK_GOES_INTO= PreferenceConstants.DOUBLE_CLICK_GOES_INTO; 59 private static final String DOUBLE_CLICK_EXPANDS= PreferenceConstants.DOUBLE_CLICK_EXPANDS; 60 61 private ArrayList fCheckBoxes; 62 private ArrayList fRadioButtons; 63 private ArrayList fTextControls; 64 65 public JavaBasePreferencePage() { 66 super(); 67 setPreferenceStore(JavaPlugin.getDefault().getPreferenceStore()); 68 setDescription(PreferencesMessages.JavaBasePreferencePage_description); 69 70 fRadioButtons= new ArrayList (); 71 fCheckBoxes= new ArrayList (); 72 fTextControls= new ArrayList (); 73 } 74 75 78 public void init(IWorkbench workbench) { 79 } 80 81 84 public void createControl(Composite parent) { 85 super.createControl(parent); 86 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaHelpContextIds.JAVA_BASE_PREFERENCE_PAGE); 87 } 88 89 private Button addRadioButton(Composite parent, String label, String key, String value) { 90 GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); 91 92 Button button= new Button(parent, SWT.RADIO); 93 button.setText(label); 94 button.setData(new String [] { key, value }); 95 button.setLayoutData(gd); 96 97 button.setSelection(value.equals(getPreferenceStore().getString(key))); 98 99 fRadioButtons.add(button); 100 return button; 101 } 102 103 private Button addCheckBox(Composite parent, String label, String key) { 104 GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); 105 106 Button button= new Button(parent, SWT.CHECK); 107 button.setText(label); 108 button.setData(key); 109 button.setLayoutData(gd); 110 111 button.setSelection(getPreferenceStore().getBoolean(key)); 112 113 fCheckBoxes.add(button); 114 return button; 115 } 116 117 protected Control createContents(Composite parent) { 118 initializeDialogUnits(parent); 119 120 Composite result= new Composite(parent, SWT.NONE); 121 GridLayout layout= new GridLayout(); 122 layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); 123 layout.marginWidth= 0; 124 layout.verticalSpacing= convertVerticalDLUsToPixels(10); 125 layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); 126 result.setLayout(layout); 127 128 137 139 Group doubleClickGroup= new Group(result, SWT.NONE); 140 doubleClickGroup.setLayout(new GridLayout()); 141 doubleClickGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 142 doubleClickGroup.setText(PreferencesMessages.JavaBasePreferencePage_doubleclick_action); 143 addRadioButton(doubleClickGroup, PreferencesMessages.JavaBasePreferencePage_doubleclick_gointo, DOUBLE_CLICK, DOUBLE_CLICK_GOES_INTO); 144 addRadioButton(doubleClickGroup, PreferencesMessages.JavaBasePreferencePage_doubleclick_expand, DOUBLE_CLICK, DOUBLE_CLICK_EXPANDS); 145 146 148 Group typeHierarchyGroup= new Group(result, SWT.NONE); 149 typeHierarchyGroup.setLayout(new GridLayout()); 150 typeHierarchyGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 151 typeHierarchyGroup.setText(PreferencesMessages.JavaBasePreferencePage_openTypeHierarchy); 152 addRadioButton(typeHierarchyGroup, PreferencesMessages.JavaBasePreferencePage_inPerspective, OPEN_TYPE_HIERARCHY, OPEN_TYPE_HIERARCHY_IN_PERSPECTIVE); 153 addRadioButton(typeHierarchyGroup, PreferencesMessages.JavaBasePreferencePage_inView, OPEN_TYPE_HIERARCHY, OPEN_TYPE_HIERARCHY_IN_VIEW_PART); 154 155 Group refactoringGroup= new Group(result, SWT.NONE); 156 refactoringGroup.setLayout(new GridLayout()); 157 refactoringGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 158 refactoringGroup.setText(PreferencesMessages.JavaBasePreferencePage_refactoring_title); 159 addCheckBox(refactoringGroup, 160 PreferencesMessages.JavaBasePreferencePage_refactoring_auto_save, 161 RefactoringSavePreferences.PREF_SAVE_ALL_EDITORS); 162 addCheckBox(refactoringGroup, 163 PreferencesMessages.JavaBasePreferencePage_refactoring_lightweight, 164 PreferenceConstants.REFACTOR_LIGHTWEIGHT); 165 166 Group group= new Group(result, SWT.NONE); 167 group.setLayout(new GridLayout()); 168 group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 169 group.setText(PreferencesMessages.JavaBasePreferencePage_search); 170 171 addCheckBox(group, PreferencesMessages.JavaBasePreferencePage_search_small_menu, PreferenceConstants.SEARCH_USE_REDUCED_MENU); 172 173 174 layout= new GridLayout(); 175 layout.numColumns= 2; 176 177 Group dontAskGroup= new Group(result, SWT.NONE); 178 dontAskGroup.setLayout(layout); 179 dontAskGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 180 dontAskGroup.setText(PreferencesMessages.JavaBasePreferencePage_dialogs); 181 182 Label label= new Label(dontAskGroup, SWT.WRAP); 183 label.setText(PreferencesMessages.JavaBasePreferencePage_do_not_hide_description); 184 GridData data= new GridData(GridData.FILL, GridData.CENTER, true, false); 185 data.widthHint= convertVerticalDLUsToPixels(50); 186 label.setLayoutData(data); 187 188 Button clearButton= new Button(dontAskGroup, SWT.PUSH); 189 clearButton.setText(PreferencesMessages.JavaBasePreferencePage_do_not_hide_button); 190 clearButton.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, false, false)); 191 clearButton.addSelectionListener(new SelectionListener() { 192 public void widgetSelected(SelectionEvent e) { 193 unhideAllDialogs(); 194 } 195 public void widgetDefaultSelected(SelectionEvent e) { 196 unhideAllDialogs(); 197 } 198 }); 199 200 201 SWTUtil.setButtonDimensionHint(clearButton); 202 Dialog.applyDialogFont(result); 203 return result; 204 } 205 206 protected final void unhideAllDialogs() { 207 OptionalMessageDialog.clearAllRememberedStates(); 208 MessageDialog.openInformation(getShell(), PreferencesMessages.JavaBasePreferencePage_do_not_hide_dialog_title, PreferencesMessages.JavaBasePreferencePage_do_not_hide_dialog_message); 209 } 210 211 214 protected void performDefaults() { 215 IPreferenceStore store= getPreferenceStore(); 216 for (int i= 0; i < fCheckBoxes.size(); i++) { 217 Button button= (Button) fCheckBoxes.get(i); 218 String key= (String ) button.getData(); 219 button.setSelection(store.getDefaultBoolean(key)); 220 } 221 for (int i= 0; i < fRadioButtons.size(); i++) { 222 Button button= (Button) fRadioButtons.get(i); 223 String [] info= (String []) button.getData(); 224 button.setSelection(info[1].equals(store.getDefaultString(info[0]))); 225 } 226 for (int i= 0; i < fTextControls.size(); i++) { 227 Text text= (Text) fTextControls.get(i); 228 String key= (String ) text.getData(); 229 text.setText(store.getDefaultString(key)); 230 } 231 super.performDefaults(); 232 } 233 234 237 public boolean performOk() { 238 IPreferenceStore store= getPreferenceStore(); 239 for (int i= 0; i < fCheckBoxes.size(); i++) { 240 Button button= (Button) fCheckBoxes.get(i); 241 String key= (String ) button.getData(); 242 store.setValue(key, button.getSelection()); 243 } 244 for (int i= 0; i < fRadioButtons.size(); i++) { 245 Button button= (Button) fRadioButtons.get(i); 246 if (button.getSelection()) { 247 String [] info= (String []) button.getData(); 248 store.setValue(info[0], info[1]); 249 } 250 } 251 for (int i= 0; i < fTextControls.size(); i++) { 252 Text text= (Text) fTextControls.get(i); 253 String key= (String ) text.getData(); 254 store.setValue(key, text.getText()); 255 } 256 257 JavaPlugin.getDefault().savePluginPreferences(); 258 return super.performOk(); 259 } 260 261 262 } 263 264 265 | Popular Tags |