diff options
4 files changed, 60 insertions, 2 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IMemento.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IMemento.java index 7ea81fa33e9..5618b86ec4b 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IMemento.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IMemento.java @@ -99,6 +99,16 @@ public interface IMemento { */ public IMemento getChild(String type); + /** + * Returns all children of this node. + * + * @return an array of children of this node. This will not be + * <code>null</code>. If there are no children, an array of length + * zero will be returned. + * @since 3.8 + */ + public IMemento[] getChildren(); + /** * Returns all children with the given type id. * diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/XMLMemento.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/XMLMemento.java index 25292d5b701..7a138515e13 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/XMLMemento.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/XMLMemento.java @@ -270,6 +270,35 @@ public final class XMLMemento implements IMemento { return null; } + /* + * (non-Javadoc) Method declared in IMemento. + */ + public IMemento[] getChildren() { + + // Get the nodes. + final NodeList nodes = element.getChildNodes(); + int size = nodes.getLength(); + if (size == 0) { + return new IMemento[0]; + } + + // Extract each node with given type. + ArrayList list = new ArrayList(size); + for (int nX = 0; nX < size; nX++) { + final Node node = nodes.item(nX); + if (node instanceof Element) + list.add(node); + } + + // Create a memento for each node. + size = list.size(); + IMemento[] results = new IMemento[size]; + for (int x = 0; x < size; x++) { + results[x] = new XMLMemento(factory, (Element) list.get(x)); + } + return results; + } + /* (non-Javadoc) * Method declared in IMemento. */ diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/util/ConfigurationElementMemento.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/util/ConfigurationElementMemento.java index 35a6865bb52..9aa4bd0cfdc 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/util/ConfigurationElementMemento.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/util/ConfigurationElementMemento.java @@ -46,11 +46,21 @@ public final class ConfigurationElementMemento implements IMemento { return null; } + public IMemento[] getChildren() { + IConfigurationElement[] configurationElements = configurationElement.getChildren(); + + return getMementoArray(configurationElements); + } + public IMemento[] getChildren(String type) { IConfigurationElement[] configurationElements = configurationElement .getChildren(type); - if (configurationElements != null && configurationElements.length >= 1) { + return getMementoArray(configurationElements); + } + + private IMemento[] getMementoArray(IConfigurationElement[] configurationElements) { + if (configurationElements != null && configurationElements.length > 0) { IMemento mementos[] = new ConfigurationElementMemento[configurationElements.length]; for (int i = 0; i < configurationElements.length; i++) { @@ -62,7 +72,7 @@ public final class ConfigurationElementMemento implements IMemento { } return new IMemento[0]; - } + } public Float getFloat(String key) { String string = configurationElement.getAttribute(key); diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/TestMemento.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/TestMemento.java index 56bc8231668..93db7fabb20 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/TestMemento.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/TestMemento.java @@ -57,6 +57,15 @@ public class TestMemento implements IMemento { return null; } + /* (non-Javadoc) + * @see org.eclipse.ui.IMemento#getChildren() + */ + public IMemento[] getChildren() { + IMemento[] returnValue = new IMemento[children.size()]; + children.toArray(returnValue); + return returnValue; + } + public IMemento[] getChildren(String type) { Iterator iterator = children.iterator(); Collection matches = new HashSet(); |
