Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 111669 Details for
Bug 198389
[MessageBox] MessageBox missing
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
JUnit tests added.
patch.txt (text/plain), 32.52 KB, created by
Ivan Furnadjiev
on 2008-09-04 09:53:07 EDT
(
hide
)
Description:
JUnit tests added.
Filename:
MIME Type:
Creator:
Ivan Furnadjiev
Created:
2008-09-04 09:53:07 EDT
Size:
32.52 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.rap.rwt >Index: src/org/eclipse/swt/SWT.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.rap/org.eclipse.rap.rwt/src/org/eclipse/swt/SWT.java,v >retrieving revision 1.32 >diff -u -r1.32 SWT.java >--- src/org/eclipse/swt/SWT.java 1 Sep 2008 22:39:11 -0000 1.32 >+++ src/org/eclipse/swt/SWT.java 4 Sep 2008 13:49:23 -0000 >@@ -1114,34 +1114,101 @@ > /** > * The <code>MessageBox</code> style constant for error icon > * behavior (value is 1). >+ * @since 1.2 > */ > public static final int ICON_ERROR = 1; > > /** > * The <code>MessageBox</code> style constant for information icon > * behavior (value is 1<<1). >+ * @since 1.2 > */ > public static final int ICON_INFORMATION = 1 << 1; > > /** > * The <code>MessageBox</code> style constant for question icon > * behavior (value is 1<<2). >+ * @since 1.2 > */ > public static final int ICON_QUESTION = 1 << 2; > > /** > * The <code>MessageBox</code> style constant for warning icon > * behavior (value is 1<<3). >+ * @since 1.2 > */ > public static final int ICON_WARNING = 1 << 3; > > /** > * The <code>MessageBox</code> style constant for "working" icon > * behavior (value is 1<<4). >+ * @since 1.2 > */ > public static final int ICON_WORKING = 1 << 4; > > /** >+ * The <code>MessageBox</code> style constant for an OK button; >+ * valid combinations are OK, OK|CANCEL >+ * (value is 1<<5). >+ * @since 1.2 >+ */ >+ public static final int OK = 1 << 5; >+ >+ /** >+ * The <code>MessageBox</code> style constant for YES button; >+ * valid combinations are YES|NO, YES|NO|CANCEL >+ * (value is 1<<6). >+ * @since 1.2 >+ */ >+ public static final int YES = 1 << 6; >+ >+ /** >+ * The <code>MessageBox</code> style constant for NO button; >+ * valid combinations are YES|NO, YES|NO|CANCEL >+ * (value is 1<<7). >+ * @since 1.2 >+ */ >+ public static final int NO = 1 << 7; >+ >+ /** >+ * The <code>MessageBox</code> style constant for a CANCEL button; >+ * valid combinations are OK|CANCEL, YES|NO|CANCEL, RETRY|CANCEL >+ * (value is 1<<8). This style constant is also used with >+ * <code>Text</code> in combination with SEARCH. >+ * >+ * <p><b>Used By:</b><ul> >+ * <li><code>MessageBox</code></li> >+ * <li><code>Text</code></li> >+ * </ul></p> >+ * @since 1.2 >+ */ >+ public static final int CANCEL = 1 << 8; >+ >+ /** >+ * The <code>MessageBox</code> style constant for an ABORT button; >+ * the only valid combination is ABORT|RETRY|IGNORE >+ * (value is 1<<9). >+ * @since 1.2 >+ */ >+ public static final int ABORT = 1 << 9; >+ >+ /** >+ * The <code>MessageBox</code> style constant for a RETRY button; >+ * valid combinations are ABORT|RETRY|IGNORE, RETRY|CANCEL >+ * (value is 1<<10). >+ * @since 1.2 >+ */ >+ public static final int RETRY = 1 << 10; >+ >+ /** >+ * The <code>MessageBox</code> style constant for an IGNORE button; >+ * the only valid combination is ABORT|RETRY|IGNORE >+ * (value is 1<<11). >+ * @since 1.2 >+ */ >+ public static final int IGNORE = 1 << 11; >+ >+ /** > * The <code>Composite</code> constant to indicate that > * an attribute (such as background) is not inherited > * by the children (value is 0). >Index: src/org/eclipse/swt/widgets/MessageBox.java >=================================================================== >RCS file: src/org/eclipse/swt/widgets/MessageBox.java >diff -N src/org/eclipse/swt/widgets/MessageBox.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/swt/widgets/MessageBox.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,320 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Innoopract Informationssysteme GmbH. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Innoopract Informationssysteme GmbH - initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.swt.widgets; >+ >+import java.util.StringTokenizer; >+ >+import org.eclipse.rwt.graphics.Graphics; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.SWTException; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.graphics.*; >+import org.eclipse.swt.internal.graphics.TextSizeDetermination; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+ >+/** >+ * Instances of this class are used to inform or warn the user. >+ * <dl> >+ * <dt><b>Styles:</b></dt> >+ * <dd>ICON_ERROR, ICON_INFORMATION, ICON_QUESTION, ICON_WARNING, ICON_WORKING</dd> >+ * <dd>OK, OK | CANCEL</dd> >+ * <dd>YES | NO, YES | NO | CANCEL</dd> >+ * <dd>RETRY | CANCEL</dd> >+ * <dd>ABORT | RETRY | IGNORE</dd> >+ * <dt><b>Events:</b></dt> >+ * <dd>(none)</dd> >+ * </dl> >+ * <p> >+ * Note: Only one of the styles ICON_ERROR, ICON_INFORMATION, ICON_QUESTION, >+ * ICON_WARNING and ICON_WORKING may be specified. >+ * </p><p> >+ * IMPORTANT: This class is intended to be subclassed <em>only</em> >+ * within the SWT implementation. >+ * </p> >+ * @since 1.2 >+ */ >+public class MessageBox extends Dialog { >+ >+ private static final int BUTTON_WIDTH = 61; >+ private static final int HORIZONTAL_DIALOG_UNIT_PER_CHAR = 4; >+ private static final int MAX_WIDTH = 640; >+ >+ private Shell shell; >+ private String message = ""; >+ private int result; >+ >+ /** >+ * Constructs a new instance of this class given only its parent. >+ * >+ * @param parent a shell which will be the parent of the new instance >+ * >+ * @exception IllegalArgumentException <ul> >+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> >+ * </ul> >+ * @exception SWTException <ul> >+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> >+ * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> >+ * </ul> >+ */ >+ public MessageBox( final Shell parent ) { >+ this( parent, SWT.OK | SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL ); >+ } >+ >+ /** >+ * Constructs a new instance of this class given its parent >+ * and a style value describing its behavior and appearance. >+ * <p> >+ * The style value is either one of the style constants defined in >+ * class <code>SWT</code> which is applicable to instances of this >+ * class, or must be built by <em>bitwise OR</em>'ing together >+ * (that is, using the <code>int</code> "|" operator) two or more >+ * of those <code>SWT</code> style constants. The class description >+ * lists the style constants that are applicable to the class. >+ * Style bits are also inherited from superclasses. >+ * >+ * @param parent a shell which will be the parent of the new instance >+ * @param style the style of dialog to construct >+ * >+ * @exception IllegalArgumentException <ul> >+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> >+ * </ul> >+ * @exception SWTException <ul> >+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> >+ * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> >+ * </ul> >+ */ >+ public MessageBox( final Shell parent, final int style ) { >+ super( parent, checkStyle ( style ) ); >+ checkSubclass(); >+ } >+ >+ static int checkStyle( final int style ) { >+ int chkStyle = 0; >+ int mask = ( SWT.YES | SWT.NO >+ | SWT.OK | SWT.CANCEL >+ | SWT.ABORT | SWT.RETRY | SWT.IGNORE ); >+ int bits = style & mask; >+ if( bits == SWT.OK || bits == SWT.CANCEL >+ || bits == ( SWT.OK | SWT.CANCEL ) ) { >+ chkStyle = style; >+ } else if( bits == SWT.YES || bits == SWT.NO >+ || bits == ( SWT.YES | SWT.NO ) >+ || bits == ( SWT.YES | SWT.NO | SWT.CANCEL ) ) { >+ chkStyle = style; >+ } else if( bits == ( SWT.RETRY | SWT.CANCEL ) >+ || bits == ( SWT.ABORT | SWT.RETRY | SWT.IGNORE ) ) { >+ chkStyle = style; >+ } else { >+ chkStyle = ( style & ~mask ) | SWT.OK; >+ } >+ return chkStyle; >+ } >+ >+ /** >+ * Returns the dialog's message, or an empty string if it does not have one. >+ * The message is a description of the purpose for which the dialog was opened. >+ * This message will be visible in the dialog while it is open. >+ * >+ * @return the message >+ */ >+ public String getMessage() { >+ return message; >+ } >+ >+ /** >+ * Sets the dialog's message, which is a description of >+ * the purpose for which it was opened. This message will be >+ * visible on the dialog while it is open. >+ * >+ * @param string the message >+ * >+ * @exception IllegalArgumentException <ul> >+ * <li>ERROR_NULL_ARGUMENT - if the string is null</li> >+ * </ul> >+ */ >+ public void setMessage( final String string ) { >+ if( string == null ) { >+ error( SWT.ERROR_NULL_ARGUMENT ); >+ } >+ message = string; >+ } >+ >+ /** >+ * Makes the dialog visible and brings it to the front >+ * of the display. >+ * >+ * @return the ID of the button that was selected to dismiss the >+ * message box (e.g. SWT.OK, SWT.CANCEL, etc.) >+ * >+ * @exception SWTException <ul> >+ * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li> >+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li> >+ * </ul> >+ */ >+ public int open() { >+ shell = new Shell( parent, SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL ); >+ shell.setText( getText() ); >+ >+ createControls( shell ); >+ >+ Rectangle parentSize = parent.getBounds(); >+ Point prefSize = shell.computeSize( SWT.DEFAULT, SWT.DEFAULT ); >+ if( prefSize.x > MAX_WIDTH ) { >+ prefSize.x = MAX_WIDTH; >+ } >+ shell.setSize( prefSize ); >+ >+ int locationX = ( parentSize.width - prefSize.x ) / 2 + parentSize.x; >+ int locationY = ( parentSize.height - prefSize.y ) / 2 + parentSize.y; >+ shell.setLocation( new Point( locationX, locationY ) ); >+ >+ shell.pack(); >+ shell.open(); >+ >+ Display display = parent.getDisplay(); >+ while( !shell.isDisposed() ) { >+ if( !display.readAndDispatch() ) { >+ display.sleep(); >+ } >+ } >+ >+ return result; >+ } >+ >+ private void createControls( final Composite parent ) { >+ Display display = parent.getDisplay(); >+ Image icon = null; >+ parent.setLayout( new GridLayout( 2, false ) ); >+ >+ // Icon >+ int systemImageID = -1; >+ if( ( style & SWT.ICON_ERROR ) != 0 ) { >+ systemImageID = SWT.ICON_ERROR; >+ } else if( ( style & SWT.ICON_INFORMATION ) != 0 ) { >+ systemImageID = SWT.ICON_INFORMATION; >+ } else if( ( style & SWT.ICON_QUESTION ) != 0 ) { >+ systemImageID = SWT.ICON_QUESTION; >+ } else if( ( style & SWT.ICON_WARNING ) != 0 ) { >+ systemImageID = SWT.ICON_WARNING; >+ } else if( ( style & SWT.ICON_WORKING ) != 0 ) { >+ systemImageID = SWT.ICON_WORKING; >+ } >+ if( systemImageID != -1 ) { >+ icon = display.getSystemImage( systemImageID ); >+ createIcon( parent, icon ); >+ } >+ >+ // Text >+ createText( parent, icon ); >+ >+ // Buttons >+ Composite buttonComp = new Composite( parent, SWT.NONE ); >+ buttonComp.setLayout( new GridLayout( 0, true ) ); >+ GridData buttonData = new GridData( SWT.CENTER, SWT.CENTER, true, false ); >+ buttonData.horizontalSpan = 2; >+ buttonComp.setLayoutData( buttonData ); >+ >+ if( ( style & SWT.YES ) == SWT.YES ) { >+ createButton( buttonComp, SWT.getMessage( "SWT_Yes" ), SWT.YES ); >+ } >+ if( ( style & SWT.NO ) == SWT.NO ) { >+ createButton( buttonComp, SWT.getMessage( "SWT_No" ), SWT.NO ); >+ } >+ if( ( style & SWT.OK ) == SWT.OK ) { >+ createButton( buttonComp, SWT.getMessage( "SWT_OK" ), SWT.OK ); >+ } >+ if( ( style & SWT.ABORT ) == SWT.ABORT ) { >+ createButton( buttonComp, SWT.getMessage( "SWT_Abort" ), SWT.ABORT ); >+ } >+ if( ( style & SWT.RETRY ) == SWT.RETRY ) { >+ createButton( buttonComp, SWT.getMessage( "SWT_Retry" ), SWT.RETRY ); >+ } >+ if( ( style & SWT.CANCEL ) == SWT.CANCEL ) { >+ createButton( buttonComp, SWT.getMessage( "SWT_Cancel" ), SWT.CANCEL ); >+ } >+ if( ( style & SWT.IGNORE ) == SWT.IGNORE ) { >+ createButton( buttonComp, SWT.getMessage( "SWT_Ignore" ), SWT.IGNORE ); >+ } >+ } >+ >+ private void createButton( final Composite parent, >+ final String btnText, >+ final int resCode ) { >+ // Increment the number of columns in the button bar >+ ( ( GridLayout ) parent.getLayout() ).numColumns++; >+ Button btn = new Button( parent, SWT.PUSH ); >+ // Set button layout data >+ GridData data = new GridData( GridData.HORIZONTAL_ALIGN_FILL ); >+ int widthHint = convertHorizontalDLUsToPixels( BUTTON_WIDTH ); >+ Point minSize = btn.computeSize( SWT.DEFAULT, SWT.DEFAULT, true ); >+ data.widthHint = Math.max( widthHint, minSize.x ); >+ btn.setLayoutData( data ); >+ // Set text >+ btn.setText( btnText ); >+ btn.addSelectionListener( new SelectionAdapter() { >+ public void widgetSelected( final SelectionEvent event ) { >+ result = resCode; >+ shell.close(); >+ } >+ } ); >+ } >+ >+ private void createIcon( final Composite parent, final Image icon ) { >+ Label iconLabel = new Label( parent, SWT.CENTER ); >+ // Set label layout data >+ GridData data = new GridData( SWT.CENTER, SWT.TOP, false, false ); >+ data.widthHint = icon.getBounds().width + 20; >+ iconLabel.setLayoutData( data ); >+ // Set image >+ iconLabel.setImage( icon ); >+ } >+ >+ private void createText( final Composite parent, final Image icon ) { >+ Label textLabel = new Label( parent, SWT.WRAP ); >+ String text = getMessage(); >+ Font font = textLabel.getFont(); >+ // Set label layout data >+ GridData data = new GridData( GridData.HORIZONTAL_ALIGN_FILL ); >+ int iconWidth = icon == null ? 0 : icon.getBounds().width; >+ int maxTextWidth = MAX_WIDTH - iconWidth - 20; >+ // Determine the max line length >+ int maxLineWidth = 0; >+ StringTokenizer st = new StringTokenizer( text, "\n" ); >+ while( st.hasMoreTokens() ) { >+ String line = st.nextToken(); >+ int lineWidth = TextSizeDetermination.stringExtent( font, line ).x; >+ maxLineWidth = Math.max( maxLineWidth, lineWidth ); >+ } >+ // Set wrap width >+ if( maxLineWidth > maxTextWidth ){ >+ data.widthHint = maxTextWidth; >+ } >+ textLabel.setLayoutData( data ); >+ textLabel.setText( text ); >+ } >+ >+ /** >+ * Returns the number of pixels corresponding to the given number of >+ * horizontal dialog units. >+ * >+ * @param dlus >+ * the number of horizontal dialog units >+ * @return the number of pixels >+ */ >+ private int convertHorizontalDLUsToPixels( final int dlus ) { >+ Font dialogFont = shell.getFont(); >+ return ( int)( ( Graphics.getAvgCharWidth( dialogFont ) * dlus >+ + HORIZONTAL_DIALOG_UNIT_PER_CHAR / 2 ) >+ / HORIZONTAL_DIALOG_UNIT_PER_CHAR ); >+ } >+} >#P org.eclipse.rap.demo >Index: src/org/eclipse/rap/demo/controls/DialogsTab.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.rap/org.eclipse.rap.demo/src/org/eclipse/rap/demo/controls/DialogsTab.java,v >retrieving revision 1.16 >diff -u -r1.16 DialogsTab.java >--- src/org/eclipse/rap/demo/controls/DialogsTab.java 19 Aug 2008 16:47:02 -0000 1.16 >+++ src/org/eclipse/rap/demo/controls/DialogsTab.java 4 Sep 2008 13:49:27 -0000 >@@ -17,8 +17,7 @@ > import org.eclipse.jface.dialogs.Dialog; > import org.eclipse.swt.SWT; > import org.eclipse.swt.custom.CTabFolder; >-import org.eclipse.swt.events.SelectionAdapter; >-import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.*; > import org.eclipse.swt.layout.GridData; > import org.eclipse.swt.layout.GridLayout; > import org.eclipse.swt.widgets.*; >@@ -30,12 +29,25 @@ > private Label loginDlgResLabel; > private Label messageDlgResLabel; > private Label errorDlgResLabel; >+ private Label messageBoxDlgResLabel; >+ >+ private Button okButton, cancelButton; >+ private Button yesButton, noButton; >+ private Button retryButton; >+ private Button abortButton, ignoreButton; >+ private Button iconErrorButton, iconInformationButton, iconQuestionButton; >+ private Button iconWarningButton, iconWorkingButton, noIconButton; >+ >+ private Button showMessageBoxDlgButton; > > public DialogsTab( final CTabFolder topFolder ) { > super( topFolder, "Dialogs" ); > } > > protected void createStyleControls( final Composite parent ) { >+ parent.setLayout( new GridLayout( 1, true ) ); >+ >+ createMessageBoxStyleControls( parent ); > } > > protected void createExampleControls( final Composite parent ) { >@@ -44,7 +56,7 @@ > group1.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); > group1.setText( "JFace Dialogs" ); > group1.setLayout( new GridLayout( 3, true ) ); >- >+ > // JFace input dialog > Button showInputDlgButton = new Button( group1, SWT.PUSH ); > showInputDlgButton.setText( "Input Dialog" ); >@@ -55,13 +67,13 @@ > } ); > showInputDlgButton.setLayoutData( createGridDataFillBoth() ); > insertSpaceLabels( group1, 2 ); >- >+ > inputDlgResLabel = new Label( group1, SWT.WRAP ); > inputDlgResLabel.setText( "Result:" ); > GridData gdInputDlgResLabel = new GridData(); > gdInputDlgResLabel.horizontalSpan = 3; > inputDlgResLabel.setLayoutData( gdInputDlgResLabel ); >- >+ > Button showMessageInfoDlgButton = new Button( group1, SWT.PUSH ); > showMessageInfoDlgButton.setLayoutData( createGridDataFillBoth() ); > showMessageInfoDlgButton.setText( "Info Message" ); >@@ -70,7 +82,7 @@ > showMessageDialogInfo(); > } > } ); >- >+ > Button showMessageWarningDlgButton = new Button( group1, SWT.PUSH ); > showMessageWarningDlgButton.setLayoutData( createGridDataFillBoth() ); > showMessageWarningDlgButton.setText( "Warning Dialog" ); >@@ -87,7 +99,7 @@ > showMessageDialogError(); > } > } ); >- >+ > Button showMessageQuestionDlgButton = new Button( group1, SWT.PUSH ); > showMessageQuestionDlgButton.setLayoutData( createGridDataFillBoth() ); > showMessageQuestionDlgButton.setText( "Question Dialog" ); >@@ -96,7 +108,7 @@ > showMessageDialogQuestion(); > } > } ); >- >+ > Button showMessageConfirmDlgButton = new Button( group1, SWT.PUSH ); > showMessageConfirmDlgButton.setLayoutData( createGridDataFillBoth() ); > showMessageConfirmDlgButton.setText( "Confirm Message" ); >@@ -106,11 +118,11 @@ > } > } ); > insertSpaceLabels( group1, 1 ); >- >+ > messageDlgResLabel = new Label( group1, SWT.WRAP ); > messageDlgResLabel.setText( "Result:" ); > insertSpaceLabels( group1, 2 ); >- >+ > Button showErrorDlgButton = new Button( group1, SWT.PUSH ); > showErrorDlgButton.setLayoutData( createGridDataFillBoth() ); > showErrorDlgButton.setText( "Error Dialog" ); >@@ -124,8 +136,8 @@ > errorDlgResLabel = new Label( group1, SWT.WRAP ); > errorDlgResLabel.setText( "Result:" ); > insertSpaceLabels( group1, 2 ); >- >- >+ >+ > Group group2 = new Group( parent, SWT.NONE ); > group2.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); > group2.setText( "Custom Dialogs" ); >@@ -140,9 +152,28 @@ > } ); > showLoginDlgButton.setLayoutData( createGridDataFillBoth() ); > insertSpaceLabels( group2, 2 ); >- >+ > loginDlgResLabel = new Label( group2, SWT.WRAP ); > loginDlgResLabel.setText( "Result:" ); >+ >+ Group group3 = new Group( parent, SWT.NONE ); >+ group3.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); >+ group3.setText( "SWT Dialogs" ); >+ group3.setLayout( new GridLayout( 3, true ) ); >+ >+ showMessageBoxDlgButton = new Button( group3, SWT.PUSH ); >+ showMessageBoxDlgButton.setText( "MessageBox Dialog" ); >+ showMessageBoxDlgButton.addSelectionListener( new SelectionAdapter() { >+ >+ public void widgetSelected( final SelectionEvent event ) { >+ showMessageBoxDialog(); >+ } >+ } ); >+ showMessageBoxDlgButton.setLayoutData( createGridDataFillBoth() ); >+ insertSpaceLabels( group3, 2 ); >+ >+ messageBoxDlgResLabel = new Label( group3, SWT.WRAP ); >+ messageBoxDlgResLabel.setText( "Result:" ); > } > > private GridData createGridDataFillBoth() { >@@ -157,7 +188,7 @@ > > private void showInputDialog() { > final IInputValidator val = new IInputValidator() { >- public String isValid( String newText ) { >+ public String isValid( final String newText ) { > String result = null; > if( newText.length() < 5 ) { > result = "Input text too short!"; >@@ -265,4 +296,172 @@ > } > return result ; > } >+ >+ private void showMessageBoxDialog() { >+ int style = getStyle(); >+ if( okButton.getEnabled() && okButton.getSelection() ) { >+ style |= SWT.OK; >+ } >+ if( cancelButton.getEnabled() && cancelButton.getSelection() ) { >+ style |= SWT.CANCEL; >+ } >+ if( yesButton.getEnabled() && yesButton.getSelection() ) { >+ style |= SWT.YES; >+ } >+ if( noButton.getEnabled() && noButton.getSelection() ) { >+ style |= SWT.NO; >+ } >+ if( retryButton.getEnabled() && retryButton.getSelection() ) { >+ style |= SWT.RETRY; >+ } >+ if( abortButton.getEnabled() && abortButton.getSelection() ) { >+ style |= SWT.ABORT; >+ } >+ if( ignoreButton.getEnabled() && ignoreButton.getSelection() ) { >+ style |= SWT.IGNORE; >+ } >+ if( iconErrorButton.getEnabled() && iconErrorButton.getSelection() ) { >+ style |= SWT.ICON_ERROR; >+ } >+ if( iconInformationButton.getEnabled() >+ && iconInformationButton.getSelection() ) { >+ style |= SWT.ICON_INFORMATION; >+ } >+ if( iconQuestionButton.getEnabled() && iconQuestionButton.getSelection() ) { >+ style |= SWT.ICON_QUESTION; >+ } >+ if( iconWarningButton.getEnabled() && iconWarningButton.getSelection() ) { >+ style |= SWT.ICON_WARNING; >+ } >+ if( iconWorkingButton.getEnabled() && iconWorkingButton.getSelection() ) { >+ style |= SWT.ICON_WORKING; >+ } >+ >+ String title = "MessageBox Title"; >+ String mesg = "Lorem ipsum dolor sit amet consectetuer adipiscing elit."; >+ MessageBox mb = new MessageBox( getShell(), style ); >+ mb.setText( title ); >+ mb.setMessage( mesg ); >+ int result = mb.open(); >+ String strResult = ""; >+ switch( result ) { >+ case SWT.OK: >+ strResult = "SWT.OK"; >+ break; >+ case SWT.YES: >+ strResult = "SWT.YES"; >+ break; >+ case SWT.NO: >+ strResult = "SWT.NO"; >+ break; >+ case SWT.CANCEL: >+ strResult = "SWT.CANCEL"; >+ break; >+ case SWT.ABORT: >+ strResult = "SWT.ABORT"; >+ break; >+ case SWT.RETRY: >+ strResult = "SWT.RETRY"; >+ break; >+ case SWT.IGNORE: >+ strResult = "SWT.IGNORE"; >+ break; >+ default: >+ strResult = "" + result; >+ break; >+ } >+ messageBoxDlgResLabel.setText( "Result: " + strResult ); >+ messageBoxDlgResLabel.pack(); >+ } >+ >+ private void createMessageBoxStyleControls( final Composite parent ) { >+ Group buttonStyleGroup = new Group( parent, SWT.NONE ); >+ buttonStyleGroup.setLayout( new GridLayout() ); >+ buttonStyleGroup.setLayoutData( new GridData( GridData.HORIZONTAL_ALIGN_FILL >+ | GridData.VERTICAL_ALIGN_FILL ) ); >+ buttonStyleGroup.setText( "SWT MessageBox Styles" ); >+ >+ okButton = new Button( buttonStyleGroup, SWT.CHECK ); >+ okButton.setText( "SWT.OK" ); >+ cancelButton = new Button( buttonStyleGroup, SWT.CHECK ); >+ cancelButton.setText( "SWT.CANCEL" ); >+ yesButton = new Button( buttonStyleGroup, SWT.CHECK ); >+ yesButton.setText( "SWT.YES" ); >+ noButton = new Button( buttonStyleGroup, SWT.CHECK ); >+ noButton.setText( "SWT.NO" ); >+ retryButton = new Button( buttonStyleGroup, SWT.CHECK ); >+ retryButton.setText( "SWT.RETRY" ); >+ abortButton = new Button( buttonStyleGroup, SWT.CHECK ); >+ abortButton.setText( "SWT.ABORT" ); >+ ignoreButton = new Button( buttonStyleGroup, SWT.CHECK ); >+ ignoreButton.setText( "SWT.IGNORE" ); >+ >+ Group iconStyleGroup = new Group( parent, SWT.NONE ); >+ iconStyleGroup.setLayout( new GridLayout() ); >+ iconStyleGroup.setLayoutData( new GridData( GridData.HORIZONTAL_ALIGN_FILL >+ | GridData.VERTICAL_ALIGN_FILL ) ); >+ iconStyleGroup.setText( "SWT MessageBox Icon Styles" ); >+ >+ iconErrorButton = new Button( iconStyleGroup, SWT.RADIO ); >+ iconErrorButton.setText( "SWT.ICON_ERROR" ); >+ iconInformationButton = new Button( iconStyleGroup, SWT.RADIO ); >+ iconInformationButton.setText( "SWT.ICON_INFORMATION" ); >+ iconQuestionButton = new Button( iconStyleGroup, SWT.RADIO ); >+ iconQuestionButton.setText( "SWT.ICON_QUESTION" ); >+ iconWarningButton = new Button( iconStyleGroup, SWT.RADIO ); >+ iconWarningButton.setText( "SWT.ICON_WARNING" ); >+ iconWorkingButton = new Button( iconStyleGroup, SWT.RADIO ); >+ iconWorkingButton.setText( "SWT.ICON_WORKING" ); >+ noIconButton = new Button( iconStyleGroup, SWT.RADIO ); >+ noIconButton.setText( "No Icon" ); >+ >+ SelectionListener buttonStyleListener = new SelectionAdapter() { >+ >+ public void widgetSelected( final SelectionEvent event ) { >+ buttonStyleSelected( event ); >+ } >+ }; >+ >+ okButton.addSelectionListener( buttonStyleListener ); >+ cancelButton.addSelectionListener( buttonStyleListener ); >+ yesButton.addSelectionListener( buttonStyleListener ); >+ noButton.addSelectionListener( buttonStyleListener ); >+ retryButton.addSelectionListener( buttonStyleListener ); >+ abortButton.addSelectionListener( buttonStyleListener ); >+ ignoreButton.addSelectionListener( buttonStyleListener ); >+ >+ noIconButton.setSelection( true ); >+ } >+ >+ private void buttonStyleSelected( final SelectionEvent event ) { >+ boolean ok = okButton.getSelection(); >+ boolean cancel = cancelButton.getSelection(); >+ boolean yes = yesButton.getSelection(); >+ boolean no = noButton.getSelection(); >+ boolean abort = abortButton.getSelection(); >+ boolean retry = retryButton.getSelection(); >+ boolean ignore = ignoreButton.getSelection(); >+ >+ okButton.setEnabled( !( yes || no || retry || abort || ignore ) ); >+ cancelButton.setEnabled( !( abort || ignore || ( yes != no ) ) ); >+ yesButton.setEnabled( !( ok || retry || abort || ignore || ( cancel && !yes && !no ) ) ); >+ noButton.setEnabled( !( ok || retry || abort || ignore || ( cancel && !yes && !no ) ) ); >+ retryButton.setEnabled( !( ok || yes || no ) ); >+ abortButton.setEnabled( !( ok || cancel || yes || no ) ); >+ ignoreButton.setEnabled( !( ok || cancel || yes || no ) ); >+ >+ showMessageBoxDlgButton.setEnabled( !( ok >+ || cancel >+ || yes >+ || no >+ || retry >+ || abort || ignore ) >+ || ok >+ || ( ok && cancel ) >+ || ( yes && no ) >+ || ( yes && no && cancel ) >+ || ( retry && cancel ) >+ || ( abort && retry && ignore ) ); >+ >+ } > } >#P org.eclipse.rap.rwt.test >Index: src/org/eclipse/swt/widgets/MessageBox_Test.java >=================================================================== >RCS file: src/org/eclipse/swt/widgets/MessageBox_Test.java >diff -N src/org/eclipse/swt/widgets/MessageBox_Test.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/swt/widgets/MessageBox_Test.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,100 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Innoopract Informationssysteme GmbH. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Innoopract Informationssysteme GmbH - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.swt.widgets; >+ >+import junit.framework.TestCase; >+ >+import org.eclipse.swt.RWTFixture; >+import org.eclipse.swt.SWT; >+ >+public class MessageBox_Test extends TestCase { >+ >+ protected void setUp() throws Exception { >+ RWTFixture.setUp(); >+ } >+ >+ protected void tearDown() throws Exception { >+ RWTFixture.tearDown(); >+ } >+ >+ public void testMessage() { >+ Display display = new Display(); >+ Shell shell = new Shell( display , SWT.NONE ); >+ String mesg = "Lorem ipsum dolor sit amet consectetuer adipiscing elit."; >+ MessageBox mb = new MessageBox( shell, SWT.NONE ); >+ mb.setMessage( mesg ); >+ assertEquals( mesg, mb.getMessage() ); >+ } >+ >+ public void testText() { >+ Display display = new Display(); >+ Shell shell = new Shell( display , SWT.NONE ); >+ String title = "MessageBox Title"; >+ MessageBox mb = new MessageBox( shell, SWT.NONE ); >+ mb.setText( title ); >+ assertEquals( title, mb.getText() ); >+ } >+ >+ public void testStyle() { >+ Display display = new Display(); >+ Shell shell = new Shell( display , SWT.NONE ); >+ // Test SWT.NONE >+ MessageBox mb = new MessageBox( shell, SWT.NONE ); >+ assertTrue( ( mb.getStyle() & SWT.OK ) != 0 ); >+ >+ // Test SWT.OK | SWT.CANCEL >+ mb = new MessageBox( shell, SWT.OK | SWT.CANCEL ); >+ assertTrue( ( mb.getStyle() & SWT.OK ) != 0 ); >+ assertTrue( ( mb.getStyle() & SWT.CANCEL ) != 0 ); >+ mb = new MessageBox( shell, SWT.OK | SWT.CANCEL | SWT.YES ); >+ assertTrue( ( mb.getStyle() & SWT.OK ) != 0 ); >+ assertTrue( ( mb.getStyle() & SWT.CANCEL ) == 0 ); >+ assertTrue( ( mb.getStyle() & SWT.YES ) == 0 ); >+ >+ // Test SWT.YES | SWT.NO | SWT.CANCEL >+ mb = new MessageBox( shell, SWT.YES ); >+ assertTrue( ( mb.getStyle() & SWT.YES ) != 0 ); >+ mb = new MessageBox( shell, SWT.NO ); >+ assertTrue( ( mb.getStyle() & SWT.NO ) != 0 ); >+ mb = new MessageBox( shell, SWT.YES | SWT.NO ); >+ assertTrue( ( mb.getStyle() & SWT.YES ) != 0 ); >+ assertTrue( ( mb.getStyle() & SWT.NO ) != 0 ); >+ mb = new MessageBox( shell, SWT.YES | SWT.NO | SWT.CANCEL ); >+ assertTrue( ( mb.getStyle() & SWT.YES ) != 0 ); >+ assertTrue( ( mb.getStyle() & SWT.NO ) != 0 ); >+ assertTrue( ( mb.getStyle() & SWT.CANCEL ) != 0 ); >+ mb = new MessageBox( shell, SWT.YES | SWT.CANCEL ); >+ assertTrue( ( mb.getStyle() & SWT.OK ) != 0 ); >+ assertTrue( ( mb.getStyle() & SWT.YES ) == 0 ); >+ assertTrue( ( mb.getStyle() & SWT.NO ) == 0 ); >+ assertTrue( ( mb.getStyle() & SWT.CANCEL ) == 0 ); >+ mb = new MessageBox( shell, SWT.NO | SWT.CANCEL ); >+ assertTrue( ( mb.getStyle() & SWT.OK ) != 0 ); >+ assertTrue( ( mb.getStyle() & SWT.YES ) == 0 ); >+ assertTrue( ( mb.getStyle() & SWT.NO ) == 0 ); >+ assertTrue( ( mb.getStyle() & SWT.CANCEL ) == 0 ); >+ >+ // Test SWT.ABORT | SWT.RETRY | SWT.IGNORE >+ mb = new MessageBox( shell, SWT.ABORT | SWT.RETRY | SWT.IGNORE ); >+ assertTrue( ( mb.getStyle() & SWT.ABORT ) != 0 ); >+ assertTrue( ( mb.getStyle() & SWT.RETRY ) != 0 ); >+ assertTrue( ( mb.getStyle() & SWT.IGNORE ) != 0 ); >+ mb = new MessageBox( shell, SWT.CANCEL | SWT.RETRY ); >+ assertTrue( ( mb.getStyle() & SWT.CANCEL ) != 0 ); >+ assertTrue( ( mb.getStyle() & SWT.RETRY ) != 0 ); >+ mb = new MessageBox( shell, SWT.YES | SWT.RETRY | SWT.IGNORE ); >+ assertTrue( ( mb.getStyle() & SWT.OK ) != 0 ); >+ assertTrue( ( mb.getStyle() & SWT.YES ) == 0 ); >+ assertTrue( ( mb.getStyle() & SWT.RETRY ) == 0 ); >+ assertTrue( ( mb.getStyle() & SWT.IGNORE ) == 0 ); >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 198389
:
110081
| 111669