1 11 package org.eclipse.ui.internal.dialogs; 12 13 import org.eclipse.jface.dialogs.IDialogConstants; 14 import org.eclipse.jface.preference.IPreferenceStore; 15 import org.eclipse.jface.preference.PreferencePage; 16 import org.eclipse.jface.util.OpenStrategy; 17 import org.eclipse.swt.SWT; 18 import org.eclipse.swt.events.SelectionAdapter; 19 import org.eclipse.swt.events.SelectionEvent; 20 import org.eclipse.swt.graphics.Font; 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.Combo; 25 import org.eclipse.swt.widgets.Composite; 26 import org.eclipse.swt.widgets.Control; 27 import org.eclipse.swt.widgets.Group; 28 import org.eclipse.swt.widgets.Label; 29 import org.eclipse.ui.IWorkbench; 30 import org.eclipse.ui.IWorkbenchPreferenceConstants; 31 import org.eclipse.ui.IWorkbenchPreferencePage; 32 import org.eclipse.ui.IWorkbenchWindow; 33 import org.eclipse.ui.PlatformUI; 34 import org.eclipse.ui.internal.IPreferenceConstants; 35 import org.eclipse.ui.internal.IWorkbenchHelpContextIds; 36 import org.eclipse.ui.internal.WorkbenchMessages; 37 import org.eclipse.ui.internal.WorkbenchPlugin; 38 import org.eclipse.ui.internal.WorkbenchWindow; 39 import org.eclipse.ui.internal.util.PrefUtil; 40 41 44 public class WorkbenchPreferencePage extends PreferencePage implements 45 IWorkbenchPreferencePage { 46 private Button stickyCycleButton; 47 48 private Button doubleClickButton; 49 50 private Button singleClickButton; 51 52 private Button selectOnHoverButton; 53 54 private Button openAfterDelayButton; 55 56 private Button showUserDialogButton; 57 58 private boolean openOnSingleClick; 59 60 private boolean selectOnHover; 61 62 private boolean openAfterDelay; 63 64 private Button showHeapStatusButton; 65 66 71 protected Control createContents(Composite parent) { 72 73 PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, 76 IWorkbenchHelpContextIds.WORKBENCH_PREFERENCE_PAGE); 77 78 Composite composite = createComposite(parent); 79 80 createButtons(composite); 81 82 createSpace(composite); 83 createOpenModeGroup(composite); 84 85 applyDialogFont(composite); 86 87 return composite; 88 } 89 90 94 protected void createButtons(Composite composite) { 95 createShowUserDialogPref(composite); 96 createStickyCyclePref(composite); 97 createHeapStatusPref(composite); 98 } 99 100 105 protected void createShowUserDialogPref(Composite composite) { 106 showUserDialogButton = new Button(composite, SWT.CHECK); 107 showUserDialogButton.setText(WorkbenchMessages.WorkbenchPreference_RunInBackgroundButton); 108 showUserDialogButton.setToolTipText(WorkbenchMessages.WorkbenchPreference_RunInBackgroundToolTip); 109 showUserDialogButton.setSelection(WorkbenchPlugin.getDefault() 110 .getPreferenceStore().getBoolean( 111 IPreferenceConstants.RUN_IN_BACKGROUND)); 112 } 113 114 119 protected void createHeapStatusPref(Composite composite) { 120 showHeapStatusButton = new Button(composite, SWT.CHECK); 121 showHeapStatusButton.setText(WorkbenchMessages.WorkbenchPreference_HeapStatusButton); 122 showHeapStatusButton.setToolTipText(WorkbenchMessages.WorkbenchPreference_HeapStatusButtonToolTip); 123 124 showHeapStatusButton.setSelection(PrefUtil.getAPIPreferenceStore().getBoolean( 125 IWorkbenchPreferenceConstants.SHOW_MEMORY_MONITOR)); 126 } 127 128 136 protected Composite createComposite(Composite parent) { 137 Composite composite = new Composite(parent, SWT.NONE); 138 GridLayout layout = new GridLayout(); 139 layout.marginWidth = 0; 140 layout.marginHeight = 0; 141 composite.setLayout(layout); 142 composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL 143 | GridData.HORIZONTAL_ALIGN_FILL)); 144 return composite; 145 } 146 147 protected void createStickyCyclePref(Composite composite) { 148 stickyCycleButton = new Button(composite, SWT.CHECK); 149 stickyCycleButton.setText(WorkbenchMessages.WorkbenchPreference_stickyCycleButton); 150 stickyCycleButton.setSelection(getPreferenceStore().getBoolean( 151 IPreferenceConstants.STICKY_CYCLE)); 152 } 153 154 protected void createOpenModeGroup(Composite composite) { 155 156 Font font = composite.getFont(); 157 158 Group buttonComposite = new Group(composite, SWT.LEFT); 159 GridLayout layout = new GridLayout(); 160 buttonComposite.setLayout(layout); 161 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL 162 | GridData.GRAB_HORIZONTAL); 163 buttonComposite.setLayoutData(data); 164 buttonComposite.setText(WorkbenchMessages.WorkbenchPreference_openMode); 165 166 String label = WorkbenchMessages.WorkbenchPreference_doubleClick; 167 doubleClickButton = createRadioButton(buttonComposite, label); 168 doubleClickButton.addSelectionListener(new SelectionAdapter() { 169 170 public void widgetSelected(SelectionEvent e) { 171 selectClickMode(singleClickButton.getSelection()); 172 } 173 }); 174 doubleClickButton.setSelection(!openOnSingleClick); 175 176 label = WorkbenchMessages.WorkbenchPreference_singleClick; 177 singleClickButton = createRadioButton(buttonComposite, label); 178 singleClickButton.addSelectionListener(new SelectionAdapter() { 179 180 public void widgetSelected(SelectionEvent e) { 181 selectClickMode(singleClickButton.getSelection()); 182 } 183 }); 184 singleClickButton.setSelection(openOnSingleClick); 185 186 label = WorkbenchMessages.WorkbenchPreference_singleClick_SelectOnHover; 187 selectOnHoverButton = new Button(buttonComposite, SWT.CHECK | SWT.LEFT); 188 selectOnHoverButton.setText(label); 189 selectOnHoverButton.setEnabled(openOnSingleClick); 190 selectOnHoverButton.setSelection(selectOnHover); 191 selectOnHoverButton.addSelectionListener(new SelectionAdapter() { 192 193 public void widgetSelected(SelectionEvent e) { 194 selectOnHover = selectOnHoverButton.getSelection(); 195 } 196 }); 197 data = new GridData(); 198 data.horizontalIndent = 20; 199 selectOnHoverButton.setLayoutData(data); 200 201 label = WorkbenchMessages.WorkbenchPreference_singleClick_OpenAfterDelay; 202 openAfterDelayButton = new Button(buttonComposite, SWT.CHECK | SWT.LEFT); 203 openAfterDelayButton.setText(label); 204 openAfterDelayButton.setEnabled(openOnSingleClick); 205 openAfterDelayButton.setSelection(openAfterDelay); 206 openAfterDelayButton.addSelectionListener(new SelectionAdapter() { 207 208 public void widgetSelected(SelectionEvent e) { 209 openAfterDelay = openAfterDelayButton.getSelection(); 210 } 211 }); 212 data = new GridData(); 213 data.horizontalIndent = 20; 214 openAfterDelayButton.setLayoutData(data); 215 216 createNoteComposite(font, buttonComposite, WorkbenchMessages.Preference_note, 217 WorkbenchMessages.WorkbenchPreference_noEffectOnAllViews); 218 } 219 220 private void selectClickMode(boolean singleClick) { 221 openOnSingleClick = singleClick; 222 selectOnHoverButton.setEnabled(openOnSingleClick); 223 openAfterDelayButton.setEnabled(openOnSingleClick); 224 } 225 226 236 protected static Button createRadioButton(Composite parent, String label) { 237 Button button = new Button(parent, SWT.RADIO | SWT.LEFT); 238 button.setText(label); 239 return button; 240 } 241 242 249 protected static Combo createCombo(Composite parent) { 250 Combo combo = new Combo(parent, SWT.READ_ONLY); 251 GridData data = new GridData(GridData.FILL_HORIZONTAL); 252 data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH; 253 combo.setLayoutData(data); 254 return combo; 255 } 256 257 267 protected static Label createLabel(Composite parent, String text) { 268 Label label = new Label(parent, SWT.LEFT); 269 label.setText(text); 270 GridData data = new GridData(); 271 data.horizontalSpan = 1; 272 data.horizontalAlignment = GridData.FILL; 273 label.setLayoutData(data); 274 return label; 275 } 276 277 283 protected static void createSpace(Composite parent) { 284 Label vfiller = new Label(parent, SWT.LEFT); 285 GridData gridData = new GridData(); 286 gridData = new GridData(); 287 gridData.horizontalAlignment = GridData.BEGINNING; 288 gridData.grabExcessHorizontalSpace = false; 289 gridData.verticalAlignment = GridData.CENTER; 290 gridData.grabExcessVerticalSpace = false; 291 vfiller.setLayoutData(gridData); 292 } 293 294 299 protected IPreferenceStore doGetPreferenceStore() { 300 return WorkbenchPlugin.getDefault().getPreferenceStore(); 301 } 302 303 306 public void init(IWorkbench aWorkbench) { 307 IPreferenceStore store = getPreferenceStore(); 308 openOnSingleClick = store 309 .getBoolean(IPreferenceConstants.OPEN_ON_SINGLE_CLICK); 310 selectOnHover = store.getBoolean(IPreferenceConstants.SELECT_ON_HOVER); 311 openAfterDelay = store 312 .getBoolean(IPreferenceConstants.OPEN_AFTER_DELAY); 313 } 314 315 318 protected void performDefaults() { 319 IPreferenceStore store = getPreferenceStore(); 320 stickyCycleButton.setSelection(store 321 .getBoolean(IPreferenceConstants.STICKY_CYCLE)); 322 openOnSingleClick = store 323 .getDefaultBoolean(IPreferenceConstants.OPEN_ON_SINGLE_CLICK); 324 selectOnHover = store 325 .getDefaultBoolean(IPreferenceConstants.SELECT_ON_HOVER); 326 openAfterDelay = store 327 .getDefaultBoolean(IPreferenceConstants.OPEN_AFTER_DELAY); 328 singleClickButton.setSelection(openOnSingleClick); 329 doubleClickButton.setSelection(!openOnSingleClick); 330 selectOnHoverButton.setSelection(selectOnHover); 331 openAfterDelayButton.setSelection(openAfterDelay); 332 selectOnHoverButton.setEnabled(openOnSingleClick); 333 openAfterDelayButton.setEnabled(openOnSingleClick); 334 stickyCycleButton.setSelection(store 335 .getDefaultBoolean(IPreferenceConstants.STICKY_CYCLE)); 336 showUserDialogButton.setSelection(store.getDefaultBoolean( 337 IPreferenceConstants.RUN_IN_BACKGROUND)); 338 showHeapStatusButton.setSelection(PrefUtil.getAPIPreferenceStore().getDefaultBoolean( 339 IWorkbenchPreferenceConstants.SHOW_MEMORY_MONITOR)); 340 341 super.performDefaults(); 342 } 343 344 347 public boolean performOk() { 348 IPreferenceStore store = getPreferenceStore(); 349 350 store.setValue(IPreferenceConstants.STICKY_CYCLE, stickyCycleButton 352 .getSelection()); 353 store.setValue(IPreferenceConstants.OPEN_ON_SINGLE_CLICK, 354 openOnSingleClick); 355 store.setValue(IPreferenceConstants.SELECT_ON_HOVER, selectOnHover); 356 store.setValue(IPreferenceConstants.OPEN_AFTER_DELAY, openAfterDelay); 357 store.setValue(IPreferenceConstants.RUN_IN_BACKGROUND, 358 showUserDialogButton.getSelection()); 359 PrefUtil.getAPIPreferenceStore().setValue(IWorkbenchPreferenceConstants.SHOW_MEMORY_MONITOR, showHeapStatusButton.getSelection()); 360 updateHeapStatus(showHeapStatusButton.getSelection()); 361 362 int singleClickMethod = openOnSingleClick ? OpenStrategy.SINGLE_CLICK 363 : OpenStrategy.DOUBLE_CLICK; 364 if (openOnSingleClick) { 365 if (selectOnHover) { 366 singleClickMethod |= OpenStrategy.SELECT_ON_HOVER; 367 } 368 if (openAfterDelay) { 369 singleClickMethod |= OpenStrategy.ARROW_KEYS_OPEN; 370 } 371 } 372 OpenStrategy.setOpenMethod(singleClickMethod); 373 374 PrefUtil.savePrefs(); 375 return true; 376 } 377 378 382 private void updateHeapStatus(boolean selection) { 383 IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); 384 for (int i = 0; i < windows.length; i++) { 385 IWorkbenchWindow window = windows[i]; 386 if(window instanceof WorkbenchWindow){ 387 ((WorkbenchWindow) window).showHeapStatus(selection); 388 } 389 } 390 391 } 392 } 393 | Popular Tags |