Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2013-07-11 09:31:02 +0000
committercletavernie2013-07-11 09:31:02 +0000
commitd6539eb0fde54d7b652e4099d99e79f6bd149071 (patch)
tree57edd04038787c5711245030a59a3c0dc20595d1 /plugins/views/org.eclipse.papyrus.views.search
parentd12d7dff848e88655e0d4241a9b7b96c06975ac8 (diff)
downloadorg.eclipse.papyrus-d6539eb0fde54d7b652e4099d99e79f6bd149071.tar.gz
org.eclipse.papyrus-d6539eb0fde54d7b652e4099d99e79f6bd149071.tar.xz
org.eclipse.papyrus-d6539eb0fde54d7b652e4099d99e79f6bd149071.zip
[SVN] Move the search plug-ins to their final location
Diffstat (limited to 'plugins/views/org.eclipse.papyrus.views.search')
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/.classpath7
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/.project28
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/.settings/org.eclipse.jdt.core.prefs11
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/META-INF/MANIFEST.MF30
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/about.html28
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/build.properties7
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/plugin.properties2
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/Activator.java67
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/Messages.java34
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/messages.properties3
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/regex/PatternHelper.java99
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/AbstractResultEntry.java178
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/AttributeMatch.java119
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/ModelElementMatch.java70
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/ModelMatch.java29
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/ResultEntry.java68
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/ViewerMatch.java87
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/IScopeCollector.java37
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/ResourceVisitor.java71
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/ScopeCollector.java259
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/ScopeEntry.java210
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/utils/MatchUtils.java83
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/utils/ModelUtils.java51
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/validator/IParticipantValidator.java38
-rw-r--r--plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/validator/ParticipantValidator.java71
25 files changed, 1687 insertions, 0 deletions
diff --git a/plugins/views/org.eclipse.papyrus.views.search/.classpath b/plugins/views/org.eclipse.papyrus.views.search/.classpath
new file mode 100644
index 00000000000..da1049abda9
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src/"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/views/org.eclipse.papyrus.views.search/.project b/plugins/views/org.eclipse.papyrus.views.search/.project
new file mode 100644
index 00000000000..957e039a408
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.views.search</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/views/org.eclipse.papyrus.views.search/.settings/org.eclipse.jdt.core.prefs b/plugins/views/org.eclipse.papyrus.views.search/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..060c5ee3d2e
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/plugins/views/org.eclipse.papyrus.views.search/META-INF/MANIFEST.MF b/plugins/views/org.eclipse.papyrus.views.search/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..19886bf244b
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/META-INF/MANIFEST.MF
@@ -0,0 +1,30 @@
+Manifest-Version: 1.0
+Require-Bundle: org.eclipse.ui;bundle-version="3.105.0",
+ org.eclipse.core.runtime,
+ org.eclipse.papyrus.infra.core;bundle-version="0.10.1",
+ org.eclipse.emf;bundle-version="2.6.0",
+ org.eclipse.core.resources;bundle-version="3.8.100",
+ org.eclipse.emf.common;bundle-version="2.9.0",
+ org.eclipse.emf.ecore;bundle-version="2.9.0",
+ org.eclipse.search;bundle-version="3.8.100",
+ org.eclipse.papyrus.infra.onefile;bundle-version="0.10.1",
+ org.eclipse.papyrus.infra.emf;bundle-version="0.10.1",
+ org.eclipse.ui.ide,
+ org.eclipse.papyrus.infra.core.log;bundle-version="0.10.1",
+ org.eclipse.papyrus.infra.services.labelprovider;bundle-version="0.10.1",
+ org.eclipse.papyrus.infra.services.openelement;bundle-version="0.10.1"
+Export-Package: org.eclipse.papyrus.views.search.regex,
+ org.eclipse.papyrus.views.search.results,
+ org.eclipse.papyrus.views.search.scope,
+ org.eclipse.papyrus.views.search.utils,
+ org.eclipse.papyrus.views.search.validator
+Bundle-Vendor: %vendorName
+Bundle-ActivationPolicy: lazy
+Bundle-Version: 0.10.1.qualifier
+Bundle-Name: %pluginName
+Bundle-Localization: plugin
+Bundle-ManifestVersion: 2
+Bundle-Activator: org.eclipse.papyrus.views.search.Activator
+Bundle-SymbolicName: org.eclipse.papyrus.views.search;singleton:=true
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+
diff --git a/plugins/views/org.eclipse.papyrus.views.search/about.html b/plugins/views/org.eclipse.papyrus.views.search/about.html
new file mode 100644
index 00000000000..5ddc72c177f
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>November 20, 2008</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p>
+
+</body>
+</html> \ No newline at end of file
diff --git a/plugins/views/org.eclipse.papyrus.views.search/build.properties b/plugins/views/org.eclipse.papyrus.views.search/build.properties
new file mode 100644
index 00000000000..1b08f841b5e
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/build.properties
@@ -0,0 +1,7 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ about.html,\
+ plugin.properties
+src.includes = about.html
diff --git a/plugins/views/org.eclipse.papyrus.views.search/plugin.properties b/plugins/views/org.eclipse.papyrus.views.search/plugin.properties
new file mode 100644
index 00000000000..bae6446b0a9
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/plugin.properties
@@ -0,0 +1,2 @@
+pluginName=Papyrus Search (Incubation)
+vendorName=Eclipse Modeling Project \ No newline at end of file
diff --git a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/Activator.java b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/Activator.java
new file mode 100644
index 00000000000..235d04812f0
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/Activator.java
@@ -0,0 +1,67 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.search;
+
+import org.eclipse.papyrus.infra.core.log.LogHelper;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle.
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.views.search"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ public static LogHelper log;
+
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
+ * )
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ log = new LogHelper(this);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
+ * )
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/Messages.java b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/Messages.java
new file mode 100644
index 00000000000..8d38f665efb
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/Messages.java
@@ -0,0 +1,34 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.search;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.views.search.messages"; //$NON-NLS-1$
+
+ public static String ScopeCollector_0;
+
+ public static String ScopeEntry_0;
+
+ public static String ScopeEntry_1;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/messages.properties b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/messages.properties
new file mode 100644
index 00000000000..d87d91eeb45
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/messages.properties
@@ -0,0 +1,3 @@
+ScopeCollector_0=An error occured while trying to find models to search in from root :
+ScopeEntry_0=Failed to create and start servicesRegistry
+ScopeEntry_1=Failed to open ModelSet for resource:
diff --git a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/regex/PatternHelper.java b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/regex/PatternHelper.java
new file mode 100644
index 00000000000..2ad1497849b
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/regex/PatternHelper.java
@@ -0,0 +1,99 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.search.regex;
+
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ *
+ * Singleton helper class used to find pattern queries in strings
+ *
+ */
+public class PatternHelper {
+
+ private static PatternHelper instance = null;
+
+ private PatternHelper() {
+ super();
+ }
+
+ /**
+ * Singleton
+ *
+ * @return the helper
+ */
+ public final static PatternHelper getInstance() {
+
+ if(PatternHelper.instance == null) {
+ synchronized(PatternHelper.class) {
+ if(PatternHelper.instance == null) {
+ PatternHelper.instance = new PatternHelper();
+ }
+ }
+ }
+ return PatternHelper.instance;
+ }
+
+ /**
+ * Create a pattern
+ *
+ * @param query
+ * the query text
+ * @param isCaseSensitive
+ * if it is a case sensitive pattern
+ * @param isRegularExpression
+ * if it i a regular expression pattern
+ * @return
+ * the pattern corresponding to the query text and the parameters
+ * @throws PatternSyntaxException
+ */
+ public Pattern createPattern(String query, boolean isCaseSensitive, boolean isRegularExpression) throws PatternSyntaxException {
+ int options = Pattern.MULTILINE;
+
+ if(!isRegularExpression) {
+ // query = ".*" + Pattern.quote(query); //$NON-NLS-1$
+ query = Pattern.quote(query); //$NON-NLS-1$
+ }
+
+ if(!isCaseSensitive) {
+ options |= Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE;
+ }
+
+ Pattern pattern = Pattern.compile(query, options);
+ return pattern;
+
+ }
+
+ // /**
+ // * Check whether a string matches a certain pattern in a matcher
+ // *
+ // * @param m
+ // * the matcher
+ // * @param isRegularExpression
+ // * specify if it is a regular expression pattern
+ // * @return
+ // * true if the text matches the pattern, else false
+ // */
+ // public boolean evaluate(Matcher m, boolean isRegularExpression) {
+ //
+ //
+ // if(isRegularExpression) {
+ // return m.matches();
+ // } else {
+ // return m.lookingAt();
+ // }
+ // }
+
+}
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
new file mode 100644
index 00000000000..f4cc60bec0f
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/AbstractResultEntry.java
@@ -0,0 +1,178 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.search.results;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.services.openelement.service.OpenElementService;
+import org.eclipse.papyrus.views.search.scope.ScopeEntry;
+import org.eclipse.search.ui.text.Match;
+import org.eclipse.search.ui.text.MatchFilter;
+import org.eclipse.ui.PartInitException;
+
+/**
+ *
+ * Abstract implementation of Result entry. A ResultEntry is an entry that will appear in the result of a search. It provides a tree structure.
+ * It is abstract because entries can be real matches i.e. {@see ModelMatch} or entries shown for hierarchical reasons i.e. {@see ResultEntry}.
+ *
+ */
+public abstract class AbstractResultEntry extends Match {
+
+ /**
+ * The source element that raised a match
+ */
+ protected Object source;
+
+ /**
+ * The parent of this result entry in the hierarchy
+ */
+ protected Object parent;
+
+ /**
+ * Used to specify offset and length of {@link Match} when these attributes are not meaningful
+ */
+ final protected static int UNSPECIFIED = -1;
+
+ /**
+ * Every implementation of {@link AbstractResultEntry} must implement this to define what should be displayed in labelproviders
+ *
+ * @return
+ * the element to display in labelproviders
+ */
+ public abstract Object elementToDisplay();
+
+ /**
+ * Every implementation of {@link AbstractResultEntry} must implement this to define what element is to give to the {@link OpenElementService}
+ *
+ * @return
+ * the element to open with {@link OpenElementService}
+ */
+ public abstract Object openElement(OpenElementService service) throws ServiceException, PartInitException;
+
+ /**
+ * Every implementation of {@link AbstractResultEntry} must implement this to define what element is to be analyzed by {@link MatchFilter}(s)
+ *
+ * @return
+ * the element to analyze to filter matches
+ */
+ public abstract Object elementToCheckFilterFor();
+
+ /**
+ * Compute the parent hierarchy of parents of a element in a model
+ *
+ * @param child
+ * the element to search parents for
+ * @param scopeEntry
+ * the {@link ScopeEntry} corresponding to the resource that contains the element that matches
+ */
+ protected void recursiveHierarchy(AbstractResultEntry child, ScopeEntry scopeEntry) {
+ if(child.getSource() instanceof EObject) {
+ EObject potentialParent = ((EObject)child.getSource()).eContainer();
+
+ if(potentialParent != null) {
+ ResultEntry theParent = new ResultEntry(potentialParent, scopeEntry);
+ child.setParent(theParent);
+ recursiveHierarchy(theParent, scopeEntry);
+ } else {
+ ResultEntry theParent = new ResultEntry(scopeEntry.getResource(), scopeEntry);
+ child.setParent(theParent);
+ }
+ }
+ }
+
+ protected AbstractResultEntry getLastParent(AbstractResultEntry child, ScopeEntry scopeEntry) {
+ if(child.getSource() instanceof EObject) {
+
+
+ EObject potentialParent = ((EObject)child.getSource()).eContainer();
+ ResultEntry theParent = null;
+
+ while(potentialParent != null) {
+ theParent = new ResultEntry(potentialParent, scopeEntry);
+ theParent.setParent(new ResultEntry(scopeEntry.getResource(), scopeEntry));
+
+ potentialParent = potentialParent.eContainer();
+ }
+
+ if(theParent == null) {
+
+ theParent = new ResultEntry(scopeEntry.getResource(), scopeEntry);
+
+ }
+ return theParent;
+
+ }
+
+ return null;
+
+ }
+
+ /**
+ * It is a really important override that used to not duplicate elements in the result hierarchy. Extensions of {@link AbstractResultEntry} may
+ * specialize this method
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ *
+ * @param obj
+ * @return
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if(obj instanceof AbstractResultEntry) {
+ if(((AbstractResultEntry)obj).getSource().equals(this.source)) {
+ if(((AbstractResultEntry)obj).getOffset() == this.getOffset()) {
+ if(((AbstractResultEntry)obj).getLength() == this.getLength()) {
+ return true;
+ }
+ }
+ }
+ return false;
+
+ }
+ return super.equals(obj);
+ }
+
+ /**
+ * @see Match#Match(Object, int, int)
+ *
+ * @param offset
+ *
+ * @param lenght
+ *
+ * @param source
+ * the element that raised the match
+ * @param scopeEntry
+ * the {@link ScopeEntry} that correspond to the resource that contains the element that raised the match
+ */
+ public AbstractResultEntry(int offset, int lenght, Object source, ScopeEntry scopeEntry) {
+ super(scopeEntry, offset, lenght);
+ this.source = source;
+ }
+
+ public Object getSource() {
+ return source;
+ }
+
+ public void setSource(Object source) {
+ this.source = source;
+ }
+
+ public Object getParent() {
+ return parent;
+ }
+
+ public void setParent(Object parent) {
+ this.parent = parent;
+ }
+}
diff --git a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/AttributeMatch.java b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/AttributeMatch.java
new file mode 100644
index 00000000000..a15e90b3706
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/AttributeMatch.java
@@ -0,0 +1,119 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.search.results;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.services.openelement.service.OpenElementService;
+import org.eclipse.papyrus.views.search.scope.ScopeEntry;
+import org.eclipse.ui.PartInitException;
+
+/**
+ *
+ * A match raised by the value of an attribute
+ *
+ */
+public class AttributeMatch extends ModelMatch {
+
+ /**
+ * The element containing the value of the attribute that matches
+ */
+ protected Object target;
+
+ /**
+ * Similar to {@link AbstractResultEntry} but adds an information about which attribute raised the match and which element contains the value of
+ * the attribute that matches
+ *
+ * @param offset
+ * @param lenght
+ * @param target
+ * the element containing the value of the attribute that matches
+ * @param scopeEntry
+ * @param attribute
+ * the attribute that raised the match
+ */
+ public AttributeMatch(int offset, int lenght, Object target, ScopeEntry scopeEntry, Object attribute) {
+ super(offset, lenght, attribute, scopeEntry);
+ this.target = target;
+ this.parent = new ModelElementMatch(target, scopeEntry);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#equals(java.lang.Object)
+ * In addition, it checks if target is the same as well.
+ *
+ * @param obj
+ * @return
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if(obj instanceof AttributeMatch) {
+ if(super.equals(obj)) {
+ if(((AttributeMatch)obj).getTarget().equals(this.target)) {
+ return true;
+ }
+ }
+ return false;
+
+ } else {
+ return false;
+ }
+ }
+
+ public Object getTarget() {
+ return target;
+ }
+
+ public void setTarget(Object target) {
+ this.target = target;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#elementToDisplay()
+ *
+ * @return
+ */
+ @Override
+ public Object elementToDisplay() {
+ return this;
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#elementToCheckFilterFor()
+ *
+ * @return
+ */
+ @Override
+ public Object elementToCheckFilterFor() {
+ return target;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#openElement()
+ *
+ * @return
+ */
+ @Override
+ public Object openElement(OpenElementService service) throws ServiceException, PartInitException {
+ if(target instanceof EObject) {
+ return service.openSemanticElement((EObject)target);
+ }
+ return null;
+ }
+}
diff --git a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/ModelElementMatch.java b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/ModelElementMatch.java
new file mode 100644
index 00000000000..60ed57f2fcc
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/ModelElementMatch.java
@@ -0,0 +1,70 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.search.results;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.services.openelement.service.OpenElementService;
+import org.eclipse.papyrus.views.search.scope.ScopeEntry;
+import org.eclipse.ui.PartInitException;
+
+/**
+ *
+ * A match raised by an element in a model
+ *
+ */
+public class ModelElementMatch extends ModelMatch {
+
+ public ModelElementMatch(Object source, ScopeEntry scopeEntry) {
+ super(UNSPECIFIED, UNSPECIFIED, source, scopeEntry);
+ recursiveHierarchy(this, scopeEntry);
+ // this.parent = new ResultEntry(scopeEntry.getResource(), scopeEntry);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#elementToDisplay()
+ *
+ * @return
+ */
+ @Override
+ public Object elementToDisplay() {
+ return source;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#elementToCheckFilterFor()
+ *
+ * @return
+ */
+ @Override
+ public Object elementToCheckFilterFor() {
+ return source;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#openElement()
+ *
+ * @return
+ */
+ @Override
+ public Object openElement(OpenElementService service) throws ServiceException, PartInitException {
+ if(source instanceof EObject) {
+ return service.openSemanticElement((EObject)source);
+ }
+ return null;
+ }
+}
diff --git a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/ModelMatch.java b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/ModelMatch.java
new file mode 100644
index 00000000000..538966607f8
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/ModelMatch.java
@@ -0,0 +1,29 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.search.results;
+
+import org.eclipse.papyrus.views.search.scope.ScopeEntry;
+
+/**
+ *
+ * A real result entry in a model
+ *
+ */
+public abstract class ModelMatch extends AbstractResultEntry {
+
+ public ModelMatch(int offset, int lenght, Object source, ScopeEntry scopeEntry) {
+ super(offset, lenght, source, scopeEntry);
+ }
+
+}
diff --git a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/ResultEntry.java b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/ResultEntry.java
new file mode 100644
index 00000000000..cd93a65c61d
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/ResultEntry.java
@@ -0,0 +1,68 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.search.results;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.services.openelement.service.OpenElementService;
+import org.eclipse.papyrus.views.search.scope.ScopeEntry;
+import org.eclipse.ui.PartInitException;
+
+/**
+ *
+ * Implements a result entry that doesn't correspond to a real match. it is used to create hierarchies
+ *
+ */
+public class ResultEntry extends AbstractResultEntry {
+
+ public ResultEntry(Object source, ScopeEntry scopeEntry) {
+ super(UNSPECIFIED, UNSPECIFIED, source, scopeEntry);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#elementToDisplay()
+ *
+ * @return
+ */
+ @Override
+ public Object elementToDisplay() {
+ return source;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#elementToCheckFilterFor()
+ *
+ * @return
+ */
+ @Override
+ public Object elementToCheckFilterFor() {
+ return source;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#openElement()
+ *
+ * @return
+ */
+ @Override
+ public Object openElement(OpenElementService service) throws ServiceException, PartInitException {
+ if(source instanceof EObject) {
+ return service.openElement((EObject)source);
+ }
+ return null;
+ }
+}
diff --git a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/ViewerMatch.java b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/ViewerMatch.java
new file mode 100644
index 00000000000..06c152c236d
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/ViewerMatch.java
@@ -0,0 +1,87 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.search.results;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.services.openelement.service.OpenElementService;
+import org.eclipse.papyrus.views.search.scope.ScopeEntry;
+import org.eclipse.ui.PartInitException;
+
+/**
+ *
+ * A match raised by a viewer (i.e. something that is a view of a real match) in a model
+ *
+ */
+public class ViewerMatch extends AbstractResultEntry {
+
+ /**
+ * The model element that is represented by the viewer
+ */
+ protected Object semanticElement;
+
+ public ViewerMatch(Object source, ScopeEntry scopeEntry, Object semanticElement) {
+ super(UNSPECIFIED, UNSPECIFIED, source, scopeEntry);
+ this.semanticElement = semanticElement;
+
+ this.parent = getLastParent(this, scopeEntry);
+ // this.parent = new ResultEntry(scopeEntry.getResource(), scopeEntry);
+
+ }
+
+ public Object getSemanticElement() {
+ return semanticElement;
+ }
+
+ public void setSemanticElement(Object semanticElement) {
+ this.semanticElement = semanticElement;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#elementToDisplay()
+ *
+ * @return
+ */
+ @Override
+ public Object elementToDisplay() {
+ return source;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#elementToCheckFilterFor()
+ *
+ * @return
+ */
+ @Override
+ public Object elementToCheckFilterFor() {
+ return semanticElement;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#openElement()
+ *
+ * @return
+ */
+ @Override
+ public Object openElement(OpenElementService service) throws ServiceException, PartInitException {
+ if(source instanceof EObject) {
+ return service.openElement((EObject)source);
+ }
+ 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
new file mode 100644
index 00000000000..9d4d920e169
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/IScopeCollector.java
@@ -0,0 +1,37 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.search.scope;
+
+import java.util.Collection;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.search.ui.ISearchPageContainer;
+
+/**
+ *
+ * Interface that must be implemented to generate scope (i.e. list of {@link IResource}) from a {@link ISearchPageContainer}
+ *
+ */
+public interface IScopeCollector {
+
+ /**
+ * Find a collection of {@link IResource} that can be processed from those available in the container
+ *
+ * @param container
+ * the container to search in
+ * @return
+ * a collection of {@link IResource} that can be processed
+ */
+ public Collection<IResource> 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
new file mode 100644
index 00000000000..61d396c9c37
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/ResourceVisitor.java
@@ -0,0 +1,71 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.search.scope;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceProxy;
+import org.eclipse.core.resources.IResourceProxyVisitor;
+import org.eclipse.core.runtime.CoreException;
+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.views.search.utils.ModelUtils;
+
+/**
+ *
+ * Implements a visitor that goes through a hierarchy of Iresource from a root and collect only those that can be processed for search
+ *
+ */
+public class ResourceVisitor implements IResourceProxyVisitor {
+
+ private List<IResource> participants;
+
+ public ResourceVisitor() {
+ super();
+ this.participants = new ArrayList<IResource>();
+ }
+
+ public boolean visit(IResourceProxy proxy) throws CoreException {
+ switch(proxy.getType()) {
+ case IResource.FILE:
+ IResource resource = proxy.requestResource();
+
+ URI uri = URI.createPlatformResourceURI(resource.getFullPath().toString(), true);
+
+ if("di".equals(uri.fileExtension())) { //$NON-NLS-1$
+ //Verify that it is a true papyrus model
+ try {
+ ModelSet modelSet = ModelUtils.openFile(resource);
+ modelSet.unload();
+ participants.add(resource);
+ } catch (ModelMultiException e) {
+ }
+
+ }
+
+ break;
+ default:
+ break;
+ }
+ return true;
+ }
+
+ public List<IResource> getParticipants() {
+ return participants;
+ }
+
+}
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
new file mode 100644
index 00000000000..ddfdf7f4431
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/ScopeCollector.java
@@ -0,0 +1,259 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.search.scope;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+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.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.infra.core.resource.ModelMultiException;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.NotFoundException;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModel;
+import org.eclipse.papyrus.infra.emf.utils.BusinessModelResolver;
+import org.eclipse.papyrus.infra.onefile.model.IPapyrusFile;
+import org.eclipse.papyrus.views.search.Activator;
+import org.eclipse.papyrus.views.search.Messages;
+import org.eclipse.papyrus.views.search.utils.ModelUtils;
+import org.eclipse.search.ui.ISearchPageContainer;
+import org.eclipse.ui.IWorkingSet;
+
+public class ScopeCollector implements IScopeCollector {
+
+ private static ScopeCollector instance = null;
+
+ 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;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.views.search.scope.IScopeCollector#computeSearchScope(org.eclipse.search.ui.ISearchPageContainer)
+ *
+ * @param container
+ * @return
+ */
+ public Collection<IResource> computeSearchScope(ISearchPageContainer container) {
+
+ Set<IResource> results = new HashSet<IResource>();
+
+ if(container == null) {
+ //Worksapce scope
+ results.addAll(createWorkspaceScope());
+
+ } else {
+ switch(container.getSelectedScope()) {
+ case ISearchPageContainer.WORKSPACE_SCOPE:
+ {
+ results.addAll(createWorkspaceScope());
+ break;
+ }
+ case ISearchPageContainer.SELECTION_SCOPE:
+ {
+ ISelection selection = container.getSelection();
+
+ if(!selection.isEmpty()) {
+ if(selection instanceof IStructuredSelection) {
+ results.addAll(createSelectionScope((IStructuredSelection)selection));
+ } else {
+ //Do a workspace search instead
+ results.addAll(createWorkspaceScope());
+ }
+ } else {
+ //Do a workspace search instead
+ results.addAll(createWorkspaceScope());
+ }
+ break;
+ }
+ case ISearchPageContainer.SELECTED_PROJECTS_SCOPE:
+ {
+ String[] projects = container.getSelectedProjectNames();
+ results.addAll(createProjectsScope(projects));
+ break;
+ }
+ case ISearchPageContainer.WORKING_SET_SCOPE:
+ {
+ IWorkingSet[] workingSets = container.getSelectedWorkingSets();
+ results.addAll(createWorkingSetsScope(workingSets));
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
+ }
+
+ return results;
+
+ }
+
+ /**
+ * Create a scope when the container is ISearchPageContainer.SELECTION_SCOPE
+ *
+ * @param selection
+ * the selection of the container
+ * @return
+ * the scope
+ */
+ protected List<IResource> createSelectionScope(IStructuredSelection selection) {
+ List<IResource> results = new ArrayList<IResource>();
+
+ Iterator it = selection.iterator();
+ while(it.hasNext()) {
+ Object object = (Object)it.next();
+
+ if(object instanceof IPapyrusFile) {
+ results.add(((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) {
+ try {
+ ModelSet modelSet = ModelUtils.openFile(resource);
+ SashModel sashModel = (SashModel)modelSet.getModelChecked(SashModel.MODEL_ID);
+ IFile diResource = ModelUtils.getIFile(sashModel.getResource());
+ results.add((IFile)diResource);
+ modelSet.unload();
+ } catch (ModelMultiException e) {
+ //Do a workspace search instead
+ results.addAll(createWorkspaceScope());
+ } catch (NotFoundException e) {
+ //Do a workspace search instead
+ results.addAll(createWorkspaceScope());
+ }
+
+ } else {
+ //Do a workspace search instead
+ results.addAll(createWorkspaceScope());
+ }
+
+ } else {
+ //Do a workspace search instead
+ results.addAll(createWorkspaceScope());
+ }
+
+ }
+ }
+ return results;
+ }
+
+ /**
+ * Create a scope when the container is ISearchPageContainer.SELECTED_PROJECTS_SCOPE
+ *
+ * @param projects
+ * the selected scope
+ * @return
+ * the scope
+ */
+ protected List<IResource> createProjectsScope(String[] projects) {
+ List<IResource> results = new ArrayList<IResource>();
+
+ for(String projectName : projects) {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ if(project.isOpen()) {
+ results.addAll(findPapyrusModels(project));
+ }
+ }
+ return results;
+ }
+
+ /**
+ * Create a scope when the container is ISearchPageContainer.WORKING_SET_SCOPE
+ *
+ * @param workingSets
+ * the selected workingSets
+ * @return
+ * the scope
+ */
+ protected List<IResource> createWorkingSetsScope(IWorkingSet[] workingSets) {
+ List<IResource> results = new ArrayList<IResource>();
+
+ if(workingSets != null && workingSets.length > 0) {
+ for(IWorkingSet iWorkingSet : workingSets) {
+ for(IAdaptable element : iWorkingSet.getElements()) {
+ Object resource = element.getAdapter(IResource.class);
+ if(resource instanceof IResource) {
+ results.addAll(findPapyrusModels((IResource)resource));
+ }
+ }
+ }
+ }
+
+ return results;
+ }
+
+ /**
+ * Find all Papyrus models from a specific root
+ *
+ * @param res
+ * the root
+ * @return
+ * the found Papyrus models
+ */
+ protected List<IResource> findPapyrusModels(IResource res) {
+ ResourceVisitor visitor = new ResourceVisitor();
+ try {
+ res.accept(visitor, IResource.DEPTH_INFINITE);
+ } catch (CoreException e) {
+ Activator.log.warn(Messages.ScopeCollector_0 + res);
+ }
+
+ return visitor.getParticipants();
+ }
+
+ /**
+ * Create a scope when the container is ISearchPageContainer.WORKSPACE_SCOPE
+ *
+ * @return
+ * the scope
+ */
+ protected List<IResource> createWorkspaceScope() {
+
+ //Go through the workspace root
+ IResource root = ResourcesPlugin.getWorkspace().getRoot();
+
+ return findPapyrusModels(root);
+ }
+
+}
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
new file mode 100644
index 00000000000..b1a76dd602b
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/scope/ScopeEntry.java
@@ -0,0 +1,210 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.search.scope;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.eclipse.core.resources.IResource;
+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.ServiceUtils;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResourceInitializerService;
+import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
+import org.eclipse.papyrus.infra.services.labelprovider.service.impl.LabelProviderServiceImpl;
+import org.eclipse.papyrus.infra.services.openelement.service.OpenElementService;
+import org.eclipse.papyrus.infra.services.openelement.service.impl.OpenElementServiceImpl;
+import org.eclipse.papyrus.views.search.Activator;
+import org.eclipse.papyrus.views.search.Messages;
+import org.eclipse.papyrus.views.search.utils.ModelUtils;
+import org.eclipse.ui.IEditorPart;
+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;
+
+/**
+ *
+ * This class is used to aggregate information about the resource that contains the element that raised a match
+ *
+ */
+public class ScopeEntry {
+
+ /**
+ * The modelSet that contains the model element
+ */
+ private ModelSet modelSet;
+
+ /**
+ * The corresponding {@link ServicesRegistry}
+ */
+ private ServicesRegistry servicesRegistry;
+
+ /**
+ * The resource that contains the element that raised a match
+ */
+ private IResource resource;
+
+
+ public ScopeEntry(IResource resource) {
+ super();
+ this.resource = resource;
+ this.modelSet = getModelSet();
+ this.servicesRegistry = getServicesRegistry();
+ }
+
+ // public boolean isOpen() {
+ // return isOpen;
+ // }
+ //
+ //
+ // public void setOpen(boolean isOpen) {
+ // this.isOpen = isOpen;
+ // }
+
+ private Collection<IEditorPart> getEditors() {
+ Collection<IEditorPart> results = new HashSet<IEditorPart>();
+ IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
+ for(IWorkbenchWindow iWorkbenchWindow : windows) {
+ IWorkbenchPage[] pages = iWorkbenchWindow.getPages();
+ for(IWorkbenchPage iWorkbenchPage : pages) {
+ IEditorReference[] references = iWorkbenchPage.getEditorReferences();
+ for(IEditorReference ref : references) {
+ IEditorPart editor = ref.getEditor(true);
+ results.add(editor);
+ }
+ }
+ }
+
+ return results;
+ }
+
+ private ServicesRegistry createServicesRegistry() {
+
+ try {
+ ServicesRegistry serviceRegistry = new ServicesRegistry();
+ serviceRegistry.add(LabelProviderService.class, 10, new LabelProviderServiceImpl());
+ serviceRegistry.add(OpenElementService.class, 10, new OpenElementServiceImpl());
+ // PageIconRegistryServiceFactory factory = new PageIconRegistryServiceFactory();
+ // Object instance = factory.createServiceInstance();
+ // serviceRegistry.add(IPageIconsRegistry.class, 10, instance);
+ // serviceRegistry.add(IPageIconsRegistry.class, 10, new PageIconRegistryServiceFactory());
+ serviceRegistry.startRegistry();
+
+ return serviceRegistry;
+ } catch (ServiceException e) {
+ Activator.log.error(Messages.ScopeEntry_0, e);
+ }
+ return null;
+ }
+
+ public ModelSet getModelSet() {
+ //If null, try to find one or create one
+ if(modelSet == null) {
+ try {
+ modelSet = ServiceUtils.getInstance().getModelSet(getServicesRegistry());
+ } catch (ServiceException e) {
+ //Create one
+ try {
+ modelSet = ModelUtils.openFile(resource);
+ 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 + resource, modelMultiException);
+ } catch (ServiceMultiException e1) {
+ Activator.log.error(e1);
+ } catch (ServiceNotFoundException e1) {
+ Activator.log.error(e1);
+ }
+ }
+ }
+ return modelSet;
+ }
+
+ public void setModelSet(ModelSet modelSet) {
+ this.modelSet = modelSet;
+ }
+
+ private IEditorPart editorOnResource() {
+ Collection<IEditorPart> editors = getEditors();
+
+ for(IEditorPart editor : editors) {
+
+ if(editor != null) {
+ if(ResourceUtil.getResource(editor.getEditorInput()).equals(resource)) {
+ return editor;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private ServicesRegistry getUpdatedServiceRegistry() {
+ IEditorPart editor = editorOnResource();
+ if(editor != null) {
+
+ ServicesRegistry registry = (ServicesRegistry)editor.getAdapter(ServicesRegistry.class);
+
+ return registry;
+
+ }
+
+ return servicesRegistry;
+ }
+
+ public ServicesRegistry getServicesRegistry() {
+
+ if(servicesRegistry == null) {
+ //Try to find existing
+ ServicesRegistry registry = getUpdatedServiceRegistry();
+ if(registry != null) {
+ //If the OpenElementService is no yet available, we must start it
+ try {
+ registry.getService(OpenElementService.class);
+ } catch (ServiceException e) {
+ registry.add(OpenElementService.class, 10, new OpenElementServiceImpl());
+ }
+
+ servicesRegistry = registry;
+ // this.isOpen = true;
+
+ } else {
+ // this.isOpen = false;
+ servicesRegistry = createServicesRegistry();
+ }
+ }
+
+ return servicesRegistry;
+ }
+
+ public void setServicesRegistry(ServicesRegistry servicesRegistry) {
+ this.servicesRegistry = servicesRegistry;
+ }
+
+ public IResource getResource() {
+ return resource;
+ }
+
+ public void setResource(IResource resource) {
+ this.resource = resource;
+ }
+
+}
diff --git a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/utils/MatchUtils.java b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/utils/MatchUtils.java
new file mode 100644
index 00000000000..5a52dfaab2e
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/utils/MatchUtils.java
@@ -0,0 +1,83 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.search.utils;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.papyrus.views.search.results.AbstractResultEntry;
+import org.eclipse.search.ui.text.AbstractTextSearchResult;
+import org.eclipse.search.ui.text.Match;
+
+/**
+ *
+ * Util class to manipulate ModelMatches
+ *
+ */
+public class MatchUtils {
+
+ /**
+ * Get all matches from a search result whose element as a specific type
+ *
+ * @param searchResult
+ * @param type
+ * the type of the element
+ * @param checkFiltered
+ * whether filtered matches must be considered are not
+ * @return
+ */
+ public static Set<AbstractResultEntry> getMatches(AbstractTextSearchResult searchResult, Class<?> type, boolean checkFiltered) {
+ Set<AbstractResultEntry> results = new HashSet<AbstractResultEntry>();
+
+ List<Object> elementList = Arrays.asList(searchResult.getElements());
+
+ for(Object element : elementList) {
+ for(Match match : searchResult.getMatches(element)) {
+ if(match instanceof AbstractResultEntry) {
+ boolean toAdd = false;
+ if(checkFiltered) {
+ if(!match.isFiltered()) {
+ toAdd = true;
+ }
+ } else {
+ toAdd = true;
+ }
+
+ if(toAdd) {
+ if(type.isAssignableFrom(((AbstractResultEntry)match).elementToCheckFilterFor().getClass())) {
+ results.add((AbstractResultEntry)match);
+ }
+ }
+ }
+ }
+ }
+
+ return results;
+ }
+
+ /**
+ * Get all matches from a search result whose element as a specific type
+ *
+ * @param searchResult
+ * @param checkFiltered
+ * whether filtered matches must be considered are not
+ *
+ * @return
+ */
+ public static Set<AbstractResultEntry> getMatches(AbstractTextSearchResult searchResult, boolean checkFiltered) {
+ return getMatches(searchResult, Object.class, checkFiltered);
+ }
+}
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
new file mode 100644
index 00000000000..bfc485fcde5
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/utils/ModelUtils.java
@@ -0,0 +1,51 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+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) {
+ ModelSet modelSet = new ModelSet();
+ ModelsReader reader = new ModelsReader();
+ reader.readModel(modelSet);
+ modelSet.loadModels((IFile)object);
+ 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;
+ }
+}
diff --git a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/validator/IParticipantValidator.java b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/validator/IParticipantValidator.java
new file mode 100644
index 00000000000..f4e3547728b
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/validator/IParticipantValidator.java
@@ -0,0 +1,38 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.search.validator;
+
+import java.util.Collection;
+
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ *
+ * Interface to implement to have a specific content validator. It is used to select only the elements that will be used to find patterns.
+ *
+ */
+public interface IParticipantValidator {
+
+ /**
+ * Return the elements that will participate (i.e. the participants) in the search query based on a list of types
+ *
+ * @param root
+ * all the children and itself will be check against the list of types
+ * @param participantsTypes
+ * the types of the wanted participants
+ * @return
+ * the elements that are of wanted types
+ */
+ public Collection<? extends Object> getParticipants(EObject root, Object[] participantsTypes);
+}
diff --git a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/validator/ParticipantValidator.java b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/validator/ParticipantValidator.java
new file mode 100644
index 00000000000..ddc4a7825df
--- /dev/null
+++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/validator/ParticipantValidator.java
@@ -0,0 +1,71 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.search.validator;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ *
+ * A generic implementation of participant validator that works on EMF basis
+ *
+ */
+public class ParticipantValidator implements IParticipantValidator {
+
+ private static ParticipantValidator instance = null;
+
+ private ParticipantValidator() {
+ super();
+ }
+
+ public final static ParticipantValidator getInstance() {
+
+ if(ParticipantValidator.instance == null) {
+ synchronized(ParticipantValidator.class) {
+ if(ParticipantValidator.instance == null) {
+ ParticipantValidator.instance = new ParticipantValidator();
+ }
+ }
+ }
+ return ParticipantValidator.instance;
+ }
+
+ public Collection<EObject> getParticipants(EObject root, Object[] participantsTypes) {
+
+ List<Object> participantsTypesList = Arrays.asList(participantsTypes);
+ List<EObject> results = new ArrayList<EObject>();
+
+ // Evaluate root...
+ if(participantsTypesList.contains(root.eClass())) {
+ results.add(root);
+ }
+
+ // ... and all its content
+ TreeIterator<EObject> it = root.eAllContents();
+ while(it.hasNext()) {
+ EObject modelElement = (EObject)it.next();
+ //Check that metaclass of this element is a supported metaclass
+ if(participantsTypesList.contains(modelElement.eClass())) {
+ results.add(modelElement);
+ }
+ }
+
+ return results;
+ }
+}

Back to the top