diff options
5 files changed, 133 insertions, 18 deletions
diff --git a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/AllOtherCheatSheetTests.java b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/AllOtherCheatSheetTests.java index 895a86f62..da03fd191 100644 --- a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/AllOtherCheatSheetTests.java +++ b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/AllOtherCheatSheetTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. + * Copyright (c) 2006, 2008 IBM Corporation 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 @@ -26,6 +26,7 @@ public class AllOtherCheatSheetTests { suite.addTestSuite(TestStatePersistence.class); suite.addTestSuite(TestEscape.class); suite.addTestSuite(TestCheatSheetManager.class); + suite.addTestSuite(TestCheatSheetCollection.class); //$JUnit-END$ return suite; } diff --git a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetCollection.java b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetCollection.java new file mode 100644 index 000000000..6eba26d22 --- /dev/null +++ b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetCollection.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.ua.tests.cheatsheet.other; + +import junit.framework.TestCase; + +import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetCollectionElement; +import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement; + +public class TestCheatSheetCollection extends TestCase { + + private CheatSheetCollectionElement root; + private CheatSheetElement csA; + private CheatSheetElement csB; + private CheatSheetElement cs12A; + private CheatSheetElement cs2A; + private CheatSheetCollectionElement c1; + private CheatSheetCollectionElement c2; + private CheatSheetCollectionElement c11; + private CheatSheetCollectionElement c12; + + protected void setUp() throws Exception { + root = new CheatSheetCollectionElement("rootPlugin", "rootId", "rootName", root); + csA = new CheatSheetElement("A"); + csA.setID("idA"); + csB = new CheatSheetElement("B"); + csB.setID("idB"); + cs12A = new CheatSheetElement("12A"); + cs12A.setID("id12A"); + cs2A = new CheatSheetElement("2A"); + cs2A.setID("id2A"); + c1 = new CheatSheetCollectionElement("p1", "c1Id", "c1", root); + c2 = new CheatSheetCollectionElement("p2", "c2Id", "c2", root); + c11 = new CheatSheetCollectionElement("p11", "c11Id", "c11", c1); + c12 = new CheatSheetCollectionElement("p12", "c12Id", "c12", c1); + root.add(c1); + root.add(csA); + root.add(csB); + root.add(c2); + c1.add(c11); + c1.add(c12); + c2.add(cs2A); + c12.add(cs12A); + } + + public void testRoot() { + assertEquals(2, root.getChildren().length); + assertEquals(2, root.getCheatSheets().length); + assertFalse(root.isEmpty()); + assertEquals("rootName", root.getLabel(null)); + assertEquals("rootId", root.getId()); + assertEquals("rootPlugin", root.getPluginId()); + } + + public void testTopLevelChildCategories() { + Object[] children = root.getChildren(); + assertEquals(c1, children[0]); + assertEquals(c2, children[1]); + assertEquals(2, c1.getChildren().length); + assertEquals(0, c1.getCheatSheets().length); + assertFalse(c1.isEmpty()); + assertEquals(0, c2.getChildren().length); + assertEquals(1, c2.getCheatSheets().length); + assertFalse(c2.isEmpty()); + } + + public void testTopLevelCheatsheets() { + Object[] cheatsheets = root.getCheatSheets(); + assertEquals(csA, cheatsheets[0]); + assertEquals(csB, cheatsheets[1]); + } + + public void testSecondLevelChildCategories() { + Object[] children = c1.getChildren(); + assertEquals(c11, children[0]); + assertEquals(c12, children[1]); + assertEquals(0, c11.getChildren().length); + assertEquals(0, c11.getCheatSheets().length); + assertTrue(c11.isEmpty()); + assertEquals(0, c12.getChildren().length); + assertEquals(1, c12.getCheatSheets().length); + assertFalse(c12.isEmpty()); + } + + public void testFind() { + assertEquals(csA, root.findCheatSheet("idA", true)); + assertEquals(csA, root.findCheatSheet("idA", false)); + assertNull(root.findCheatSheet("idC", true)); + assertEquals(cs12A, root.findCheatSheet("id12A", true)); + assertNull(root.findCheatSheet("id12A", false)); + } +} diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/dialogs/CheatSheetCategoryBasedSelectionDialog.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/dialogs/CheatSheetCategoryBasedSelectionDialog.java index 77039986b..ea472feee 100644 --- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/dialogs/CheatSheetCategoryBasedSelectionDialog.java +++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/dialogs/CheatSheetCategoryBasedSelectionDialog.java @@ -482,13 +482,16 @@ public class CheatSheetCategoryBasedSelectionDialog extends TrayDialog //extends return new BaseWorkbenchContentProvider() { public Object[] getChildren(Object o) { Object[] cheatsheets; + Object[] subCategories; if (o instanceof CheatSheetCollectionElement) { cheatsheets = ((CheatSheetCollectionElement) o) .getCheatSheets(); + subCategories = ((CheatSheetCollectionElement) o).getChildren(); } else { cheatsheets = new Object[0]; + subCategories = new Object[0]; } - Object[] subCategories = super.getChildren(o); + if (cheatsheets.length == 0) { return subCategories; } else if (subCategories.length == 0) { diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/registry/CheatSheetCollectionElement.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/registry/CheatSheetCollectionElement.java index 926be793c..f3748c5fc 100644 --- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/registry/CheatSheetCollectionElement.java +++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/registry/CheatSheetCollectionElement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. + * Copyright (c) 2002, 2008 IBM Corporation 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 @@ -10,24 +10,28 @@ *******************************************************************************/ package org.eclipse.ui.internal.cheatsheets.registry; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import org.eclipse.core.runtime.*; import org.eclipse.ui.IPluginContribution; import org.eclipse.ui.internal.cheatsheets.ICheatSheetResource; import org.eclipse.ui.model.AdaptableList; import org.eclipse.ui.model.IWorkbenchAdapter; +import org.eclipse.ui.model.WorkbenchAdapter; /** * Instances of this class are a collection of CheatSheetCollectionElements, * thereby facilitating the definition of tree structures composed of * these elements. Instances also store a list of cheatsheets. */ -public class CheatSheetCollectionElement extends AdaptableList implements IPluginContribution { +public class CheatSheetCollectionElement extends WorkbenchAdapter implements IPluginContribution { private String pluginId; private String id; private String name; private CheatSheetCollectionElement parent; private AdaptableList cheatsheets = new AdaptableList(); + private List childCollections = new ArrayList(); /** * Creates a new <code>CheatSheetCollectionElement</code>. Parent can be null. @@ -44,13 +48,12 @@ public class CheatSheetCollectionElement extends AdaptableList implements IPlugi /** * Adds a cheatsheet collection to this collection. */ - public AdaptableList add(IAdaptable a) { + public void add(IAdaptable a) { if (a instanceof CheatSheetElement) { cheatsheets.add(a); } else { - super.add(a); + childCollections.add(a); } - return this; } /** @@ -62,7 +65,7 @@ public class CheatSheetCollectionElement extends AdaptableList implements IPlugi * @return CheatSheetCollectionElement */ public CheatSheetCollectionElement findChildCollection(IPath searchPath) { - Object[] children = getChildren(null); + Object[] children = getChildren(); String searchString = searchPath.segment(0); for (int i = 0; i < children.length; ++i) { CheatSheetCollectionElement currentCategory = (CheatSheetCollectionElement) children[i]; @@ -90,7 +93,7 @@ public class CheatSheetCollectionElement extends AdaptableList implements IPlugi } if (!recursive) return null; - for (Iterator iterator = children.iterator(); iterator.hasNext();) { + for (Iterator iterator = childCollections.iterator(); iterator.hasNext();) { CheatSheetCollectionElement child = (CheatSheetCollectionElement) iterator.next(); CheatSheetElement result = child.findCheatSheet(searchId, true); if (result != null) @@ -153,7 +156,7 @@ public class CheatSheetCollectionElement extends AdaptableList implements IPlugi * Returns true if this element has no children and no cheatsheets. */ public boolean isEmpty() { - return size() == 0 && cheatsheets.size() == 0; + return childCollections.size() == 0 && cheatsheets.size() == 0; } /** @@ -175,7 +178,7 @@ public class CheatSheetCollectionElement extends AdaptableList implements IPlugi */ public String toString() { StringBuffer buf = new StringBuffer("CheatSheetCollection, "); //$NON-NLS-1$ - buf.append(children.size()); + buf.append(childCollections.size()); buf.append(" children, "); //$NON-NLS-1$ buf.append(cheatsheets.size()); buf.append(" cheatsheets"); //$NON-NLS-1$ @@ -189,4 +192,12 @@ public class CheatSheetCollectionElement extends AdaptableList implements IPlugi public String getPluginId() { return pluginId; } + + public Object[] getChildren() { + return childCollections.toArray(); + } + + public void add(CheatSheetCollectionElement newElement) { + childCollections.add(newElement); + } } diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/registry/CheatSheetRegistryReader.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/registry/CheatSheetRegistryReader.java index 2a073d62e..8bea4bfe8 100644 --- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/registry/CheatSheetRegistryReader.java +++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/registry/CheatSheetRegistryReader.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. + * Copyright (c) 2002, 2008 IBM Corporation 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 @@ -20,7 +20,6 @@ import java.util.StringTokenizer; import org.eclipse.core.runtime.*; import org.eclipse.ui.internal.cheatsheets.*; -import org.eclipse.ui.model.AdaptableList; /** * Instances access the registry that is provided at creation time @@ -164,7 +163,7 @@ public class CheatSheetRegistryReader extends RegistryReader implements IRegistr } protected ArrayList cheatsheetItemExtensions; - protected AdaptableList cheatsheets; + protected CheatSheetCollectionElement cheatsheets; private ArrayList deferCategories = null; private ArrayList deferCheatSheets = null; private final String csItemExtension = "cheatSheetItemExtension"; //$NON-NLS-1$ @@ -185,7 +184,7 @@ public class CheatSheetRegistryReader extends RegistryReader implements IRegistr * <code>readCheatSheets</code>. * </p> */ - protected void addNewElementToResult(CheatSheetElement element, IConfigurationElement config, AdaptableList result) { + protected void addNewElementToResult(CheatSheetElement element, IConfigurationElement config, CheatSheetCollectionElement cheatsheets2) { deferCheatSheet(element); } @@ -229,7 +228,7 @@ public class CheatSheetRegistryReader extends RegistryReader implements IRegistr * Creates empty element collection. Overrider to fill * initial elements, if needed. */ - protected AdaptableList createEmptyCheatSheetCollection() { + protected CheatSheetCollectionElement createEmptyCheatSheetCollection() { return new CheatSheetCollectionElement(null, "root", "root", null); //$NON-NLS-1$//$NON-NLS-2$ } @@ -385,7 +384,7 @@ public class CheatSheetRegistryReader extends RegistryReader implements IRegistr * @param extension * @param currentResult CheatSheetCollectionElement */ - private void finishCheatSheet(CheatSheetElement element, IConfigurationElement config, AdaptableList result) { + private void finishCheatSheet(CheatSheetElement element, IConfigurationElement config, CheatSheetCollectionElement result) { CheatSheetCollectionElement currentResult = (CheatSheetCollectionElement) result; StringTokenizer familyTokenizer = new StringTokenizer(getCategoryStringFor(config), CATEGORY_SEPARATOR); @@ -443,7 +442,7 @@ public class CheatSheetRegistryReader extends RegistryReader implements IRegistr * The return value for this method is cached since computing its value * requires non-trivial work. */ - public AdaptableList getCheatSheets() { + public CheatSheetCollectionElement getCheatSheets() { if (cheatsheets == null) readCheatSheets(); return cheatsheets; |