summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorRüdiger Herrmann2012-12-10 09:26:01 (EST)
committer Paul Webster2012-12-10 09:26:01 (EST)
commit7147bbedd962edf38b8e43ff47bd45c4412b2fe3 (patch)
tree92f1e666bb840cb3b3b5f95d8ded01252688c0cd
parent27d838d28e86ab5d79d20d7eeda638e258666d70 (diff)
downloadeclipse.platform.ui-7147bbedd962edf38b8e43ff47bd45c4412b2fe3.zip
eclipse.platform.ui-7147bbedd962edf38b8e43ff47bd45c4412b2fe3.tar.gz
eclipse.platform.ui-7147bbedd962edf38b8e43ff47bd45c4412b2fe3.tar.bz2
Bug 395426 - [JFace] StatusDialog should escape ampersand in status
message
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/StatusDialog.java4
-rw-r--r--tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/dialogs/AllTests.java1
-rwxr-xr-xtests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/dialogs/StatusDialogTest.java77
3 files changed, 81 insertions, 1 deletions
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/StatusDialog.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/StatusDialog.java
index 7c7f436..32c08db 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/StatusDialog.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/StatusDialog.java
@@ -7,11 +7,13 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Rüdiger Herrmann - 395426: [JFace] StatusDialog should escape ampersand in status message
*******************************************************************************/
package org.eclipse.jface.dialogs;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.LegacyActionTools;
import org.eclipse.jface.resource.JFaceColors;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.util.Policy;
@@ -107,7 +109,7 @@ public abstract class StatusDialog extends TrayDialog {
if (status != null && !status.isOK()) {
String message = status.getMessage();
if (message != null && message.length() > 0) {
- setText(message);
+ setText(LegacyActionTools.escapeMnemonics(message));
// unqualified call of setImage is too ambiguous for
// Foundation 1.0 compiler
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=140576
diff --git a/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/dialogs/AllTests.java b/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/dialogs/AllTests.java
index 2e74b55..11a6e47 100644
--- a/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/dialogs/AllTests.java
+++ b/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/dialogs/AllTests.java
@@ -25,6 +25,7 @@ public class AllTests extends TestSuite {
public AllTests() {
addTestSuite(DialogTest.class);
+ addTestSuite(StatusDialogTest.class);
addTestSuite(DialogSettingsTest.class);
addTestSuite(InputDialogTest.class);
addTestSuite(TitleAreaDialogTest.class);
diff --git a/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/dialogs/StatusDialogTest.java b/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/dialogs/StatusDialogTest.java
new file mode 100755
index 0000000..f7d5261
--- /dev/null
+++ b/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/dialogs/StatusDialogTest.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Rüdiger Herrmann 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Rüdiger Herrmann - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jface.tests.dialogs;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.StatusDialog;
+import org.eclipse.swt.custom.CLabel;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+public class StatusDialogTest extends TestCase {
+
+ private static final String PLUGIN_ID = "org.eclipse.ui.tests";
+
+ private Shell shell;
+
+ public void testEscapeAmpesandInStatusLabelBug395426() {
+ TestableStatusDialog dialog = new TestableStatusDialog(shell);
+ dialog.open();
+ dialog.updateStatus(new Status(IStatus.ERROR, PLUGIN_ID, "&"));
+ CLabel statusLabel = findStatusLabel(dialog.getShell());
+ assertEquals( "&&", statusLabel.getText());
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ shell = new Shell();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ shell.dispose();
+ }
+
+ private CLabel findStatusLabel(Composite parent) {
+ CLabel result = null;
+ Control[] children = parent.getChildren();
+ for (int i = 0; i < children.length; i++) {
+ if (children[i] instanceof CLabel) {
+ result = (CLabel) children[i];
+ }
+ }
+ if (result == null) {
+ for (int i = 0; i < children.length; i++) {
+ if (children[i] instanceof Composite) {
+ result = findStatusLabel((Composite) children[i]);
+ }
+ }
+ }
+ return result;
+ }
+
+ public class TestableStatusDialog extends StatusDialog {
+
+ public TestableStatusDialog(Shell parent) {
+ super(parent);
+ setBlockOnOpen(false);
+ }
+
+ @Override
+ protected void updateStatus(IStatus status) {
+ super.updateStatus(status);
+ }
+ }
+}