diff options
author | cletavernie | 2013-07-11 09:32:16 +0000 |
---|---|---|
committer | cletavernie | 2013-07-11 09:32:16 +0000 |
commit | 1e5ae0cef628a00b6c3e5f210e90d14c2ce5f55b (patch) | |
tree | 1b2f154ba5803f99df1c673fa2701843f8ae9689 /plugins | |
parent | 9a0568a7778f0ef0f7dee5df9b683c366a9dc49a (diff) | |
download | org.eclipse.papyrus-1e5ae0cef628a00b6c3e5f210e90d14c2ce5f55b.tar.gz org.eclipse.papyrus-1e5ae0cef628a00b6c3e5f210e90d14c2ce5f55b.tar.xz org.eclipse.papyrus-1e5ae0cef628a00b6c3e5f210e90d14c2ce5f55b.zip |
[SVN] Move the search plug-ins to their final location
Diffstat (limited to 'plugins')
36 files changed, 3835 insertions, 0 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/.classpath b/plugins/uml/org.eclipse.papyrus.uml.search.ui/.classpath new file mode 100644 index 00000000000..da1049abda9 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/.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/uml/org.eclipse.papyrus.uml.search.ui/.project b/plugins/uml/org.eclipse.papyrus.uml.search.ui/.project new file mode 100644 index 00000000000..ae9fd8fd6a5 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.uml.search.ui</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/uml/org.eclipse.papyrus.uml.search.ui/.settings/org.eclipse.jdt.core.prefs b/plugins/uml/org.eclipse.papyrus.uml.search.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..060c5ee3d2e --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/.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/uml/org.eclipse.papyrus.uml.search.ui/META-INF/MANIFEST.MF b/plugins/uml/org.eclipse.papyrus.uml.search.ui/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..7ac51cb9c3a --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/META-INF/MANIFEST.MF @@ -0,0 +1,32 @@ +Manifest-Version: 1.0
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.search;bundle-version="3.8.0",
+ org.eclipse.papyrus.infra.core;bundle-version="0.10.1",
+ org.eclipse.core.resources;bundle-version="3.8.1",
+ org.eclipse.papyrus.editor;bundle-version="0.10.1",
+ org.eclipse.papyrus.views.search;bundle-version="0.10.1",
+ org.eclipse.papyrus.infra.onefile;bundle-version="0.10.1",
+ org.eclipse.emf;bundle-version="2.6.0",
+ org.eclipse.ui.ide;bundle-version="3.8.100",
+ org.eclipse.papyrus.infra.emf;bundle-version="0.10.1",
+ org.eclipse.emf.facet.infra.browser.uicore;bundle-version="0.3.0",
+ org.eclipse.papyrus.uml.tools;bundle-version="0.10.1",
+ org.eclipse.uml2.uml;bundle-version="4.0.100",
+ org.eclipse.papyrus.infra.services.viewersearch;bundle-version="0.10.1",
+ org.eclipse.papyrus.infra.services.openelement;bundle-version="0.10.1",
+ org.eclipse.papyrus.infra.core.log;bundle-version="0.10.1",
+ org.eclipse.jface,
+ org.eclipse.emf.transaction,
+ org.eclipse.papyrus.infra.services.labelprovider;bundle-version="0.10.1"
+Export-Package: org.eclipse.papyrus.uml.search.ui.providers
+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.uml.search.ui.Activator
+Bundle-SymbolicName: org.eclipse.papyrus.uml.search.ui;singleton:=true
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/about.html b/plugins/uml/org.eclipse.papyrus.uml.search.ui/about.html new file mode 100644 index 00000000000..5ddc72c177f --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/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 ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). 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, "Program" 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 ("Redistributor") 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/uml/org.eclipse.papyrus.uml.search.ui/build.properties b/plugins/uml/org.eclipse.papyrus.uml.search.ui/build.properties new file mode 100644 index 00000000000..7915e442db0 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/build.properties @@ -0,0 +1,9 @@ +source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ icons/,\
+ about.html,\
+ plugin.properties
+src.includes = about.html
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/icons/PapyrusSearch.png b/plugins/uml/org.eclipse.papyrus.uml.search.ui/icons/PapyrusSearch.png Binary files differnew file mode 100644 index 00000000000..877307424d4 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/icons/PapyrusSearch.png diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/icons/filter.png b/plugins/uml/org.eclipse.papyrus.uml.search.ui/icons/filter.png Binary files differnew file mode 100644 index 00000000000..576f1722074 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/icons/filter.png diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/plugin.properties b/plugins/uml/org.eclipse.papyrus.uml.search.ui/plugin.properties new file mode 100644 index 00000000000..bfb773f3019 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/plugin.properties @@ -0,0 +1,5 @@ +pluginName=Papyrus Search UI (Incubation)
+vendorName=Eclipse Modeling Project
+
+searchPageLabel=Papyrus Search
+SearchResultPageLabel=Papyrus Search Results
\ No newline at end of file diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/plugin.xml b/plugins/uml/org.eclipse.papyrus.uml.search.ui/plugin.xml new file mode 100644 index 00000000000..2837c7fa5f4 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/plugin.xml @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.search.searchPages">
+ <page
+ canSearchEnclosingProjects="true"
+ class="org.eclipse.papyrus.uml.search.ui.pages.PapyrusSearchPage"
+ enabled="true"
+ extensions="di:99"
+ icon="icons/PapyrusSearch.png"
+ id="org.eclipse.papyrus.search.ui.pages.PapyrusSearchPage"
+ label="%searchPageLabel"
+ showScopeSection="true">
+ </page>
+ </extension>
+ <extension
+ point="org.eclipse.search.searchResultViewPages">
+ <viewPage
+ class="org.eclipse.papyrus.uml.search.ui.pages.PapyrusSearchResultPage"
+ icon="icons/PapyrusSearch.png"
+ id="org.eclipse.papyrus.search.ui.pages.PapyrusSearchResultPage"
+ label="%SearchResultPageLabel"
+ searchResultClass="org.eclipse.papyrus.uml.search.ui.results.PapyrusSearchResult">
+ </viewPage>
+ </extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.papyrus.uml.search.ui.handlers.SearchCommandHandler"
+ commandId="org.eclipse.ui.edit.findReplace">
+ <activeWhen>
+ <or>
+ <with
+ variable="activeEditorId">
+ <equals
+ value="org.eclipse.papyrus.infra.core.papyrusEditor">
+ </equals>
+ </with>
+ </or>
+ </activeWhen>
+ </handler>
+ </extension>
+ <extension
+ point="org.eclipse.papyrus.infra.services.labelprovider.labelProvider">
+ <labelProvider
+ priority="10"
+ provider="org.eclipse.papyrus.uml.search.ui.providers.AttributeMatchLabelProvider">
+ </labelProvider>
+ </extension>
+ <extension
+ point="org.eclipse.core.runtime.adapters">
+ <factory
+ adaptableType="org.eclipse.core.runtime.IAdaptable"
+ class="org.eclipse.papyrus.uml.search.ui.adapter.PapyrusSearchAdapterFactory">
+ <adapter
+ type="org.eclipse.search.ui.ISearchPageScoreComputer">
+ </adapter>
+ </factory>
+ </extension>
+
+</plugin>
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/com/swtdesigner/ResourceManager.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/com/swtdesigner/ResourceManager.java new file mode 100644 index 00000000000..8e97c09fdb9 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/com/swtdesigner/ResourceManager.java @@ -0,0 +1,463 @@ +/***************************************************************************** + * 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 com.swtdesigner; + +import java.io.File; +import java.io.InputStream; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.resource.CompositeImageDescriptor; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.osgi.framework.Bundle; + +/** + * Utility class for managing OS resources associated with SWT/JFace controls such as colors, fonts, images, + * etc. + * + * !!! IMPORTANT !!! Application code must explicitly invoke the <code>dispose()</code> method to release the + * operating system resources managed by cached objects when those objects and OS resources are no longer + * needed (e.g. on application shutdown) + * + * This class may be freely distributed as part of any application or plugin. + * <p> + * Copyright (c) 2003 - 2007, Instantiations, Inc. <br> + * All Rights Reserved + * + * @author scheglov_ke + * @author Dan Rubel + */ +public class ResourceManager extends SWTResourceManager { + + //////////////////////////////////////////////////////////////////////////// + // + // Image + // + //////////////////////////////////////////////////////////////////////////// + /** The m_descriptor image map. */ + private static Map<ImageDescriptor, Image> m_descriptorImageMap = new HashMap<ImageDescriptor, Image>(); + + /** + * Returns an {@link ImageDescriptor} stored in the file at the specified path relative to the specified + * class. + * + * @param clazz + * the {@link Class} relative to which to find the image descriptor. + * @param path + * the path to the image file. + * @return the {@link ImageDescriptor} stored in the file at the specified path. + */ + public static ImageDescriptor getImageDescriptor(Class<?> clazz, String path) { + return ImageDescriptor.createFromFile(clazz, path); + } + + /** + * Returns an {@link ImageDescriptor} stored in the file at the specified path. + * + * @param path + * the path to the image file. + * @return the {@link ImageDescriptor} stored in the file at the specified path. + */ + public static ImageDescriptor getImageDescriptor(String path) { + try { + return ImageDescriptor.createFromURL(new File(path).toURI().toURL()); + } catch (MalformedURLException e) { + return null; + } + } + + /** + * Returns an {@link Image} based on the specified {@link ImageDescriptor}. + * + * @param descriptor + * the {@link ImageDescriptor} for the {@link Image}. + * @return the {@link Image} based on the specified {@link ImageDescriptor}. + */ + public static Image getImage(ImageDescriptor descriptor) { + if(descriptor == null) { + return null; + } + Image image = m_descriptorImageMap.get(descriptor); + if(image == null) { + image = descriptor.createImage(); + m_descriptorImageMap.put(descriptor, image); + } + return image; + } + + /** + * Maps images to decorated images. + */ + @SuppressWarnings("unchecked") + private static Map<Image, Map<Image, Image>>[] m_decoratedImageMap = new Map[LAST_CORNER_KEY]; + + /** + * Returns an {@link Image} composed of a base image decorated by another image. + * + * @param baseImage + * the base {@link Image} that should be decorated. + * @param decorator + * the {@link Image} to decorate the base image. + * @return {@link Image} The resulting decorated image. + */ + public static Image decorateImage(Image baseImage, Image decorator) { + return decorateImage(baseImage, decorator, BOTTOM_RIGHT); + } + + /** + * Returns an {@link Image} composed of a base image decorated by another image. + * + * @param baseImage + * the base {@link Image} that should be decorated. + * @param decorator + * the {@link Image} to decorate the base image. + * @param corner + * the corner to place decorator image. + * @return the resulting decorated {@link Image}. + */ + public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) { + if(corner <= 0 || corner >= LAST_CORNER_KEY) { + throw new IllegalArgumentException("Wrong decorate corner"); + } + Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[corner]; + if(cornerDecoratedImageMap == null) { + cornerDecoratedImageMap = new HashMap<Image, Map<Image, Image>>(); + m_decoratedImageMap[corner] = cornerDecoratedImageMap; + } + Map<Image, Image> decoratedMap = cornerDecoratedImageMap.get(baseImage); + if(decoratedMap == null) { + decoratedMap = new HashMap<Image, Image>(); + cornerDecoratedImageMap.put(baseImage, decoratedMap); + } + // + Image result = decoratedMap.get(decorator); + if(result == null) { + final Rectangle bib = baseImage.getBounds(); + final Rectangle dib = decorator.getBounds(); + final Point baseImageSize = new Point(bib.width, bib.height); + CompositeImageDescriptor compositImageDesc = new CompositeImageDescriptor() { + + @Override + protected void drawCompositeImage(int width, int height) { + drawImage(baseImage.getImageData(), 0, 0); + if(corner == TOP_LEFT) { + drawImage(decorator.getImageData(), 0, 0); + } else if(corner == TOP_RIGHT) { + drawImage(decorator.getImageData(), bib.width - dib.width, 0); + } else if(corner == BOTTOM_LEFT) { + drawImage(decorator.getImageData(), 0, bib.height - dib.height); + } else if(corner == BOTTOM_RIGHT) { + drawImage(decorator.getImageData(), bib.width - dib.width, bib.height - dib.height); + } + } + + @Override + protected Point getSize() { + return baseImageSize; + } + }; + // + result = compositImageDesc.createImage(); + decoratedMap.put(decorator, result); + } + return result; + } + + /** + * Dispose all of the cached images. + */ + public static void disposeImages() { + SWTResourceManager.disposeImages(); + // dispose ImageDescriptor images + { + for(Iterator<Image> I = m_descriptorImageMap.values().iterator(); I.hasNext();) { + I.next().dispose(); + } + m_descriptorImageMap.clear(); + } + // dispose decorated images + for(int i = 0; i < m_decoratedImageMap.length; i++) { + Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[i]; + if(cornerDecoratedImageMap != null) { + for(Map<Image, Image> decoratedMap : cornerDecoratedImageMap.values()) { + for(Image image : decoratedMap.values()) { + image.dispose(); + } + decoratedMap.clear(); + } + cornerDecoratedImageMap.clear(); + } + } + // dispose plugin images + { + for(Iterator<Image> I = m_URLImageMap.values().iterator(); I.hasNext();) { + I.next().dispose(); + } + m_URLImageMap.clear(); + } + } + + //////////////////////////////////////////////////////////////////////////// + // + // Plugin images support + // + //////////////////////////////////////////////////////////////////////////// + /** + * Maps URL to images. + */ + private static Map<String, Image> m_URLImageMap = new HashMap<String, Image>(); + + /** + * Provider for plugin resources, used by WindowBuilder at design time. + */ + public interface PluginResourceProvider { + + /** + * Gets the entry. + * + * @param symbolicName + * the symbolic name + * @param path + * the path + * @return the entry + */ + URL getEntry(String symbolicName, String path); + } + + /** + * Instance of {@link PluginResourceProvider}, used by WindowBuilder at design time. + */ + private static PluginResourceProvider m_designTimePluginResourceProvider = null; + + /** + * Returns an {@link Image} based on a plugin and file path. + * + * @param plugin + * the plugin {@link Object} containing the image + * @param name + * the path to the image within the plugin + * @return the {@link Image} stored in the file at the specified path + * + * @deprecated Use {@link #getPluginImage(String, String)} instead. + */ + @Deprecated + public static Image getPluginImage(Object plugin, String name) { + try { + URL url = getPluginImageURL(plugin, name); + if(url != null) { + return getPluginImageFromUrl(url); + } + } catch (Throwable e) { + // Ignore any exceptions + } + return null; + } + + /** + * Returns an {@link Image} based on a {@link Bundle} and resource entry path. + * + * @param symbolicName + * the symbolic name of the {@link Bundle}. + * @param path + * the path of the resource entry. + * @return the {@link Image} stored in the file at the specified path. + */ + public static Image getPluginImage(String symbolicName, String path) { + try { + URL url = getPluginImageURL(symbolicName, path); + if(url != null) { + return getPluginImageFromUrl(url); + } + } catch (Throwable e) { + // Ignore any exceptions + } + return null; + } + + /** + * Returns an {@link Image} based on given {@link URL}. + * + * @param url + * the url + * @return the plugin image from url + */ + private static Image getPluginImageFromUrl(URL url) { + try { + try { + String key = url.toExternalForm(); + Image image = m_URLImageMap.get(key); + if(image == null) { + InputStream stream = url.openStream(); + try { + image = getImage(stream); + m_URLImageMap.put(key, image); + } finally { + stream.close(); + } + } + return image; + } catch (Throwable e) { + // Ignore any exceptions + } + } catch (Throwable e) { + // Ignore any exceptions + } + return null; + } + + /** + * Returns an {@link ImageDescriptor} based on a plugin and file path. + * + * @param plugin + * the plugin {@link Object} containing the image. + * @param name + * the path to th eimage within the plugin. + * @return the {@link ImageDescriptor} stored in the file at the specified path. + * + * @deprecated Use {@link #getPluginImageDescriptor(String, String)} instead. + */ + @Deprecated + public static ImageDescriptor getPluginImageDescriptor(Object plugin, String name) { + try { + try { + URL url = getPluginImageURL(plugin, name); + return ImageDescriptor.createFromURL(url); + } catch (Throwable e) { + // Ignore any exceptions + } + } catch (Throwable e) { + // Ignore any exceptions + } + return null; + } + + /** + * Returns an {@link ImageDescriptor} based on a {@link Bundle} and resource entry path. + * + * @param symbolicName + * the symbolic name of the {@link Bundle}. + * @param path + * the path of the resource entry. + * @return the {@link ImageDescriptor} based on a {@link Bundle} and resource entry path. + */ + public static ImageDescriptor getPluginImageDescriptor(String symbolicName, String path) { + try { + URL url = getPluginImageURL(symbolicName, path); + if(url != null) { + return ImageDescriptor.createFromURL(url); + } + } catch (Throwable e) { + // Ignore any exceptions + } + return null; + } + + /** + * Returns an {@link URL} based on a {@link Bundle} and resource entry path. + * + * @param symbolicName + * the symbolic name + * @param path + * the path + * @return the plugin image url + */ + private static URL getPluginImageURL(String symbolicName, String path) { + // try runtime plugins + { + Bundle bundle = Platform.getBundle(symbolicName); + if(bundle != null) { + return bundle.getEntry(path); + } + } + // try design time provider + if(m_designTimePluginResourceProvider != null) { + return m_designTimePluginResourceProvider.getEntry(symbolicName, path); + } + // no such resource + return null; + } + + /** + * Returns an {@link URL} based on a plugin and file path. + * + * @param plugin + * the plugin {@link Object} containing the file path. + * @param name + * the file path. + * @return the {@link URL} representing the file at the specified path. + * @throws Exception + * the exception + */ + private static URL getPluginImageURL(Object plugin, String name) throws Exception { + // try to work with 'plugin' as with OSGI BundleContext + try { + Class<?> BundleClass = Class.forName("org.osgi.framework.Bundle"); //$NON-NLS-1$ + Class<?> BundleContextClass = Class.forName("org.osgi.framework.BundleContext"); //$NON-NLS-1$ + if(BundleContextClass.isAssignableFrom(plugin.getClass())) { + Method getBundleMethod = BundleContextClass.getMethod("getBundle", new Class[0]); //$NON-NLS-1$ + Object bundle = getBundleMethod.invoke(plugin, new Object[0]); + // + Class<?> PathClass = Class.forName("org.eclipse.core.runtime.Path"); //$NON-NLS-1$ + Constructor<?> pathConstructor = PathClass.getConstructor(new Class[]{ String.class }); + Object path = pathConstructor.newInstance(new Object[]{ name }); + // + Class<?> IPathClass = Class.forName("org.eclipse.core.runtime.IPath"); //$NON-NLS-1$ + Class<?> PlatformClass = Class.forName("org.eclipse.core.runtime.Platform"); //$NON-NLS-1$ + Method findMethod = PlatformClass.getMethod("find", new Class[]{ BundleClass, IPathClass }); //$NON-NLS-1$ + return (URL)findMethod.invoke(null, new Object[]{ bundle, path }); + } + } catch (Throwable e) { + // Ignore any exceptions + } + // else work with 'plugin' as with usual Eclipse plugin + { + Class<?> PluginClass = Class.forName("org.eclipse.core.runtime.Plugin"); //$NON-NLS-1$ + if(PluginClass.isAssignableFrom(plugin.getClass())) { + // + Class<?> PathClass = Class.forName("org.eclipse.core.runtime.Path"); //$NON-NLS-1$ + Constructor<?> pathConstructor = PathClass.getConstructor(new Class[]{ String.class }); + Object path = pathConstructor.newInstance(new Object[]{ name }); + // + Class<?> IPathClass = Class.forName("org.eclipse.core.runtime.IPath"); //$NON-NLS-1$ + Method findMethod = PluginClass.getMethod("find", new Class[]{ IPathClass }); //$NON-NLS-1$ + return (URL)findMethod.invoke(plugin, new Object[]{ path }); + } + } + return null; + } + + //////////////////////////////////////////////////////////////////////////// + // + // General + // + //////////////////////////////////////////////////////////////////////////// + /** + * Dispose of cached objects and their underlying OS resources. This should only be called when the cached + * objects are no longer needed (e.g. on application shutdown). + */ + public static void dispose() { + disposeColors(); + disposeFonts(); + disposeImages(); + } +} diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/com/swtdesigner/SWTResourceManager.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/com/swtdesigner/SWTResourceManager.java new file mode 100644 index 00000000000..fef8f8ded2a --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/com/swtdesigner/SWTResourceManager.java @@ -0,0 +1,488 @@ +/***************************************************************************** + * 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 com.swtdesigner; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Display; + +/** + * Utility class for managing OS resources associated with SWT controls such as colors, fonts, images, etc. + * <p> + * !!! IMPORTANT !!! Application code must explicitly invoke the <code>dispose()</code> method to release the operating system resources managed by + * cached objects when those objects and OS resources are no longer needed (e.g. on application shutdown) + * <p> + * This class may be freely distributed as part of any application or plugin. + * <p> + * Copyright (c) 2003 - 2007, Instantiations, Inc. <br> + * All Rights Reserved + * + * @author scheglov_ke + * @author Dan Rubel + */ +public class SWTResourceManager { + + //////////////////////////////////////////////////////////////////////////// + // + // Color + // + //////////////////////////////////////////////////////////////////////////// + /** The m_color map. */ + private static Map<RGB, Color> m_colorMap = new HashMap<RGB, Color>(); + + /** + * Returns the system {@link Color} matching the specific ID. + * + * @param systemColorID + * the ID value for the color + * @return the system {@link Color} matching the specific ID + */ + public static Color getColor(int systemColorID) { + Display display = Display.getCurrent(); + return display.getSystemColor(systemColorID); + } + + /** + * Returns a {@link Color} given its red, green and blue component values. + * + * @param r + * the red component of the color + * @param g + * the green component of the color + * @param b + * the blue component of the color + * @return the {@link Color} matching the given red, green and blue component values + */ + public static Color getColor(int r, int g, int b) { + return getColor(new RGB(r, g, b)); + } + + /** + * Returns a {@link Color} given its RGB value. + * + * @param rgb + * the {@link RGB} value of the color + * @return the {@link Color} matching the RGB value + */ + public static Color getColor(RGB rgb) { + Color color = m_colorMap.get(rgb); + if(color == null) { + Display display = Display.getCurrent(); + color = new Color(display, rgb); + m_colorMap.put(rgb, color); + } + return color; + } + + /** + * Dispose of all the cached {@link Color}'s. + */ + public static void disposeColors() { + for(Color color : m_colorMap.values()) { + color.dispose(); + } + m_colorMap.clear(); + } + + //////////////////////////////////////////////////////////////////////////// + // + // Image + // + //////////////////////////////////////////////////////////////////////////// + /** + * Maps image paths to images. + */ + private static Map<String, Image> m_imageMap = new HashMap<String, Image>(); + + /** + * Returns an {@link Image} encoded by the specified {@link InputStream}. + * + * @param stream + * the {@link InputStream} encoding the image data + * @return the {@link Image} encoded by the specified input stream + * @throws IOException + * Signals that an I/O exception has occurred. + */ + protected static Image getImage(InputStream stream) throws IOException { + try { + Display display = Display.getCurrent(); + ImageData data = new ImageData(stream); + if(data.transparentPixel > 0) { + return new Image(display, data, data.getTransparencyMask()); + } + return new Image(display, data); + } finally { + stream.close(); + } + } + + /** + * Returns an {@link Image} stored in the file at the specified path. + * + * @param path + * the path to the image file + * @return the {@link Image} stored in the file at the specified path + */ + public static Image getImage(String path) { + Image image = m_imageMap.get(path); + if(image == null) { + try { + image = getImage(new FileInputStream(path)); + m_imageMap.put(path, image); + } catch (Exception e) { + image = getMissingImage(); + m_imageMap.put(path, image); + } + } + return image; + } + + /** + * Returns an {@link Image} stored in the file at the specified path relative to the specified class. + * + * @param clazz + * the {@link Class} relative to which to find the image + * @param path + * the path to the image file, if starts with <code>'/'</code> + * @return the {@link Image} stored in the file at the specified path + */ + public static Image getImage(Class<?> clazz, String path) { + String key = clazz.getName() + '|' + path; + Image image = m_imageMap.get(key); + if(image == null) { + try { + image = getImage(clazz.getResourceAsStream(path)); + m_imageMap.put(key, image); + } catch (Exception e) { + image = getMissingImage(); + m_imageMap.put(key, image); + } + } + return image; + } + + /** The Constant MISSING_IMAGE_SIZE. */ + private static final int MISSING_IMAGE_SIZE = 10; + + /** + * Gets the missing image. + * + * @return the small {@link Image} that can be used as placeholder for missing image. + */ + private static Image getMissingImage() { + Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE); + // + GC gc = new GC(image); + gc.setBackground(getColor(SWT.COLOR_RED)); + gc.fillRectangle(0, 0, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE); + gc.dispose(); + // + return image; + } + + /** + * Style constant for placing decorator image in top left corner of base image. + */ + public static final int TOP_LEFT = 1; + + /** + * Style constant for placing decorator image in top right corner of base image. + */ + public static final int TOP_RIGHT = 2; + + /** + * Style constant for placing decorator image in bottom left corner of base image. + */ + public static final int BOTTOM_LEFT = 3; + + /** + * Style constant for placing decorator image in bottom right corner of base image. + */ + public static final int BOTTOM_RIGHT = 4; + + /** + * Internal value. + */ + protected static final int LAST_CORNER_KEY = 5; + + /** + * Maps images to decorated images. + */ + @SuppressWarnings("unchecked") + private static Map<Image, Map<Image, Image>>[] m_decoratedImageMap = new Map[LAST_CORNER_KEY]; + + /** + * Returns an {@link Image} composed of a base image decorated by another image. + * + * @param baseImage + * the base {@link Image} that should be decorated + * @param decorator + * the {@link Image} to decorate the base image + * @return {@link Image} The resulting decorated image + */ + public static Image decorateImage(Image baseImage, Image decorator) { + return decorateImage(baseImage, decorator, BOTTOM_RIGHT); + } + + /** + * Returns an {@link Image} composed of a base image decorated by another image. + * + * @param baseImage + * the base {@link Image} that should be decorated + * @param decorator + * the {@link Image} to decorate the base image + * @param corner + * the corner to place decorator image + * @return the resulting decorated {@link Image} + */ + public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) { + if(corner <= 0 || corner >= LAST_CORNER_KEY) { + throw new IllegalArgumentException("Wrong decorate corner"); + } + Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[corner]; + if(cornerDecoratedImageMap == null) { + cornerDecoratedImageMap = new HashMap<Image, Map<Image, Image>>(); + m_decoratedImageMap[corner] = cornerDecoratedImageMap; + } + Map<Image, Image> decoratedMap = cornerDecoratedImageMap.get(baseImage); + if(decoratedMap == null) { + decoratedMap = new HashMap<Image, Image>(); + cornerDecoratedImageMap.put(baseImage, decoratedMap); + } + // + Image result = decoratedMap.get(decorator); + if(result == null) { + Rectangle bib = baseImage.getBounds(); + Rectangle dib = decorator.getBounds(); + // + result = new Image(Display.getCurrent(), bib.width, bib.height); + // + GC gc = new GC(result); + gc.drawImage(baseImage, 0, 0); + if(corner == TOP_LEFT) { + gc.drawImage(decorator, 0, 0); + } else if(corner == TOP_RIGHT) { + gc.drawImage(decorator, bib.width - dib.width, 0); + } else if(corner == BOTTOM_LEFT) { + gc.drawImage(decorator, 0, bib.height - dib.height); + } else if(corner == BOTTOM_RIGHT) { + gc.drawImage(decorator, bib.width - dib.width, bib.height - dib.height); + } + gc.dispose(); + // + decoratedMap.put(decorator, result); + } + return result; + } + + /** + * Dispose all of the cached {@link Image}'s. + */ + public static void disposeImages() { + // dispose loaded images + { + for(Image image : m_imageMap.values()) { + image.dispose(); + } + m_imageMap.clear(); + } + // dispose decorated images + for(int i = 0; i < m_decoratedImageMap.length; i++) { + Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[i]; + if(cornerDecoratedImageMap != null) { + for(Map<Image, Image> decoratedMap : cornerDecoratedImageMap.values()) { + for(Image image : decoratedMap.values()) { + image.dispose(); + } + decoratedMap.clear(); + } + cornerDecoratedImageMap.clear(); + } + } + } + + //////////////////////////////////////////////////////////////////////////// + // + // Font + // + //////////////////////////////////////////////////////////////////////////// + /** + * Maps font names to fonts. + */ + private static Map<String, Font> m_fontMap = new HashMap<String, Font>(); + + /** + * Maps fonts to their bold versions. + */ + private static Map<Font, Font> m_fontToBoldFontMap = new HashMap<Font, Font>(); + + /** + * Returns a {@link Font} based on its name, height and style. + * + * @param name + * the name of the font + * @param height + * the height of the font + * @param style + * the style of the font + * @return {@link Font} The font matching the name, height and style + */ + public static Font getFont(String name, int height, int style) { + return getFont(name, height, style, false, false); + } + + /** + * Returns a {@link Font} based on its name, height and style. Windows-specific strikeout and underline + * flags are also supported. + * + * @param name + * the name of the font + * @param size + * the size of the font + * @param style + * the style of the font + * @param strikeout + * the strikeout flag (warning: Windows only) + * @param underline + * the underline flag (warning: Windows only) + * @return {@link Font} The font matching the name, height, style, strikeout and underline + */ + public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline) { + String fontName = name + '|' + size + '|' + style + '|' + strikeout + '|' + underline; + Font font = m_fontMap.get(fontName); + if(font == null) { + FontData fontData = new FontData(name, size, style); + if(strikeout || underline) { + try { + Class<?> logFontClass = Class.forName("org.eclipse.swt.internal.win32.LOGFONT"); //$NON-NLS-1$ + Object logFont = FontData.class.getField("data").get(fontData); //$NON-NLS-1$ + if(logFont != null && logFontClass != null) { + if(strikeout) { + logFontClass.getField("lfStrikeOut").set(logFont, Byte.valueOf((byte)1)); //$NON-NLS-1$ + } + if(underline) { + logFontClass.getField("lfUnderline").set(logFont, Byte.valueOf((byte)1)); //$NON-NLS-1$ + } + } + } catch (Throwable e) { + System.err.println("Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + font = new Font(Display.getCurrent(), fontData); + m_fontMap.put(fontName, font); + } + return font; + } + + /** + * Returns a bold version of the given {@link Font}. + * + * @param baseFont + * the {@link Font} for which a bold version is desired + * @return the bold version of the given {@link Font} + */ + public static Font getBoldFont(Font baseFont) { + Font font = m_fontToBoldFontMap.get(baseFont); + if(font == null) { + FontData fontDatas[] = baseFont.getFontData(); + FontData data = fontDatas[0]; + font = new Font(Display.getCurrent(), data.getName(), data.getHeight(), SWT.BOLD); + m_fontToBoldFontMap.put(baseFont, font); + } + return font; + } + + /** + * Dispose all of the cached {@link Font}'s. + */ + public static void disposeFonts() { + // clear fonts + for(Font font : m_fontMap.values()) { + font.dispose(); + } + m_fontMap.clear(); + // clear bold fonts + for(Font font : m_fontToBoldFontMap.values()) { + font.dispose(); + } + m_fontToBoldFontMap.clear(); + } + + //////////////////////////////////////////////////////////////////////////// + // + // Cursor + // + //////////////////////////////////////////////////////////////////////////// + /** + * Maps IDs to cursors. + */ + private static Map<Integer, Cursor> m_idToCursorMap = new HashMap<Integer, Cursor>(); + + /** + * Returns the system cursor matching the specific ID. + * + * @param id + * int The ID value for the cursor + * @return Cursor The system cursor matching the specific ID + */ + public static Cursor getCursor(int id) { + Integer key = Integer.valueOf(id); + Cursor cursor = m_idToCursorMap.get(key); + if(cursor == null) { + cursor = new Cursor(Display.getDefault(), id); + m_idToCursorMap.put(key, cursor); + } + return cursor; + } + + /** + * Dispose all of the cached cursors. + */ + public static void disposeCursors() { + for(Cursor cursor : m_idToCursorMap.values()) { + cursor.dispose(); + } + m_idToCursorMap.clear(); + } + + //////////////////////////////////////////////////////////////////////////// + // + // General + // + //////////////////////////////////////////////////////////////////////////// + /** + * Dispose of cached objects and their underlying OS resources. This should only be called when the cached + * objects are no longer needed (e.g. on application shutdown). + */ + public static void dispose() { + disposeColors(); + disposeImages(); + disposeFonts(); + disposeCursors(); + } +} diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/Activator.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/Activator.java new file mode 100644 index 00000000000..ec9b0579d40 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/Activator.java @@ -0,0 +1,88 @@ +/*****************************************************************************
+ * 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.uml.search.ui;
+
+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
+ /** The Constant PLUGIN_ID. */
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.uml.search.ui"; //$NON-NLS-1$
+
+ // The shared instance
+ /** The plugin. */
+ private static Activator plugin;
+
+ /** The log. */
+ public static LogHelper log;
+
+ /**
+ * The constructor.
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ /**
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ *
+ * @param context
+ * @throws Exception
+ */
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ log = new LogHelper(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ /**
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ *
+ * @param context
+ * @throws Exception
+ */
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance.
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/CheckBoxFilteredTree.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/CheckBoxFilteredTree.java new file mode 100644 index 00000000000..67d8179fa10 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/CheckBoxFilteredTree.java @@ -0,0 +1,55 @@ +/*****************************************************************************
+ * 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.uml.search.ui;
+
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.dialogs.FilteredTree;
+import org.eclipse.ui.dialogs.PatternFilter;
+
+/**
+ *
+ * An custom FilteredTree that provides Checkboxes for items
+ *
+ */
+public class CheckBoxFilteredTree extends FilteredTree {
+
+ public CheckBoxFilteredTree(Composite parent, int style, PatternFilter filter, boolean useNewLook) {
+ super(parent, style, filter, useNewLook);
+ }
+
+ /**
+ * Override to create a CheckBoxTreeViewer instead
+ *
+ * @see org.eclipse.ui.dialogs.FilteredTree#doCreateTreeViewer(org.eclipse.swt.widgets.Composite, int)
+ *
+ * @param parent
+ * @param style
+ * @return
+ */
+ @Override
+ protected TreeViewer doCreateTreeViewer(Composite parent, int style) {
+ return new CheckboxTreeViewer(parent, style);
+ }
+
+ /**
+ * Give an access to the viewer with appropriate typing
+ *
+ * @return the CheckBoxTreeViewer
+ */
+ public CheckboxTreeViewer getCheckboxTreeViewer() {
+ return (CheckboxTreeViewer)getViewer();
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/Messages.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/Messages.java new file mode 100644 index 00000000000..ea2488db4fd --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/Messages.java @@ -0,0 +1,130 @@ +/*****************************************************************************
+ * 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.uml.search.ui;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.uml.search.ui.messages"; //$NON-NLS-1$
+
+ public static String AttributeMatchLabelProvider_0;
+
+ public static String AttributeMatchLabelProvider_3;
+
+ public static String AttributeMatchLabelProvider_8;
+
+ public static String FilterTypeLabelProvider_0;
+
+ public static String FilterTypesAction_0;
+
+ public static String FilterTypesAction_1;
+
+ public static String PapyrusQuery_0;
+
+ public static String PapyrusQuery_5;
+
+ public static String PapyrusQuery_6;
+
+ public static String PapyrusSearchPage_0;
+
+ public static String PapyrusSearchPage_1;
+
+ public static String PapyrusSearchPage_10;
+
+ public static String PapyrusSearchPage_2;
+
+ public static String PapyrusSearchPage_3;
+
+ public static String PapyrusSearchPage_4;
+
+ public static String PapyrusSearchPage_5;
+
+ public static String PapyrusSearchPage_6;
+
+ public static String PapyrusSearchPage_8;
+
+ public static String PapyrusSearchPage_9;
+
+ public static String PapyrusSearchResult_0;
+
+ public static String PapyrusSearchResult_1;
+
+ public static String PapyrusSearchResult_2;
+
+ public static String PapyrusSearchResult_4;
+
+ public static String PapyrusSearchResult_5;
+
+ public static String PapyrusSearchResultPage_0;
+
+ public static String PapyrusSearchResultPage_1;
+
+ public static String ReplaceDialog_0;
+
+ public static String ReplaceDialog_1;
+
+ public static String ReplaceDialog_2;
+
+ public static String ReplaceDialog_3;
+
+ public static String ReplaceDialog_4;
+
+ public static String ResultContentProvider_0;
+
+ public static String ResultContentProvider_10;
+
+ public static String ResultContentProvider_11;
+
+ public static String ResultContentProvider_12;
+
+ public static String ResultContentProvider_13;
+
+ public static String ResultContentProvider_14;
+
+ public static String ResultContentProvider_15;
+
+ public static String ResultContentProvider_3;
+
+ public static String ResultContentProvider_4;
+
+ public static String ResultContentProvider_5;
+
+ public static String ResultContentProvider_6;
+
+ public static String ResultContentProvider_7;
+
+ public static String ResultContentProvider_8;
+
+ public static String ResultContentProvider_9;
+
+ public static String ResultLabelProvider_0;
+
+ public static String ResultLabelProvider_1;
+
+ public static String TypesFilterDialog_0;
+
+ public static String TypesMatchFilter_0;
+
+ public static String TypesMatchFilter_2;
+
+ public static String TypesMatchFilter_3;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/FilterTypesAction.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/FilterTypesAction.java new file mode 100644 index 00000000000..e4138149a75 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/FilterTypesAction.java @@ -0,0 +1,58 @@ +/*****************************************************************************
+ * 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.uml.search.ui.actions;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.papyrus.uml.search.ui.Activator;
+import org.eclipse.papyrus.uml.search.ui.Messages;
+import org.eclipse.papyrus.uml.search.ui.dialogs.TypesFilterDialog;
+import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
+
+import com.swtdesigner.ResourceManager;
+
+/**
+ *
+ * Action that opens a {@link org.eclipse.papyrus.uml.search.ui.dialogs.TypesFilterDialog} in order to filter search results
+ *
+ */
+public class FilterTypesAction extends Action {
+
+ private AbstractTextSearchViewPage fPage;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param page
+ * the result page whose results while be filtered
+ */
+ public FilterTypesAction(AbstractTextSearchViewPage page) {
+ fPage = page;
+ setText(Messages.FilterTypesAction_0);
+ setToolTipText(Messages.FilterTypesAction_1);
+ this.setImageDescriptor(ResourceManager.getPluginImageDescriptor(Activator.PLUGIN_ID, "icons/filter.png")); //$NON-NLS-1$
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ *
+ */
+ @Override
+ public void run() {
+ TypesFilterDialog typesFilterDialog = new TypesFilterDialog(null, fPage);
+ typesFilterDialog.open();
+
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/ReplaceAction.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/ReplaceAction.java new file mode 100644 index 00000000000..5cde7e08c7f --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/ReplaceAction.java @@ -0,0 +1,59 @@ +/*****************************************************************************
+ * 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.uml.search.ui.actions;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.papyrus.uml.search.ui.dialogs.ReplaceDialog;
+import org.eclipse.papyrus.uml.search.ui.pages.PapyrusSearchResultPage;
+import org.eclipse.swt.widgets.Shell;
+
+public class ReplaceAction extends Action {
+
+ private final PapyrusSearchResultPage fResultPage;
+
+ private final Object[] fSelection;
+
+ private final Shell fShell;
+
+ /**
+ * Creates the replace action to be
+ *
+ * @param shell
+ * the parent shell
+ * @param resultPage
+ * .getInput()
+ * the file search page to
+ * @param selection
+ * the selected entries or <code>null</code> to replace all
+ */
+ public ReplaceAction(Shell shell, PapyrusSearchResultPage resultPage, Object[] selection) {
+ fShell = shell;
+ fResultPage = resultPage;
+ fSelection = selection;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+
+ ReplaceDialog replaceDialog = new ReplaceDialog(fShell, fResultPage, fSelection);
+ replaceDialog.open();
+
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/adapter/PapyrusSearchAdapterFactory.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/adapter/PapyrusSearchAdapterFactory.java new file mode 100644 index 00000000000..d26efd0b20e --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/adapter/PapyrusSearchAdapterFactory.java @@ -0,0 +1,41 @@ +/*****************************************************************************
+ * 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:
+ * Camille Letavernier (camille.letavernier@cea.fr) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.search.ui.adapter;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.search.ui.ISearchPageScoreComputer;
+
+/**
+ * Adapter factory for Papyrus Search
+ *
+ * @author Camille
+ *
+ */
+public class PapyrusSearchAdapterFactory implements IAdapterFactory {
+
+ public PapyrusSearchAdapterFactory() {
+ //Nothing
+ }
+
+ public Object getAdapter(Object adaptableObject, Class adapterType) {
+ if(adapterType == ISearchPageScoreComputer.class) {
+ return new PapyrusSearchPageScoreComputer();
+ }
+ return null;
+ }
+
+ public Class[] getAdapterList() {
+ return new Class[]{ ISearchPageScoreComputer.class };
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/adapter/PapyrusSearchPageScoreComputer.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/adapter/PapyrusSearchPageScoreComputer.java new file mode 100644 index 00000000000..493c102e68b --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/adapter/PapyrusSearchPageScoreComputer.java @@ -0,0 +1,46 @@ +/*****************************************************************************
+ * 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:
+ * Camille Letavernier (camille.letavernier@cea.fr) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.search.ui.adapter;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.search.ui.ISearchPageScoreComputer;
+
+/**
+ * Computes the search page score for the Papyrus Search Page
+ *
+ * @author Camille Letavernier
+ */
+public class PapyrusSearchPageScoreComputer implements ISearchPageScoreComputer {
+
+ public int computeScore(String pageId, Object input) {
+ if("org.eclipse.papyrus.search.ui.pages.PapyrusSearchPage".equals(pageId)) {
+ EObject currentEObject = EMFHelper.getEObject(input);
+ if(currentEObject != null) {
+ try {
+ ServicesRegistry registry = ServiceUtilsForEObject.getInstance().getServiceRegistry(currentEObject);
+ if(registry != null) {
+ return 99;
+ }
+ } catch (Exception ex) {
+ //Nothing
+ }
+ }
+ }
+ return UNKNOWN;
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/dialogs/ReplaceDialog.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/dialogs/ReplaceDialog.java new file mode 100644 index 00000000000..65e23138344 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/dialogs/ReplaceDialog.java @@ -0,0 +1,255 @@ +/*****************************************************************************
+ * 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.uml.search.ui.dialogs;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.papyrus.uml.search.ui.Activator;
+import org.eclipse.papyrus.uml.search.ui.Messages;
+import org.eclipse.papyrus.uml.search.ui.pages.PapyrusSearchResultPage;
+import org.eclipse.papyrus.views.search.regex.PatternHelper;
+import org.eclipse.papyrus.views.search.results.AbstractResultEntry;
+import org.eclipse.papyrus.views.search.results.AttributeMatch;
+import org.eclipse.papyrus.views.search.scope.ScopeEntry;
+import org.eclipse.papyrus.views.search.utils.MatchUtils;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+
+import com.swtdesigner.ResourceManager;
+
+public class ReplaceDialog extends Dialog {
+
+ PapyrusSearchResultPage fResultPage;
+
+ org.eclipse.papyrus.uml.search.ui.query.PapyrusQuery fQuery;
+
+ Object[] fSelection;
+
+ Text replaceText;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param parentShell
+ * the parent shell, or <code>null</code> to create a top-level
+ * shell
+ * @param fSelection
+ * @param fResult
+ * @param page
+ * the result page whose results while be filtered
+ */
+ public ReplaceDialog(Shell parentShell, PapyrusSearchResultPage fResultPage, Object[] selection) {
+ super(parentShell);
+
+ this.fResultPage = fResultPage;
+ this.fSelection = selection;
+ this.fQuery = (org.eclipse.papyrus.uml.search.ui.query.PapyrusQuery)fResultPage.getInput().getQuery();
+
+ }
+
+ @Override
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ shell.setText(Messages.ReplaceDialog_0);
+ shell.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/PapyrusSearch.png")); //$NON-NLS-1$)
+ }
+
+ @Override
+ protected boolean isResizable() {
+ return true;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+
+ parent.setLayout(new GridLayout(1, true));
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ composite.setLayout(new GridLayout(2, false));
+
+ Label labelQueryText = new Label(composite, SWT.NONE);
+ labelQueryText.setText(Messages.ReplaceDialog_1);
+
+ Text queyText = new Text(composite, SWT.BORDER);
+ queyText.setEnabled(false);
+ queyText.setText(fQuery.getSearchQueryText());
+ queyText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 0, 0));
+
+ Label labelReplace = new Label(composite, SWT.NONE);
+ labelReplace.setText(Messages.ReplaceDialog_2);
+
+ replaceText = new Text(composite, SWT.BORDER);
+ replaceText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 0, 0));
+
+ Label warningLabel = new Label(composite, SWT.NONE);
+ warningLabel.setText(Messages.ReplaceDialog_3);
+ warningLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 0));
+
+ return parent;
+ }
+
+ private String computeReplacementString(Pattern pattern, String originalText, String replacementText) throws PatternSyntaxException {
+ if(pattern != null) {
+ try {
+
+ Matcher matcher = pattern.matcher(originalText);
+ StringBuffer sb = new StringBuffer();
+ matcher.reset();
+ if(matcher.find()) {
+ matcher.appendReplacement(sb, replacementText);
+ } else {
+ return null;
+ }
+ matcher.appendTail(sb);
+ return sb.toString();
+ } catch (IndexOutOfBoundsException ex) {
+ throw new PatternSyntaxException(ex.getLocalizedMessage(), replacementText, -1);
+ }
+ }
+ return replacementText;
+ }
+
+ private void change(AttributeMatch match) {
+ if(match.getTarget() instanceof EObject) {
+
+ EObject target = (EObject)match.getTarget();
+
+ if(match.getSource() instanceof EAttribute) {
+ Object value = target.eGet((EAttribute)match.getSource());
+ if(value != null) {
+ if(value instanceof String) {
+ String originalvalue = (String)value;
+ Pattern pattern = PatternHelper.getInstance().createPattern(fQuery.getSearchQueryText(), fQuery.isCaseSensitive(), fQuery.isRegularExpression());
+
+ String newValue = computeReplacementString(pattern, originalvalue, replaceText.getText());
+
+ target.eSet((EAttribute)match.getSource(), newValue);
+
+ }
+ }
+ } else if(match.getSource() instanceof Property) {
+ Property source = (Property)match.getSource();
+ Class containingClass = source.getClass_();
+ if(containingClass instanceof Stereotype) {
+ if(target instanceof Element) {
+ Object tagValue = ((Element)target).getValue((Stereotype)containingClass, source.getName());
+ if(tagValue instanceof String) {
+ Object value = tagValue;
+
+ if(value != null) {
+ if(value instanceof String) {
+ String originalvalue = (String)value;
+ Pattern pattern = PatternHelper.getInstance().createPattern(fQuery.getSearchQueryText(), fQuery.isCaseSensitive(), fQuery.isRegularExpression());
+
+ String newValue = computeReplacementString(pattern, originalvalue, replaceText.getText());
+
+ ((Element)target).setValue((Stereotype)containingClass, source.getName(), newValue);
+
+ }
+ }
+
+ }
+ }
+ }
+ }
+
+ }
+
+ }
+
+ @Override
+ protected void okPressed() {
+
+ Set<AbstractResultEntry> toProcess = new HashSet<AbstractResultEntry>();
+ Set<ScopeEntry> toSave = new HashSet<ScopeEntry>();
+
+ if(fSelection == null) {
+ toProcess.addAll(MatchUtils.getMatches(fResultPage.getInput(), false));
+
+ } else {
+ for(Object selected : Arrays.asList(fSelection)) {
+ if(selected instanceof AbstractResultEntry) {
+ toProcess.add((AbstractResultEntry)selected);
+ }
+ }
+ }
+
+ for(AbstractResultEntry match : toProcess) {
+
+ if(match instanceof AttributeMatch) {
+ final AttributeMatch attributeMatch = (AttributeMatch)match;
+
+ EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(attributeMatch.getTarget());
+
+ Object element = match.getElement();
+
+ if(editingDomain != null) {
+ if(editingDomain instanceof TransactionalEditingDomain) {
+ editingDomain.getCommandStack().execute(new RecordingCommand((TransactionalEditingDomain)editingDomain) {
+
+ @Override
+ protected void doExecute() {
+ change(attributeMatch);
+ }
+ });
+ }
+ } else {
+ if(element instanceof ScopeEntry) {
+
+ change(attributeMatch);
+
+ toSave.add((ScopeEntry)element);
+
+ }
+ }
+ }
+ }
+
+ for(ScopeEntry scopeEntry : toSave) {
+ try {
+ scopeEntry.getModelSet().save(new NullProgressMonitor());
+ } catch (IOException e) {
+ Activator.log.error(Messages.ReplaceDialog_4 + scopeEntry.getModelSet(), e);
+ }
+ }
+
+ super.okPressed();
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/dialogs/TypesFilterDialog.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/dialogs/TypesFilterDialog.java new file mode 100644 index 00000000000..d1976a25b73 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/dialogs/TypesFilterDialog.java @@ -0,0 +1,115 @@ +/*****************************************************************************
+ * 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.uml.search.ui.dialogs;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.papyrus.uml.search.ui.Activator;
+import org.eclipse.papyrus.uml.search.ui.CheckBoxFilteredTree;
+import org.eclipse.papyrus.uml.search.ui.Messages;
+import org.eclipse.papyrus.uml.search.ui.filters.TypesMatchFilter;
+import org.eclipse.papyrus.uml.search.ui.providers.FilterTypeContentProvider;
+import org.eclipse.papyrus.uml.search.ui.providers.FilterTypeLabelProvider;
+import org.eclipse.papyrus.uml.search.ui.results.PapyrusSearchResult;
+import org.eclipse.search.ui.text.AbstractTextSearchResult;
+import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
+import org.eclipse.search.ui.text.MatchFilter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.PatternFilter;
+
+import com.swtdesigner.ResourceManager;
+
+/**
+ *
+ * A dialog that let user select the types of the elements that must be filtered
+ *
+ */
+public class TypesFilterDialog extends Dialog {
+
+ private CheckBoxFilteredTree filterTypesTree;
+
+ private AbstractTextSearchViewPage fPage;
+
+ private CheckboxTreeViewer filterTypesTreeViewer;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param parentShell
+ * the parent shell, or <code>null</code> to create a top-level
+ * shell
+ * @param page
+ * the result page whose results while be filtered
+ */
+ public TypesFilterDialog(Shell parentShell, AbstractTextSearchViewPage page) {
+ super(parentShell);
+ this.fPage = page;
+
+ }
+
+ @Override
+ protected boolean isResizable() {
+ return true;
+ }
+
+ @Override
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ shell.setText(Messages.TypesFilterDialog_0);
+ shell.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/filter.png")); //$NON-NLS-1$)
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ parent.setLayout(new GridLayout());
+
+ filterTypesTree = new CheckBoxFilteredTree(parent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, new PatternFilter(), true);
+ filterTypesTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 0, 0));
+
+ parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 0, 0));
+
+ filterTypesTreeViewer = (CheckboxTreeViewer)filterTypesTree.getViewer();
+
+ filterTypesTreeViewer.setContentProvider(new FilterTypeContentProvider());
+ filterTypesTreeViewer.setLabelProvider(new FilterTypeLabelProvider());
+
+ filterTypesTreeViewer.setInput(fPage.getInput());
+
+ filterTypesTreeViewer.setAllChecked(true);
+
+ return parent;
+ }
+
+ @Override
+ protected void okPressed() {
+
+ MatchFilter typeFilter = new TypesMatchFilter(filterTypesTreeViewer.getCheckedElements());
+ MatchFilter[] filters = new MatchFilter[1];
+ filters[0] = typeFilter;
+ AbstractTextSearchResult input = fPage.getInput();
+ if(input instanceof PapyrusSearchResult) {
+ input.setActiveMatchFilters(filters);
+ ((PapyrusSearchResult)input).setPossibleMatchFilter(filters);
+ }
+
+ super.okPressed();
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/filters/TypesMatchFilter.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/filters/TypesMatchFilter.java new file mode 100644 index 00000000000..3d6236731a1 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/filters/TypesMatchFilter.java @@ -0,0 +1,88 @@ +/*****************************************************************************
+ * 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.uml.search.ui.filters;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.papyrus.uml.search.ui.Messages;
+import org.eclipse.papyrus.views.search.results.AbstractResultEntry;
+import org.eclipse.search.ui.text.Match;
+import org.eclipse.search.ui.text.MatchFilter;
+import org.eclipse.uml2.uml.Element;
+
+/**
+ *
+ * A specific kind of filter that can filter UML based results
+ *
+ */
+public class TypesMatchFilter extends MatchFilter {
+
+ private Object[] selectedTypes;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param types
+ * the collection of types whose instance are NOT filtered
+ */
+ public TypesMatchFilter(Object[] types) {
+ this.selectedTypes = types;
+ }
+
+ @Override
+ public String getName() {
+ return Messages.TypesMatchFilter_0;
+ }
+
+ @Override
+ public String getID() {
+ return "TypesMatchFilter"; //$NON-NLS-1$
+ }
+
+ @Override
+ public String getDescription() {
+ return Messages.TypesMatchFilter_2;
+ }
+
+ @Override
+ public String getActionLabel() {
+ return Messages.TypesMatchFilter_3;
+ }
+
+ @Override
+ public boolean filters(Match match) {
+ if(match instanceof AbstractResultEntry) {
+ List<Object> selectedTypesList = Arrays.asList(selectedTypes);
+
+ Object elementToValidate = ((AbstractResultEntry)match).elementToCheckFilterFor();
+ + if(elementToValidate instanceof Element) {
+
+ if(selectedTypesList.contains(((Element)elementToValidate).eClass())) {
+ return false;
+ }
+ for(Object object : selectedTypesList) {
+ if(((Element)elementToValidate).getAppliedStereotypes().contains(object)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+
+ return false;
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/handlers/SearchCommandHandler.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/handlers/SearchCommandHandler.java new file mode 100644 index 00000000000..d95764f3be8 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/handlers/SearchCommandHandler.java @@ -0,0 +1,36 @@ +/*****************************************************************************
+ * 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.uml.search.ui.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.search.internal.ui.OpenSearchDialogAction;
+
+/**
+ *
+ * Handler for findAndReplace that opens the search dialog
+ *
+ */
+public class SearchCommandHandler extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+ OpenSearchDialogAction action = new OpenSearchDialogAction();
+ action.run();
+
+ return null;
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/messages.properties b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/messages.properties new file mode 100644 index 00000000000..46809434fe5 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/messages.properties @@ -0,0 +1,51 @@ +AttributeMatchLabelProvider_0=Failed to start label service for :
+AttributeMatchLabelProvider_3=\ in
+AttributeMatchLabelProvider_8=\ attribute
+FilterTypeLabelProvider_0=Failed to start label service for :
+FilterTypesAction_0=Filter results by types
+FilterTypesAction_1=Filter results by types
+PapyrusQuery_0=Failed to get umlModel's root from modelSet:
+PapyrusQuery_5=Failed to start ViewerSearcherService to find viewers in:
+PapyrusQuery_6=Papyrus Search
+PapyrusSearchPage_0=Query expression is ill-formed
+PapyrusSearchPage_1=Query issue
+PapyrusSearchPage_10=Deselect All
+PapyrusSearchPage_2=Search in all string attributes of selected types
+PapyrusSearchPage_3=Search in all string attributes of applied stereotypes
+PapyrusSearchPage_4=Text query:
+PapyrusSearchPage_5=Case sensitive
+PapyrusSearchPage_6=Regular expression
+PapyrusSearchPage_8=Search for
+PapyrusSearchPage_9=Select All
+PapyrusSearchResult_0=\ result(s) for "
+PapyrusSearchResult_1=":
+PapyrusSearchResult_2=Papyrus search result
+PapyrusSearchResult_4=Failed to get modelSet for:
+PapyrusSearchResult_5=Failed to get SashModel for:
+PapyrusSearchResultPage_0=Failed to get openElementService to open:
+PapyrusSearchResultPage_1=Failed to open element
+ReplaceDialog_0=Replace with
+ReplaceDialog_1=Replace:
+ReplaceDialog_2=With:
+ReplaceDialog_3=WARNING: replace action is not undoable if resource containing the match is not already open in an editor.
+ReplaceDialog_4=Failed to save resource:
+ResultContentProvider_0=The plug-in
+ResultContentProvider_10=The plug-in
+ResultContentProvider_11=\ contributed an invalid extension for
+ResultContentProvider_12=. The resultContentProvider
+ResultContentProvider_13=\ must be set
+ResultContentProvider_14=The context
+ResultContentProvider_15=\ is already contributed
+ResultContentProvider_3=\ contributed an invalid extension for
+ResultContentProvider_4=. The resultContentProvider
+ResultContentProvider_5=\ must be set
+ResultContentProvider_6=The plug-in
+ResultContentProvider_7=\ contributed an invalid extension for
+ResultContentProvider_8=. The resultContentProvider
+ResultContentProvider_9=\ must be set
+ResultLabelProvider_0=Failed to get LabelProviderService to get label for:
+ResultLabelProvider_1=Failed to get LabelProviderService to get label for:
+TypesFilterDialog_0=Select types
+TypesMatchFilter_0=Filter matches by types
+TypesMatchFilter_2=Filter matches by types
+TypesMatchFilter_3=Filter matches by types
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 new file mode 100644 index 00000000000..b2a8f475e39 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchPage.java @@ -0,0 +1,307 @@ +/*****************************************************************************
+ * 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.uml.search.ui.pages;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.regex.PatternSyntaxException;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.dialogs.DialogPage;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.papyrus.uml.search.ui.CheckBoxFilteredTree;
+import org.eclipse.papyrus.uml.search.ui.Messages;
+import org.eclipse.papyrus.uml.search.ui.actions.ReplaceAction;
+import org.eclipse.papyrus.uml.search.ui.providers.ParticipantTypeContentProvider;
+import org.eclipse.papyrus.uml.search.ui.providers.ParticipantTypeLabelProvider;
+import org.eclipse.papyrus.uml.search.ui.query.PapyrusQuery;
+import org.eclipse.papyrus.views.search.regex.PatternHelper;
+import org.eclipse.papyrus.views.search.scope.ScopeCollector;
+import org.eclipse.papyrus.views.search.scope.ScopeEntry;
+import org.eclipse.search.ui.IReplacePage;
+import org.eclipse.search.ui.ISearchPage;
+import org.eclipse.search.ui.ISearchPageContainer;
+import org.eclipse.search.ui.ISearchQuery;
+import org.eclipse.search.ui.ISearchResultPage;
+import org.eclipse.search.ui.ISearchResultViewPart;
+import org.eclipse.search.ui.NewSearchUI;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.PatternFilter;
+import org.eclipse.uml2.uml.UMLPackage;
+
+/**
+ *
+ * Papyrus specific search page
+ *
+ */
+public class PapyrusSearchPage extends DialogPage implements ISearchPage, IReplacePage {
+
+ private static final String REGULAR_EXPRESSION_ILLFORMED = Messages.PapyrusSearchPage_0;
+
+ private static final String SEARCH_ISSUE = Messages.PapyrusSearchPage_1;
+
+ private static final String SEARCH_IN_ALL_STRINGS = Messages.PapyrusSearchPage_2;
+
+ private static final String SEARCH_IN_STEREOTYPE_ATTRIBUTES = Messages.PapyrusSearchPage_3;
+
+ private Text searchQueryText;
+
+ private ISearchPageContainer container;
+
+ private CheckBoxFilteredTree participantTypesTree;
+
+ private CheckboxTreeViewer participantTypesTreeViewer;
+
+ private Label searchQueryExplanatoryLabel;
+
+ private Button btnRegularExpression;
+
+ private Button btnCaseSensitive;
+
+ private Button btnSearchAllStringAttributes;
+
+ private Button btnSearchInStereotypeAttributes;
+ + public void createControl(Composite parent) {
+
+ initializeDialogUnits(parent);
+ Composite searchComposite = new Composite(parent, SWT.NONE);
+ searchComposite.setFont(parent.getFont());
+ searchComposite.setLayout(new GridLayout(1, false));
+ searchComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+
+ Label lblSearchString = new Label(searchComposite, SWT.NONE);
+ lblSearchString.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
+ lblSearchString.setText(Messages.PapyrusSearchPage_4);
+
+ Composite queryComposite = new Composite(searchComposite, SWT.NONE);
+ queryComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
+ queryComposite.setLayout(new GridLayout(2, false));
+
+ searchQueryText = new Text(queryComposite, SWT.BORDER);
+ searchQueryText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ searchQueryText.addModifyListener(new ModifyListener() {
+
+ public void modifyText(ModifyEvent evt) {
+ validateRegex();
+ }
+ });
+ searchQueryText.setFocus();
+
+ Composite compositeParameters = new Composite(queryComposite, SWT.NONE);
+ compositeParameters.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
+ compositeParameters.setLayout(new GridLayout(1, false));
+
+ btnCaseSensitive = new Button(compositeParameters, SWT.CHECK);
+ btnCaseSensitive.setText(Messages.PapyrusSearchPage_5);
+
+ btnRegularExpression = new Button(compositeParameters, SWT.CHECK);
+ btnRegularExpression.setText(Messages.PapyrusSearchPage_6);
+ btnRegularExpression.addSelectionListener(new SelectionListener() {
+
+ public void widgetSelected(SelectionEvent e) {
+ btnCaseSensitive.setEnabled(!btnRegularExpression.getSelection());
+ validateRegex();
+ searchQueryText.forceFocus();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+ });
+
+ searchQueryExplanatoryLabel = new Label(queryComposite, SWT.NONE);
+ searchQueryExplanatoryLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
+
+ Group grpSearchFor = new Group(searchComposite, SWT.NONE);
+ grpSearchFor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+ grpSearchFor.setLayout(new GridLayout(4, false));
+ grpSearchFor.setText(Messages.PapyrusSearchPage_8);
+
+ participantTypesTree = new CheckBoxFilteredTree(grpSearchFor, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, new PatternFilter(), true);
+ participantTypesTree.setLayout(new GridLayout());
+ GridData chechboxTreeViewerGridData = new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1);
+ chechboxTreeViewerGridData.heightHint = 150;
+ participantTypesTree.setLayoutData(chechboxTreeViewerGridData);
+
+ participantTypesTreeViewer = (CheckboxTreeViewer)participantTypesTree.getViewer();
+ participantTypesTreeViewer.setContentProvider(new ParticipantTypeContentProvider(this));
+ participantTypesTreeViewer.setLabelProvider(new ParticipantTypeLabelProvider());
+
+ Button btnSelectAll = new Button(grpSearchFor, SWT.PUSH);
+ btnSelectAll.setText(Messages.PapyrusSearchPage_9);
+ btnSelectAll.addMouseListener(new MouseAdapter() {
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ participantTypesTreeViewer.setAllChecked(true);
+ }
+ });
+
+ Button btnDeselectAll = new Button(grpSearchFor, SWT.PUSH);
+ btnDeselectAll.setText(Messages.PapyrusSearchPage_10);
+ btnDeselectAll.addMouseListener(new MouseAdapter() {
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ participantTypesTreeViewer.setAllChecked(false);
+ }
+ });
+
+ btnSearchAllStringAttributes = new Button(grpSearchFor, SWT.CHECK);
+ btnSearchAllStringAttributes.setText(SEARCH_IN_ALL_STRINGS);
+ btnSearchAllStringAttributes.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, false, 0, 0));
+ btnSearchAllStringAttributes.addMouseListener(new MouseAdapter() {
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ participantTypesTreeViewer.refresh();
+ }
+ });
+
+ btnSearchInStereotypeAttributes = new Button(grpSearchFor, SWT.CHECK);
+ btnSearchInStereotypeAttributes.setText(SEARCH_IN_STEREOTYPE_ATTRIBUTES);
+ btnSearchInStereotypeAttributes.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false, 0, 0));
+ btnSearchInStereotypeAttributes.setSelection(true);
+
+ participantTypesTreeViewer.setInput(UMLPackage.eINSTANCE);
+ participantTypesTreeViewer.setAllChecked(true);
+
+ setControl(parent);
+ }
+
+ public boolean getSearchAllStringAttributes() {
+ if(btnSearchAllStringAttributes != null) {
+ return btnSearchAllStringAttributes.getSelection();
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Validate syntax of the regular expression of the search query text.
+ *
+ * @return true, if successful
+ */
+ private boolean validateRegex() {
+
+ try {
+ PatternHelper.getInstance().createPattern(searchQueryText.getText(), btnCaseSensitive.getSelection(), btnRegularExpression.getSelection());
+ searchQueryExplanatoryLabel.setForeground(getControl().getForeground());
+ searchQueryExplanatoryLabel.setText(""); //$NON-NLS-1$
+ return true;
+
+ } catch (PatternSyntaxException e) {
+ searchQueryExplanatoryLabel.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
+ searchQueryExplanatoryLabel.setText(e.getDescription());
+
+ return false;
+ }
+ }
+
+ /**
+ * Create scopeEntries based on an IResources
+ *
+ * @return the created scopeEntries
+ */
+ private Collection<ScopeEntry> createScopeEntries(Collection<IResource> scope) {
+ Collection<ScopeEntry> results = new HashSet<ScopeEntry>();
+
+ for(IResource resource : scope) {
+
+ ScopeEntry scopeEntry = new ScopeEntry(resource);
+
+ results.add(scopeEntry);
+
+ }
+
+ return results;
+ }
+
+ public boolean performAction() {
+
+ if(validateRegex()) {
+ Collection<IResource> scope = ScopeCollector.getInstance().computeSearchScope(container);
+
+ Collection<ScopeEntry> scopeEntries = createScopeEntries(scope);
+
+ ISearchQuery query = new PapyrusQuery(searchQueryText.getText(), btnCaseSensitive.getSelection(), btnRegularExpression.getSelection(), btnSearchInStereotypeAttributes.getSelection(), scopeEntries, participantTypesTreeViewer.getCheckedElements(), btnSearchAllStringAttributes.getSelection());
+
+ if(query.canRunInBackground()) {
+ NewSearchUI.runQueryInBackground(query);
+ }
+ return true;
+ } else {
+ MessageDialog.openError(Display.getCurrent().getActiveShell(), SEARCH_ISSUE, REGULAR_EXPRESSION_ILLFORMED);
+ return false;
+ }
+ }
+
+ public void setContainer(ISearchPageContainer container) {
+ this.container = container;
+ this.container.setPerformActionEnabled(true);
+ }
+
+ public boolean performReplace() {
+ + if(validateRegex()) {
+ Collection<IResource> scope = ScopeCollector.getInstance().computeSearchScope(container);
+
+ Collection<ScopeEntry> scopeEntries = createScopeEntries(scope);
+
+ PapyrusQuery query = new PapyrusQuery(searchQueryText.getText(), btnCaseSensitive.getSelection(), btnRegularExpression.getSelection(), btnSearchInStereotypeAttributes.getSelection(), scopeEntries, participantTypesTreeViewer.getCheckedElements(), btnSearchAllStringAttributes.getSelection());
+ + NewSearchUI.runQueryInForeground(container.getRunnableContext(), query);
+ + Display.getCurrent().syncExec(new Runnable() {
+
+ public void run() {
+ ISearchResultViewPart view = NewSearchUI.activateSearchResultView();
+ if(view != null) {
+ ISearchResultPage page = view.getActivePage();
+
+ if(page instanceof PapyrusSearchResultPage) {
+ PapyrusSearchResultPage resultPage = (PapyrusSearchResultPage)page;
+ ReplaceAction replaceAction = new ReplaceAction(resultPage.getSite().getShell(), resultPage, null);
+ replaceAction.run();
+ }
+ }
+ }
+ });
+ + NewSearchUI.runQueryInForeground(container.getRunnableContext(), query);
+
+ return true;
+ } else {
+ MessageDialog.openError(Display.getCurrent().getActiveShell(), SEARCH_ISSUE, REGULAR_EXPRESSION_ILLFORMED);
+ return false;
+ }
+ + }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchResultPage.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchResultPage.java new file mode 100644 index 00000000000..e3ed21b5fc4 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchResultPage.java @@ -0,0 +1,167 @@ +/*****************************************************************************
+ * 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.uml.search.ui.pages;
+
+import java.util.Set;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.OpenEvent;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.services.openelement.service.OpenElementService;
+import org.eclipse.papyrus.uml.search.ui.Activator;
+import org.eclipse.papyrus.uml.search.ui.Messages;
+import org.eclipse.papyrus.uml.search.ui.actions.FilterTypesAction;
+import org.eclipse.papyrus.uml.search.ui.providers.ResultContentProvider;
+import org.eclipse.papyrus.uml.search.ui.providers.ResultLabelProvider;
+import org.eclipse.papyrus.views.search.results.AbstractResultEntry;
+import org.eclipse.papyrus.views.search.scope.ScopeEntry;
+import org.eclipse.papyrus.views.search.utils.MatchUtils;
+import org.eclipse.search.ui.IContextMenuConstants;
+import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
+import org.eclipse.search.ui.text.Match;
+import org.eclipse.ui.PartInitException;
+
+/**
+ *
+ * Papyrus specific search results page
+ *
+ */
+public class PapyrusSearchResultPage extends AbstractTextSearchViewPage {
+
+ ResultContentProvider fContentProvider = null;
+
+ private IAction fFiltertypesAction = null;
+
+ private static final int DEFAULT_ELEMENT_LIMIT = 1000;
+
+ public PapyrusSearchResultPage() {
+ super(FLAG_LAYOUT_TREE);
+ setElementLimit(new Integer(DEFAULT_ELEMENT_LIMIT));
+ fFiltertypesAction = new FilterTypesAction(this);
+ }
+
+ @Override
+ public Match[] getDisplayedMatches(Object element) {
+
+ Set<AbstractResultEntry> results = MatchUtils.getMatches(this.getInput(), true);
+
+ if(element instanceof AbstractResultEntry) {
+ AbstractResultEntry resultEntry = (AbstractResultEntry)element;
+
+ if(results.contains(resultEntry)) {
+
+ return new Match[]{ resultEntry };
+
+ }
+ return new Match[0];
+ } else {
+ return super.getDisplayedMatches(element);
+ }
+ }
+
+ @Override
+ public int getDisplayedMatchCount(Object element) {
+
+ if(element instanceof AbstractResultEntry) {
+ AbstractResultEntry resultEntry = (AbstractResultEntry)element;
+
+ Set<AbstractResultEntry> results = MatchUtils.getMatches(this.getInput(), true);
+ if(results.contains(resultEntry)) {
+ return 1;
+ }
+
+ return 0;
+ } else {
+ return super.getDisplayedMatchCount(element);
+ }
+ }
+
+ @Override
+ protected void fillToolbar(IToolBarManager tbm) {
+ super.fillToolbar(tbm);
+ tbm.appendToGroup(IContextMenuConstants.GROUP_REMOVE_MATCHES, fFiltertypesAction);
+ }
+
+ @Override
+ protected void handleOpen(OpenEvent event) {
+
+ ISelection selection = event.getSelection();
+ if(!selection.isEmpty()) {
+ if(selection instanceof IStructuredSelection) {
+ Object firstElement = ((IStructuredSelection)selection).getFirstElement();
+
+ if(firstElement instanceof AbstractResultEntry) {
+ AbstractResultEntry resultEntry = (AbstractResultEntry)firstElement;
+ ScopeEntry scopeEntry = (ScopeEntry)resultEntry.getElement();
+ if(scopeEntry != null && scopeEntry.getServicesRegistry() != null) {
+ try {
+ OpenElementService service = scopeEntry.getServicesRegistry().getService(OpenElementService.class);
+ resultEntry.openElement(service);
+ } catch (ServiceException e) {
+ // Activator.log.error(Messages.PapyrusSearchResultPage_0 + resultEntry.elementToOpen(), e);
+ } catch (PartInitException e) {
+ Activator.log.error(Messages.PapyrusSearchResultPage_1, e);
+ }
+ }
+
+ }
+
+ }
+
+ }
+
+ // super.handleOpen(event);
+ }
+
+ @Override
+ protected void elementsChanged(Object[] objects) {
+ if(fContentProvider != null) {
+ fContentProvider.elementsChanged(objects);
+ }
+ }
+
+ @Override
+ protected void evaluateChangedElements(Match[] matches, Set changedElements) {
+
+ for(int i = 0; i < matches.length; i++) {
+ changedElements.add(matches[i]);
+ }
+
+ }
+
+ @Override
+ protected void clear() {
+ if(fContentProvider != null) {
+ fContentProvider.clear();
+ }
+ }
+
+ @Override
+ protected void configureTreeViewer(TreeViewer viewer) {
+ viewer.setContentProvider(new ResultContentProvider(this, viewer));
+ viewer.setLabelProvider(new ResultLabelProvider());
+ fContentProvider = (ResultContentProvider)viewer.getContentProvider();
+ }
+
+ @Override
+ protected void configureTableViewer(TableViewer viewer) {
+
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/AttributeMatchLabelProvider.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/AttributeMatchLabelProvider.java new file mode 100644 index 00000000000..d6195e61ea4 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/AttributeMatchLabelProvider.java @@ -0,0 +1,109 @@ +/*****************************************************************************
+ * 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.uml.search.ui.providers;
+
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.services.labelprovider.service.IFilteredLabelProvider;
+import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
+import org.eclipse.papyrus.infra.services.labelprovider.service.impl.LabelProviderServiceImpl;
+import org.eclipse.papyrus.uml.search.ui.Activator;
+import org.eclipse.papyrus.uml.search.ui.Messages;
+import org.eclipse.papyrus.views.search.results.AttributeMatch;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+
+public class AttributeMatchLabelProvider implements IFilteredLabelProvider {
+
+ public Image getImage(Object element) {
+ if(element instanceof AttributeMatch) {
+ LabelProviderService service = new LabelProviderServiceImpl();
+ try {
+ service.startService();
+ return service.getLabelProvider().getImage(((AttributeMatch)element).getSource());
+ } catch (ServiceException e) {
+ Activator.log.warn(Messages.AttributeMatchLabelProvider_0 + ((AttributeMatch)element).getSource());
+ }
+ }
+ return null;
+ }
+
+ private String printResult(String sectionThatMatch, String value, int offset, int lenght, String attributeName) {
+ return "\"" + sectionThatMatch + "\"" + Messages.AttributeMatchLabelProvider_3 + "\"" + value + "\" [" + offset + "," + lenght + "] (" + attributeName + Messages.AttributeMatchLabelProvider_8 + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
+ }
+
+ public String getText(Object element) {
+
+ if(element instanceof AttributeMatch) {
+ AttributeMatch attributeMatch = ((AttributeMatch)element);
+ if((attributeMatch).getTarget() instanceof EObject) {
+ EObject target = (EObject)attributeMatch.getTarget();
+ if(attributeMatch.getSource() instanceof EAttribute) {
+ EAttribute source = (EAttribute)attributeMatch.getSource();
+ if(target.eGet(source) instanceof String) {
+ String value = (String)target.eGet(source);
+ return printResult(value.substring(attributeMatch.getOffset(), attributeMatch.getLength()), value, attributeMatch.getOffset(), attributeMatch.getLength(), source.getName());
+
+ }
+ } else if(attributeMatch.getSource() instanceof Property) {
+ Property source = (Property)attributeMatch.getSource();
+ Class containingClass = source.getClass_();
+ if(containingClass instanceof Stereotype) {
+ if(target instanceof Element) {
+ Object tagValue = ((Element)target).getValue((Stereotype)containingClass, source.getName());
+ if(tagValue instanceof String) {
+ String value = (String)tagValue;
+ return printResult(value.substring(attributeMatch.getOffset(), attributeMatch.getLength()), value, attributeMatch.getOffset(), attributeMatch.getLength(), source.getName());
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return ""; //$NON-NLS-1$
+
+ }
+
+ public void addListener(ILabelProviderListener listener) {
+
+ }
+
+ public void dispose() {
+
+ }
+
+ public boolean isLabelProperty(Object element, String property) {
+
+ return false;
+ }
+
+ public void removeListener(ILabelProviderListener listener) {
+
+ }
+
+ public boolean accept(Object element) {
+ if(element instanceof AttributeMatch) {
+ return true;
+
+ }
+ return false;
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/FilterTypeContentProvider.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/FilterTypeContentProvider.java new file mode 100644 index 00000000000..da32c4d3444 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/FilterTypeContentProvider.java @@ -0,0 +1,76 @@ +/*****************************************************************************
+ * 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.uml.search.ui.providers;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.views.search.results.AbstractResultEntry;
+import org.eclipse.papyrus.views.search.utils.MatchUtils;
+import org.eclipse.search.ui.text.AbstractTextSearchResult;
+import org.eclipse.uml2.uml.Element;
+
+/**
+ *
+ * Content provider used by the filter dialog to list available types in a search result
+ *
+ */
+public class FilterTypeContentProvider implements ITreeContentProvider {
+
+ public void dispose() {
+
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+
+ }
+
+ public Object[] getElements(Object inputElement) {
+ Set<Object> results = new HashSet<Object>();
+
+ if(inputElement instanceof AbstractTextSearchResult) {
+ + Collection<AbstractResultEntry> matches = MatchUtils.getMatches((AbstractTextSearchResult)inputElement, Element.class, false);
+
+ for(AbstractResultEntry match : matches) {
+
+ results.add(((EObject)match.elementToCheckFilterFor()).eClass());
+ results.addAll(((Element)match.elementToCheckFilterFor()).getAppliedStereotypes());
+ + }
+ }
+
+ return results.toArray();
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ Set<Object> results = new HashSet<Object>();
+
+ return results.toArray();
+ }
+
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+
+ return false;
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/FilterTypeLabelProvider.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/FilterTypeLabelProvider.java new file mode 100644 index 00000000000..9a7536900b7 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/FilterTypeLabelProvider.java @@ -0,0 +1,65 @@ +/*****************************************************************************
+ * 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.uml.search.ui.providers;
+
+import org.eclipse.emf.ecore.ENamedElement;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
+import org.eclipse.papyrus.infra.services.labelprovider.service.impl.LabelProviderServiceImpl;
+import org.eclipse.papyrus.uml.search.ui.Activator;
+import org.eclipse.papyrus.uml.search.ui.Messages;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.uml2.uml.Stereotype;
+
+import com.swtdesigner.ResourceManager;
+
+/**
+ *
+ * Label provider used by the filter dialog to list available types in a search result
+ *
+ */
+public class FilterTypeLabelProvider extends LabelProvider {
+
+ @Override
+ public Image getImage(Object object) {
+ if(object instanceof ENamedElement) {
+ String imagePath = "/icons/full/obj16/" + ((ENamedElement)object).getName() + ".gif"; //$NON-NLS-1$ //$NON-NLS-2$
+ return ResourceManager.getPluginImage("org.eclipse.uml2.uml.edit", imagePath); //$NON-NLS-1$
+ } else if(object instanceof Stereotype) {
+ LabelProviderService service = new LabelProviderServiceImpl();
+ try {
+ service.startService();
+ return service.getLabelProvider().getImage(object);
+ } catch (ServiceException e) {
+ Activator.log.warn(Messages.FilterTypeLabelProvider_0 + object);
+ return null;
+ }
+ } else {
+ return null;
+ }
+
+ }
+
+ @Override
+ public String getText(Object object) {
+ if(object instanceof ENamedElement) {
+ return ((ENamedElement)object).getName();
+ } else if(object instanceof Stereotype) {
+ return ((Stereotype)object).getName();
+ } else {
+ return ""; //$NON-NLS-1$
+ }
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/IResultContentProvider.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/IResultContentProvider.java new file mode 100644 index 00000000000..dc3988b87dc --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/IResultContentProvider.java @@ -0,0 +1,47 @@ +/*****************************************************************************
+ * 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.uml.search.ui.providers;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.jface.viewers.AbstractTreeViewer;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.papyrus.views.search.results.AbstractResultEntry;
+import org.eclipse.search.ui.text.AbstractTextSearchResult;
+
+/**
+ *
+ * Interface of the ResultContentProvider extension point that contributors must implement
+ *
+ */
+public interface IResultContentProvider {
+
+ /**
+ * Based on inputElement, add content to the resultHierarchy. Contributors must read the results to identify the elements they can process and add
+ * the corresponding content to the hierarchy
+ *
+ * @param inputElement
+ * the results
+ *
+ * @param resultHierarchy
+ * the hierarchy to contribute to
+ */
+ public void getHierarchy(AbstractTextSearchResult inputElement, Set<AbstractResultEntry> resultHierarchy);
+
+ public void initialize(AbstractTextSearchResult inputElement, Map<Object, Set<Object>> fChildrenMap, ITreeContentProvider treeContentProvider, AbstractTreeViewer viewer);
+
+ public void elementsChanged(Object[] updatedElements, AbstractTextSearchResult inputElement, Map<Object, Set<Object>> fChildrenMap, ITreeContentProvider treeContentProvider, AbstractTreeViewer viewer);
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ParticipantTypeContentProvider.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ParticipantTypeContentProvider.java new file mode 100644 index 00000000000..d2cffccc763 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ParticipantTypeContentProvider.java @@ -0,0 +1,96 @@ +/*****************************************************************************
+ * 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.uml.search.ui.providers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.uml.search.ui.pages.PapyrusSearchPage;
+import org.eclipse.uml2.uml.UMLPackage;
+
+/**
+ *
+ * A content provider for a ePackage
+ *
+ */
+public class ParticipantTypeContentProvider implements ITreeContentProvider {
+
+ private EPackage ePackage = null;
+
+ PapyrusSearchPage papyrusSearchPage = null;
+
+ public ParticipantTypeContentProvider(PapyrusSearchPage papyrusSearchPage) {
+ this.papyrusSearchPage = papyrusSearchPage;
+ }
+
+ public void dispose() {
+
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+
+ }
+
+ public Object[] getElements(Object inputElement) {
+ List<EObject> result = new ArrayList<EObject>();
+ if(inputElement instanceof EPackage) {
+ ePackage = (EPackage)inputElement;
+
+ for(EClassifier classifier : ePackage.getEClassifiers()) {
+ if(classifier instanceof EClass) {
+ if(papyrusSearchPage != null) {
+ if(papyrusSearchPage.getSearchAllStringAttributes()) {
+ result.add(classifier);
+ } else {
+
+ if(classifier == UMLPackage.eINSTANCE.getNamedElement()) {
+ result.add(classifier);
+ }
+ EList<EClass> supers = ((EClass)classifier).getEAllSuperTypes();
+ if(supers.contains(UMLPackage.eINSTANCE.getNamedElement())) {
+ result.add(classifier);
+ }
+ }
+
+ } else {
+ result.add(classifier);
+ }
+ }
+ }
+
+ }
+
+ return result.toArray();
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ return null;
+ }
+
+ public Object getParent(Object element) {
+
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ return false;
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ParticipantTypeLabelProvider.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ParticipantTypeLabelProvider.java new file mode 100644 index 00000000000..393b0598925 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ParticipantTypeLabelProvider.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.uml.search.ui.providers;
+
+import org.eclipse.emf.ecore.ENamedElement;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+import com.swtdesigner.ResourceManager;
+
+public class ParticipantTypeLabelProvider extends LabelProvider {
+ + @Override
+ public Image getImage(Object object) {
+ if(object instanceof ENamedElement) {
+ String imagePath = "/icons/full/obj16/" + ((ENamedElement)object).getName() + ".gif"; //$NON-NLS-1$ //$NON-NLS-2$
+ return ResourceManager.getPluginImage("org.eclipse.uml2.uml.edit", imagePath); //$NON-NLS-1$
+ }
+ return null;
+ }
+ + @Override
+ public String getText(Object object) {
+ return object instanceof ENamedElement ? ((ENamedElement)object).getName() : null;
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ResultContentProvider.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ResultContentProvider.java new file mode 100644 index 00000000000..aafaa9b5f2b --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ResultContentProvider.java @@ -0,0 +1,279 @@ +/*****************************************************************************
+ * 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.uml.search.ui.providers;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.jface.viewers.AbstractTreeViewer;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.uml.search.ui.pages.PapyrusSearchResultPage;
+import org.eclipse.papyrus.uml.search.ui.results.PapyrusSearchResult;
+import org.eclipse.papyrus.views.search.results.AbstractResultEntry;
+import org.eclipse.papyrus.views.search.results.ModelMatch;
+import org.eclipse.papyrus.views.search.results.ResultEntry;
+import org.eclipse.papyrus.views.search.utils.MatchUtils;
+import org.eclipse.search.ui.text.AbstractTextSearchResult;
+
+/**
+ *
+ * A content provider that generate the content through the results computed by resultContentProviders
+ *
+ */
+public class ResultContentProvider implements ITreeContentProvider {
+
+ private final Object[] EMPTY_ARR = new Object[0];
+
+ private AbstractTextSearchResult fResult = null;
+
+ private PapyrusSearchResultPage fPage = null;
+
+ private AbstractTreeViewer fViewer;
+
+ private Map<Object, Set<Object>> fChildrenMap;
+
+ public ResultContentProvider(PapyrusSearchResultPage page, AbstractTreeViewer viewer) {
+ fPage = page;
+
+ this.fViewer = viewer;
+ }
+
+ public void dispose() {
+
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if(newInput != null) {
+ if(newInput instanceof PapyrusSearchResult) {
+ fResult = (AbstractTextSearchResult)newInput;
+ initialize();
+ }
+ }
+ }
+
+ public Object[] getElements(Object inputElement) {
+ Object[] children = getChildren(inputElement);
+ int elementLimit = getElementLimit();
+ if(elementLimit != -1 && elementLimit < children.length) {
+ Object[] limitedChildren = new Object[elementLimit];
+ System.arraycopy(children, 0, limitedChildren, 0, elementLimit);
+ return limitedChildren;
+ }
+ return children;
+ }
+
+ private int getElementLimit() {
+ return fPage.getElementLimit().intValue();
+ }
+
+ /**
+ * Used to clear the content
+ */
+ public void clear() {
+ initialize();
+ fViewer.refresh();
+ }
+
+ private void initialize() {
+
+ fChildrenMap = new HashMap<Object, Set<Object>>();
+
+ Set<AbstractResultEntry> realMatches = MatchUtils.getMatches(fResult, true);
+
+ for(AbstractResultEntry resultEntry : realMatches) {
+ insert(resultEntry, false);
+ }
+
+ }
+
+ protected boolean insertChild(Object parent, Object child) {
+
+ Set<Object> children = fChildrenMap.get(parent);
+
+ if(children == null) {
+ children = new HashSet<Object>();
+ fChildrenMap.put(parent, children);
+ }
+
+ boolean found = false;
+
+ for(Object object : children) {
+ if(child instanceof AbstractResultEntry) {
+ if(object instanceof AbstractResultEntry) {
+ if(((AbstractResultEntry)object).equals((AbstractResultEntry)child)) {
+
+ found = true;
+ break;
+
+ }
+ }
+ }
+ }
+
+ if(!found) {
+ children.add(child);
+ return true;
+ } else {
+
+ return false;
+ }
+
+ }
+
+ protected Object getUpdateParent(Object child) {
+ Object parent = getParent(child);
+
+ for(Object key : fChildrenMap.keySet()) {
+ if(key instanceof AbstractResultEntry) {
+ if(((AbstractResultEntry)key).equals(parent)) {
+ if((parent instanceof ModelMatch) && key instanceof ResultEntry) {
+ //Must replace ResultEntry in the tree by RealMatch
+ for(Object childInMap : fChildrenMap.get(key)) {
+ if(childInMap instanceof AbstractResultEntry) {
+ ((AbstractResultEntry)childInMap).setParent(parent);
+ }
+ }
+ key = parent;
+
+ } else {
+ parent = key;
+ ((AbstractResultEntry)child).setParent(parent);
+ }
+
+ }
+ }
+
+ }
+
+ return parent;
+
+ }
+
+ protected void insert(Object child, boolean refreshViewer) {
+
+ Object parent = getUpdateParent(child);
+
+ while(parent != null) {
+ if(insertChild(parent, child)) {
+ if(refreshViewer) {
+ fViewer.add(parent, child);
+ }
+ } else {
+ if(refreshViewer) {
+ fViewer.refresh(parent);
+ }
+ return;
+ }
+ child = parent;
+ parent = getUpdateParent(child);
+ }
+
+ if(insertChild(fResult, child)) {
+ if(refreshViewer) {
+ fViewer.add(fResult, child);
+ }
+ }
+ }
+
+ protected boolean hasChild(Object parent, Object child, Map<Object, Set<Object>> fChildrenMap) {
+ Set<Object> children = fChildrenMap.get(parent);
+ return children != null && children.contains(child);
+ }
+
+ protected void removeFromSiblings(Object element, Object parent) {
+ Set<Object> siblings = fChildrenMap.get(parent);
+ if(siblings != null) {
+ siblings.remove(element);
+ }
+ }
+
+ protected void remove(Object element, boolean refreshViewer) {
+ if(hasChildren(element)) {
+ if(refreshViewer) {
+ fViewer.refresh(element);
+ }
+ } else {
+ fChildrenMap.remove(element);
+ Object parent = getUpdateParent(element);
+ if(parent != null) {
+ removeFromSiblings(element, parent);
+ remove(parent, refreshViewer);
+ } else {
+ removeFromSiblings(element, fResult);
+ if(refreshViewer) {
+ fViewer.refresh();
+ }
+ }
+
+ }
+ }
+
+ /**
+ * Signal the objects that changed in the content
+ *
+ * @param objects
+ * objects that changed
+ */
+ public synchronized void elementsChanged(Object[] updatedElements) {
+
+ for(int i = 0; i < updatedElements.length; i++) {
+
+ if(updatedElements[i] instanceof AbstractResultEntry) {
+ Set<AbstractResultEntry> matches = MatchUtils.getMatches(fResult, true);
+
+ if(matches.contains(updatedElements[i])) {
+ AbstractResultEntry resultEntry = (AbstractResultEntry)updatedElements[i];
+ Object parent = getUpdateParent(updatedElements[i]);
+
+ if(hasChild(parent, updatedElements[i], fChildrenMap)) {
+ fViewer.update(new Object[]{ resultEntry, parent }, null);
+ } else {
+ insert(updatedElements[i], true); //or update
+ }
+
+ } else {
+ remove(updatedElements[i], true);
+ }
+ } else {
+ if(fResult.getMatchCount(updatedElements[i]) > 0) {
+ insert(updatedElements[i], true);
+ } else {
+ remove(updatedElements[i], true);
+ }
+ }
+ }
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ Set<Object> children = fChildrenMap.get(parentElement);
+ if(children == null)
+ return EMPTY_ARR;
+ return children.toArray();
+ }
+
+ public Object getParent(Object element) {
+ if(element instanceof AbstractResultEntry) {
+ AbstractResultEntry match = (AbstractResultEntry)element;
+ return match.getParent();
+ }
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ return getChildren(element).length > 0;
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ResultLabelProvider.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ResultLabelProvider.java new file mode 100644 index 00000000000..989ede3387c --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ResultLabelProvider.java @@ -0,0 +1,59 @@ +/*****************************************************************************
+ * 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.uml.search.ui.providers;
+
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
+import org.eclipse.papyrus.infra.services.labelprovider.service.impl.LabelProviderServiceImpl;
+import org.eclipse.papyrus.views.search.results.AbstractResultEntry;
+import org.eclipse.swt.graphics.Image;
+
+public class ResultLabelProvider extends LabelProvider {
+
+ private LabelProviderService labelProviderService;
+
+ public ResultLabelProvider() {
+ labelProviderService = new LabelProviderServiceImpl();
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ if(element instanceof AbstractResultEntry) {
+ return labelProviderService.getLabelProvider().getImage(((AbstractResultEntry)element).elementToDisplay());
+ }
+
+ return null;
+ }
+
+ @Override
+ public String getText(Object element) {
+ if(element instanceof AbstractResultEntry) {
+ return labelProviderService.getLabelProvider().getText(((AbstractResultEntry)element).elementToDisplay());
+ }
+
+ return ""; //$NON-NLS-1$
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ try {
+ labelProviderService.disposeService();
+ } catch (ServiceException ex) {
+ //Ignore
+ }
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusQuery.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusQuery.java new file mode 100644 index 00000000000..02e4e8c9e69 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusQuery.java @@ -0,0 +1,290 @@ +/*****************************************************************************
+ * 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.uml.search.ui.query;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.infra.core.resource.NotFoundException;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.services.viewersearch.impl.ViewerSearchService;
+import org.eclipse.papyrus.uml.search.ui.Activator;
+import org.eclipse.papyrus.uml.search.ui.Messages;
+import org.eclipse.papyrus.uml.search.ui.results.PapyrusSearchResult;
+import org.eclipse.papyrus.uml.tools.model.UmlModel;
+import org.eclipse.papyrus.views.search.regex.PatternHelper;
+import org.eclipse.papyrus.views.search.results.AbstractResultEntry;
+import org.eclipse.papyrus.views.search.results.AttributeMatch;
+import org.eclipse.papyrus.views.search.results.ModelMatch;
+import org.eclipse.papyrus.views.search.results.ViewerMatch;
+import org.eclipse.papyrus.views.search.scope.ScopeEntry;
+import org.eclipse.papyrus.views.search.validator.ParticipantValidator;
+import org.eclipse.search.ui.ISearchQuery;
+import org.eclipse.search.ui.ISearchResult;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.UMLPackage;
+
+/**
+ *
+ * Papyrus specific search query
+ *
+ */
+public class PapyrusQuery implements ISearchQuery {
+
+ public boolean isCaseSensitive() {
+ return isCaseSensitive;
+ }
+
+ public boolean isRegularExpression() {
+ return isRegularExpression;
+ }
+
+ private String searchQueryText;
+
+ private boolean isCaseSensitive;
+
+ private boolean isRegularExpression;
+
+ private Collection<ScopeEntry> scopeEntries;
+
+ private Object[] participantsTypes;
+
+ private PapyrusSearchResult results;
+
+ private boolean searchAllStringAttributes;
+
+ protected Set<AbstractResultEntry> fResults = null;
+
+ private boolean searchStereotypeAttributes;
+
+ public PapyrusQuery(String searchQueryText, boolean isCaseSensitive, boolean isRegularExpression, boolean searchStereotypeAttributes, Collection<ScopeEntry> scopeEntries, Object[] participantsTypes, boolean searchAllStringAttributes) {
+ this.searchQueryText = searchQueryText;
+ this.isCaseSensitive = isCaseSensitive;
+ this.isRegularExpression = isRegularExpression;
+ this.scopeEntries = scopeEntries;
+ this.participantsTypes = participantsTypes;
+ this.searchAllStringAttributes = searchAllStringAttributes;
+ this.searchStereotypeAttributes = searchStereotypeAttributes;
+ results = new PapyrusSearchResult(this);
+ fResults = new HashSet<AbstractResultEntry>();
+ }
+
+ public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
+ results.removeAll();
+ fResults.clear();
+
+ for(ScopeEntry scopeEntry : scopeEntries) {
+ try {
+
+ if(scopeEntry.getModelSet() != null) {
+
+ UmlModel umlModel = (UmlModel)scopeEntry.getModelSet().getModelChecked(UmlModel.MODEL_ID);
+
+ EObject root = umlModel.lookupRoot();
+
+ Collection<EObject> participants = ParticipantValidator.getInstance().getParticipants(root, participantsTypes);
+
+ evaluate(participants, scopeEntry);
+ }
+ } catch (NotFoundException e) {
+ Activator.log.error(Messages.PapyrusQuery_0 + scopeEntry.getModelSet(), e);
+ }
+ }
+ monitor.done();
+
+ return Status.OK_STATUS;
+ }
+
+ /**
+ * Evaluate if the value matches the pattern
+ *
+ * @param value
+ * the value to evaluate
+ * @param attribute
+ * the attribute has the value
+ * @param pattern
+ * the pattern that is searched
+ * @param participant
+ * the element that contains the value
+ * @param scopeEntry
+ * the scopeEntry that contains the participant
+ */
+ protected void evaluateAndAddToResult(String value, Object attribute, Pattern pattern, Object participant, ScopeEntry scopeEntry) {
+
+ value = value != null ? value : ""; //$NON-NLS-1$
+
+ Matcher m = pattern.matcher(value);
+
+ if(isRegularExpression) {
+ if(m.matches()) {
+ int start = m.start();
+ int end = m.end();
+ ModelMatch match = new AttributeMatch(start, end, participant, scopeEntry, attribute);
+
+ fResults.add(match);
+ }
+ } else {
+ while(m.find()) {
+ int start = m.start();
+ int end = m.end();
+ AttributeMatch match = new AttributeMatch(start, end, participant, scopeEntry, attribute);
+ fResults.add(match);
+ }
+ }
+
+ // if(PatternHelper.getInstance().evaluate(m, isRegularExpression)) {
+ // int start = m.start();
+ // int end = m.end();
+ // ModelMatch match = new AttributeMatch(start, end, participant, scopeEntry, attribute);
+ //
+ // fResults.add(match);
+ // }
+ }
+
+ /**
+ * Try to find elements that match in the participants
+ *
+ * @param participants
+ * @param scopeEntry
+ */
+ protected void evaluate(Collection<EObject> participants, ScopeEntry scopeEntry) {
+
+ for(EObject participant : participants) {
+
+ String query = searchQueryText;
+ if(searchQueryText.equals("")) { //$NON-NLS-1$
+ query = ".*"; //$NON-NLS-1$
+ }
+
+ Pattern pattern = PatternHelper.getInstance().createPattern(query, isCaseSensitive, isRegularExpression);
+
+ if(pattern != null) {
+ if(searchAllStringAttributes) {
+
+ for(EAttribute attribute : participant.eClass().getEAllAttributes()) {
+ Object value = participant.eGet(attribute);
+
+ if(value instanceof String) {
+ String stringValue = (String)value;
+ evaluateAndAddToResult(stringValue, attribute, pattern, participant, scopeEntry);
+ }
+ }
+
+ } else {
+ if(participant instanceof NamedElement) {
+ String umlElementName = ((NamedElement)participant).getName();
+ umlElementName = umlElementName != null ? umlElementName : ""; //$NON-NLS-1$
+
+ evaluateAndAddToResult(umlElementName, UMLPackage.eINSTANCE.getNamedElement_Name(), pattern, participant, scopeEntry);
+ }
+ }
+ if(searchStereotypeAttributes) {
+ if(participant instanceof Element) {
+ EList<Stereotype> stereotypes = ((Element)participant).getAppliedStereotypes();
+ for(Stereotype stereotype : stereotypes) {
+ for(Property stereotypeProperty : stereotype.getAllAttributes()) {
+ if(!stereotypeProperty.getName().startsWith("base_")) {
+ Object value = ((Element)participant).getValue(stereotype, stereotypeProperty.getName());
+ if(value != null) {
+
+ if(value instanceof String) {
+ String stringValue = (String)value;
+ evaluateAndAddToResult(stringValue, stereotypeProperty, pattern, participant, scopeEntry);
+ }
+ }
+ }
+ }
+
+ }
+ }
+ }
+
+ }
+ }
+
+ //Now, find in diagram and others the elements we found
+ ViewerSearchService viewerSearcherService = new ViewerSearchService();
+ try {
+ viewerSearcherService.startService();
+
+ //Get sources elements that matched
+ Set<Object> sources = new HashSet<Object>();
+ for(AbstractResultEntry match : fResults) {
+ if(match instanceof AttributeMatch) {
+ sources.add(((AttributeMatch)match).getTarget());
+ } else {
+ sources.add(match.getSource());
+ }
+ }
+
+ //Get viewer of these sources
+ Map<Object, Map<Object, Object>> viewersMappings = viewerSearcherService.getViewers(sources, scopeEntry.getModelSet());
+
+ //Add viewers to results
+ for(Object containingModelSet : viewersMappings.keySet()) {
+ for(Object view : viewersMappings.get(containingModelSet).keySet()) {
+ Object semanticElement = viewersMappings.get(containingModelSet).get(view);
+ ViewerMatch viewMatch = new ViewerMatch(view, scopeEntry, semanticElement);
+ fResults.add(viewMatch);
+ }
+ }
+
+ } catch (ServiceException e) {
+ Activator.log.error(Messages.PapyrusQuery_5 + scopeEntry.getModelSet(), e);
+ }
+ }
+
+ public String getLabel() {
+ return Messages.PapyrusQuery_6;
+ }
+
+ public boolean canRerun() {
+ return false;
+ }
+
+ public boolean canRunInBackground() {
+ return true;
+ }
+
+ public ISearchResult getSearchResult() {
+ for(AbstractResultEntry match : fResults) {
+ results.addMatch(match);
+ }
+ return results;
+ }
+
+ /**
+ * Getter for the text query
+ *
+ * @return the the query text
+ */
+ public String getSearchQueryText() {
+ return searchQueryText;
+ }
+
+}
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 new file mode 100644 index 00000000000..e68da3bd423 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/results/PapyrusSearchResult.java @@ -0,0 +1,147 @@ +/*****************************************************************************
+ * 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.uml.search.ui.results;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.papyrus.uml.search.ui.Activator;
+import org.eclipse.papyrus.uml.search.ui.Messages;
+import org.eclipse.papyrus.uml.search.ui.query.PapyrusQuery;
+import org.eclipse.papyrus.views.search.results.AbstractResultEntry;
+import org.eclipse.papyrus.views.search.scope.ScopeEntry;
+import org.eclipse.papyrus.views.search.utils.MatchUtils;
+import org.eclipse.search.ui.text.AbstractTextSearchResult;
+import org.eclipse.search.ui.text.IEditorMatchAdapter;
+import org.eclipse.search.ui.text.IFileMatchAdapter;
+import org.eclipse.search.ui.text.Match;
+import org.eclipse.search.ui.text.MatchFilter;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.ide.ResourceUtil;
+
+import com.swtdesigner.ResourceManager;
+
+public class PapyrusSearchResult extends AbstractTextSearchResult implements IEditorMatchAdapter, IFileMatchAdapter {
+
+ MatchFilter[] possibleMatchFilter;
+
+
+
+ private PapyrusQuery searchQuery;
+
+ public PapyrusSearchResult(PapyrusQuery query) {
+ this.searchQuery = query;
+ possibleMatchFilter = new MatchFilter[0];
+ }
+
+ public PapyrusQuery getQuery() {
+ return searchQuery;
+ }
+
+
+ public void setPossibleMatchFilter(MatchFilter[] possibleMatchFilter) {
+ this.possibleMatchFilter = possibleMatchFilter;
+ }
+
+ @Override
+ public MatchFilter[] getAllMatchFilters() {
+ return possibleMatchFilter;
+
+ }
+
+ public String getLabel() {
+
+ return getMatchCount() + Messages.PapyrusSearchResult_0 + searchQuery.getSearchQueryText() + Messages.PapyrusSearchResult_1;
+ }
+
+ public String getTooltip() {
+
+ return Messages.PapyrusSearchResult_2;
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return ResourceManager.getPluginImageDescriptor(Activator.PLUGIN_ID, "icons/PapyrusSearch.png"); //$NON-NLS-1$
+ }
+
+ @Override
+ public IEditorMatchAdapter getEditorMatchAdapter() {
+ return this;
+ }
+
+ @Override
+ public IFileMatchAdapter getFileMatchAdapter() {
+ return this;
+ }
+
+ public Match[] computeContainedMatches(AbstractTextSearchResult result, IFile file) {
+ Set<Match> results = new HashSet<Match>();
+ Set<AbstractResultEntry> allMatches = MatchUtils.getMatches(result, true);
+ for(AbstractResultEntry modelMatch : allMatches) {
+ Object element = modelMatch.getElement();
+ if(element instanceof ScopeEntry) {
+ if(((ScopeEntry)element).getResource().equals(file)) {
+ results.add(modelMatch);
+ }
+ }
+ }
+ Match[] arrayResult = new Match[results.size()];
+
+ return results.toArray(arrayResult);
+ }
+
+ public IFile getFile(Object element) {
+ if(element instanceof ScopeEntry) {
+ if(((ScopeEntry)element).getResource() instanceof IFile) {
+ return (IFile)((ScopeEntry)element).getResource();
+ }
+ }
+ return null;
+ }
+
+ public boolean isShownInEditor(Match match, IEditorPart editor) {
+ if(match instanceof AbstractResultEntry) {
+ Object element = match.getElement();
+ if(element instanceof ScopeEntry) {
+ ((ScopeEntry)element).getResource();
+
+ if(((ScopeEntry)element).getResource().equals(ResourceUtil.getResource(editor.getEditorInput()))) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ public Match[] computeContainedMatches(AbstractTextSearchResult result, IEditorPart editor) {
+ Set<Object> results = new HashSet<Object>();
+
+ Set<AbstractResultEntry> allMatches = MatchUtils.getMatches(result, true);
+ for(AbstractResultEntry modelMatch : allMatches) {
+ Object element = modelMatch.getElement();
+ if(element instanceof ScopeEntry) {
+ if(((ScopeEntry)element).getResource().equals(ResourceUtil.getResource(editor.getEditorInput()))) {
+ results.add(modelMatch);
+ }
+ }
+ }
+
+ Match[] arrayResult = new Match[results.size()];
+
+ return results.toArray(arrayResult);
+ }
+
+}
|