1 11 12 package org.eclipse.pde.internal.ui.parts; 13 14 import org.eclipse.swt.SWT; 15 import org.eclipse.swt.events.SelectionAdapter; 16 import org.eclipse.swt.events.SelectionEvent; 17 import org.eclipse.swt.graphics.Image; 18 import org.eclipse.swt.layout.GridData; 19 import org.eclipse.swt.widgets.Button; 20 import org.eclipse.swt.widgets.Composite; 21 import org.eclipse.swt.widgets.Control; 22 import org.eclipse.swt.widgets.Shell; 23 24 import org.eclipse.jface.dialogs.IDialogConstants; 25 import org.eclipse.jface.dialogs.MessageDialog; 26 import org.eclipse.jface.preference.IPreferenceStore; 27 28 import org.eclipse.ui.internal.WorkbenchMessages; 29 30 36 public class MessageDialogWithToggle extends MessageDialog { 37 38 41 private String toggleMessage = null; 42 private boolean toggleState = false; 43 private Button toggleButton = null; 44 45 48 IPreferenceStore fStore = null; 49 50 59 public MessageDialogWithToggle(Shell parentShell, String dialogTitle, Image image, String message, int dialogImageType, String [] dialogButtonLabels, int defaultIndex, String toggleMessage, boolean toggleState) { 60 super(parentShell, dialogTitle, image, message, dialogImageType, dialogButtonLabels, defaultIndex); 61 this.toggleMessage = toggleMessage; 62 this.toggleState = toggleState; 63 } 64 65 72 public boolean getToggleState() { 73 return toggleState; 74 } 75 76 79 protected Control createDialogArea(Composite parent) { 80 Composite dialogArea = (Composite) super.createDialogArea(parent); 81 toggleButton = createToggleButton(dialogArea); 82 return dialogArea; 83 } 84 85 88 protected Button createToggleButton(Composite parent) { 89 final Button button= new Button(parent, SWT.CHECK | SWT.LEFT); 90 String text = toggleMessage; 91 if (text == null) { 92 text = WorkbenchMessages.getString("MessageDialogWithToggle.defaultToggleMessage"); } 94 button.setText(text); 95 button.setSelection(toggleState); 96 97 GridData data = new GridData(SWT.NONE); 98 data.horizontalSpan= 2; 99 data.horizontalAlignment= GridData.CENTER; 100 button.setLayoutData(data); 101 button.setFont(parent.getFont()); 102 103 button.addSelectionListener(new SelectionAdapter() { 104 public void widgetSelected(SelectionEvent e) { 105 toggleState = button.getSelection(); 106 } 107 108 }); 109 return button; 110 } 111 112 117 protected Button getToggleButton() { 118 return toggleButton; 119 } 120 121 133 public static MessageDialogWithToggle openConfirm(Shell parent, String title, String message, String toggleMessage, boolean toggleState) { 134 MessageDialogWithToggle dialog = new MessageDialogWithToggle( 135 parent, 136 title, 137 null, message, 139 QUESTION, 140 new String [] {IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL}, 141 0, toggleMessage, 143 toggleState); 144 dialog.open(); 145 return dialog; 146 } 147 148 160 public static MessageDialogWithToggle openError(Shell parent, String title, String message, String toggleMessage, boolean toggleState) { 161 MessageDialogWithToggle dialog = new MessageDialogWithToggle( 162 parent, 163 title, 164 null, message, 166 ERROR, 167 new String [] {IDialogConstants.OK_LABEL}, 168 0, toggleMessage, 170 toggleState); 171 dialog.open(); 172 return dialog; 173 } 174 175 187 public static MessageDialogWithToggle openInformation(Shell parent, String title, String message, String toggleMessage, boolean toggleState) { 188 MessageDialogWithToggle dialog = new MessageDialogWithToggle( 189 parent, 190 title, 191 null, message, 193 INFORMATION, 194 new String [] { IDialogConstants.OK_LABEL }, 195 0, toggleMessage, 197 toggleState); 198 dialog.open(); 199 return dialog; 200 } 201 202 214 public static MessageDialogWithToggle openQuestion(Shell parent, String title, String message, String toggleMessage, boolean toggleState) { 215 MessageDialogWithToggle dialog = new MessageDialogWithToggle( 216 parent, 217 title, 218 null, message, 220 QUESTION, 221 new String [] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL}, 222 0, toggleMessage, 224 toggleState); 225 dialog.open(); 226 return dialog; 227 } 228 229 241 public static MessageDialogWithToggle openWarning(Shell parent, String title, String message, String toggleMessage, boolean toggleState) { 242 MessageDialogWithToggle dialog = new MessageDialogWithToggle( 243 parent, 244 title, 245 null, message, 247 WARNING, 248 new String [] {IDialogConstants.OK_LABEL}, 249 0, toggleMessage, 251 toggleState); 252 dialog.open(); 253 return dialog; 254 } 255 256 } 257 | Popular Tags |