Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/MessageBox.java40
-rw-r--r--examples/org.eclipse.rap.demo.controls/src/org/eclipse/rap/demo/controls/DialogsTab.java34
-rw-r--r--tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/MessageBox_Test.java118
3 files changed, 116 insertions, 76 deletions
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/MessageBox.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/MessageBox.java
index 02a53156ea..37f47fc1ef 100644
--- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/MessageBox.java
+++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/MessageBox.java
@@ -11,9 +11,11 @@
******************************************************************************/
package org.eclipse.swt.widgets;
+import static org.eclipse.rap.rwt.internal.textsize.TextSizeUtil.stringExtent;
+
import java.util.StringTokenizer;
-import org.eclipse.rap.rwt.internal.textsize.TextSizeUtil;
+import org.eclipse.rap.rwt.RWT;
import org.eclipse.rap.rwt.widgets.DialogCallback;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
@@ -56,6 +58,7 @@ public class MessageBox extends Dialog {
private Image image;
private String message;
+ private boolean markupEnabled;
/**
* Constructs a new instance of this class given only its parent.
@@ -71,7 +74,7 @@ public class MessageBox extends Dialog {
* </ul>
*/
public MessageBox( Shell parent ) {
- this( parent, SWT.OK | SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL );
+ this( parent, SWT.OK | SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL );
}
/**
@@ -98,9 +101,9 @@ public class MessageBox extends Dialog {
* </ul>
*/
public MessageBox( Shell parent, int style ) {
- super( parent, checkStyle ( style ) );
- checkSubclass();
- message = "";
+ super( parent, checkStyle ( style ) );
+ checkSubclass();
+ message = "";
}
/**
@@ -111,7 +114,7 @@ public class MessageBox extends Dialog {
* @return the message
*/
public String getMessage() {
- return message;
+ return message;
}
/**
@@ -133,6 +136,20 @@ public class MessageBox extends Dialog {
}
/**
+ * Controls whether the use of <em>markup</em> in message is enabled. Once the markup in message
+ * is enabled it's not possible to disable it.
+ *
+ * @param markupEnabled true to enable the markup in message
+ *
+ * @since 3.2
+ */
+ public void setMarkupEnabled( boolean markupEnabled ) {
+ if( !this.markupEnabled ) {
+ this.markupEnabled = markupEnabled;
+ }
+ }
+
+ /**
* Makes the dialog visible and brings it to the front
* of the display.
*
@@ -209,6 +226,9 @@ public class MessageBox extends Dialog {
private void createText() {
Label textLabel = new Label( shell, SWT.WRAP );
+ if( markupEnabled ) {
+ textLabel.setData( RWT.MARKUP_ENABLED, Boolean.TRUE );
+ }
GridData data = new GridData( GridData.HORIZONTAL_ALIGN_FILL );
int imageWidth = image == null ? 0 : image.getBounds().width;
int maxTextWidth = MAX_WIDTH - imageWidth - SPACING;
@@ -267,12 +287,13 @@ public class MessageBox extends Dialog {
}
private int getMaxMessageLineWidth() {
- Font font = shell.getFont();
int result = 0;
- StringTokenizer tokenizer = new StringTokenizer( message, "\n" );
+ Font font = shell.getFont();
+ String lineSeparator = markupEnabled ? "<br/>" : "\n";
+ StringTokenizer tokenizer = new StringTokenizer( message, lineSeparator );
while( tokenizer.hasMoreTokens() ) {
String line = tokenizer.nextToken();
- int lineWidth = TextSizeUtil.stringExtent( font, line ).x;
+ int lineWidth = stringExtent( font, line, markupEnabled ).x;
result = Math.max( result, lineWidth );
}
return result;
@@ -299,4 +320,5 @@ public class MessageBox extends Dialog {
}
return chkStyle;
}
+
}
diff --git a/examples/org.eclipse.rap.demo.controls/src/org/eclipse/rap/demo/controls/DialogsTab.java b/examples/org.eclipse.rap.demo.controls/src/org/eclipse/rap/demo/controls/DialogsTab.java
index 2064acb81f..125d98c6cd 100644
--- a/examples/org.eclipse.rap.demo.controls/src/org/eclipse/rap/demo/controls/DialogsTab.java
+++ b/examples/org.eclipse.rap.demo.controls/src/org/eclipse/rap/demo/controls/DialogsTab.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2002, 2012 Innoopract Informationssysteme GmbH and others.
+ * Copyright (c) 2002, 2016 Innoopract Informationssysteme GmbH and others.
* 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
@@ -24,7 +24,6 @@ import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.window.Window;
import org.eclipse.rap.rwt.widgets.DialogCallback;
-import org.eclipse.rap.rwt.widgets.DialogUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -64,7 +63,8 @@ public class DialogsTab extends ExampleTab {
private Button showMessageBoxDlgButton;
private Button showColorDialogButton;
private Button showFontDialogButton;
- protected boolean useDialogCallback;
+ private boolean useDialogCallback;
+ private boolean useMarkup;
public DialogsTab() {
super( "Dialogs" );
@@ -208,7 +208,7 @@ public class DialogsTab extends ExampleTab {
final Button cbUseDialogCallback = new Button( swtDialogsGroup, SWT.CHECK );
cbUseDialogCallback.setText( "Use DialogCallback" );
cbUseDialogCallback.setSelection( useDialogCallback );
- cbUseDialogCallback.setLayoutData( new GridData( SWT.LEFT, SWT.CENTER, false, false, 3, 1 ) );
+ cbUseDialogCallback.setLayoutData( new GridData( SWT.LEFT, SWT.CENTER, false, false, 1, 1 ) );
cbUseDialogCallback.addSelectionListener( new SelectionAdapter() {
@Override
public void widgetSelected( SelectionEvent event ) {
@@ -216,6 +216,17 @@ public class DialogsTab extends ExampleTab {
}
} );
+ final Button cbUseMarkup = new Button( swtDialogsGroup, SWT.CHECK );
+ cbUseMarkup.setText( "Use markup" );
+ cbUseMarkup.setSelection( useMarkup );
+ cbUseMarkup.setLayoutData( new GridData( SWT.LEFT, SWT.CENTER, false, false, 2, 1 ) );
+ cbUseMarkup.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected( SelectionEvent event ) {
+ useMarkup = cbUseMarkup.getSelection();
+ }
+ } );
+
showMessageBoxDlgButton = new Button( swtDialogsGroup, SWT.PUSH );
showMessageBoxDlgButton.setText( "MessageBox Dialog" );
showMessageBoxDlgButton.addSelectionListener( new SelectionAdapter() {
@@ -264,6 +275,7 @@ public class DialogsTab extends ExampleTab {
private void showInputDialog() {
final IInputValidator val = new IInputValidator() {
+ @Override
public String isValid( final String newText ) {
String result = null;
if( newText.length() < 5 ) {
@@ -290,6 +302,7 @@ public class DialogsTab extends ExampleTab {
ProgressMonitorDialog dialog = new ProgressMonitorDialog( getShell() );
try {
dialog.run( true, true, new IRunnableWithProgress() {
+ @Override
public void run( final IProgressMonitor monitor )
throws InvocationTargetException, InterruptedException
{
@@ -434,12 +447,14 @@ public class DialogsTab extends ExampleTab {
style |= SWT.ICON_WORKING;
}
String title = "MessageBox Title";
- String mesg = "Lorem ipsum dolor sit amet consectetuer adipiscing elit.";
+ String mesg = "Lorem <b>ipsum</b> dolor sit amet consectetuer adipiscing elit.";
MessageBox mb = new MessageBox( getShell(), style );
+ mb.setMarkupEnabled( useMarkup );
mb.setText( title );
mb.setMessage( mesg );
if( useDialogCallback ) {
- DialogUtil.open( mb, new DialogCallback() {
+ mb.open( new DialogCallback() {
+ @Override
public void dialogClosed( int returnCode ) {
String returnCodeText = returnCodeText( returnCode );
messageBoxDlgResLabel.setText( "Result: " + returnCodeText );
@@ -457,7 +472,8 @@ public class DialogsTab extends ExampleTab {
private void showColorDialog() {
final ColorDialog dialog = new ColorDialog( getShell() );
if( useDialogCallback ) {
- DialogUtil.open( dialog, new DialogCallback() {
+ dialog.open( new DialogCallback() {
+ @Override
public void dialogClosed( int returnCode ) {
RGB result = dialog.getRGB();
messageBoxDlgResLabel.setText( "Result: " + result );
@@ -474,7 +490,8 @@ public class DialogsTab extends ExampleTab {
protected void showFontDialog() {
final FontDialog dialog = new FontDialog( getShell(), SWT.SHELL_TRIM );
if( useDialogCallback ) {
- DialogUtil.open( dialog, new DialogCallback() {
+ dialog.open( new DialogCallback() {
+ @Override
public void dialogClosed( int returnCode ) {
FontData fontData = returnCode == SWT.OK ? dialog.getFontList()[ 0 ] : null;
RGB rgb = dialog.getRGB();
@@ -567,4 +584,5 @@ public class DialogsTab extends ExampleTab {
}
return strResult;
}
+
}
diff --git a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/MessageBox_Test.java b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/MessageBox_Test.java
index 391b8dca01..2bc529b713 100644
--- a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/MessageBox_Test.java
+++ b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/MessageBox_Test.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2014 Innoopract Informationssysteme GmbH.
+ * Copyright (c) 2008, 2016 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
@@ -14,98 +14,98 @@ package org.eclipse.swt.widgets;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import org.eclipse.rap.rwt.testfixture.internal.Fixture;
+import org.eclipse.rap.rwt.testfixture.TestContext;
import org.eclipse.swt.SWT;
-import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
public class MessageBox_Test {
- private Display display;
+ @Rule
+ public TestContext context = new TestContext();
+
private Shell shell;
+ private MessageBox messageBox;
@Before
public void setUp() {
- Fixture.setUp();
- display = new Display();
+ Display display = new Display();
shell = new Shell( display, SWT.NONE );
- }
-
- @After
- public void tearDown() {
- Fixture.tearDown();
+ messageBox = new MessageBox( shell, SWT.NONE );
}
@Test
- public void testMessage() {
+ public void testSetMessage() {
String msg = "Lorem ipsum dolor sit amet consectetuer adipiscing elit.";
- MessageBox messageBox = new MessageBox( shell, SWT.NONE );
+
messageBox.setMessage( msg );
+
assertEquals( msg, messageBox.getMessage() );
}
@Test
- public void testText() {
+ public void testSetText() {
String title = "MessageBox Title";
- MessageBox messageBox = new MessageBox( shell, SWT.NONE );
+
messageBox.setText( title );
+
assertEquals( title, messageBox.getText() );
}
@Test
public void testStyle() {
// Test SWT.NONE
- MessageBox mb = new MessageBox( shell, SWT.NONE );
- assertTrue( ( mb.getStyle() & SWT.OK ) != 0 );
+ assertTrue( ( messageBox.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 );
+ messageBox = new MessageBox( shell, SWT.OK | SWT.CANCEL );
+ assertTrue( ( messageBox.getStyle() & SWT.OK ) != 0 );
+ assertTrue( ( messageBox.getStyle() & SWT.CANCEL ) != 0 );
+ messageBox = new MessageBox( shell, SWT.OK | SWT.CANCEL | SWT.YES );
+ assertTrue( ( messageBox.getStyle() & SWT.OK ) != 0 );
+ assertTrue( ( messageBox.getStyle() & SWT.CANCEL ) == 0 );
+ assertTrue( ( messageBox.getStyle() & SWT.YES ) == 0 );
// Test SWT.YES | SWT.NO | SWT.CANCEL
- mb = new MessageBox( shell, SWT.YES );
- assertTrue( ( mb.getStyle() & SWT.OK ) != 0 );
- assertTrue( ( mb.getStyle() & SWT.YES ) == 0 );
- mb = new MessageBox( shell, SWT.NO );
- assertTrue( ( mb.getStyle() & SWT.OK ) != 0 );
- 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 );
+ messageBox = new MessageBox( shell, SWT.YES );
+ assertTrue( ( messageBox.getStyle() & SWT.OK ) != 0 );
+ assertTrue( ( messageBox.getStyle() & SWT.YES ) == 0 );
+ messageBox = new MessageBox( shell, SWT.NO );
+ assertTrue( ( messageBox.getStyle() & SWT.OK ) != 0 );
+ assertTrue( ( messageBox.getStyle() & SWT.NO ) == 0 );
+ messageBox = new MessageBox( shell, SWT.YES | SWT.NO );
+ assertTrue( ( messageBox.getStyle() & SWT.YES ) != 0 );
+ assertTrue( ( messageBox.getStyle() & SWT.NO ) != 0 );
+ messageBox = new MessageBox( shell, SWT.YES | SWT.NO | SWT.CANCEL );
+ assertTrue( ( messageBox.getStyle() & SWT.YES ) != 0 );
+ assertTrue( ( messageBox.getStyle() & SWT.NO ) != 0 );
+ assertTrue( ( messageBox.getStyle() & SWT.CANCEL ) != 0 );
+ messageBox = new MessageBox( shell, SWT.YES | SWT.CANCEL );
+ assertTrue( ( messageBox.getStyle() & SWT.OK ) != 0 );
+ assertTrue( ( messageBox.getStyle() & SWT.YES ) == 0 );
+ assertTrue( ( messageBox.getStyle() & SWT.NO ) == 0 );
+ assertTrue( ( messageBox.getStyle() & SWT.CANCEL ) == 0 );
+ messageBox = new MessageBox( shell, SWT.NO | SWT.CANCEL );
+ assertTrue( ( messageBox.getStyle() & SWT.OK ) != 0 );
+ assertTrue( ( messageBox.getStyle() & SWT.YES ) == 0 );
+ assertTrue( ( messageBox.getStyle() & SWT.NO ) == 0 );
+ assertTrue( ( messageBox.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 );
+ messageBox = new MessageBox( shell, SWT.ABORT | SWT.RETRY | SWT.IGNORE );
+ assertTrue( ( messageBox.getStyle() & SWT.ABORT ) != 0 );
+ assertTrue( ( messageBox.getStyle() & SWT.RETRY ) != 0 );
+ assertTrue( ( messageBox.getStyle() & SWT.IGNORE ) != 0 );
+ messageBox = new MessageBox( shell, SWT.CANCEL | SWT.RETRY );
+ assertTrue( ( messageBox.getStyle() & SWT.CANCEL ) != 0 );
+ assertTrue( ( messageBox.getStyle() & SWT.RETRY ) != 0 );
+ messageBox = new MessageBox( shell, SWT.YES | SWT.RETRY | SWT.IGNORE );
+ assertTrue( ( messageBox.getStyle() & SWT.OK ) != 0 );
+ assertTrue( ( messageBox.getStyle() & SWT.YES ) == 0 );
+ assertTrue( ( messageBox.getStyle() & SWT.RETRY ) == 0 );
+ assertTrue( ( messageBox.getStyle() & SWT.IGNORE ) == 0 );
}
+
}

Back to the top