Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2013-08-28 20:48:40 +0000
committerChristian W. Damus2013-09-06 18:38:58 +0000
commitbdc0bb85cd600f2496b29e1006e0dbce106181eb (patch)
treec4cbb5d8e7e89275aef68c66bd80197c7d70a86d /plugins
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')
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/EditorUtils.java66
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchPage.java16
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/results/PapyrusSearchResult.java33
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/StereotypeCollector.java47
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/UMLResourceVisitor.java11
-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
11 files changed, 211 insertions, 156 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/EditorUtils.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/EditorUtils.java
index b39091c5798..d7b4ff60f42 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/EditorUtils.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/EditorUtils.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2008 CEA LIST.
+ * Copyright (c) 2008, 2013 CEA LIST and others.
*
*
* All rights reserved. This program and the accompanying materials
@@ -11,6 +11,7 @@
* Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
* <a href="mailto:thomas.szadel@atosorigin.com">Thomas Szadel</a>: Code simplification and NPE
* management.
+ * Christian W. Damus (CEA LIST) - API for determining URI of a resource in an editor
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.utils;
@@ -19,6 +20,8 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.common.ui.URIEditorInput;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.papyrus.infra.core.Activator;
@@ -34,11 +37,14 @@ import org.eclipse.papyrus.infra.core.sasheditor.editor.IPage;
import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IURIEditorInput;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
/**
@@ -670,4 +676,62 @@ public class EditorUtils {
}
}
+ /**
+ * Obtains the URI of the EMF resource identified by the given editor reference.
+ *
+ * @param editorRef
+ * an editor reference
+ *
+ * @return the best-effort URI of the resource that it edits, or {@code null} if it could not be determined,
+ * including the case when the editor input could not be obtained from the reference
+ */
+ public static URI getResourceURI(IEditorReference editorRef) {
+ try {
+ return getResourceURI(editorRef.getEditorInput());
+ } catch (PartInitException e) {
+ Activator.log.error("Could not obtain editor input from editor reference.", e); //$NON-NLS-1$
+ return null;
+ }
+ }
+
+ /**
+ * Obtains the URI of the EMF resource edited by the given {@code editor}.
+ *
+ * @param editor
+ * an open editor
+ *
+ * @return the best-effort URI of the resource that it edits, or {@code null} if it could not be determined,
+ * such as if the editor input could not be obtained from the editor
+ */
+ public static URI getResourceURI(IEditorPart editor) {
+ return getResourceURI(editor.getEditorInput());
+ }
+
+ /**
+ * Obtains the URI of the EMF resource identified by the given editor input.
+ *
+ * @param editorInput
+ * an editor input
+ *
+ * @return the best-effort URI of the resource that it edits, or {@code null} if it could not be determined
+ */
+ public static URI getResourceURI(IEditorInput editorInput) {
+ URI result = null;
+
+ if(editorInput instanceof IFileEditorInput) {
+ result = URI.createPlatformResourceURI(((IFileEditorInput)editorInput).getFile().getFullPath().toString(), true);
+ } else if(editorInput instanceof URIEditorInput) {
+ result = ((URIEditorInput)editorInput).getURI();
+ } else if(editorInput instanceof IURIEditorInput) {
+ result = URI.createURI(((IURIEditorInput)editorInput).getURI().toASCIIString(), true);
+ } else if(editorInput != null) {
+ // desperation
+ Object adapter = editorInput.getAdapter(URI.class);
+ if(adapter instanceof URI) {
+ result = (URI)adapter;
+ }
+ }
+
+ return result;
+ }
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchPage.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchPage.java
index 0dee544a5ef..bff352aa856 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchPage.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchPage.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.uml.search.ui.pages;
@@ -23,7 +24,6 @@ import java.util.List;
import java.util.Set;
import java.util.regex.PatternSyntaxException;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.util.URI;
@@ -791,7 +791,7 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
protected ScopeEntry getCurrentScopeEntry() {
if(container.getSelectedScope() == ISearchPageContainer.SELECTION_SCOPE) {
- Collection<IResource> scope = ScopeCollector.getInstance().computeSearchScope(container);
+ Collection<URI> scope = ScopeCollector.getInstance().computeSearchScope(container);
Collection<ScopeEntry> scopeEntries = createScopeEntries(scope);
@@ -969,17 +969,17 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
}
/**
- * Create scopeEntries based on IResources.
+ * Create scopeEntries based on URIs.
*
* @return the created scopeEntries
*/
- private Collection<ScopeEntry> createScopeEntries(Collection<IResource> scope) {
+ private Collection<ScopeEntry> createScopeEntries(Collection<URI> scope) {
IServiceRegistryTracker tracker = createServiceRegistryTracker();
Collection<ScopeEntry> results = new HashSet<ScopeEntry>();
- for(IResource resource : scope) {
+ for(URI uri : scope) {
- ScopeEntry scopeEntry = new ScopeEntry(resource, tracker);
+ ScopeEntry scopeEntry = new ScopeEntry(uri, tracker);
results.add(scopeEntry);
@@ -996,7 +996,7 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
if(queryKind.getSelectionIndex() == TEXT_QUERY_KIND) {
if(validateRegex()) {
- Collection<IResource> scope = ScopeCollector.getInstance().computeSearchScope(container);
+ Collection<URI> scope = ScopeCollector.getInstance().computeSearchScope(container);
Collection<ScopeEntry> scopeEntries = createScopeEntries(scope);
ISearchQuery query;
if(searchKind.getSelectionIndex() == SIMPLE_SEARCH) {
@@ -1092,7 +1092,7 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
return false;
}
- Collection<IResource> scope = ScopeCollector.getInstance().computeSearchScope(container);
+ Collection<URI> scope = ScopeCollector.getInstance().computeSearchScope(container);
Collection<ScopeEntry> scopeEntries = createScopeEntries(scope);
AbstractPapyrusQuery query;
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/results/PapyrusSearchResult.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/results/PapyrusSearchResult.java
index 5b07cce5762..ab64b08cc8e 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/results/PapyrusSearchResult.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/results/PapyrusSearchResult.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.uml.search.ui.results;
@@ -22,9 +23,13 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
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.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.papyrus.infra.core.utils.EditorUtils;
import org.eclipse.papyrus.uml.search.ui.Activator;
import org.eclipse.papyrus.uml.search.ui.Messages;
import org.eclipse.papyrus.uml.search.ui.query.AbstractPapyrusQuery;
@@ -46,6 +51,7 @@ import org.eclipse.ui.ide.ResourceUtil;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Property;
+import com.google.common.base.Objects;
import com.swtdesigner.ResourceManager;
public class PapyrusSearchResult extends AbstractTextSearchResult implements IEditorMatchAdapter, IFileMatchAdapter {
@@ -105,7 +111,7 @@ public class PapyrusSearchResult extends AbstractTextSearchResult implements IEd
for(AbstractResultEntry modelMatch : allMatches) {
Object element = modelMatch.getElement();
if(element instanceof ScopeEntry) {
- if(((ScopeEntry)element).getResource().equals(file)) {
+ if(file.equals(getWorkspaceResource((ScopeEntry) element))) {
results.add(modelMatch);
}
}
@@ -115,10 +121,23 @@ public class PapyrusSearchResult extends AbstractTextSearchResult implements IEd
return results.toArray(arrayResult);
}
+ protected IResource getWorkspaceResource(ScopeEntry scopeEntry) {
+ IResource result = null;
+
+ URI uri = scopeEntry.getResourceURI();
+ if((uri != null) && uri.isPlatformResource()) {
+ String path = uri.toPlatformString(true);
+ result = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
+ }
+
+ return result;
+ }
+
public IFile getFile(Object element) {
if(element instanceof ScopeEntry) {
- if(((ScopeEntry)element).getResource() instanceof IFile) {
- return (IFile)((ScopeEntry)element).getResource();
+ IResource resource = getWorkspaceResource((ScopeEntry) element);
+ if(resource instanceof IFile) {
+ return (IFile)resource;
}
}
return null;
@@ -128,9 +147,7 @@ public class PapyrusSearchResult extends AbstractTextSearchResult implements IEd
if(match instanceof AbstractResultEntry) {
Object element = match.getElement();
if(element instanceof ScopeEntry) {
- ((ScopeEntry)element).getResource();
-
- if(((ScopeEntry)element).getResource().equals(ResourceUtil.getResource(editor.getEditorInput()))) {
+ if(Objects.equal(EditorUtils.getResourceURI(editor), ((ScopeEntry) element).getResourceURI())) {
return true;
}
}
@@ -229,7 +246,7 @@ public class PapyrusSearchResult extends AbstractTextSearchResult implements IEd
for(AbstractResultEntry modelMatch : allMatches) {
Object element = modelMatch.getElement();
if(element instanceof ScopeEntry) {
- if(((ScopeEntry)element).getResource().equals(ResourceUtil.getResource(editor.getEditorInput()))) {
+ if(((ScopeEntry)element).getResourceURI().equals(EditorUtils.getResourceURI(editor))) {
results.add(modelMatch);
}
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/StereotypeCollector.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/StereotypeCollector.java
index 329e278692a..09e2def3e46 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/StereotypeCollector.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/StereotypeCollector.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.uml.stereotypecollector;
@@ -20,7 +21,6 @@ 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;
@@ -37,7 +37,6 @@ import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.papyrus.infra.emf.utils.BusinessModelResolver;
import org.eclipse.papyrus.infra.onefile.model.IPapyrusFile;
-import org.eclipse.papyrus.views.search.utils.ModelUtils;
import org.eclipse.search.ui.ISearchPageContainer;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.uml2.uml.Classifier;
@@ -47,21 +46,13 @@ import org.eclipse.uml2.uml.Stereotype;
public class StereotypeCollector implements IStereotypeCollector {
- private static StereotypeCollector instance = null;
+ private static final StereotypeCollector instance = new StereotypeCollector();
private StereotypeCollector() {
super();
}
public final static StereotypeCollector getInstance() {
-
- if(StereotypeCollector.instance == null) {
- synchronized(StereotypeCollector.class) {
- if(StereotypeCollector.instance == null) {
- StereotypeCollector.instance = new StereotypeCollector();
- }
- }
- }
return StereotypeCollector.instance;
}
@@ -71,10 +62,9 @@ public class StereotypeCollector implements IStereotypeCollector {
Set<Profile> profiles = new HashSet<Profile>();
- Set<IResource> umlResources = new HashSet<IResource>();
+ Set<URI> umlResources = new HashSet<URI>();
if(container == null) {
- //Worksapce scope
umlResources.addAll(createWorkspaceScope());
} else {
@@ -120,8 +110,7 @@ public class StereotypeCollector implements IStereotypeCollector {
}
}
- for(IResource umlRes : umlResources) {
- URI uri = URI.createPlatformResourceURI(umlRes.getFullPath().toString(), true);
+ for(URI uri : umlResources) {
ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet.getResource(uri, true);
@@ -206,10 +195,10 @@ public class StereotypeCollector implements IStereotypeCollector {
* @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();
@@ -225,10 +214,10 @@ public class StereotypeCollector implements IStereotypeCollector {
Object element = BusinessModelResolver.getInstance().getBusinessModel(object);
if(element instanceof EObject) {
- Resource eResource = ((EObject)element).eResource();
- IFile resource = ModelUtils.getIFile(eResource);
- if(resource != null) {
- results.add(resource);
+ // CDO resource *are* EObjects
+ Resource eResource = (element instanceof Resource) ? (Resource) element : ((EObject)element).eResource();
+ if(eResource != null) {
+ results.add(eResource.getURI());
} else {
//Do a workspace search instead
@@ -253,8 +242,8 @@ public class StereotypeCollector implements IStereotypeCollector {
* @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);
@@ -273,8 +262,8 @@ public class StereotypeCollector implements IStereotypeCollector {
* @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) {
@@ -298,7 +287,7 @@ public class StereotypeCollector implements IStereotypeCollector {
* @return
* the found Papyrus models
*/
- protected Collection<IResource> findUMLModels(IResource res) {
+ protected Collection<URI> findUMLModels(IResource res) {
UMLResourceVisitor visitor = new UMLResourceVisitor();
try {
res.accept(visitor, IResource.DEPTH_INFINITE);
@@ -306,7 +295,7 @@ public class StereotypeCollector implements IStereotypeCollector {
org.eclipse.papyrus.uml.search.ui.Activator.log.warn(Messages.StereotypeCollector_0 + res);
}
- return visitor.getParticipants();
+ return visitor.getParticipantURIs();
}
/**
@@ -315,7 +304,7 @@ public class StereotypeCollector implements IStereotypeCollector {
* @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/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/UMLResourceVisitor.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/UMLResourceVisitor.java
index a5ca8a3f4de..2c85c2ef447 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/UMLResourceVisitor.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/UMLResourceVisitor.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.uml.stereotypecollector;
@@ -29,11 +30,11 @@ import org.eclipse.emf.common.util.URI;
*/
public class UMLResourceVisitor implements IResourceProxyVisitor {
- private Collection<IResource> participants;
+ private Collection<URI> participantURIs;
public UMLResourceVisitor() {
super();
- this.participants = new HashSet<IResource>();
+ this.participantURIs = new HashSet<URI>();
}
public boolean visit(IResourceProxy proxy) throws CoreException {
@@ -44,7 +45,7 @@ public class UMLResourceVisitor implements IResourceProxyVisitor {
URI uri = URI.createPlatformResourceURI(resource.getFullPath().toString(), true);
if("uml".equals(uri.fileExtension())) { //$NON-NLS-1$
- participants.add(resource);
+ participantURIs.add(uri);
}
@@ -55,8 +56,8 @@ public class UMLResourceVisitor 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/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