Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2013-07-11 09:32:16 +0000
committercletavernie2013-07-11 09:32:16 +0000
commit1e5ae0cef628a00b6c3e5f210e90d14c2ce5f55b (patch)
tree1b2f154ba5803f99df1c673fa2701843f8ae9689 /plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org
parent9a0568a7778f0ef0f7dee5df9b683c366a9dc49a (diff)
downloadorg.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/uml/org.eclipse.papyrus.uml.search.ui/src/org')
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/Activator.java88
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/CheckBoxFilteredTree.java55
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/Messages.java130
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/FilterTypesAction.java58
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/ReplaceAction.java59
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/adapter/PapyrusSearchAdapterFactory.java41
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/adapter/PapyrusSearchPageScoreComputer.java46
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/dialogs/ReplaceDialog.java255
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/dialogs/TypesFilterDialog.java115
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/filters/TypesMatchFilter.java88
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/handlers/SearchCommandHandler.java36
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/messages.properties51
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchPage.java307
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchResultPage.java167
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/AttributeMatchLabelProvider.java109
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/FilterTypeContentProvider.java76
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/FilterTypeLabelProvider.java65
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/IResultContentProvider.java47
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ParticipantTypeContentProvider.java96
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ParticipantTypeLabelProvider.java38
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ResultContentProvider.java279
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ResultLabelProvider.java59
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusQuery.java290
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/results/PapyrusSearchResult.java147
24 files changed, 2702 insertions, 0 deletions
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);
+ }
+
+}

Back to the top