Mercurial > projects > dwt-addons
annotate dwtx/jface/dialogs/MessageDialogWithToggle.d @ 70:46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 22 May 2008 01:36:46 +0200 |
parents | ea8ff534f622 |
children | c3583c6ec027 |
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; | |
420 } | |
421 } | |
422 } | |
423 | |
424 /** | |
425 * @see Dialog#createButtonBar(Composite) | |
426 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
427 protected override void createButtonsForButtonBar(Composite parent) { |
22 | 428 String[] buttonLabels = getButtonLabels(); |
429 Button[] buttons = new Button[buttonLabels.length]; | |
430 int defaultButtonIndex = getDefaultButtonIndex(); | |
431 | |
432 int suggestedId = IDialogConstants.INTERNAL_ID; | |
433 for (int i = 0; i < buttonLabels.length; i++) { | |
434 String label = buttonLabels[i]; | |
435 // get the JFace button ID that matches the label, or use the specified | |
436 // id if there is no match. | |
437 int id = mapButtonLabelToButtonID(label, suggestedId); | |
438 | |
439 // if the suggested id was used, increment the default for next use | |
440 if (id is suggestedId) { | |
441 suggestedId++; | |
442 } | |
443 | |
444 Button button = createButton(parent, id, label, | |
445 defaultButtonIndex is i); | |
446 buttons[i] = button; | |
447 | |
448 } | |
449 setButtons(buttons); | |
450 } | |
451 | |
452 /** | |
453 * @see Dialog#createDialogArea(Composite) | |
454 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
455 protected override Control createDialogArea(Composite parent) { |
22 | 456 Composite dialogAreaComposite = cast(Composite) super |
457 .createDialogArea(parent); | |
458 setToggleButton(createToggleButton(dialogAreaComposite)); | |
459 return dialogAreaComposite; | |
460 } | |
461 | |
462 /** | |
463 * Creates a toggle button without any text or state. The text and state | |
464 * will be created by <code>createDialogArea</code>. | |
465 * | |
466 * @param parent | |
467 * The composite in which the toggle button should be placed; | |
468 * must not be <code>null</code>. | |
469 * @return The added toggle button; never <code>null</code>. | |
470 */ | |
471 protected Button createToggleButton(Composite parent) { | |
472 Button button = new Button(parent, DWT.CHECK | DWT.LEFT); | |
473 | |
474 GridData data = new GridData(DWT.NONE); | |
475 data.horizontalSpan = 2; | |
476 button.setLayoutData(data); | |
477 button.setFont(parent.getFont()); | |
478 | |
39 | 479 button.addSelectionListener(new class(button) SelectionAdapter { |
22 | 480 Button button_; |
39 | 481 this(Button b){ button_=b; } |
22 | 482 public void widgetSelected(SelectionEvent e) { |
483 toggleState = button_.getSelection(); | |
484 } | |
485 | |
486 }); | |
487 | |
488 return button; | |
489 } | |
490 | |
491 /** | |
492 * Returns the toggle button. | |
493 * | |
494 * @return the toggle button | |
495 */ | |
496 protected Button getToggleButton() { | |
497 return toggleButton; | |
498 } | |
499 | |
500 /** | |
501 * An accessor for the current preference store for this dialog. | |
502 * | |
503 * @return The preference store; this value may be <code>null</code> if no | |
504 * preference is being used. | |
505 */ | |
506 public IPreferenceStore getPrefStore() { | |
507 return prefStore; | |
508 } | |
509 | |
510 /** | |
511 * An accessor for the current key of the toggle preference. | |
512 * | |
513 * @return The preference key; this value may be <code>null</code> if no | |
514 * preference is being used. | |
515 */ | |
516 public String getPrefKey() { | |
517 return prefKey; | |
518 } | |
519 | |
520 /** | |
521 * Returns the toggle state. This can be called even after the dialog is | |
522 * closed. | |
523 * | |
524 * @return <code>true</code> if the toggle button is checked, | |
525 * <code>false</code> if not | |
526 */ | |
527 public bool getToggleState() { | |
528 return toggleState; | |
529 } | |
530 | |
531 /** | |
532 * A mutator for the key of the preference to be modified by the toggle | |
533 * button. | |
534 * | |
535 * @param prefKey | |
536 * The prefKey to set. If this value is <code>null</code>, | |
537 * then no preference will be modified. | |
538 */ | |
539 public void setPrefKey(String prefKey) { | |
540 this.prefKey = prefKey; | |
541 } | |
542 | |
543 /** | |
544 * A mutator for the preference store to be modified by the toggle button. | |
545 * | |
546 * @param prefStore | |
547 * The prefStore to set. If this value is <code>null</code>, | |
548 * then no preference will be modified. | |
549 */ | |
550 public void setPrefStore(IPreferenceStore prefStore) { | |
551 this.prefStore = prefStore; | |
552 } | |
553 | |
554 /** | |
555 * A mutator for the button providing the toggle option. If the button | |
556 * exists, then it will automatically get the text set to the current toggle | |
557 * message, and its selection state set to the current selection state. | |
558 * | |
559 * @param button | |
560 * The button to use; must not be <code>null</code>. | |
561 */ | |
562 protected void setToggleButton(Button button) { | |
563 if (button is null) { | |
564 throw new NullPointerException( | |
565 "A message dialog with toggle may not have a null toggle button.");} //$NON-NLS-1$ | |
566 | |
567 if (!button.isDisposed()) { | |
568 String text; | |
569 if (toggleMessage is null) { | |
570 text = JFaceResources | |
571 .getString("MessageDialogWithToggle.defaultToggleMessage"); //$NON-NLS-1$ | |
572 } else { | |
573 text = toggleMessage; | |
574 } | |
575 button.setText(text); | |
576 button.setSelection(toggleState); | |
577 } | |
578 | |
579 this.toggleButton = button; | |
580 } | |
581 | |
582 /** | |
583 * A mutator for the text on the toggle button. The button will | |
584 * automatically get updated with the new text, if it exists. | |
585 * | |
586 * @param message | |
587 * The new text of the toggle button; if it is <code>null</code>, | |
588 * then used the default toggle message. | |
589 */ | |
590 protected void setToggleMessage(String message) { | |
591 this.toggleMessage = message; | |
592 | |
593 if ((toggleButton !is null) && (!toggleButton.isDisposed())) { | |
594 String text; | |
595 if (toggleMessage is null) { | |
596 text = JFaceResources | |
597 .getString("MessageDialogWithToggle.defaultToggleMessage"); //$NON-NLS-1$ | |
598 } else { | |
599 text = toggleMessage; | |
600 } | |
601 toggleButton.setText(text); | |
602 } | |
603 } | |
604 | |
605 /** | |
606 * A mutator for the state of the toggle button. This method will update the | |
607 * button, if it exists. | |
608 * | |
609 * @param toggleState | |
610 * The desired state of the toggle button (<code>true</code> | |
611 * means the toggle should be selected). | |
612 */ | |
613 public void setToggleState(bool toggleState) { | |
614 this.toggleState = toggleState; | |
615 | |
616 // Update the button, if it exists. | |
617 if ((toggleButton !is null) && (!toggleButton.isDisposed())) { | |
618 toggleButton.setSelection(toggleState); | |
619 } | |
620 } | |
621 | |
622 /** | |
623 * Attempt to find a standard JFace button id that matches the specified button | |
624 * label. If no match can be found, use the default id provided. | |
625 * | |
626 * @param buttonLabel the button label whose id is sought | |
627 * @param defaultId the id to use for the button if there is no standard id | |
628 * @return the id for the specified button label | |
629 */ | |
630 private int mapButtonLabelToButtonID(String buttonLabel, int defaultId) { | |
631 // Not pretty but does the job... | |
632 if (IDialogConstants.OK_LABEL.equals(buttonLabel)) { | |
633 return IDialogConstants.OK_ID; | |
634 } | |
635 | |
636 if (IDialogConstants.YES_LABEL.equals(buttonLabel)) { | |
637 return IDialogConstants.YES_ID; | |
638 } | |
639 | |
640 if (IDialogConstants.NO_LABEL.equals(buttonLabel)) { | |
641 return IDialogConstants.NO_ID; | |
642 } | |
643 | |
644 if (IDialogConstants.CANCEL_LABEL.equals(buttonLabel)) { | |
645 return IDialogConstants.CANCEL_ID; | |
646 } | |
647 | |
648 if (IDialogConstants.YES_TO_ALL_LABEL.equals(buttonLabel)) { | |
649 return IDialogConstants.YES_TO_ALL_ID; | |
650 } | |
651 | |
652 if (IDialogConstants.SKIP_LABEL.equals(buttonLabel)) { | |
653 return IDialogConstants.SKIP_ID; | |
654 } | |
655 | |
656 if (IDialogConstants.STOP_LABEL.equals(buttonLabel)) { | |
657 return IDialogConstants.STOP_ID; | |
658 } | |
659 | |
660 if (IDialogConstants.ABORT_LABEL.equals(buttonLabel)) { | |
661 return IDialogConstants.ABORT_ID; | |
662 } | |
663 | |
664 if (IDialogConstants.RETRY_LABEL.equals(buttonLabel)) { | |
665 return IDialogConstants.RETRY_ID; | |
666 } | |
667 | |
668 if (IDialogConstants.IGNORE_LABEL.equals(buttonLabel)) { | |
669 return IDialogConstants.IGNORE_ID; | |
670 } | |
671 | |
672 if (IDialogConstants.PROCEED_LABEL.equals(buttonLabel)) { | |
673 return IDialogConstants.PROCEED_ID; | |
674 } | |
675 | |
676 if (IDialogConstants.OPEN_LABEL.equals(buttonLabel)) { | |
677 return IDialogConstants.OPEN_ID; | |
678 } | |
679 | |
680 if (IDialogConstants.CLOSE_LABEL.equals(buttonLabel)) { | |
681 return IDialogConstants.CLOSE_ID; | |
682 } | |
683 | |
684 if (IDialogConstants.BACK_LABEL.equals(buttonLabel)) { | |
685 return IDialogConstants.BACK_ID; | |
686 } | |
687 | |
688 if (IDialogConstants.NEXT_LABEL.equals(buttonLabel)) { | |
689 return IDialogConstants.NEXT_ID; | |
690 } | |
691 | |
692 if (IDialogConstants.FINISH_LABEL.equals(buttonLabel)) { | |
693 return IDialogConstants.FINISH_ID; | |
694 } | |
695 | |
696 if (IDialogConstants.HELP_LABEL.equals(buttonLabel)) { | |
697 return IDialogConstants.HELP_ID; | |
698 } | |
699 | |
700 if (IDialogConstants.NO_TO_ALL_LABEL.equals(buttonLabel)) { | |
701 return IDialogConstants.NO_TO_ALL_ID; | |
702 } | |
703 | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
704 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
|
705 return IDialogConstants.DETAILS_ID; |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
706 } |
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 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
|
709 return IDialogConstants.DETAILS_ID; |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
710 } |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
711 |
22 | 712 // No XXX_LABEL in IDialogConstants for these. Unlikely |
713 // they would be used in a message dialog though. | |
714 // public int SELECT_ALL_ID = 18; | |
715 // public int DESELECT_ALL_ID = 19; | |
716 // public int SELECT_TYPES_ID = 20; | |
717 | |
718 return defaultId; | |
719 } | |
720 } |