summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Reckord2012-10-29 18:17:55 (EDT)
committer Carsten Reckord2012-11-01 13:18:51 (EDT)
commitfdaaad040d8da3099c37abdaa5e07a3e7e9f9220 (patch)
treee1e3e2b8c7ee8e8f2c57274b5ae1c41a6716cce4
parent19c9224312f266459379e63b4d034c772e813a90 (diff)
downloadorg.eclipse.mylyn.context-fdaaad040d8da3099c37abdaa5e07a3e7e9f9220.zip
org.eclipse.mylyn.context-fdaaad040d8da3099c37abdaa5e07a3e7e9f9220.tar.gz
org.eclipse.mylyn.context-fdaaad040d8da3099c37abdaa5e07a3e7e9f9220.tar.bz2
334024: [context] focused package explorer not working if top level element is working setrefs/changes/06/8406/4
Moved handling of IWorkingSets from CDT and Java bridge to ResourceStructureBridge Bug: 334024 Change-Id: I690ee478d5f1d0fc09f56c8e5cce4ab1d336782b Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=334024
-rw-r--r--org.eclipse.mylyn.cdt.ui/src/org/eclipse/mylyn/internal/cdt/ui/CDTStructureBridge.java19
-rw-r--r--org.eclipse.mylyn.java.tests/src/org/eclipse/mylyn/java/tests/InterestFilterTest.java10
-rw-r--r--org.eclipse.mylyn.java.tests/src/org/eclipse/mylyn/java/tests/ResourceStructureMappingTest.java46
-rw-r--r--org.eclipse.mylyn.java.ui/src/org/eclipse/mylyn/internal/java/ui/JavaStructureBridge.java18
-rw-r--r--org.eclipse.mylyn.resources.tests/src/org/eclipse/mylyn/resources/tests/ResourceContextTest.java53
-rw-r--r--org.eclipse.mylyn.resources.ui/src/org/eclipse/mylyn/internal/resources/ui/ResourceStructureBridge.java24
6 files changed, 129 insertions, 41 deletions
diff --git a/org.eclipse.mylyn.cdt.ui/src/org/eclipse/mylyn/internal/cdt/ui/CDTStructureBridge.java b/org.eclipse.mylyn.cdt.ui/src/org/eclipse/mylyn/internal/cdt/ui/CDTStructureBridge.java
index 83ab556..3207869 100644
--- a/org.eclipse.mylyn.cdt.ui/src/org/eclipse/mylyn/internal/cdt/ui/CDTStructureBridge.java
+++ b/org.eclipse.mylyn.cdt.ui/src/org/eclipse/mylyn/internal/cdt/ui/CDTStructureBridge.java
@@ -31,7 +31,6 @@ import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.mylyn.context.core.AbstractContextStructureBridge;
import org.eclipse.mylyn.context.core.ContextCore;
import org.eclipse.mylyn.context.core.IInteractionElement;
-import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.views.markers.internal.ConcreteMarker;
/**
@@ -186,28 +185,14 @@ public class CDTStructureBridge extends AbstractContextStructureBridge {
}
boolean accepts = (object instanceof ICElement && !(object instanceof IBinary))
- || object instanceof IWorkingSet || object instanceof CElementGrouping;
+ || object instanceof CElementGrouping;
return accepts;
}
@Override
public boolean canFilter(Object object) {
- if (object instanceof IWorkingSet) {
- try {
- IWorkingSet workingSet = (IWorkingSet) object;
- IAdaptable[] elements = workingSet.getElements();
- for (IAdaptable adaptable : elements) {
- IInteractionElement element = ContextCore.getContextManager().getElement(
- getHandleIdentifier(adaptable));
- if (element != null && element.getInterest().isInteresting()) {
- return false;
- }
- }
- } catch (Exception e) {
- return false;
- }
- } else if (object instanceof CElementGrouping) {
+ if (object instanceof CElementGrouping) {
try {
CElementGrouping grouping = (CElementGrouping) object;
Object[] elements = grouping.getChildren(grouping);
diff --git a/org.eclipse.mylyn.java.tests/src/org/eclipse/mylyn/java/tests/InterestFilterTest.java b/org.eclipse.mylyn.java.tests/src/org/eclipse/mylyn/java/tests/InterestFilterTest.java
index e9c719e..d2f125f 100644
--- a/org.eclipse.mylyn.java.tests/src/org/eclipse/mylyn/java/tests/InterestFilterTest.java
+++ b/org.eclipse.mylyn.java.tests/src/org/eclipse/mylyn/java/tests/InterestFilterTest.java
@@ -15,6 +15,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.ui.filters.ImportDeclarationFilter;
@@ -25,6 +26,9 @@ import org.eclipse.mylyn.context.sdk.java.AbstractJavaContextTest;
import org.eclipse.mylyn.context.ui.AbstractFocusViewAction;
import org.eclipse.mylyn.context.ui.InterestFilter;
import org.eclipse.mylyn.internal.java.ui.actions.FocusPackageExplorerAction;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetManager;
+import org.eclipse.ui.PlatformUI;
/**
* @author Mik Kersten
@@ -47,11 +51,6 @@ public class InterestFilterTest extends AbstractJavaContextTest {
assertTrue(applyAction instanceof FocusPackageExplorerAction);
}
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
public void testPreservedFilterRemovalExclusion() throws JavaModelException {
List<Class<?>> filterClasses = new ArrayList<Class<?>>();
for (ViewerFilter filter : Arrays.asList(explorer.getTreeViewer().getFilters())) {
@@ -108,5 +107,4 @@ public class InterestFilterTest extends AbstractJavaContextTest {
// // teardown
// filter.setExcludedMatches(null);
}
-
}
diff --git a/org.eclipse.mylyn.java.tests/src/org/eclipse/mylyn/java/tests/ResourceStructureMappingTest.java b/org.eclipse.mylyn.java.tests/src/org/eclipse/mylyn/java/tests/ResourceStructureMappingTest.java
index 77acbf6..f13fcfd 100644
--- a/org.eclipse.mylyn.java.tests/src/org/eclipse/mylyn/java/tests/ResourceStructureMappingTest.java
+++ b/org.eclipse.mylyn.java.tests/src/org/eclipse/mylyn/java/tests/ResourceStructureMappingTest.java
@@ -7,24 +7,30 @@
*
* Contributors:
* Tasktop Technologies - initial API and implementation
+ * Yatta Solutions - WorkingSet tests (bug 334024)
*******************************************************************************/
package org.eclipse.mylyn.java.tests;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.mylyn.commons.sdk.util.UiTestUtil;
+import org.eclipse.mylyn.context.core.AbstractContextStructureBridge;
import org.eclipse.mylyn.context.core.ContextCore;
import org.eclipse.mylyn.context.core.IInteractionElement;
import org.eclipse.mylyn.context.sdk.java.AbstractJavaContextTest;
import org.eclipse.mylyn.internal.resources.ui.ResourcesUiBridgePlugin;
import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetManager;
import org.eclipse.ui.PlatformUI;
/**
* @author Mik Kersten
+ * @author Carsten Reckord (bug 334024: focused package explorer not working if top level element is working set)
*/
public class ResourceStructureMappingTest extends AbstractJavaContextTest {
@@ -35,6 +41,17 @@ public class ResourceStructureMappingTest extends AbstractJavaContextTest {
UiTestUtil.openResourceNavigator();
}
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
+ IWorkingSet workingSet = workingSetManager.getWorkingSet("TestWorkingSet");
+ if (workingSet != null) {
+ workingSetManager.removeWorkingSet(workingSet);
+ }
+ }
+
public void testParentResourceMapping() throws CoreException {
IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
IMethod m1 = type1.createMethod("public void m1() { }", null, true, null);
@@ -47,4 +64,33 @@ public class ResourceStructureMappingTest extends AbstractJavaContextTest {
assertEquals(m1.getCompilationUnit().getAdapter(IResource.class), containingResource);
}
+ /**
+ * Test that working sets are correctly handled in the presence of the Java bridge
+ */
+ public void testWorkingSetFiltering() throws CoreException {
+ IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
+ IWorkingSet workingSet = workingSetManager.createWorkingSet("TestWorkingSet",
+ new IAdaptable[] { project.getProject() });
+ workingSet.setId("org.eclipse.jdt.ui.JavaWorkingSetPage");
+ workingSetManager.addWorkingSet(workingSet);
+
+ context.reset();
+ assertEquals(0, context.getInteractionHistory().size());
+
+ // make sure the correct bridge is used in the presence of the java bridge
+ AbstractContextStructureBridge workingSetBridge = ContextCore.getStructureBridge(workingSet);
+ assertEquals(ContextCore.CONTENT_TYPE_RESOURCE, workingSetBridge.getContentType());
+
+ // without an interesting project, the working set should be filtered
+ assertTrue(workingSetBridge.canFilter(workingSet));
+
+ IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
+ monitor.selectionChanged(part, new StructuredSelection(type1));
+ IInteractionElement element = ContextCore.getContextManager().getElement(type1.getHandleIdentifier());
+ assertTrue(element.getInterest().isInteresting());
+
+ // with an interesting project, the working set should no longer be filtered
+ assertFalse(workingSetBridge.canFilter(workingSet));
+
+ }
}
diff --git a/org.eclipse.mylyn.java.ui/src/org/eclipse/mylyn/internal/java/ui/JavaStructureBridge.java b/org.eclipse.mylyn.java.ui/src/org/eclipse/mylyn/internal/java/ui/JavaStructureBridge.java
index b06ba80..17be59e 100644
--- a/org.eclipse.mylyn.java.ui/src/org/eclipse/mylyn/internal/java/ui/JavaStructureBridge.java
+++ b/org.eclipse.mylyn.java.ui/src/org/eclipse/mylyn/internal/java/ui/JavaStructureBridge.java
@@ -45,7 +45,6 @@ import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.context.core.AbstractContextStructureBridge;
import org.eclipse.mylyn.context.core.ContextCore;
import org.eclipse.mylyn.context.core.IInteractionElement;
-import org.eclipse.ui.internal.WorkingSet;
import org.eclipse.ui.views.markers.internal.ConcreteMarker;
/**
@@ -210,7 +209,7 @@ public class JavaStructureBridge extends AbstractContextStructureBridge {
boolean accepts = object instanceof IJavaElement || object instanceof PackageFragmentRootContainer
|| object instanceof ClassPathContainer.RequiredProjectWrapper || object instanceof JarEntryFile
- || object instanceof IPackageFragment || object instanceof WorkingSet || isWtpClass(object);
+ || object instanceof IPackageFragment || isWtpClass(object);
return accepts;
}
@@ -238,21 +237,6 @@ public class JavaStructureBridge extends AbstractContextStructureBridge {
}
}
}
- } else if (object instanceof WorkingSet) {
- try {
- WorkingSet workingSet = (WorkingSet) object;
- IAdaptable[] elements = workingSet.getElements();
- for (IAdaptable adaptable : elements) {
- IInteractionElement interactionElement = ContextCore.getContextManager().getElement(
- getHandleIdentifier(adaptable));
- if (interactionElement != null && interactionElement.getInterest().isInteresting()) {
- return false;
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
}
return true;
}
diff --git a/org.eclipse.mylyn.resources.tests/src/org/eclipse/mylyn/resources/tests/ResourceContextTest.java b/org.eclipse.mylyn.resources.tests/src/org/eclipse/mylyn/resources/tests/ResourceContextTest.java
index 96a1c3a..a19602e 100644
--- a/org.eclipse.mylyn.resources.tests/src/org/eclipse/mylyn/resources/tests/ResourceContextTest.java
+++ b/org.eclipse.mylyn.resources.tests/src/org/eclipse/mylyn/resources/tests/ResourceContextTest.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Tasktop Technologies - initial API and implementation
+ * Yatta Solutions - WorkingSet tests (bug 334024)
*******************************************************************************/
package org.eclipse.mylyn.resources.tests;
@@ -21,17 +22,23 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.mylyn.commons.sdk.util.ResourceTestUtil;
+import org.eclipse.mylyn.context.core.AbstractContextStructureBridge;
import org.eclipse.mylyn.context.core.ContextCore;
import org.eclipse.mylyn.context.core.IInteractionElement;
import org.eclipse.mylyn.context.sdk.util.AbstractResourceContextTest;
import org.eclipse.mylyn.context.sdk.util.ContextTestUtil;
import org.eclipse.mylyn.internal.resources.ui.ResourcesUiBridgePlugin;
import org.eclipse.mylyn.internal.resources.ui.ResourcesUiPreferenceInitializer;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetManager;
+import org.eclipse.ui.PlatformUI;
/**
* @author Mik Kersten
+ * @author Carsten Reckord (bug 334024: focused package explorer not working if top level element is working set)
*/
public class ResourceContextTest extends AbstractResourceContextTest {
@@ -56,6 +63,12 @@ public class ResourceContextTest extends AbstractResourceContextTest {
ResourcesUiBridgePlugin.getDefault()
.getPreferenceStore()
.setValue(ResourcesUiPreferenceInitializer.PREF_MODIFIED_DATE_EXCLUSIONS, true);
+
+ IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
+ IWorkingSet workingSet = workingSetManager.getWorkingSet("TestWorkingSet");
+ if (workingSet != null) {
+ workingSetManager.removeWorkingSet(workingSet);
+ }
}
public void testResourceSelect() throws CoreException {
@@ -183,6 +196,46 @@ public class ResourceContextTest extends AbstractResourceContextTest {
assertEquals(0, context.getInteractionHistory().size());
}
+ /**
+ * Test that working sets are properly handled by the resource bridge
+ */
+ public void testWorkingSetHandledByResourceBridge() {
+ IProject project2 = project.getProject();
+
+ IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
+ IWorkingSet workingSet = workingSetManager.createWorkingSet("TestWorkingSet", new IAdaptable[] { project2 });
+
+ assertTrue(structureBridge.acceptsObject(workingSet));
+
+ AbstractContextStructureBridge workingSetBridge = ContextCore.getStructureBridge(workingSet);
+ assertEquals(ContextCore.CONTENT_TYPE_RESOURCE, workingSetBridge.getContentType());
+ }
+
+ /**
+ * Test that working sets are filtered based on the interest of their contents
+ */
+ public void testWorkingSetFiltering() throws CoreException {
+ IProject project2 = project.getProject();
+ IFile file = project2.getFile("file");
+ file.create(null, true, null);
+ assertTrue(file.exists());
+
+ IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
+ IWorkingSet workingSet = workingSetManager.createWorkingSet("TestWorkingSet", new IAdaptable[] { project2 });
+ workingSetManager.addWorkingSet(workingSet);
+
+ context.reset();
+ assertEquals(0, context.getInteractionHistory().size());
+
+ assertTrue(structureBridge.canFilter(workingSet));
+
+ monitor.selectionChanged(navigator, new StructuredSelection(file));
+ IInteractionElement element = ContextCore.getContextManager().getElement(
+ structureBridge.getHandleIdentifier(file));
+ assertTrue(element.getInterest().isInteresting());
+ assertFalse(structureBridge.canFilter(workingSet));
+ }
+
@SuppressWarnings("deprecation")
private void createRealFiles(IProject project) throws CoreException, UnsupportedEncodingException {
// we need to have contents for the file to be local
diff --git a/org.eclipse.mylyn.resources.ui/src/org/eclipse/mylyn/internal/resources/ui/ResourceStructureBridge.java b/org.eclipse.mylyn.resources.ui/src/org/eclipse/mylyn/internal/resources/ui/ResourceStructureBridge.java
index 41f19bc..6282d41 100644
--- a/org.eclipse.mylyn.resources.ui/src/org/eclipse/mylyn/internal/resources/ui/ResourceStructureBridge.java
+++ b/org.eclipse.mylyn.resources.ui/src/org/eclipse/mylyn/internal/resources/ui/ResourceStructureBridge.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Tasktop Technologies - initial API and implementation
+ * Yatta Solutions - WorkingSet filtering (bug 334024)
*******************************************************************************/
package org.eclipse.mylyn.internal.resources.ui;
@@ -32,11 +33,14 @@ import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.context.core.AbstractContextStructureBridge;
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.resources.ui.ResourcesUi;
+import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.views.markers.internal.ConcreteMarker;
/**
* @author Mik Kersten
+ * @author Carsten Reckord (bug 334024: focused package explorer not working if top level element is working set)
*/
public class ResourceStructureBridge extends AbstractContextStructureBridge {
@@ -179,7 +183,7 @@ public class ResourceStructureBridge extends AbstractContextStructureBridge {
@Override
public boolean acceptsObject(Object object) {
- if (object instanceof IResource) {
+ if (object instanceof IResource || object instanceof IWorkingSet) {
return true;
}
if (object instanceof IAdaptable) {
@@ -195,6 +199,24 @@ public class ResourceStructureBridge extends AbstractContextStructureBridge {
@Override
public boolean canFilter(Object element) {
+ if (element instanceof IWorkingSet) {
+ try {
+ IWorkingSet workingSet = (IWorkingSet) element;
+ IAdaptable[] elements = workingSet.getElements();
+ for (IAdaptable adaptable : elements) {
+ final AbstractContextStructureBridge elementBridge = ContextCore.getStructureBridge(adaptable);
+ String handle = elementBridge.getHandleIdentifier(adaptable);
+ if (handle != null) {
+ IInteractionElement interactionElement = ContextCore.getContextManager().getElement(handle);
+ if (interactionElement != null && interactionElement.getInterest().isInteresting()) {
+ return false;
+ }
+ }
+ }
+ } catch (Exception e) {
+ return false;
+ }
+ }
return true;
}