Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2013-08-28 16:48:40 -0400
committerChristian W. Damus2013-09-06 14:38:58 -0400
commitbdc0bb85cd600f2496b29e1006e0dbce106181eb (patch)
treec4cbb5d8e7e89275aef68c66bd80197c7d70a86d /plugins/views/org.eclipse.papyrus.views.search
parent9d01a18c89648cf929923214886c3ae02cf9dcf0 (diff)
downloadorg.eclipse.papyrus-bdc0bb85cd600f2496b29e1006e0dbce106181eb.tar.gz
org.eclipse.papyrus-bdc0bb85cd600f2496b29e1006e0dbce106181eb.tar.xz
org.eclipse.papyrus-bdc0bb85cd600f2496b29e1006e0dbce106181eb.zip
415371: [CDO] Refactor search API to prefer URI over IResource
https://bugs.eclipse.org/bugs/show_bug.cgi?id=415371 Refactored various search scope and result APIs to use URIs instead of IResources to support non-workspace search scopes. IResource dependencies naturally remain for workspace scoping options and reporting text files matching search results.
Diffstat (limited to 'plugins/views/org.eclipse.papyrus.views.search')
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/AbstractResultEntry.java24
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/IScopeCollector.java6
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/ResourceVisitor.java11
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/ScopeCollector.java68
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/ScopeEntry.java59
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/utils/ModelUtils.java26
6 files changed, 89 insertions, 105 deletions
diff --git a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/AbstractResultEntry.java b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/AbstractResultEntry.java
index 17f561a69ca..f2f26d7d687 100644
--- a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/AbstractResultEntry.java
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/AbstractResultEntry.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
+ * Copyright (c) 2013 CEA LIST and others.
*
*
* All rights reserved. This program and the accompanying materials
@@ -9,6 +9,7 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
+ * Christian W. Damus (CEA LIST) - Replace workspace IResource dependency with URI for CDO compatibility
*
*****************************************************************************/
package org.eclipse.papyrus.views.search.results;
@@ -20,6 +21,7 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.papyrus.infra.core.services.ServiceException;
@@ -50,6 +52,8 @@ public abstract class AbstractResultEntry extends Match {
protected URI uriSource;
protected java.net.URI uriResource;
+
+ protected URI uriEResource;
/**
* Used to specify offset and length of {@link Match} when these attributes are not meaningful
@@ -97,7 +101,7 @@ public abstract class AbstractResultEntry extends Match {
child.setParent(theParent);
recursiveHierarchy(theParent);
} else {
- ResultEntry theParent = new ResultEntry(((ScopeEntry)this.getElement()).getResource(), (ScopeEntry)this.getElement());
+ ResultEntry theParent = new ResultEntry(((ScopeEntry)this.getElement()).getResourceURI(), (ScopeEntry)this.getElement());
child.setParent(theParent);
}
}
@@ -112,14 +116,14 @@ public abstract class AbstractResultEntry extends Match {
while(potentialParent != null) {
theParent = new ResultEntry(potentialParent, scopeEntry);
- theParent.setParent(new ResultEntry(scopeEntry.getResource(), scopeEntry));
+ theParent.setParent(new ResultEntry(scopeEntry.getResourceURI(), scopeEntry));
potentialParent = potentialParent.eContainer();
}
if(theParent == null) {
- theParent = new ResultEntry(scopeEntry.getResource(), scopeEntry);
+ theParent = new ResultEntry(scopeEntry.getResourceURI(), scopeEntry);
}
return theParent;
@@ -188,6 +192,15 @@ public abstract class AbstractResultEntry extends Match {
this.uriSource = EcoreUtil.getURI((EObject)source);
} else if(source instanceof IResource) {
this.uriResource = ((IResource)source).getLocationURI();
+ } else if (source instanceof URI) {
+ URI uri = (URI) source;
+
+ if (uri.isPlatformResource()) {
+ // we use this as a proxy for IResources
+ this.uriResource = java.net.URI.create(((URI) source).toString());
+ } else {
+ this.uriEResource = uri;
+ }
}
}
@@ -202,6 +215,9 @@ public abstract class AbstractResultEntry extends Match {
IPath path = new Path(this.uriResource.getPath());
return root.getFile(path);
+ } else if (this.uriEResource != null) {
+ ResourceSet rset = ((ScopeEntry)this.getElement()).getModelSet();
+ return rset.getResource(this.uriEResource, true);
}
return null;
diff --git a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/IScopeCollector.java b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/IScopeCollector.java
index 9d4d920e169..b05140843b3 100644
--- a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/IScopeCollector.java
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/IScopeCollector.java
@@ -9,6 +9,7 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
+ * Christian W. Damus (CEA LIST) - Replace workspace IResource dependency with URI for CDO compatibility
*
*****************************************************************************/
package org.eclipse.papyrus.views.search.scope;
@@ -16,11 +17,12 @@ package org.eclipse.papyrus.views.search.scope;
import java.util.Collection;
import org.eclipse.core.resources.IResource;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.search.ui.ISearchPageContainer;
/**
*
- * Interface that must be implemented to generate scope (i.e. list of {@link IResource}) from a {@link ISearchPageContainer}
+ * Interface that must be implemented to generate scope (i.e. list of {@link URI}s) from a {@link ISearchPageContainer}
*
*/
public interface IScopeCollector {
@@ -33,5 +35,5 @@ public interface IScopeCollector {
* @return
* a collection of {@link IResource} that can be processed
*/
- public Collection<IResource> computeSearchScope(ISearchPageContainer container);
+ public Collection<URI> computeSearchScope(ISearchPageContainer container);
}
diff --git a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/ResourceVisitor.java b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/ResourceVisitor.java
index 5d68a942328..0a314036266 100644
--- a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/ResourceVisitor.java
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/ResourceVisitor.java
@@ -9,6 +9,7 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
+ * Christian W. Damus (CEA LIST) - Replace workspace IResource dependency with URI for CDO compatibility
*
*****************************************************************************/
package org.eclipse.papyrus.views.search.scope;
@@ -29,11 +30,11 @@ import org.eclipse.emf.common.util.URI;
*/
public class ResourceVisitor implements IResourceProxyVisitor {
- private Collection<IResource> participants;
+ private Collection<URI> participantURIs;
public ResourceVisitor() {
super();
- this.participants = new HashSet<IResource>();
+ this.participantURIs = new HashSet<URI>();
}
public boolean visit(IResourceProxy proxy) throws CoreException {
@@ -48,7 +49,7 @@ public class ResourceVisitor implements IResourceProxyVisitor {
// try {
// ModelSet modelSet = ModelUtils.openFile(resource);
// modelSet.unload();
- participants.add(resource);
+ participantURIs.add(uri);
// } catch (ModelMultiException e) {
// }
}
@@ -60,8 +61,8 @@ public class ResourceVisitor implements IResourceProxyVisitor {
return true;
}
- public Collection<IResource> getParticipants() {
- return participants;
+ public Collection<URI> getParticipantURIs() {
+ return participantURIs;
}
}
diff --git a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/ScopeCollector.java b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/ScopeCollector.java
index ec2ddfd5975..fbcd9adff3f 100644
--- a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/ScopeCollector.java
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/ScopeCollector.java
@@ -9,6 +9,7 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
+ * Christian W. Damus (CEA LIST) - Replace workspace IResource dependency with URI for CDO compatibility
*
*****************************************************************************/
package org.eclipse.papyrus.views.search.scope;
@@ -20,12 +21,12 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.jface.viewers.ISelection;
@@ -44,21 +45,13 @@ import org.eclipse.ui.IWorkingSet;
public class ScopeCollector implements IScopeCollector {
- private static ScopeCollector instance = null;
+ private static final ScopeCollector instance = new ScopeCollector();
private ScopeCollector() {
super();
}
public final static ScopeCollector getInstance() {
-
- if(ScopeCollector.instance == null) {
- synchronized(ScopeCollector.class) {
- if(ScopeCollector.instance == null) {
- ScopeCollector.instance = new ScopeCollector();
- }
- }
- }
return ScopeCollector.instance;
}
@@ -68,12 +61,11 @@ public class ScopeCollector implements IScopeCollector {
* @param container
* @return
*/
- public Collection<IResource> computeSearchScope(ISearchPageContainer container) {
+ public Collection<URI> computeSearchScope(ISearchPageContainer container) {
- Set<IResource> results = new HashSet<IResource>();
+ Set<URI> results = new HashSet<URI>();
if(container == null) {
- //Worksapce scope
results.addAll(createWorkspaceScope());
} else {
@@ -131,38 +123,48 @@ public class ScopeCollector implements IScopeCollector {
* @return
* the scope
*/
- protected List<IResource> createSelectionScope(IStructuredSelection selection) {
- List<IResource> results = new ArrayList<IResource>();
+ protected List<URI> createSelectionScope(IStructuredSelection selection) {
+ List<URI> results = new ArrayList<URI>();
- Iterator it = selection.iterator();
+ Iterator<?> it = selection.iterator();
while(it.hasNext()) {
Object object = (Object)it.next();
if(object instanceof IPapyrusFile) {
- results.add(((IPapyrusFile)object).getMainFile());
+ results.addAll(findPapyrusModels(((IPapyrusFile)object).getMainFile()));
} else if(object instanceof IResource) {
results.addAll(findPapyrusModels((IResource)object));
} else {
-
Object element = BusinessModelResolver.getInstance().getBusinessModel(object);
if(element instanceof EObject) {
- Resource eResource = ((EObject)element).eResource();
- IFile resource = ModelUtils.getIFile(eResource);
- if(resource != null) {
+ // CDO resource *are* EObjects
+ Resource eResource = (element instanceof Resource) ? (Resource) element : ((EObject)element).eResource();
+ if(eResource != null) {
+ ModelSet modelSet = null;
+
try {
- ModelSet modelSet = ModelUtils.openFile(resource);
+ modelSet = ModelUtils.openResource(eResource.getURI());
SashModel sashModel = (SashModel)modelSet.getModelChecked(SashModel.MODEL_ID);
- IFile diResource = ModelUtils.getIFile(sashModel.getResource());
- results.add((IFile)diResource);
- modelSet.unload();
+ Resource diResource = sashModel.getResource();
+ if (diResource != null) {
+ results.add(diResource.getURI());
+ }
} catch (ModelMultiException e) {
//Do a workspace search instead
results.addAll(createWorkspaceScope());
} catch (NotFoundException e) {
//Do a workspace search instead
results.addAll(createWorkspaceScope());
+ } finally {
+ if (modelSet != null) {
+ try {
+ modelSet.unload();
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
}
-
+
} else {
//Do a workspace search instead
results.addAll(createWorkspaceScope());
@@ -186,8 +188,8 @@ public class ScopeCollector implements IScopeCollector {
* @return
* the scope
*/
- protected List<IResource> createProjectsScope(String[] projects) {
- List<IResource> results = new ArrayList<IResource>();
+ protected List<URI> createProjectsScope(String[] projects) {
+ List<URI> results = new ArrayList<URI>();
for(String projectName : projects) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
@@ -206,8 +208,8 @@ public class ScopeCollector implements IScopeCollector {
* @return
* the scope
*/
- protected List<IResource> createWorkingSetsScope(IWorkingSet[] workingSets) {
- List<IResource> results = new ArrayList<IResource>();
+ protected List<URI> createWorkingSetsScope(IWorkingSet[] workingSets) {
+ List<URI> results = new ArrayList<URI>();
if(workingSets != null && workingSets.length > 0) {
for(IWorkingSet iWorkingSet : workingSets) {
@@ -231,7 +233,7 @@ public class ScopeCollector implements IScopeCollector {
* @return
* the found Papyrus models
*/
- protected Collection<IResource> findPapyrusModels(IResource res) {
+ protected Collection<URI> findPapyrusModels(IResource res) {
ResourceVisitor visitor = new ResourceVisitor();
try {
res.accept(visitor, IResource.DEPTH_INFINITE);
@@ -239,7 +241,7 @@ public class ScopeCollector implements IScopeCollector {
Activator.log.warn(Messages.ScopeCollector_0 + res);
}
- return visitor.getParticipants();
+ return visitor.getParticipantURIs();
}
/**
@@ -248,7 +250,7 @@ public class ScopeCollector implements IScopeCollector {
* @return
* the scope
*/
- protected Collection<IResource> createWorkspaceScope() {
+ protected Collection<URI> createWorkspaceScope() {
//Go through the workspace root
IResource root = ResourcesPlugin.getWorkspace().getRoot();
diff --git a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/ScopeEntry.java b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/ScopeEntry.java
index 40dd73e3b01..8ea82e4ca06 100644
--- a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/ScopeEntry.java
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/ScopeEntry.java
@@ -10,6 +10,7 @@
* Contributors:
* CEA LIST - Initial API and implementation
* Christian W. Damus (CEA LIST) - Fix leaking of all UML models in search results
+ * Christian W. Damus (CEA LIST) - Replace workspace IResource dependency with URI for CDO compatibility
*
*****************************************************************************/
package org.eclipse.papyrus.views.search.scope;
@@ -17,17 +18,14 @@ package org.eclipse.papyrus.views.search.scope;
import java.util.Collection;
import java.util.HashSet;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.papyrus.infra.core.resource.ModelMultiException;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServiceMultiException;
import org.eclipse.papyrus.infra.core.services.ServiceNotFoundException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.core.utils.EditorUtils;
import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResourceInitializerService;
import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
@@ -43,7 +41,6 @@ import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.ide.ResourceUtil;
/**
*
@@ -68,21 +65,20 @@ public class ScopeEntry {
private ServicesRegistry servicesRegistry;
/**
- * The resource that contains the element that raised a match
+ * The URI of the resource that contains the element that raised a match.
*/
- // private IResource resource;
+ private URI resourceURI;
- private IPath pathResource;
- public ScopeEntry(IResource resource) {
- this(resource, null);
+ public ScopeEntry(URI resourceURI) {
+ this(resourceURI, null);
}
- public ScopeEntry(IResource resource, IServiceRegistryTracker serviceRegistryTracker) {
+ public ScopeEntry(URI resourceURI, IServiceRegistryTracker serviceRegistryTracker) {
super();
-
+
this.serviceRegistryTracker = serviceRegistryTracker;
- this.pathResource = resource.getFullPath();
+ this.resourceURI = resourceURI;
this.modelSet = getModelSet();
this.servicesRegistry = getServicesRegistry();
}
@@ -137,12 +133,12 @@ public class ScopeEntry {
//Create one
try {
- modelSet = ModelUtils.openFile(this.getResource());
+ modelSet = ModelUtils.openResource(getResourceURI());
getServicesRegistry().add(ModelSet.class, 10, modelSet);
getServicesRegistry().add(ServiceUtilsForResourceInitializerService.class, 10, new ServiceUtilsForResourceInitializerService());
getServicesRegistry().startServicesByClassKeys(ModelSet.class, ServiceUtilsForResourceInitializerService.class);
} catch (ModelMultiException modelMultiException) {
- Activator.log.error(Messages.ScopeEntry_1 + this.getResource(), modelMultiException);
+ Activator.log.error(Messages.ScopeEntry_1 + this.getResourceURI(), modelMultiException);
} catch (ServiceMultiException e1) {
Activator.log.error(e1);
} catch (ServiceNotFoundException e1) {
@@ -163,7 +159,7 @@ public class ScopeEntry {
for(IEditorPart editor : editors) {
if(editor != null) {
- if(ResourceUtil.getResource(editor.getEditorInput()).equals(this.getResource())) {
+ if(getResourceURI().equals(EditorUtils.getResourceURI(editor))) {
return editor;
}
}
@@ -208,31 +204,12 @@ public class ScopeEntry {
return servicesRegistry;
}
- public void setServicesRegistry(ServicesRegistry servicesRegistry) {
- this.servicesRegistry = servicesRegistry;
+ public URI getResourceURI() {
+ return resourceURI;
}
-
- public IResource getResource() {
-
-
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- IFile file = root.getFile(pathResource);
-
- return (IResource)file;
- // if(this.uriResource != null) {
- //
- // IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- //
- //
- // IPath path = new Path(this.uriResource.getPath());
- // return root.getFile(path);
- // } else {
- // return null;
- // }
- }
-
- public void setResource(IResource resource) {
- this.pathResource = resource.getFullPath();
+
+ public void setResourceURI(URI resourceURI) {
+ this.resourceURI = resourceURI;
}
}
diff --git a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/utils/ModelUtils.java b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/utils/ModelUtils.java
index bfc485fcde5..625c3388ba2 100644
--- a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/utils/ModelUtils.java
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/utils/ModelUtils.java
@@ -9,43 +9,29 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
+ * Christian W. Damus (CEA LIST) - Replace workspace IResource dependency with URI for CDO compatibility
*
*****************************************************************************/
package org.eclipse.papyrus.views.search.utils;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.papyrus.infra.core.resource.ModelMultiException;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.resource.ModelsReader;
public class ModelUtils {
- public final static ModelSet openFile(IResource object) throws ModelMultiException {
-
- if(object instanceof IFile) {
+ public final static ModelSet openResource(URI resourceURI) throws ModelMultiException {
+ if(resourceURI != null) {
+ // TODO: Need to be able to create CDOAwareModelSet
ModelSet modelSet = new ModelSet();
ModelsReader reader = new ModelsReader();
reader.readModel(modelSet);
- modelSet.loadModels((IFile)object);
+ modelSet.loadModels(resourceURI);
return modelSet;
} else {
return null;
}
}
-
- public final static IFile getIFile(Resource eResource) {
- URI eUri = eResource.getURI();
- if(eUri.isPlatformResource()) {
- String platformString = eUri.toPlatformString(true);
- IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(platformString);
- if(resource instanceof IFile) {
- return (IFile)resource;
- }
- }
- return null;
- }
+
}

Back to the top