From cd4780b72db3a26966e3fe5609fe0bdd01e6c1a3 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Fri, 27 Jul 2012 23:11:23 +0200 Subject: 385908: [api] provide API to delete elements from specific context Currently, the InteractionContextManager only allows to delete elements of a currently active context. This patch extends the API to pass a specific context where elements should be deleted from. Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=385908 Change-Id: I9dcfc39cc12b1f23e2391dd6c58ebd71c3390b59 --- .../context/core/IInteractionContextManager.java | 9 +++++++ .../context/core/InteractionContextManager.java | 27 +++++++++++--------- .../java/tests/InteractionContextManagerTest.java | 29 ++++++++++++++++++++++ 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/context/core/IInteractionContextManager.java b/org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/context/core/IInteractionContextManager.java index 84b4ebabf..de48c9070 100644 --- a/org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/context/core/IInteractionContextManager.java +++ b/org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/context/core/IInteractionContextManager.java @@ -57,6 +57,10 @@ public interface IInteractionContextManager { public abstract void updateHandle(IInteractionElement element, String newHandle); + /** + * @deprecated use {@link #deleteElements(Collection)} + */ + @Deprecated public abstract void deleteElement(IInteractionElement element); /** @@ -64,6 +68,11 @@ public interface IInteractionContextManager { */ public abstract void deleteElements(Collection elements); + /** + * @since 3.9 + */ + public abstract void deleteElements(Collection elements, IInteractionContext context); + public IInteractionElement getActiveElement(); public IInteractionElement processInteractionEvent(InteractionEvent event); diff --git a/org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/internal/context/core/InteractionContextManager.java b/org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/internal/context/core/InteractionContextManager.java index 631138699..3504a03d1 100644 --- a/org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/internal/context/core/InteractionContextManager.java +++ b/org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/internal/context/core/InteractionContextManager.java @@ -479,32 +479,35 @@ public class InteractionContextManager implements IInteractionContextManager { } } + @Deprecated public void deleteElement(IInteractionElement element) { - delete(element, getActiveContext()); - notifyElementsDeleted(getActiveContext(), Arrays.asList(new IInteractionElement[] { element }), false); + deleteElements(Arrays.asList(new IInteractionElement[] { element }), getActiveContext(), false, true); } public void deleteElements(Collection elements) { - deleteElements(elements, false); + deleteElements(elements, getActiveContext(), false, true); + } + + public void deleteElements(Collection elements, IInteractionContext context) { + deleteElements(elements, context, false, true); } public void deleteElements(Collection elements, boolean isExplicitManipulation) { + deleteElements(elements, getActiveContext(), isExplicitManipulation, true); + } + + public void deleteElements(Collection elements, IInteractionContext context, + boolean isExplicitManipulation, boolean notify) { Assert.isNotNull(elements); - IInteractionContext context = getActiveContext(); if (elements.size() == 0 || context == null) { return; } context.delete(elements); - notifyElementsDeleted(getActiveContext(), new ArrayList(elements), isExplicitManipulation); - } - - private void delete(IInteractionElement element, IInteractionContext context) { - if (element == null || context == null) { - return; + if (notify) { + notifyElementsDeleted(context, new ArrayList(elements), isExplicitManipulation); } - context.delete(element); } public void deleteContext(final String handleIdentifier) { @@ -1058,7 +1061,7 @@ public class InteractionContextManager implements IInteractionContextManager { // notifyInterestDelta(interestDelta); } else { //if (changeValue < context.getScaling().getInteresting()) { changedElements.add(element); - delete(element, context); + deleteElements(Arrays.asList(new IInteractionElement[] { element }), context, false, false); } return true; } diff --git a/org.eclipse.mylyn.java.tests/src/org/eclipse/mylyn/java/tests/InteractionContextManagerTest.java b/org.eclipse.mylyn.java.tests/src/org/eclipse/mylyn/java/tests/InteractionContextManagerTest.java index 0f287ecce..f046ba1d2 100644 --- a/org.eclipse.mylyn.java.tests/src/org/eclipse/mylyn/java/tests/InteractionContextManagerTest.java +++ b/org.eclipse.mylyn.java.tests/src/org/eclipse/mylyn/java/tests/InteractionContextManagerTest.java @@ -13,6 +13,7 @@ package org.eclipse.mylyn.java.tests; import java.io.File; import java.io.IOException; +import java.util.Arrays; import java.util.Collections; import org.eclipse.core.internal.resources.Workspace; @@ -38,6 +39,7 @@ import org.eclipse.mylyn.context.core.ContextCore; import org.eclipse.mylyn.context.core.IInteractionContext; import org.eclipse.mylyn.context.core.IInteractionElement; import org.eclipse.mylyn.context.sdk.java.AbstractJavaContextTest; +import org.eclipse.mylyn.internal.context.core.CompositeContextElement; import org.eclipse.mylyn.internal.context.core.CompositeInteractionContext; import org.eclipse.mylyn.internal.context.core.ContextCorePlugin; import org.eclipse.mylyn.internal.context.core.InteractionContext; @@ -575,6 +577,33 @@ public class InteractionContextManagerTest extends AbstractJavaContextTest { } } + public void testDeleteElementsFromContext() { + StubContextElementedDeletedListener listener = new StubContextElementedDeletedListener(); + try { + manager.addListener(listener); + IJavaProject project = type1.getJavaProject(); + InteractionEvent event = new InteractionEvent(InteractionEvent.Kind.MANIPULATION, + new JavaStructureBridge().getContentType(), project.getHandleIdentifier(), "source"); + IInteractionElement element = ContextCorePlugin.getContextManager().processInteractionEvent(event, true); + + assertEquals(0, listener.explicitDeletionEventCount); + assertEquals(0, listener.elementCount); + IInteractionElement originalElement = ContextCorePlugin.getContextManager().getElement( + element.getHandleIdentifier()); + assertEquals(element, originalElement); + assertTrue(originalElement instanceof CompositeContextElement); + assertEquals(1, ((CompositeContextElement) originalElement).getNodes().size()); + + ContextCorePlugin.getContextManager().deleteElements(Arrays.asList(new IInteractionElement[] { element })); + IInteractionElement deletedElement = ContextCorePlugin.getContextManager().getElement( + element.getHandleIdentifier()); + assertTrue(deletedElement instanceof CompositeContextElement); + assertEquals(0, ((CompositeContextElement) deletedElement).getNodes().size()); + } finally { + manager.removeListener(listener); + } + } + private class StubContextElementedDeletedListener extends AbstractContextListener { private int explicitDeletionEventCount; -- cgit v1.2.3