Mercurial > projects > dwt-addons
annotate dwtx/jface/dialogs/MessageDialogWithToggle.d @ 192:c3583c6ec027
Added missing default cases for switch statements
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 03 Nov 2008 22:52:26 +0100 |
parents | 46a6e0e6ccd4 |
children |
rev | line source |
---|---|
22 | 1 /******************************************************************************* |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
22 | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 | |
14 module dwtx.jface.dialogs.MessageDialogWithToggle; | |
15 | |
16 import dwtx.jface.dialogs.MessageDialog; | |
17 import dwtx.jface.dialogs.IDialogConstants; | |
18 | |
19 import dwt.DWT; | |
20 import dwt.events.SelectionAdapter; | |
21 import dwt.events.SelectionEvent; | |
22 import dwt.graphics.Image; | |
23 import dwt.layout.GridData; | |
24 import dwt.widgets.Button; | |
25 import dwt.widgets.Composite; | |
26 import dwt.widgets.Control; | |
27 import dwt.widgets.Shell; | |
28 import dwtx.jface.preference.IPreferenceStore; | |
29 import dwtx.jface.resource.JFaceResources; | |
30 | |
31 import dwt.dwthelper.utils; | |
32 | |
33 /** | |
34 * <p> | |
35 * A message dialog which also allows the user to adjust a toggle setting. If a | |
36 * preference store is provided and the user selects the toggle, then the user's | |
37 * answer (yes/ok or no) will be persisted in the store. If no store is | |
38 * provided, then this information can be queried after the dialog closes. | |
39 * </p> | |
40 * <p> | |
41 * This type of dialog should be used whenever you want to user to be able to | |
42 * avoid being prompted in the future. It is <strong>strongly </strong> | |
43 * recommended that a cancel option be provided, so that the user has the option | |
44 * of making the decision at a later point in time. The semantic for a cancel | |
45 * button should be to cancel the operation (if it has not yet started), or stop | |
46 * the operation (if it has already started). | |
47 * </p> | |
48 * <p> | |
49 * It is the responsibility of the developer to provide a mechanism for the user | |
50 * to change this preference at some later point in time (e.g., through a | |
51 * preference page). | |
52 * </p> | |
53 * | |
54 * @since 3.0 | |
55 */ | |
56 public class MessageDialogWithToggle : MessageDialog { | |
57 | |
58 /** | |
59 * The value of the preference when the user has asked that the answer to | |
60 * the question always be "okay" or "yes". | |
61 */ | |
62 public static const String ALWAYS = "always"; //$NON-NLS-1$ | |
63 | |
64 /** | |
65 * The value of the preference when the user has asked that the answer to | |
66 * the question always be "no". | |
67 */ | |
68 public static const String NEVER = "never"; //$NON-NLS-1$ | |
69 | |
70 /** | |
71 * The value of the preference when the user wishes to prompted for an | |
72 * answer every time the question is to be asked. | |
73 */ | |
74 public static const String PROMPT = "prompt"; //$NON-NLS-1$ | |
75 | |
76 /** | |
77 * Convenience method to open a standard error dialog. | |
78 * | |
79 * @param parent | |
80 * the parent shell of the dialog, or <code>null</code> if none | |
81 * @param title | |
82 * the dialog's title, or <code>null</code> if none | |
83 * @param message | |
84 * the message | |
85 * @param toggleMessage | |
86 * the message for the toggle control, or <code>null</code> for | |
87 * the default message | |
88 * @param toggleState | |
89 * the initial state for the toggle | |
90 * @param store | |
91 * the IPreference store in which the user's preference should be | |
92 * persisted; <code>null</code> if you don't want it persisted | |
93 * automatically. | |
94 * @param key | |
95 * the key to use when persisting the user's preference; | |
96 * <code>null</code> if you don't want it persisted. | |
97 * @return the dialog, after being closed by the user, which the client can | |
98 * only call <code>getReturnCode()</code> or | |
99 * <code>getToggleState()</code> | |
100 */ | |
101 public static MessageDialogWithToggle openError(Shell parent, String title, | |
102 String message, String toggleMessage, bool toggleState, | |
103 IPreferenceStore store, String key) { | |
104 MessageDialogWithToggle dialog = new MessageDialogWithToggle(parent, | |
105 title, null, // accept the default window icon | |
106 message, ERROR, [ IDialogConstants.OK_LABEL ], 0, // ok | |
107 // is | |
108 // the | |
109 // default | |
110 toggleMessage, toggleState); | |
111 dialog.prefStore = store; | |
112 dialog.prefKey = key; | |
113 dialog.open(); | |
114 return dialog; | |
115 } | |
116 | |
117 /** | |
118 * Convenience method to open a standard information dialog. | |
119 * | |
120 * @param parent | |
121 * the parent shell of the dialog, or <code>null</code> if none | |
122 * @param title | |
123 * the dialog's title, or <code>null</code> if none | |
124 * @param message | |
125 * the message | |
126 * @param toggleMessage | |
127 * the message for the toggle control, or <code>null</code> for | |
128 * the default message | |
129 * @param toggleState | |
130 * the initial state for the toggle | |
131 * @param store | |
132 * the IPreference store in which the user's preference should be | |
133 * persisted; <code>null</code> if you don't want it persisted | |
134 * automatically. | |
135 * @param key | |
136 * the key to use when persisting the user's preference; | |
137 * <code>null</code> if you don't want it persisted. | |
138 * | |
139 * @return the dialog, after being closed by the user, which the client can | |
140 * only call <code>getReturnCode()</code> or | |
141 * <code>getToggleState()</code> | |
142 */ | |
143 public static MessageDialogWithToggle openInformation(Shell parent, | |
144 String title, String message, String toggleMessage, | |
145 bool toggleState, IPreferenceStore store, String key) { | |
146 MessageDialogWithToggle dialog = new MessageDialogWithToggle(parent, | |
147 title, null, // accept the default window icon | |
148 message, INFORMATION, | |
149 [ IDialogConstants.OK_LABEL ], 0, // ok is the | |
150 // default | |
151 toggleMessage, toggleState); | |
152 dialog.prefStore = store; | |
153 dialog.prefKey = key; | |
154 dialog.open(); | |
155 return dialog; | |
156 } | |
157 | |
158 /** | |
159 * Convenience method to open a simple confirm (OK/Cancel) dialog. | |
160 * | |
161 * @param parent | |
162 * the parent shell of the dialog, or <code>null</code> if none | |
163 * @param title | |
164 * the dialog's title, or <code>null</code> if none | |
165 * @param message | |
166 * the message | |
167 * @param toggleMessage | |
168 * the message for the toggle control, or <code>null</code> for | |
169 * the default message | |
170 * @param toggleState | |
171 * the initial state for the toggle | |
172 * @param store | |
173 * the IPreference store in which the user's preference should be | |
174 * persisted; <code>null</code> if you don't want it persisted | |
175 * automatically. | |
176 * @param key | |
177 * the key to use when persisting the user's preference; | |
178 * <code>null</code> if you don't want it persisted. | |
179 * @return the dialog, after being closed by the user, which the client can | |
180 * only call <code>getReturnCode()</code> or | |
181 * <code>getToggleState()</code> | |
182 */ | |
183 public static MessageDialogWithToggle openOkCancelConfirm(Shell parent, | |
184 String title, String message, String toggleMessage, | |
185 bool toggleState, IPreferenceStore store, String key) { | |
186 MessageDialogWithToggle dialog = new MessageDialogWithToggle(parent, | |
187 title, null, // accept the default window icon | |
188 message, QUESTION, [ IDialogConstants.OK_LABEL, | |
189 IDialogConstants.CANCEL_LABEL ], 0, // OK is the default | |
190 toggleMessage, toggleState); | |
191 dialog.prefStore = store; | |
192 dialog.prefKey = key; | |
193 dialog.open(); | |
194 return dialog; | |
195 } | |
196 | |
197 /** | |
198 * Convenience method to open a standard warning dialog. | |
199 * | |
200 * @param parent | |
201 * the parent shell of the dialog, or <code>null</code> if none | |
202 * @param title | |
203 * the dialog's title, or <code>null</code> if none | |
204 * @param message | |
205 * the message | |
206 * @param toggleMessage | |
207 * the message for the toggle control, or <code>null</code> for | |
208 * the default message | |
209 * @param toggleState | |
210 * the initial state for the toggle | |
211 * @param store | |
212 * the IPreference store in which the user's preference should be | |
213 * persisted; <code>null</code> if you don't want it persisted | |
214 * automatically. | |
215 * @param key | |
216 * the key to use when persisting the user's preference; | |
217 * <code>null</code> if you don't want it persisted. | |
218 * @return the dialog, after being closed by the user, which the client can | |
219 * only call <code>getReturnCode()</code> or | |
220 * <code>getToggleState()</code> | |
221 */ | |
222 public static MessageDialogWithToggle openWarning(Shell parent, | |
223 String title, String message, String toggleMessage, | |
224 bool toggleState, IPreferenceStore store, String key) { | |
225 MessageDialogWithToggle dialog = new MessageDialogWithToggle(parent, | |
226 title, null, // accept the default window icon | |
227 message, WARNING, [ IDialogConstants.OK_LABEL ], | |
228 0, // ok is the default | |
229 toggleMessage, toggleState); | |
230 dialog.prefStore = store; | |
231 dialog.prefKey = key; | |
232 dialog.open(); | |
233 return dialog; | |
234 } | |
235 | |
236 /** | |
237 * Convenience method to open a simple question Yes/No/Cancel dialog. | |
238 * | |
239 * @param parent | |
240 * the parent shell of the dialog, or <code>null</code> if none | |
241 * @param title | |
242 * the dialog's title, or <code>null</code> if none | |
243 * @param message | |
244 * the message | |
245 * @param toggleMessage | |
246 * the message for the toggle control, or <code>null</code> for | |
247 * the default message | |
248 * @param toggleState | |
249 * the initial state for the toggle | |
250 * @param store | |
251 * the IPreference store in which the user's preference should be | |
252 * persisted; <code>null</code> if you don't want it persisted | |
253 * automatically. | |
254 * @param key | |
255 * the key to use when persisting the user's preference; | |
256 * <code>null</code> if you don't want it persisted. | |
257 * @return the dialog, after being closed by the user, which the client can | |
258 * only call <code>getReturnCode()</code> or | |
259 * <code>getToggleState()</code> | |
260 */ | |
261 public static MessageDialogWithToggle openYesNoCancelQuestion(Shell parent, | |
262 String title, String message, String toggleMessage, | |
263 bool toggleState, IPreferenceStore store, String key) { | |
264 MessageDialogWithToggle dialog = new MessageDialogWithToggle(parent, | |
265 title, null, // accept the default window icon | |
266 message, QUESTION, [ IDialogConstants.YES_LABEL, | |
267 IDialogConstants.NO_LABEL, | |
268 IDialogConstants.CANCEL_LABEL ], 0, // YES is the | |
269 // default | |
270 toggleMessage, toggleState); | |
271 dialog.prefStore = store; | |
272 dialog.prefKey = key; | |
273 dialog.open(); | |
274 return dialog; | |
275 } | |
276 | |
277 /** | |
278 * Convenience method to open a simple Yes/No question dialog. | |
279 * | |
280 * @param parent | |
281 * the parent shell of the dialog, or <code>null</code> if none | |
282 * @param title | |
283 * the dialog's title, or <code>null</code> if none | |
284 * @param message | |
285 * the message | |
286 * @param toggleMessage | |
287 * the message for the toggle control, or <code>null</code> for | |
288 * the default message | |
289 * @param toggleState | |
290 * the initial state for the toggle | |
291 * @param store | |
292 * the IPreference store in which the user's preference should be | |
293 * persisted; <code>null</code> if you don't want it persisted | |
294 * automatically. | |
295 * @param key | |
296 * the key to use when persisting the user's preference; | |
297 * <code>null</code> if you don't want it persisted. | |
298 * | |
299 * @return the dialog, after being closed by the user, which the client can | |
300 * only call <code>getReturnCode()</code> or | |
301 * <code>getToggleState()</code> | |
302 */ | |
303 public static MessageDialogWithToggle openYesNoQuestion(Shell parent, | |
304 String title, String message, String toggleMessage, | |
305 bool toggleState, IPreferenceStore store, String key) { | |
306 MessageDialogWithToggle dialog = new MessageDialogWithToggle(parent, | |
307 title, null, // accept the default window icon | |
308 message, QUESTION, [ IDialogConstants.YES_LABEL, | |
309 IDialogConstants.NO_LABEL ], 0, // yes is the default | |
310 toggleMessage, toggleState); | |
311 dialog.prefStore = store; | |
312 dialog.prefKey = key; | |
313 dialog.open(); | |
314 return dialog; | |
315 } | |
316 | |
317 /** | |
318 * The key at which the toggle state should be stored within the | |
319 * preferences. This value may be <code>null</code>, which indicates that | |
320 * no preference should be updated automatically. It is then the | |
321 * responsibility of the user of this API to use the information from the | |
322 * toggle. Note: a <code>prefStore</code> is also needed. | |
323 */ | |
324 private String prefKey = null; | |
325 | |
326 /** | |
327 * The preference store which will be affected by the toggle button. This | |
328 * value may be <code>null</code>, which indicates that no preference | |
329 * should be updated automatically. It is then the responsibility of the | |
330 * user of this API to use the information from the toggle. Note: a | |
331 * <code>prefKey</code> is also needed. | |
332 */ | |
333 private IPreferenceStore prefStore = null; | |
334 | |
335 /** | |
336 * The toggle button (widget). This value is <code>null</code> until the | |
337 * dialog is created. | |
338 */ | |
339 private Button toggleButton = null; | |
340 | |
341 /** | |
342 * The message displayed to the user, with the toggle button. This is the | |
343 * text besides the toggle. If it is <code>null</code>, this means that | |
344 * the default text for the toggle should be used. | |
345 */ | |
346 private String toggleMessage; | |
347 | |
348 /** | |
349 * The initial selected state of the toggle. | |
350 */ | |
351 private bool toggleState; | |
352 | |
353 /** | |
354 * Creates a message dialog with a toggle. See the superclass constructor | |
355 * for info on the other parameters. | |
356 * | |
357 * @param parentShell | |
358 * the parent shell | |
359 * @param dialogTitle | |
360 * the dialog title, or <code>null</code> if none | |
361 * @param image | |
362 * the dialog title image, or <code>null</code> if none | |
363 * @param message | |
364 * the dialog message | |
365 * @param dialogImageType | |
366 * one of the following values: | |
367 * <ul> | |
368 * <li><code>MessageDialog.NONE</code> for a dialog with no | |
369 * image</li> | |
370 * <li><code>MessageDialog.ERROR</code> for a dialog with an | |
371 * error image</li> | |
372 * <li><code>MessageDialog.INFORMATION</code> for a dialog | |
373 * with an information image</li> | |
374 * <li><code>MessageDialog.QUESTION </code> for a dialog with a | |
375 * question image</li> | |
376 * <li><code>MessageDialog.WARNING</code> for a dialog with a | |
377 * warning image</li> | |
378 * </ul> | |
379 * @param dialogButtonLabels | |
380 * an array of labels for the buttons in the button bar | |
381 * @param defaultIndex | |
382 * the index in the button label array of the default button | |
383 * @param toggleMessage | |
384 * the message for the toggle control, or <code>null</code> for | |
385 * the default message | |
386 * @param toggleState | |
387 * the initial state for the toggle | |
388 * | |
389 */ | |
390 public this(Shell parentShell, String dialogTitle, | |
391 Image image, String message, int dialogImageType, | |
392 String[] dialogButtonLabels, int defaultIndex, | |
393 String toggleMessage, bool toggleState) { | |
394 super(parentShell, dialogTitle, image, message, dialogImageType, | |
395 dialogButtonLabels, defaultIndex); | |
396 this.toggleMessage = toggleMessage; | |
397 this.toggleState = toggleState; | |
398 setButtonLabels(dialogButtonLabels); | |
399 } | |
400 | |
401 /** | |
402 * @see dwtx.jface.dialogs.Dialog#buttonPressed(int) | |
403 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
404 protected override void buttonPressed(int buttonId) { |
22 | 405 super.buttonPressed(buttonId); |
406 | |
407 if (buttonId !is IDialogConstants.CANCEL_ID && toggleState | |
408 && prefStore !is null && prefKey !is null) { | |
409 switch (buttonId) { | |
410 case IDialogConstants.YES_ID: | |
411 case IDialogConstants.YES_TO_ALL_ID: | |
412 case IDialogConstants.PROCEED_ID: | |
413 case IDialogConstants.OK_ID: | |
414 prefStore.setValue(prefKey, ALWAYS); | |
415 break; | |
416 case IDialogConstants.NO_ID: | |
417 case IDialogConstants.NO_TO_ALL_ID: | |
418 prefStore.setValue(prefKey, NEVER); | |
419 break; | |
192
c3583c6ec027
Added missing default cases for switch statements
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
420 default: |
22 | 421 } |
422 } | |
423 } | |
424 | |
425 /** | |
426 * @see Dialog#createButtonBar(Composite) | |
427 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
428 protected override void createButtonsForButtonBar(Composite parent) { |
22 | 429 String[] buttonLabels = getButtonLabels(); |
430 Button[] buttons = new Button[buttonLabels.length]; | |
431 int defaultButtonIndex = getDefaultButtonIndex(); | |
432 | |
433 int suggestedId = IDialogConstants.INTERNAL_ID; | |
434 for (int i = 0; i < buttonLabels.length; i++) { | |
435 String label = buttonLabels[i]; | |
436 // get the JFace button ID that matches the label, or use the specified | |
437 // id if there is no match. | |
438 int id = mapButtonLabelToButtonID(label, suggestedId); | |
439 | |
440 // if the suggested id was used, increment the default for next use | |
441 if (id is suggestedId) { | |
442 suggestedId++; | |
443 } | |
444 | |
445 Button button = createButton(parent, id, label, | |
446 defaultButtonIndex is i); | |
447 buttons[i] = button; | |
448 | |
449 } | |
450 setButtons(buttons); | |
451 } | |
452 | |
453 /** | |
454 * @see Dialog#createDialogArea(Composite) | |
455 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
456 protected override Control createDialogArea(Composite parent) { |
22 | 457 Composite dialogAreaComposite = cast(Composite) super |
458 .createDialogArea(parent); | |
459 setToggleButton(createToggleButton(dialogAreaComposite)); | |
460 return dialogAreaComposite; | |
461 } | |
462 | |
463 /** | |
464 * Creates a toggle button without any text or state. The text and state | |
465 * will be created by <code>createDialogArea</code>. | |
466 * | |
467 * @param parent | |
468 * The composite in which the toggle button should be placed; | |
469 * must not be <code>null</code>. | |
470 * @return The added toggle button; never <code>null</code>. | |
471 */ | |
472 protected Button createToggleButton(Composite parent) { | |
473 Button button = new Button(parent, DWT.CHECK | DWT.LEFT); | |
474 | |
475 GridData data = new GridData(DWT.NONE); | |
476 data.horizontalSpan = 2; | |
477 button.setLayoutData(data); | |
478 button.setFont(parent.getFont()); | |
479 | |
39 | 480 button.addSelectionListener(new class(button) SelectionAdapter { |
22 | 481 Button button_; |
39 | 482 this(Button b){ button_=b; } |
22 | 483 public void widgetSelected(SelectionEvent e) { |
484 toggleState = button_.getSelection(); | |
485 } | |
486 | |
487 }); | |
488 | |
489 return button; | |
490 } | |
491 | |
492 /** | |
493 * Returns the toggle button. | |
494 * | |
495 * @return the toggle button | |
496 */ | |
497 protected Button getToggleButton() { | |
498 return toggleButton; | |
499 } | |
500 | |
501 /** | |
502 * An accessor for the current preference store for this dialog. | |
503 * | |
504 * @return The preference store; this value may be <code>null</code> if no | |
505 * preference is being used. | |
506 */ | |
507 public IPreferenceStore getPrefStore() { | |
508 return prefStore; | |
509 } | |
510 | |
511 /** | |
512 * An accessor for the current key of the toggle preference. | |
513 * | |
514 * @return The preference key; this value may be <code>null</code> if no | |
515 * preference is being used. | |
516 */ | |
517 public String getPrefKey() { | |
518 return prefKey; | |
519 } | |
520 | |
521 /** | |
522 * Returns the toggle state. This can be called even after the dialog is | |
523 * closed. | |
524 * | |
525 * @return <code>true</code> if the toggle button is checked, | |
526 * <code>false</code> if not | |
527 */ | |
528 public bool getToggleState() { | |
529 return toggleState; | |
530 } | |
531 | |
532 /** | |
533 * A mutator for the key of the preference to be modified by the toggle | |
534 * button. | |
535 * | |
536 * @param prefKey | |
537 * The prefKey to set. If this value is <code>null</code>, | |
538 * then no preference will be modified. | |
539 */ | |
540 public void setPrefKey(String prefKey) { | |
541 this.prefKey = prefKey; | |
542 } | |
543 | |
544 /** | |
545 * A mutator for the preference store to be modified by the toggle button. | |
546 * | |
547 * @param prefStore | |
548 * The prefStore to set. If this value is <code>null</code>, | |
549 * then no preference will be modified. | |
550 */ | |
551 public void setPrefStore(IPreferenceStore prefStore) { | |
552 this.prefStore = prefStore; | |
553 } | |
554 | |
555 /** | |
556 * A mutator for the button providing the toggle option. If the button | |
557 * exists, then it will automatically get the text set to the current toggle | |
558 * message, and its selection state set to the current selection state. | |
559 * | |
560 * @param button | |
561 * The button to use; must not be <code>null</code>. | |
562 */ | |
563 protected void setToggleButton(Button button) { | |
564 if (button is null) { | |
565 throw new NullPointerException( | |
566 "A message dialog with toggle may not have a null toggle button.");} //$NON-NLS-1$ | |
567 | |
568 if (!button.isDisposed()) { | |
569 String text; | |
570 if (toggleMessage is null) { | |
571 text = JFaceResources | |
572 .getString("MessageDialogWithToggle.defaultToggleMessage"); //$NON-NLS-1$ | |
573 } else { | |
574 text = toggleMessage; | |
575 } | |
576 button.setText(text); | |
577 button.setSelection(toggleState); | |
578 } | |
579 | |
580 this.toggleButton = button; | |
581 } | |
582 | |
583 /** | |
584 * A mutator for the text on the toggle button. The button will | |
585 * automatically get updated with the new text, if it exists. | |
586 * | |
587 * @param message | |
588 * The new text of the toggle button; if it is <code>null</code>, | |
589 * then used the default toggle message. | |
590 */ | |
591 protected void setToggleMessage(String message) { | |
592 this.toggleMessage = message; | |
593 | |
594 if ((toggleButton !is null) && (!toggleButton.isDisposed())) { | |
595 String text; | |
596 if (toggleMessage is null) { | |
597 text = JFaceResources | |
598 .getString("MessageDialogWithToggle.defaultToggleMessage"); //$NON-NLS-1$ | |
599 } else { | |
600 text = toggleMessage; | |
601 } | |
602 toggleButton.setText(text); | |
603 } | |
604 } | |
605 | |
606 /** | |
607 * A mutator for the state of the toggle button. This method will update the | |
608 * button, if it exists. | |
609 * | |
610 * @param toggleState | |
611 * The desired state of the toggle button (<code>true</code> | |
612 * means the toggle should be selected). | |
613 */ | |
614 public void setToggleState(bool toggleState) { | |
615 this.toggleState = toggleState; | |
616 | |
617 // Update the button, if it exists. | |
618 if ((toggleButton !is null) && (!toggleButton.isDisposed())) { | |
619 toggleButton.setSelection(toggleState); | |
620 } | |
621 } | |
622 | |
623 /** | |
624 * Attempt to find a standard JFace button id that matches the specified button | |
625 * label. If no match can be found, use the default id provided. | |
626 * | |
627 * @param buttonLabel the button label whose id is sought | |
628 * @param defaultId the id to use for the button if there is no standard id | |
629 * @return the id for the specified button label | |
630 */ | |
631 private int mapButtonLabelToButtonID(String buttonLabel, int defaultId) { | |
632 // Not pretty but does the job... | |
633 if (IDialogConstants.OK_LABEL.equals(buttonLabel)) { | |
634 return IDialogConstants.OK_ID; | |
635 } | |
636 | |
637 if (IDialogConstants.YES_LABEL.equals(buttonLabel)) { | |
638 return IDialogConstants.YES_ID; | |
639 } | |
640 | |
641 if (IDialogConstants.NO_LABEL.equals(buttonLabel)) { | |
642 return IDialogConstants.NO_ID; | |
643 } | |
644 | |
645 if (IDialogConstants.CANCEL_LABEL.equals(buttonLabel)) { | |
646 return IDialogConstants.CANCEL_ID; | |
647 } | |
648 | |
649 if (IDialogConstants.YES_TO_ALL_LABEL.equals(buttonLabel)) { | |
650 return IDialogConstants.YES_TO_ALL_ID; | |
651 } | |
652 | |
653 if (IDialogConstants.SKIP_LABEL.equals(buttonLabel)) { | |
654 return IDialogConstants.SKIP_ID; | |
655 } | |
656 | |
657 if (IDialogConstants.STOP_LABEL.equals(buttonLabel)) { | |
658 return IDialogConstants.STOP_ID; | |
659 } | |
660 | |
661 if (IDialogConstants.ABORT_LABEL.equals(buttonLabel)) { | |
662 return IDialogConstants.ABORT_ID; | |
663 } | |
664 | |
665 if (IDialogConstants.RETRY_LABEL.equals(buttonLabel)) { | |
666 return IDialogConstants.RETRY_ID; | |
667 } | |
668 | |
669 if (IDialogConstants.IGNORE_LABEL.equals(buttonLabel)) { | |
670 return IDialogConstants.IGNORE_ID; | |
671 } | |
672 | |
673 if (IDialogConstants.PROCEED_LABEL.equals(buttonLabel)) { | |
674 return IDialogConstants.PROCEED_ID; | |
675 } | |
676 | |
677 if (IDialogConstants.OPEN_LABEL.equals(buttonLabel)) { | |
678 return IDialogConstants.OPEN_ID; | |
679 } | |
680 | |
681 if (IDialogConstants.CLOSE_LABEL.equals(buttonLabel)) { | |
682 return IDialogConstants.CLOSE_ID; | |
683 } | |
684 | |
685 if (IDialogConstants.BACK_LABEL.equals(buttonLabel)) { | |
686 return IDialogConstants.BACK_ID; | |
687 } | |
688 | |
689 if (IDialogConstants.NEXT_LABEL.equals(buttonLabel)) { | |
690 return IDialogConstants.NEXT_ID; | |
691 } | |
692 | |
693 if (IDialogConstants.FINISH_LABEL.equals(buttonLabel)) { | |
694 return IDialogConstants.FINISH_ID; | |
695 } | |
696 | |
697 if (IDialogConstants.HELP_LABEL.equals(buttonLabel)) { | |
698 return IDialogConstants.HELP_ID; | |
699 } | |
700 | |
701 if (IDialogConstants.NO_TO_ALL_LABEL.equals(buttonLabel)) { | |
702 return IDialogConstants.NO_TO_ALL_ID; | |
703 } | |
704 | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
705 if (IDialogConstants.SHOW_DETAILS_LABEL.equals(buttonLabel)) { |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
706 return IDialogConstants.DETAILS_ID; |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
707 } |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
708 |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
709 if (IDialogConstants.HIDE_DETAILS_LABEL.equals(buttonLabel)) { |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
710 return IDialogConstants.DETAILS_ID; |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
711 } |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
712 |
22 | 713 // No XXX_LABEL in IDialogConstants for these. Unlikely |
714 // they would be used in a message dialog though. | |
715 // public int SELECT_ALL_ID = 18; | |
716 // public int DESELECT_ALL_ID = 19; | |
717 // public int SELECT_TYPES_ID = 20; | |
718 | |
719 return defaultId; | |
720 } | |
721 } |