summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Schmidt2012-07-27 17:11:23 (EDT)
committerSteffen Pingel2012-07-27 17:11:23 (EDT)
commitcd4780b72db3a26966e3fe5609fe0bdd01e6c1a3 (patch)
tree0260369dc81636b635b45ceb4b04c2ce9a5af383
parent6626dd4e186c7275d2c411f07399d1454a221dda (diff)
downloadorg.eclipse.mylyn.context-cd4780b72db3a26966e3fe5609fe0bdd01e6c1a3.zip
org.eclipse.mylyn.context-cd4780b72db3a26966e3fe5609fe0bdd01e6c1a3.tar.gz
org.eclipse.mylyn.context-cd4780b72db3a26966e3fe5609fe0bdd01e6c1a3.tar.bz2
385908: [api] provide API to delete elements from specific contextrefs/changes/16/6916/5
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
-rw-r--r--org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/context/core/IInteractionContextManager.java9
-rw-r--r--org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/internal/context/core/InteractionContextManager.java27
-rw-r--r--org.eclipse.mylyn.java.tests/src/org/eclipse/mylyn/java/tests/InteractionContextManagerTest.java29
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 84b4eba..de48c90 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<IInteractionElement> elements);
+ /**
+ * @since 3.9
+ */
+ public abstract void deleteElements(Collection<IInteractionElement> 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 6311386..3504a03 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<IInteractionElement> elements) {
- deleteElements(elements, false);
+ deleteElements(elements, getActiveContext(), false, true);
+ }
+
+ public void deleteElements(Collection<IInteractionElement> elements, IInteractionContext context) {
+ deleteElements(elements, context, false, true);
}
public void deleteElements(Collection<IInteractionElement> elements, boolean isExplicitManipulation) {
+ deleteElements(elements, getActiveContext(), isExplicitManipulation, true);
+ }
+
+ public void deleteElements(Collection<IInteractionElement> 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<IInteractionElement>(elements), isExplicitManipulation);
- }
-
- private void delete(IInteractionElement element, IInteractionContext context) {
- if (element == null || context == null) {
- return;
+ if (notify) {
+ notifyElementsDeleted(context, new ArrayList<IInteractionElement>(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 0f287ec..f046ba1 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;