1 11 package org.eclipse.jdt.internal.debug.ui; 12 13 14 import org.eclipse.core.runtime.IStatus; 15 import org.eclipse.jface.dialogs.ErrorDialog; 16 import org.eclipse.jface.dialogs.IDialogConstants; 17 import org.eclipse.jface.preference.IPreferenceStore; 18 import org.eclipse.swt.SWT; 19 import org.eclipse.swt.layout.GridData; 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.Shell; 24 25 33 public class ErrorDialogWithToggle extends ErrorDialog { 34 35 39 private String fPreferenceKey= null; 40 43 private String fToggleMessage= null; 44 private Button fToggleButton= null; 45 48 IPreferenceStore fStore= null; 49 50 public ErrorDialogWithToggle(Shell parentShell, String dialogTitle, String message, IStatus status, String preferenceKey, String toggleMessage, IPreferenceStore store) { 51 super(parentShell, dialogTitle, message, status, IStatus.WARNING | IStatus.ERROR | IStatus.INFO); 52 fStore= store; 53 fPreferenceKey= preferenceKey; 54 fToggleMessage= toggleMessage; 55 } 56 57 protected Control createDialogArea(Composite parent) { 58 Composite dialogComposite= (Composite) super.createDialogArea(parent); 59 dialogComposite.setFont(parent.getFont()); 60 setToggleButton(createCheckButton(dialogComposite, fToggleMessage)); 61 getToggleButton().setSelection(!fStore.getBoolean(fPreferenceKey)); 62 applyDialogFont(dialogComposite); 63 return dialogComposite; 64 } 65 66 70 private Button createCheckButton(Composite parent, String label) { 71 Button button= new Button(parent, SWT.CHECK | SWT.LEFT); 72 button.setText(label); 73 74 GridData data = new GridData(SWT.NONE); 75 data.horizontalSpan= 2; 76 data.horizontalAlignment= GridData.CENTER; 77 button.setLayoutData(data); 78 button.setFont(parent.getFont()); 79 80 return button; 81 } 82 83 protected void buttonPressed(int id) { 84 if (id == IDialogConstants.OK_ID) { storePreference(); 86 } 87 super.buttonPressed(id); 88 } 89 90 private void storePreference() { 91 fStore.setValue(fPreferenceKey, !getToggleButton().getSelection()); 92 } 93 94 protected Button getToggleButton() { 95 return fToggleButton; 96 } 97 98 protected void setToggleButton(Button button) { 99 fToggleButton = button; 100 } 101 102 105 protected void createButtonsForButtonBar(Composite parent) { 106 super.createButtonsForButtonBar(parent); 107 getButton(IDialogConstants.OK_ID).setFocus(); 108 } 109 } 110 | Popular Tags |