summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Doninger2012-01-09 13:05:34 (EST)
committer Shawn Minto2012-01-09 13:05:34 (EST)
commit3e5ce4fc6a57e7b4f758c4c4185fcd9aff0dcaff (patch)
tree68b6dc881685a954b1dc9583a6b05dedf26be88f
parent2056f203c875ea1aea2a69636d4ad4a9573d4ed9 (diff)
downloadorg.eclipse.mylyn.context-3e5ce4fc6a57e7b4f758c4c4185fcd9aff0dcaff.zip
org.eclipse.mylyn.context-3e5ce4fc6a57e7b4f758c4c4185fcd9aff0dcaff.tar.gz
org.eclipse.mylyn.context-3e5ce4fc6a57e7b4f758c4c4185fcd9aff0dcaff.tar.bz2
NEW - bug 364155: [api] add a method to retrieve projects in current
active context https://bugs.eclipse.org/bugs/show_bug.cgi?id=364155
-rw-r--r--org.eclipse.mylyn.resources.tests/src/org/eclipse/mylyn/resources/tests/AllResourcesTests.java1
-rw-r--r--org.eclipse.mylyn.resources.tests/src/org/eclipse/mylyn/resources/tests/ResourceStructureBridgeTest.java66
-rw-r--r--org.eclipse.mylyn.resources.ui/src/org/eclipse/mylyn/internal/resources/ui/ResourceStructureBridge.java34
3 files changed, 101 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.resources.tests/src/org/eclipse/mylyn/resources/tests/AllResourcesTests.java b/org.eclipse.mylyn.resources.tests/src/org/eclipse/mylyn/resources/tests/AllResourcesTests.java
index cba2dfa..175c53f 100644
--- a/org.eclipse.mylyn.resources.tests/src/org/eclipse/mylyn/resources/tests/AllResourcesTests.java
+++ b/org.eclipse.mylyn.resources.tests/src/org/eclipse/mylyn/resources/tests/AllResourcesTests.java
@@ -29,6 +29,7 @@ public class AllResourcesTests {
suite.addTestSuite(ResourcePatternExclusionStrategyTest.class);
suite.addTestSuite(ResourceModificationDateExclusionStrategyTest.class);
suite.addTestSuite(ResourceContextTest.class);
+ suite.addTestSuite(ResourceStructureBridgeTest.class);
return suite;
}
diff --git a/org.eclipse.mylyn.resources.tests/src/org/eclipse/mylyn/resources/tests/ResourceStructureBridgeTest.java b/org.eclipse.mylyn.resources.tests/src/org/eclipse/mylyn/resources/tests/ResourceStructureBridgeTest.java
new file mode 100644
index 0000000..6df1f66
--- /dev/null
+++ b/org.eclipse.mylyn.resources.tests/src/org/eclipse/mylyn/resources/tests/ResourceStructureBridgeTest.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Manuel Doninger.
+ * 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:
+ * Manuel Doninger - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.resources.tests;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.mylyn.commons.sdk.util.TestProject;
+import org.eclipse.mylyn.context.core.ContextCore;
+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;
+
+public class ResourceStructureBridgeTest extends AbstractResourceContextTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+// ResourcesUiBridgePlugin.getDefault().setResourceMonitoringEnabled(true);
+ ResourcesUiBridgePlugin.getInterestUpdater().setSyncExec(true);
+
+ ContextTestUtil.triggerContextUiLazyStart();
+ // disable ResourceModifiedDateExclusionStrategy
+ ResourcesUiBridgePlugin.getDefault()
+ .getPreferenceStore()
+ .setValue(ResourcesUiPreferenceInitializer.PREF_MODIFIED_DATE_EXCLUSIONS, false);
+ }
+
+ public void testGetProjectsInActiveContext() throws CoreException {
+ assertEquals(0, structureBridge.getProjectsInActiveContext().size());
+ IFile testfile1 = project.getProject().getFile("testfile1");
+ testfile1.create(null, true, null);
+ IFile testfile2 = project.getProject().getFile("testfile2");
+ testfile2.create(null, true, null);
+ assertEquals(1, structureBridge.getProjectsInActiveContext().size());
+ }
+
+ public void testGetProjectsInActiveContextWithInvalidProject() throws CoreException, InvocationTargetException,
+ InterruptedException {
+ assertEquals(0, structureBridge.getProjectsInActiveContext().size());
+ IFile testfile1 = project.getProject().getFile("testfile1");
+ testfile1.create(null, true, null);
+ IFile testfile2 = project.getProject().getFile("testfile2");
+ testfile2.create(null, true, null);
+ assertEquals(1, structureBridge.getProjectsInActiveContext().size());
+ TestProject project2 = new TestProject(this.getClass().getName() + "Invalid");
+ IFile testfile3 = project2.getProject().getFile("testfile1");
+ testfile3.create(null, true, null);
+ ContextCore.getContextManager().setContextCapturePaused(true);
+ testfile3.delete(true, null);
+ project2.getProject().delete(true, null);
+ ContextCore.getContextManager().setContextCapturePaused(false);
+ assertEquals(1, structureBridge.getProjectsInActiveContext().size());
+ }
+}
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 a0c0015..d84f814 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,13 +7,17 @@
*
* Contributors:
* Tasktop Technologies - initial API and implementation
+ * Manuel Doninger
*******************************************************************************/
package org.eclipse.mylyn.internal.resources.ui;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
+import java.util.Set;
import org.eclipse.core.internal.resources.Marker;
import org.eclipse.core.resources.IContainer;
@@ -30,6 +34,8 @@ import org.eclipse.core.runtime.Status;
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.ui.views.markers.internal.ConcreteMarker;
/**
@@ -233,4 +239,32 @@ public class ResourceStructureBridge extends AbstractContextStructureBridge {
public String getContentType(String elementHandle) {
return getContentType();
}
+
+ public Set<IProject> getProjectsInActiveContext() {
+ IInteractionContext activeContext = ContextCore.getContextManager().getActiveContext();
+ List<IInteractionElement> allElements = activeContext.getAllElements();
+ Set<IProject> projectsInContext = new HashSet<IProject>();
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ List<IProject> projectsInWorkspace = new LinkedList<IProject>();
+
+ for (IProject p : workspace.getRoot().getProjects()) {
+ if (p.exists()) {
+ projectsInWorkspace.add(p);
+ }
+ }
+
+ for (IInteractionElement element : allElements) {
+ String handle = element.getHandleIdentifier();
+ IPath path = new Path(handle);
+
+ if (path.segmentCount() == 1 && path.isValidPath(handle)) {
+ String projectName = handle.substring(1);
+ IProject project = workspace.getRoot().getProject(projectName);
+ if (projectsInWorkspace.contains(project)) {
+ projectsInContext.add(project);
+ }
+ }
+ }
+ return projectsInContext;
+ }
}