|
Lines 17-24
Link Here
|
| 17 |
import org.eclipse.jface.dialogs.Dialog; |
17 |
import org.eclipse.jface.dialogs.Dialog; |
| 18 |
import org.eclipse.swt.SWT; |
18 |
import org.eclipse.swt.SWT; |
| 19 |
import org.eclipse.swt.custom.CTabFolder; |
19 |
import org.eclipse.swt.custom.CTabFolder; |
| 20 |
import org.eclipse.swt.events.SelectionAdapter; |
20 |
import org.eclipse.swt.events.*; |
| 21 |
import org.eclipse.swt.events.SelectionEvent; |
|
|
| 22 |
import org.eclipse.swt.layout.GridData; |
21 |
import org.eclipse.swt.layout.GridData; |
| 23 |
import org.eclipse.swt.layout.GridLayout; |
22 |
import org.eclipse.swt.layout.GridLayout; |
| 24 |
import org.eclipse.swt.widgets.*; |
23 |
import org.eclipse.swt.widgets.*; |
|
Lines 30-41
Link Here
|
| 30 |
private Label loginDlgResLabel; |
29 |
private Label loginDlgResLabel; |
| 31 |
private Label messageDlgResLabel; |
30 |
private Label messageDlgResLabel; |
| 32 |
private Label errorDlgResLabel; |
31 |
private Label errorDlgResLabel; |
|
|
32 |
private Label messageBoxDlgResLabel; |
| 33 |
|
| 34 |
private Button okButton, cancelButton; |
| 35 |
private Button yesButton, noButton; |
| 36 |
private Button retryButton; |
| 37 |
private Button abortButton, ignoreButton; |
| 38 |
private Button iconErrorButton, iconInformationButton, iconQuestionButton; |
| 39 |
private Button iconWarningButton, iconWorkingButton, noIconButton; |
| 40 |
|
| 41 |
private Button showMessageBoxDlgButton; |
| 33 |
|
42 |
|
| 34 |
public DialogsTab( final CTabFolder topFolder ) { |
43 |
public DialogsTab( final CTabFolder topFolder ) { |
| 35 |
super( topFolder, "Dialogs" ); |
44 |
super( topFolder, "Dialogs" ); |
| 36 |
} |
45 |
} |
| 37 |
|
46 |
|
| 38 |
protected void createStyleControls( final Composite parent ) { |
47 |
protected void createStyleControls( final Composite parent ) { |
|
|
48 |
parent.setLayout( new GridLayout( 1, true ) ); |
| 49 |
|
| 50 |
createMessageBoxStyleControls( parent ); |
| 39 |
} |
51 |
} |
| 40 |
|
52 |
|
| 41 |
protected void createExampleControls( final Composite parent ) { |
53 |
protected void createExampleControls( final Composite parent ) { |
|
Lines 44-50
Link Here
|
| 44 |
group1.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); |
56 |
group1.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); |
| 45 |
group1.setText( "JFace Dialogs" ); |
57 |
group1.setText( "JFace Dialogs" ); |
| 46 |
group1.setLayout( new GridLayout( 3, true ) ); |
58 |
group1.setLayout( new GridLayout( 3, true ) ); |
| 47 |
|
59 |
|
| 48 |
// JFace input dialog |
60 |
// JFace input dialog |
| 49 |
Button showInputDlgButton = new Button( group1, SWT.PUSH ); |
61 |
Button showInputDlgButton = new Button( group1, SWT.PUSH ); |
| 50 |
showInputDlgButton.setText( "Input Dialog" ); |
62 |
showInputDlgButton.setText( "Input Dialog" ); |
|
Lines 55-67
Link Here
|
| 55 |
} ); |
67 |
} ); |
| 56 |
showInputDlgButton.setLayoutData( createGridDataFillBoth() ); |
68 |
showInputDlgButton.setLayoutData( createGridDataFillBoth() ); |
| 57 |
insertSpaceLabels( group1, 2 ); |
69 |
insertSpaceLabels( group1, 2 ); |
| 58 |
|
70 |
|
| 59 |
inputDlgResLabel = new Label( group1, SWT.WRAP ); |
71 |
inputDlgResLabel = new Label( group1, SWT.WRAP ); |
| 60 |
inputDlgResLabel.setText( "Result:" ); |
72 |
inputDlgResLabel.setText( "Result:" ); |
| 61 |
GridData gdInputDlgResLabel = new GridData(); |
73 |
GridData gdInputDlgResLabel = new GridData(); |
| 62 |
gdInputDlgResLabel.horizontalSpan = 3; |
74 |
gdInputDlgResLabel.horizontalSpan = 3; |
| 63 |
inputDlgResLabel.setLayoutData( gdInputDlgResLabel ); |
75 |
inputDlgResLabel.setLayoutData( gdInputDlgResLabel ); |
| 64 |
|
76 |
|
| 65 |
Button showMessageInfoDlgButton = new Button( group1, SWT.PUSH ); |
77 |
Button showMessageInfoDlgButton = new Button( group1, SWT.PUSH ); |
| 66 |
showMessageInfoDlgButton.setLayoutData( createGridDataFillBoth() ); |
78 |
showMessageInfoDlgButton.setLayoutData( createGridDataFillBoth() ); |
| 67 |
showMessageInfoDlgButton.setText( "Info Message" ); |
79 |
showMessageInfoDlgButton.setText( "Info Message" ); |
|
Lines 70-76
Link Here
|
| 70 |
showMessageDialogInfo(); |
82 |
showMessageDialogInfo(); |
| 71 |
} |
83 |
} |
| 72 |
} ); |
84 |
} ); |
| 73 |
|
85 |
|
| 74 |
Button showMessageWarningDlgButton = new Button( group1, SWT.PUSH ); |
86 |
Button showMessageWarningDlgButton = new Button( group1, SWT.PUSH ); |
| 75 |
showMessageWarningDlgButton.setLayoutData( createGridDataFillBoth() ); |
87 |
showMessageWarningDlgButton.setLayoutData( createGridDataFillBoth() ); |
| 76 |
showMessageWarningDlgButton.setText( "Warning Dialog" ); |
88 |
showMessageWarningDlgButton.setText( "Warning Dialog" ); |
|
Lines 87-93
Link Here
|
| 87 |
showMessageDialogError(); |
99 |
showMessageDialogError(); |
| 88 |
} |
100 |
} |
| 89 |
} ); |
101 |
} ); |
| 90 |
|
102 |
|
| 91 |
Button showMessageQuestionDlgButton = new Button( group1, SWT.PUSH ); |
103 |
Button showMessageQuestionDlgButton = new Button( group1, SWT.PUSH ); |
| 92 |
showMessageQuestionDlgButton.setLayoutData( createGridDataFillBoth() ); |
104 |
showMessageQuestionDlgButton.setLayoutData( createGridDataFillBoth() ); |
| 93 |
showMessageQuestionDlgButton.setText( "Question Dialog" ); |
105 |
showMessageQuestionDlgButton.setText( "Question Dialog" ); |
|
Lines 96-102
Link Here
|
| 96 |
showMessageDialogQuestion(); |
108 |
showMessageDialogQuestion(); |
| 97 |
} |
109 |
} |
| 98 |
} ); |
110 |
} ); |
| 99 |
|
111 |
|
| 100 |
Button showMessageConfirmDlgButton = new Button( group1, SWT.PUSH ); |
112 |
Button showMessageConfirmDlgButton = new Button( group1, SWT.PUSH ); |
| 101 |
showMessageConfirmDlgButton.setLayoutData( createGridDataFillBoth() ); |
113 |
showMessageConfirmDlgButton.setLayoutData( createGridDataFillBoth() ); |
| 102 |
showMessageConfirmDlgButton.setText( "Confirm Message" ); |
114 |
showMessageConfirmDlgButton.setText( "Confirm Message" ); |
|
Lines 106-116
Link Here
|
| 106 |
} |
118 |
} |
| 107 |
} ); |
119 |
} ); |
| 108 |
insertSpaceLabels( group1, 1 ); |
120 |
insertSpaceLabels( group1, 1 ); |
| 109 |
|
121 |
|
| 110 |
messageDlgResLabel = new Label( group1, SWT.WRAP ); |
122 |
messageDlgResLabel = new Label( group1, SWT.WRAP ); |
| 111 |
messageDlgResLabel.setText( "Result:" ); |
123 |
messageDlgResLabel.setText( "Result:" ); |
| 112 |
insertSpaceLabels( group1, 2 ); |
124 |
insertSpaceLabels( group1, 2 ); |
| 113 |
|
125 |
|
| 114 |
Button showErrorDlgButton = new Button( group1, SWT.PUSH ); |
126 |
Button showErrorDlgButton = new Button( group1, SWT.PUSH ); |
| 115 |
showErrorDlgButton.setLayoutData( createGridDataFillBoth() ); |
127 |
showErrorDlgButton.setLayoutData( createGridDataFillBoth() ); |
| 116 |
showErrorDlgButton.setText( "Error Dialog" ); |
128 |
showErrorDlgButton.setText( "Error Dialog" ); |
|
Lines 124-131
Link Here
|
| 124 |
errorDlgResLabel = new Label( group1, SWT.WRAP ); |
136 |
errorDlgResLabel = new Label( group1, SWT.WRAP ); |
| 125 |
errorDlgResLabel.setText( "Result:" ); |
137 |
errorDlgResLabel.setText( "Result:" ); |
| 126 |
insertSpaceLabels( group1, 2 ); |
138 |
insertSpaceLabels( group1, 2 ); |
| 127 |
|
139 |
|
| 128 |
|
140 |
|
| 129 |
Group group2 = new Group( parent, SWT.NONE ); |
141 |
Group group2 = new Group( parent, SWT.NONE ); |
| 130 |
group2.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); |
142 |
group2.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); |
| 131 |
group2.setText( "Custom Dialogs" ); |
143 |
group2.setText( "Custom Dialogs" ); |
|
Lines 140-148
Link Here
|
| 140 |
} ); |
152 |
} ); |
| 141 |
showLoginDlgButton.setLayoutData( createGridDataFillBoth() ); |
153 |
showLoginDlgButton.setLayoutData( createGridDataFillBoth() ); |
| 142 |
insertSpaceLabels( group2, 2 ); |
154 |
insertSpaceLabels( group2, 2 ); |
| 143 |
|
155 |
|
| 144 |
loginDlgResLabel = new Label( group2, SWT.WRAP ); |
156 |
loginDlgResLabel = new Label( group2, SWT.WRAP ); |
| 145 |
loginDlgResLabel.setText( "Result:" ); |
157 |
loginDlgResLabel.setText( "Result:" ); |
|
|
158 |
|
| 159 |
Group group3 = new Group( parent, SWT.NONE ); |
| 160 |
group3.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); |
| 161 |
group3.setText( "SWT Dialogs" ); |
| 162 |
group3.setLayout( new GridLayout( 3, true ) ); |
| 163 |
|
| 164 |
showMessageBoxDlgButton = new Button( group3, SWT.PUSH ); |
| 165 |
showMessageBoxDlgButton.setText( "MessageBox Dialog" ); |
| 166 |
showMessageBoxDlgButton.addSelectionListener( new SelectionAdapter() { |
| 167 |
|
| 168 |
public void widgetSelected( final SelectionEvent event ) { |
| 169 |
showMessageBoxDialog(); |
| 170 |
} |
| 171 |
} ); |
| 172 |
showMessageBoxDlgButton.setLayoutData( createGridDataFillBoth() ); |
| 173 |
insertSpaceLabels( group3, 2 ); |
| 174 |
|
| 175 |
messageBoxDlgResLabel = new Label( group3, SWT.WRAP ); |
| 176 |
messageBoxDlgResLabel.setText( "Result:" ); |
| 146 |
} |
177 |
} |
| 147 |
|
178 |
|
| 148 |
private GridData createGridDataFillBoth() { |
179 |
private GridData createGridDataFillBoth() { |
|
Lines 157-163
Link Here
|
| 157 |
|
188 |
|
| 158 |
private void showInputDialog() { |
189 |
private void showInputDialog() { |
| 159 |
final IInputValidator val = new IInputValidator() { |
190 |
final IInputValidator val = new IInputValidator() { |
| 160 |
public String isValid( String newText ) { |
191 |
public String isValid( final String newText ) { |
| 161 |
String result = null; |
192 |
String result = null; |
| 162 |
if( newText.length() < 5 ) { |
193 |
if( newText.length() < 5 ) { |
| 163 |
result = "Input text too short!"; |
194 |
result = "Input text too short!"; |
|
Lines 265-268
Link Here
|
| 265 |
} |
296 |
} |
| 266 |
return result ; |
297 |
return result ; |
| 267 |
} |
298 |
} |
|
|
299 |
|
| 300 |
private void showMessageBoxDialog() { |
| 301 |
int style = getStyle(); |
| 302 |
if( okButton.getEnabled() && okButton.getSelection() ) { |
| 303 |
style |= SWT.OK; |
| 304 |
} |
| 305 |
if( cancelButton.getEnabled() && cancelButton.getSelection() ) { |
| 306 |
style |= SWT.CANCEL; |
| 307 |
} |
| 308 |
if( yesButton.getEnabled() && yesButton.getSelection() ) { |
| 309 |
style |= SWT.YES; |
| 310 |
} |
| 311 |
if( noButton.getEnabled() && noButton.getSelection() ) { |
| 312 |
style |= SWT.NO; |
| 313 |
} |
| 314 |
if( retryButton.getEnabled() && retryButton.getSelection() ) { |
| 315 |
style |= SWT.RETRY; |
| 316 |
} |
| 317 |
if( abortButton.getEnabled() && abortButton.getSelection() ) { |
| 318 |
style |= SWT.ABORT; |
| 319 |
} |
| 320 |
if( ignoreButton.getEnabled() && ignoreButton.getSelection() ) { |
| 321 |
style |= SWT.IGNORE; |
| 322 |
} |
| 323 |
if( iconErrorButton.getEnabled() && iconErrorButton.getSelection() ) { |
| 324 |
style |= SWT.ICON_ERROR; |
| 325 |
} |
| 326 |
if( iconInformationButton.getEnabled() |
| 327 |
&& iconInformationButton.getSelection() ) { |
| 328 |
style |= SWT.ICON_INFORMATION; |
| 329 |
} |
| 330 |
if( iconQuestionButton.getEnabled() && iconQuestionButton.getSelection() ) { |
| 331 |
style |= SWT.ICON_QUESTION; |
| 332 |
} |
| 333 |
if( iconWarningButton.getEnabled() && iconWarningButton.getSelection() ) { |
| 334 |
style |= SWT.ICON_WARNING; |
| 335 |
} |
| 336 |
if( iconWorkingButton.getEnabled() && iconWorkingButton.getSelection() ) { |
| 337 |
style |= SWT.ICON_WORKING; |
| 338 |
} |
| 339 |
|
| 340 |
String title = "MessageBox Title"; |
| 341 |
String mesg = "Lorem ipsum dolor sit amet consectetuer adipiscing elit."; |
| 342 |
MessageBox mb = new MessageBox( getShell(), style ); |
| 343 |
mb.setText( title ); |
| 344 |
mb.setMessage( mesg ); |
| 345 |
int result = mb.open(); |
| 346 |
String strResult = ""; |
| 347 |
switch( result ) { |
| 348 |
case SWT.OK: |
| 349 |
strResult = "SWT.OK"; |
| 350 |
break; |
| 351 |
case SWT.YES: |
| 352 |
strResult = "SWT.YES"; |
| 353 |
break; |
| 354 |
case SWT.NO: |
| 355 |
strResult = "SWT.NO"; |
| 356 |
break; |
| 357 |
case SWT.CANCEL: |
| 358 |
strResult = "SWT.CANCEL"; |
| 359 |
break; |
| 360 |
case SWT.ABORT: |
| 361 |
strResult = "SWT.ABORT"; |
| 362 |
break; |
| 363 |
case SWT.RETRY: |
| 364 |
strResult = "SWT.RETRY"; |
| 365 |
break; |
| 366 |
case SWT.IGNORE: |
| 367 |
strResult = "SWT.IGNORE"; |
| 368 |
break; |
| 369 |
default: |
| 370 |
strResult = "" + result; |
| 371 |
break; |
| 372 |
} |
| 373 |
messageBoxDlgResLabel.setText( "Result: " + strResult ); |
| 374 |
messageBoxDlgResLabel.pack(); |
| 375 |
} |
| 376 |
|
| 377 |
private void createMessageBoxStyleControls( final Composite parent ) { |
| 378 |
Group buttonStyleGroup = new Group( parent, SWT.NONE ); |
| 379 |
buttonStyleGroup.setLayout( new GridLayout() ); |
| 380 |
buttonStyleGroup.setLayoutData( new GridData( GridData.HORIZONTAL_ALIGN_FILL |
| 381 |
| GridData.VERTICAL_ALIGN_FILL ) ); |
| 382 |
buttonStyleGroup.setText( "SWT MessageBox Styles" ); |
| 383 |
|
| 384 |
okButton = new Button( buttonStyleGroup, SWT.CHECK ); |
| 385 |
okButton.setText( "SWT.OK" ); |
| 386 |
cancelButton = new Button( buttonStyleGroup, SWT.CHECK ); |
| 387 |
cancelButton.setText( "SWT.CANCEL" ); |
| 388 |
yesButton = new Button( buttonStyleGroup, SWT.CHECK ); |
| 389 |
yesButton.setText( "SWT.YES" ); |
| 390 |
noButton = new Button( buttonStyleGroup, SWT.CHECK ); |
| 391 |
noButton.setText( "SWT.NO" ); |
| 392 |
retryButton = new Button( buttonStyleGroup, SWT.CHECK ); |
| 393 |
retryButton.setText( "SWT.RETRY" ); |
| 394 |
abortButton = new Button( buttonStyleGroup, SWT.CHECK ); |
| 395 |
abortButton.setText( "SWT.ABORT" ); |
| 396 |
ignoreButton = new Button( buttonStyleGroup, SWT.CHECK ); |
| 397 |
ignoreButton.setText( "SWT.IGNORE" ); |
| 398 |
|
| 399 |
Group iconStyleGroup = new Group( parent, SWT.NONE ); |
| 400 |
iconStyleGroup.setLayout( new GridLayout() ); |
| 401 |
iconStyleGroup.setLayoutData( new GridData( GridData.HORIZONTAL_ALIGN_FILL |
| 402 |
| GridData.VERTICAL_ALIGN_FILL ) ); |
| 403 |
iconStyleGroup.setText( "SWT MessageBox Icon Styles" ); |
| 404 |
|
| 405 |
iconErrorButton = new Button( iconStyleGroup, SWT.RADIO ); |
| 406 |
iconErrorButton.setText( "SWT.ICON_ERROR" ); |
| 407 |
iconInformationButton = new Button( iconStyleGroup, SWT.RADIO ); |
| 408 |
iconInformationButton.setText( "SWT.ICON_INFORMATION" ); |
| 409 |
iconQuestionButton = new Button( iconStyleGroup, SWT.RADIO ); |
| 410 |
iconQuestionButton.setText( "SWT.ICON_QUESTION" ); |
| 411 |
iconWarningButton = new Button( iconStyleGroup, SWT.RADIO ); |
| 412 |
iconWarningButton.setText( "SWT.ICON_WARNING" ); |
| 413 |
iconWorkingButton = new Button( iconStyleGroup, SWT.RADIO ); |
| 414 |
iconWorkingButton.setText( "SWT.ICON_WORKING" ); |
| 415 |
noIconButton = new Button( iconStyleGroup, SWT.RADIO ); |
| 416 |
noIconButton.setText( "No Icon" ); |
| 417 |
|
| 418 |
SelectionListener buttonStyleListener = new SelectionAdapter() { |
| 419 |
|
| 420 |
public void widgetSelected( final SelectionEvent event ) { |
| 421 |
buttonStyleSelected( event ); |
| 422 |
} |
| 423 |
}; |
| 424 |
|
| 425 |
okButton.addSelectionListener( buttonStyleListener ); |
| 426 |
cancelButton.addSelectionListener( buttonStyleListener ); |
| 427 |
yesButton.addSelectionListener( buttonStyleListener ); |
| 428 |
noButton.addSelectionListener( buttonStyleListener ); |
| 429 |
retryButton.addSelectionListener( buttonStyleListener ); |
| 430 |
abortButton.addSelectionListener( buttonStyleListener ); |
| 431 |
ignoreButton.addSelectionListener( buttonStyleListener ); |
| 432 |
|
| 433 |
noIconButton.setSelection( true ); |
| 434 |
} |
| 435 |
|
| 436 |
private void buttonStyleSelected( final SelectionEvent event ) { |
| 437 |
boolean ok = okButton.getSelection(); |
| 438 |
boolean cancel = cancelButton.getSelection(); |
| 439 |
boolean yes = yesButton.getSelection(); |
| 440 |
boolean no = noButton.getSelection(); |
| 441 |
boolean abort = abortButton.getSelection(); |
| 442 |
boolean retry = retryButton.getSelection(); |
| 443 |
boolean ignore = ignoreButton.getSelection(); |
| 444 |
|
| 445 |
okButton.setEnabled( !( yes || no || retry || abort || ignore ) ); |
| 446 |
cancelButton.setEnabled( !( abort || ignore || ( yes != no ) ) ); |
| 447 |
yesButton.setEnabled( !( ok || retry || abort || ignore || ( cancel && !yes && !no ) ) ); |
| 448 |
noButton.setEnabled( !( ok || retry || abort || ignore || ( cancel && !yes && !no ) ) ); |
| 449 |
retryButton.setEnabled( !( ok || yes || no ) ); |
| 450 |
abortButton.setEnabled( !( ok || cancel || yes || no ) ); |
| 451 |
ignoreButton.setEnabled( !( ok || cancel || yes || no ) ); |
| 452 |
|
| 453 |
showMessageBoxDlgButton.setEnabled( !( ok |
| 454 |
|| cancel |
| 455 |
|| yes |
| 456 |
|| no |
| 457 |
|| retry |
| 458 |
|| abort || ignore ) |
| 459 |
|| ok |
| 460 |
|| ( ok && cancel ) |
| 461 |
|| ( yes && no ) |
| 462 |
|| ( yes && no && cancel ) |
| 463 |
|| ( retry && cancel ) |
| 464 |
|| ( abort && retry && ignore ) ); |
| 465 |
|
| 466 |
} |
| 268 |
} |
467 |
} |