Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Webster2013-02-06 18:13:32 +0000
committerPaul Webster2013-02-06 18:13:32 +0000
commit05f26c2cbba44a20fc68af98fe25be755732c0ff (patch)
treed24986c1a10c8636b2adfff9b2cb2dc16b4907ad
parentc4c9477eccf52509c329373352e67cbabaa71477 (diff)
downloadeclipse.platform.ui-05f26c2cbba44a20fc68af98fe25be755732c0ff.tar.gz
eclipse.platform.ui-05f26c2cbba44a20fc68af98fe25be755732c0ff.tar.xz
eclipse.platform.ui-05f26c2cbba44a20fc68af98fe25be755732c0ff.zip
Bug 92518 - [Dialogs] Removing sections from DialogSettings
Add the ability to remove the section by name.
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/DialogSettings.java24
-rw-r--r--tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/dialogs/DialogSettingsTest.java29
2 files changed, 47 insertions, 6 deletions
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/DialogSettings.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/DialogSettings.java
index da55f28153e..381ab94165a 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/DialogSettings.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/DialogSettings.java
@@ -129,14 +129,30 @@ public class DialogSettings implements IDialogSettings {
}
/**
- * Remove a section in the receiver. If the given section does not exist, nothing is done.
+ * Remove a section in the receiver. If the given section does not exist,
+ * nothing is done.
*
* @param section
- * the section to be removed
- * @since 3.9
+ * the section to be removed. Must not be <code>null</code>.
+ * @since 3.9
*/
public void removeSection(IDialogSettings section) {
- sections.remove(section.getName());
+ if (sections.get(section.getName()) == section) {
+ sections.remove(section.getName());
+ }
+ }
+
+ /**
+ * Remove a section by name in the receiver. If the given section does not
+ * exist, nothing is done.
+ *
+ * @param sectionName
+ * the name of the section to be removed. Must not be <code>null</code>.
+ * @return The dialog section removed, or <code>null</code> if it wasn't there.
+ * @since 3.9
+ */
+ public IDialogSettings removeSection(String sectionName) {
+ return (IDialogSettings) sections.remove(sectionName);
}
/* (non-Javadoc)
diff --git a/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/dialogs/DialogSettingsTest.java b/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/dialogs/DialogSettingsTest.java
index 2f893e5da32..da0a04d0425 100644
--- a/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/dialogs/DialogSettingsTest.java
+++ b/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/dialogs/DialogSettingsTest.java
@@ -155,26 +155,51 @@ public class DialogSettingsTest extends TestCase {
public void testRemoveSection() {
DialogSettings dialogSettings = new DialogSettings(null);
IDialogSettings section = dialogSettings.addNewSection("new-section");
+ assertEquals(1, dialogSettings.getSections().length);
dialogSettings.removeSection(section);
assertEquals(0, dialogSettings.getSections().length);
}
+ public void testRemoveSectionByName() {
+ DialogSettings dialogSettings = new DialogSettings(null);
+ IDialogSettings section = dialogSettings.addNewSection("new-section");
+ assertEquals(1, dialogSettings.getSections().length);
+
+ final IDialogSettings removedSection = dialogSettings.removeSection("new-section");
+
+ assertEquals(0, dialogSettings.getSections().length);
+ assertEquals(section, removedSection);
+ }
+
public void testRemoveNonExistingSection() {
DialogSettings dialogSettings = new DialogSettings(null);
+ dialogSettings.addNewSection("new-section");
+ assertEquals(1, dialogSettings.getSections().length);
IDialogSettings otherSection = new DialogSettings(null);
dialogSettings.removeSection(otherSection);
- assertEquals(0, dialogSettings.getSections().length);
+ assertEquals(1, dialogSettings.getSections().length);
+ }
+
+ public void testRemoveOtherSection() {
+ DialogSettings dialogSettings = new DialogSettings(null);
+ dialogSettings.addNewSection("new-section");
+ assertEquals(1, dialogSettings.getSections().length);
+ IDialogSettings otherSection = new DialogSettings("new-section");
+
+ dialogSettings.removeSection(otherSection);
+
+ assertEquals(1, dialogSettings.getSections().length);
}
public void testRemoveSectionWithNullArgument() {
DialogSettings dialogSettings = new DialogSettings(null);
try {
- dialogSettings.removeSection(null);
+ dialogSettings.removeSection((IDialogSettings)null);
} catch (NullPointerException expected) {
}
}

Back to the top