Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Noyrit2013-07-16 15:50:45 +0000
committerFlorian Noyrit2013-07-16 15:50:45 +0000
commit69f6175633a55f6737e8e5734ec060d84726fafb (patch)
treee63de510c90e95ab89e1fbcd743ff723e77639b8 /plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org
parent75b5410d69a1df0e8e16a5aeacfea3cd5c1afdb2 (diff)
downloadorg.eclipse.papyrus-69f6175633a55f6737e8e5734ec060d84726fafb.tar.gz
org.eclipse.papyrus-69f6175633a55f6737e8e5734ec060d84726fafb.tar.xz
org.eclipse.papyrus-69f6175633a55f6737e8e5734ec060d84726fafb.zip
OCL-based search and type-based search
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.java4
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/Messages.java78
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/adapter/PapyrusSearchPageScoreComputer.java2
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/dialogs/ReplaceDialog.java4
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/messages.properties76
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchPage.java1083
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchResultPage.java2
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/AttributeMatchLabelProvider.java14
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/OCLContextContentProvider.java58
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ParticipantTypeAttribute.java29
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ParticipantTypeContentProvider.java108
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ParticipantTypeElement.java53
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ParticipantTypeLabelProvider.java18
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ResultContentProvider.java107
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/AbstractPapyrusQuery.java42
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusAdvancedQuery.java435
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusOCLQuery.java456
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusQuery.java32
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/results/PapyrusSearchResult.java8
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/validator/IParticipantValidator.java38
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/validator/ParticipantValidator.java101
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/IStereotypeCollector.java25
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/Messages.java17
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/StereotypeCollector.java290
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/UMLResourceVisitor.java62
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/messages.properties1
26 files changed, 2964 insertions, 179 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
index ec9b0579d40..78d2607ee2d 100644
--- 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
@@ -13,14 +13,14 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.search.ui;
+import org.eclipse.ocl.examples.xtext.essentialocl.ui.internal.EssentialOCLActivator;
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 {
+public class Activator extends EssentialOCLActivator {
// The plug-in ID
/** The Constant PLUGIN_ID. */
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
index ea2488db4fd..c524bf201a9 100644
--- 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
@@ -31,6 +31,10 @@ public class Messages extends NLS {
public static String FilterTypesAction_1;
+ public static String PapyrusOCLQuery_0;
+
+ public static String PapyrusOCLQuery_1;
+
public static String PapyrusQuery_0;
public static String PapyrusQuery_5;
@@ -43,16 +47,82 @@ public class Messages extends NLS {
public static String PapyrusSearchPage_10;
+ public static String PapyrusSearchPage_11;
+
+ public static String PapyrusSearchPage_12;
+
+ public static String PapyrusSearchPage_14;
+
+ public static String PapyrusSearchPage_15;
+
+ public static String PapyrusSearchPage_16;
+
+ public static String PapyrusSearchPage_17;
+
+ public static String PapyrusSearchPage_18;
+
+ public static String PapyrusSearchPage_19;
+
public static String PapyrusSearchPage_2;
+ public static String PapyrusSearchPage_20;
+
+ public static String PapyrusSearchPage_21;
+
+ public static String PapyrusSearchPage_22;
+
+ public static String PapyrusSearchPage_23;
+
+ public static String PapyrusSearchPage_24;
+
+ public static String PapyrusSearchPage_25;
+
+ public static String PapyrusSearchPage_26;
+
+ public static String PapyrusSearchPage_27;
+
+ public static String PapyrusSearchPage_28;
+
+ public static String PapyrusSearchPage_29;
+
public static String PapyrusSearchPage_3;
+ public static String PapyrusSearchPage_30;
+
+ public static String PapyrusSearchPage_31;
+
+ public static String PapyrusSearchPage_32;
+
+ public static String PapyrusSearchPage_33;
+
+ public static String PapyrusSearchPage_34;
+
+ public static String PapyrusSearchPage_35;
+
+ public static String PapyrusSearchPage_36;
+
+ public static String PapyrusSearchPage_37;
+
+ public static String PapyrusSearchPage_38;
+
+ public static String PapyrusSearchPage_39;
+
public static String PapyrusSearchPage_4;
+ public static String PapyrusSearchPage_40;
+
+ public static String PapyrusSearchPage_41;
+
+ public static String PapyrusSearchPage_42;
+
+ public static String PapyrusSearchPage_43;
+
public static String PapyrusSearchPage_5;
public static String PapyrusSearchPage_6;
+ public static String PapyrusSearchPage_7;
+
public static String PapyrusSearchPage_8;
public static String PapyrusSearchPage_9;
@@ -120,6 +190,14 @@ public class Messages extends NLS {
public static String TypesMatchFilter_2;
public static String TypesMatchFilter_3;
+ public static String PapyrusSearchPage_lblResearchKind_text;
+ public static String PapyrusSearchPage_txtSearchKind_text;
+ public static String PapyrusSearchPage_group_text;
+ public static String PapyrusSearchPage_btnCheckButton_text;
+ public static String PapyrusSearchPage_btnGg_text;
+ public static String PapyrusSearchPage_btnRefreshTypes_text;
+ public static String PapyrusSearchPage_btnRefreshTypes_text_1;
+ public static String PapyrusSearchPage_btnNewButton_text;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.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
index 493c102e68b..438141e0624 100644
--- 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
@@ -27,7 +27,7 @@ import org.eclipse.search.ui.ISearchPageScoreComputer;
public class PapyrusSearchPageScoreComputer implements ISearchPageScoreComputer {
public int computeScore(String pageId, Object input) {
- if("org.eclipse.papyrus.search.ui.pages.PapyrusSearchPage".equals(pageId)) {
+ if("org.eclipse.papyrus.search.ui.pages.PapyrusSearchPage".equals(pageId)) { //$NON-NLS-1$
EObject currentEObject = EMFHelper.getEObject(input);
if(currentEObject != null) {
try {
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
index 65e23138344..443b15ecd27 100644
--- 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
@@ -56,7 +56,7 @@ public class ReplaceDialog extends Dialog {
PapyrusSearchResultPage fResultPage;
- org.eclipse.papyrus.uml.search.ui.query.PapyrusQuery fQuery;
+ org.eclipse.papyrus.uml.search.ui.query.AbstractPapyrusQuery fQuery;
Object[] fSelection;
@@ -79,7 +79,7 @@ public class ReplaceDialog extends Dialog {
this.fResultPage = fResultPage;
this.fSelection = selection;
- this.fQuery = (org.eclipse.papyrus.uml.search.ui.query.PapyrusQuery)fResultPage.getInput().getQuery();
+ this.fQuery = (org.eclipse.papyrus.uml.search.ui.query.AbstractPapyrusQuery)fResultPage.getInput().getQuery();
}
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
index 46809434fe5..2f19d527713 100644
--- 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
@@ -1,34 +1,78 @@
-AttributeMatchLabelProvider_0=Failed to start label service for :
+#Eclipse modern messages class
+#Thu Jul 04 15:28:44 CEST 2013
+AttributeMatchLabelProvider_0=Failed to start label service for \:
AttributeMatchLabelProvider_3=\ in
AttributeMatchLabelProvider_8=\ attribute
-FilterTypeLabelProvider_0=Failed to start label service for :
+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:
+PapyrusOCLQuery_0=Error
+PapyrusOCLQuery_1=OCL expression is incorrect.
+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_11=Simple search
+PapyrusSearchPage_12=Advanced search
+PapyrusSearchPage_14=Select subelements
+PapyrusSearchPage_15=Refresh types
+PapyrusSearchPage_16=Search only in name attribute
+PapyrusSearchPage_17=Search in all string attributes
+PapyrusSearchPage_18=Select context
+PapyrusSearchPage_19=Select the context
PapyrusSearchPage_2=Search in all string attributes of selected types
+PapyrusSearchPage_20=Select the context of the OCL query:
+PapyrusSearchPage_21=Text search
+PapyrusSearchPage_22=OCL search
+PapyrusSearchPage_23=Warning
+PapyrusSearchPage_24=Failed to open the selected resource.
+PapyrusSearchPage_25=Warning
+PapyrusSearchPage_26=Select only one resource.
+PapyrusSearchPage_27=Warning
+PapyrusSearchPage_28=Scope must be "Selected resources"
+PapyrusSearchPage_29=Error
PapyrusSearchPage_3=Search in all string attributes of applied stereotypes
-PapyrusSearchPage_4=Text query:
+PapyrusSearchPage_30=Query text cannot be empty
+PapyrusSearchPage_31=Error
+PapyrusSearchPage_32=Select at least one element
+PapyrusSearchPage_33=Error
+PapyrusSearchPage_34=If you select an attribute you can't let query text empty
+PapyrusSearchPage_35=Error
+PapyrusSearchPage_36=Error
+PapyrusSearchPage_37=Query text cannot be empty
+PapyrusSearchPage_38=Error
+PapyrusSearchPage_39=Select at least one attribute to replace
+PapyrusSearchPage_4=Query kind\:
+PapyrusSearchPage_40=Error
+PapyrusSearchPage_41=You can replace only string attributes
+PapyrusSearchPage_42=Warning
+PapyrusSearchPage_43=Cannot perform replace action on OCL queries basis.
PapyrusSearchPage_5=Case sensitive
PapyrusSearchPage_6=Regular expression
+PapyrusSearchPage_7=Search kind:
PapyrusSearchPage_8=Search for
PapyrusSearchPage_9=Select All
+PapyrusSearchPage_btnCheckButton_text=Check Button
+PapyrusSearchPage_btnGg_text=gg
+PapyrusSearchPage_btnNewButton_text=New Button
+PapyrusSearchPage_btnRefreshTypes_text=Refresh Types
+PapyrusSearchPage_btnRefreshTypes_text_1=Refresh types
+PapyrusSearchPage_lblResearchKind_text=Research kind\:
+PapyrusSearchPage_txtSearchKind_text=Search kind\:
+PapyrusSearchResultPage_0=Failed to get openElementService to open\:
+PapyrusSearchResultPage_1=Failed to open element
PapyrusSearchResult_0=\ result(s) for "
-PapyrusSearchResult_1=":
+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
+PapyrusSearchResult_4=Failed to get modelSet for\:
+PapyrusSearchResult_5=Failed to get SashModel for\:
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:
+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
@@ -43,8 +87,8 @@ 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:
+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
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchPage.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchPage.java
index b2a8f475e39..9292a5cb988 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchPage.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchPage.java
@@ -13,20 +13,75 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.search.ui.pages;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
import java.util.regex.PatternSyntaxException;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.impl.EClassImpl;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ICheckStateProvider;
+import org.eclipse.jface.viewers.ICheckable;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.ocl.examples.domain.evaluation.DomainModelManager;
+import org.eclipse.ocl.examples.domain.values.Value;
+import org.eclipse.ocl.examples.domain.values.impl.InvalidValueException;
+import org.eclipse.ocl.examples.pivot.ExpressionInOCL;
+import org.eclipse.ocl.examples.pivot.ParserException;
+import org.eclipse.ocl.examples.pivot.context.EObjectContext;
+import org.eclipse.ocl.examples.pivot.context.ParserContext;
+import org.eclipse.ocl.examples.pivot.manager.MetaModelManager;
+import org.eclipse.ocl.examples.pivot.manager.MetaModelManagerListener;
+import org.eclipse.ocl.examples.pivot.manager.MetaModelManagerResourceSetAdapter;
+import org.eclipse.ocl.examples.pivot.utilities.BaseResource;
+import org.eclipse.ocl.examples.pivot.utilities.PivotUtil;
+import org.eclipse.ocl.examples.xtext.base.utilities.CS2PivotResourceAdapter;
+import org.eclipse.ocl.examples.xtext.console.xtfo.EmbeddedXtextEditor;
+import org.eclipse.ocl.examples.xtext.essentialocl.ui.model.BaseDocument;
+import org.eclipse.ocl.examples.xtext.essentialocl.utilities.EssentialOCLCSResource;
+import org.eclipse.ocl.examples.xtext.essentialocl.utilities.EssentialOCLPlugin;
+import org.eclipse.papyrus.infra.core.resource.NotFoundException;
+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.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.OCLContextContentProvider;
+import org.eclipse.papyrus.uml.search.ui.providers.ParticipantTypeAttribute;
import org.eclipse.papyrus.uml.search.ui.providers.ParticipantTypeContentProvider;
+import org.eclipse.papyrus.uml.search.ui.providers.ParticipantTypeElement;
import org.eclipse.papyrus.uml.search.ui.providers.ParticipantTypeLabelProvider;
+import org.eclipse.papyrus.uml.search.ui.query.AbstractPapyrusQuery;
+import org.eclipse.papyrus.uml.search.ui.query.PapyrusAdvancedQuery;
+import org.eclipse.papyrus.uml.search.ui.query.PapyrusOCLQuery;
import org.eclipse.papyrus.uml.search.ui.query.PapyrusQuery;
+import org.eclipse.papyrus.uml.stereotypecollector.StereotypeCollector;
+import org.eclipse.papyrus.uml.tools.model.UmlModel;
import org.eclipse.papyrus.views.search.regex.PatternHelper;
import org.eclipse.papyrus.views.search.scope.ScopeCollector;
import org.eclipse.papyrus.views.search.scope.ScopeEntry;
@@ -38,32 +93,67 @@ 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.custom.VerifyKeyListener;
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.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
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.IWorkbench;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
import org.eclipse.ui.dialogs.PatternFilter;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Enumeration;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.UMLPackage;
+import org.eclipse.uml2.uml.util.UMLUtil;
+import org.eclipse.xtext.resource.XtextResource;
+import org.eclipse.xtext.ui.editor.model.IXtextDocument;
+import org.eclipse.xtext.ui.editor.outline.IOutlineNode;
+import org.eclipse.xtext.ui.editor.outline.impl.EObjectNode;
+import org.eclipse.xtext.ui.editor.outline.impl.EStructuralFeatureNode;
+import org.eclipse.xtext.util.concurrent.IUnitOfWork;
+
+import com.google.inject.Injector;
/**
*
* Papyrus specific search page
*
*/
-public class PapyrusSearchPage extends DialogPage implements ISearchPage, IReplacePage {
+public class PapyrusSearchPage extends DialogPage implements ISearchPage, IReplacePage, MetaModelManagerListener {
+
+ public PapyrusSearchPage() {
+ }
+
+
+ private HashMap<ParticipantTypeElement, List<ParticipantTypeAttribute>> participantsList = new HashMap<ParticipantTypeElement, List<ParticipantTypeAttribute>>();
+
+ private ArrayList<ParticipantTypeElement> result = new ArrayList<ParticipantTypeElement>();
+
+ private Collection<Stereotype> availableStereotypes;
private static final String REGULAR_EXPRESSION_ILLFORMED = Messages.PapyrusSearchPage_0;
+ private static final String OCL_QUERY_ILLFORMED = Messages.PapyrusSearchPage_0;
+
private static final String SEARCH_ISSUE = Messages.PapyrusSearchPage_1;
private static final String SEARCH_IN_ALL_STRINGS = Messages.PapyrusSearchPage_2;
@@ -72,6 +162,8 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
private Text searchQueryText;
+ private Text oclContext;
+
private ISearchPageContainer container;
private CheckBoxFilteredTree participantTypesTree;
@@ -84,27 +176,65 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
private Button btnCaseSensitive;
+
private Button btnSearchAllStringAttributes;
- private Button btnSearchInStereotypeAttributes;
+ private Button btnSearchInName;
- public void createControl(Composite parent) {
+ private Combo queryKind;
- 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));
+ private Combo searchKind;
- Label lblSearchString = new Label(searchComposite, SWT.NONE);
- lblSearchString.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
- lblSearchString.setText(Messages.PapyrusSearchPage_4);
+ private EmbeddedXtextEditor oclEditor;
+
+ private Composite queryComposite;
+
+ private EObject contextObject;
+
+ private static final int TEXT_QUERY_KIND = 0;
+
+ private static final int OCL_QUERY_KIND = 1;
+
+ private static final int SIMPLE_SEARCH = 0;
+
+ private static final int ADVANCED_SEARCH = 1;
+
+ private ParserContext parserContext;
- 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));
+ private MetaModelManager nullMetaModelManager = null;
- searchQueryText = new Text(queryComposite, SWT.BORDER);
+ private DomainModelManager modelManager = null;
+
+ protected Composite textQueryComposite;
+
+ protected Composite textQueryComposite2;
+
+
+
+ private Composite advancedSearchComposite;
+
+ protected Group grpSearchFor;
+
+ private Composite textQueryFieldsComposite;
+
+ protected Set<EObject> umlMetaClasses = new HashSet<EObject>();
+
+ protected ParticipantTypeContentProvider participantTypeContentProvider = new ParticipantTypeContentProvider();
+
+
+
+
+ protected void createSimpleSearchQueryField() {
+
+ textQueryComposite = new Composite(queryComposite, SWT.NONE);
+ textQueryComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+ textQueryComposite.setLayout(new GridLayout(2, false));
+
+ textQueryFieldsComposite = new Composite(textQueryComposite, SWT.NONE);
+ textQueryFieldsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
+ textQueryFieldsComposite.setLayout(new GridLayout(1, false));
+
+ searchQueryText = new Text(textQueryFieldsComposite, SWT.BORDER);
searchQueryText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
searchQueryText.addModifyListener(new ModifyListener() {
@@ -114,10 +244,16 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
});
searchQueryText.setFocus();
- Composite compositeParameters = new Composite(queryComposite, SWT.NONE);
+ searchQueryExplanatoryLabel = new Label(textQueryFieldsComposite, SWT.NONE);
+ searchQueryExplanatoryLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
+
+
+ Composite compositeParameters = new Composite(textQueryComposite, 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);
@@ -136,62 +272,657 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
}
});
- 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 = new Group(textQueryComposite, SWT.NONE);
+ grpSearchFor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
+ grpSearchFor.setLayout(new GridLayout(1, false));
grpSearchFor.setText(Messages.PapyrusSearchPage_8);
- participantTypesTree = new CheckBoxFilteredTree(grpSearchFor, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, new PatternFilter(), true);
+ Composite groupComposite = new Composite(grpSearchFor, SWT.NONE);
+ groupComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+ groupComposite.setLayout(new GridLayout(2, false));
+
+ Label lblSearchKind = new Label(groupComposite, SWT.NONE);
+ lblSearchKind.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));
+ lblSearchKind.setText(Messages.PapyrusSearchPage_7);
+
+ searchKind = new Combo(groupComposite, SWT.VERTICAL | SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
+ searchKind.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1));
+ searchKind.add(Messages.PapyrusSearchPage_11);
+ searchKind.add(Messages.PapyrusSearchPage_12);
+ searchKind.select(SIMPLE_SEARCH);
+ searchKind.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent e) {
+ for(Control childControl : advancedSearchComposite.getChildren()) {
+ childControl.dispose();
+ }
+
+ if(searchKind.getSelectionIndex() == ADVANCED_SEARCH) {
+ if(participantsList.size() == 0) {
+ createResultList();
+ }
+ createAdvancedSearch();
+ } else {
+ simpleSearch();
+ }
+ advancedSearchComposite.layout();
+ }
+ });
+
+ advancedSearchComposite = new Composite(groupComposite, SWT.NONE);
+ // gd_advancedSearchComposite.widthHint = 479;
+ advancedSearchComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
+ advancedSearchComposite.setLayout(new GridLayout(2, false));
+
+ simpleSearch();
+
+
+
+ }
+
+ protected void createResultList() {
+ ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
+ IRunnableWithProgress computeAvailableTypes = new IRunnableWithProgress() {
+
+ public void run(IProgressMonitor thePM) throws InterruptedException {
+
+ //UML metaclasses
+ for(EClassifier eClassifier : UMLPackage.eINSTANCE.getEClassifiers()) {
+ if(eClassifier instanceof EClass) {
+ ParticipantTypeElement parentElement = new ParticipantTypeElement(eClassifier);
+ if(parentElement.getElement() instanceof EClass) {
+ List<ParticipantTypeAttribute> attributeList = new ArrayList<ParticipantTypeAttribute>();
+ for(EObject eAttribute : ((EClass)(parentElement).getElement()).getEAllAttributes()) {
+ ParticipantTypeAttribute attribute = new ParticipantTypeAttribute(eAttribute, ((ParticipantTypeElement)parentElement));
+ attributeList.add(attribute);
+
+
+ }
+ participantsList.put(parentElement, attributeList);
+ }
+ }
+ }
+
+
+ //Find available stereotypes
+ availableStereotypes = StereotypeCollector.getInstance().computeAvailableStereotypes(container);
+ for(Stereotype stereotype : availableStereotypes) {
+ ParticipantTypeElement parentElement = new ParticipantTypeElement(stereotype);
+ List<ParticipantTypeAttribute> attributeList = new ArrayList<ParticipantTypeAttribute>();
+ for(Property property : ((Stereotype)((ParticipantTypeElement)parentElement).getElement()).getAllAttributes()) {
+ if(!property.getName().startsWith("base_")) { //$NON-NLS-1$
+ if(property.getType() instanceof Element) {
+ if(UMLUtil.isBoolean(property.getType()) || UMLUtil.isString(property.getType()) || UMLUtil.isInteger(property.getType()) || UMLUtil.isReal(property.getType()) || UMLUtil.isUnlimitedNatural(property.getType()) || property.getType() instanceof Enumeration) {
+ ParticipantTypeAttribute attribute = new ParticipantTypeAttribute(property, (ParticipantTypeElement)parentElement);
+ attributeList.add(attribute);
+ }
+
+ }
+ }
+
+ }
+ boolean test = ((Stereotype)parentElement.getElement()).isAbstract();
+ participantsList.put(parentElement, attributeList);
+
+
+ }
+
+
+ }
+
+ };
+
+ try {
+ dialog.run(true, true, computeAvailableTypes);
+ } catch (InvocationTargetException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ } catch (InterruptedException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ }
+
+ protected void createAdvancedSearch() {
+
+
+
+
+ participantTypesTree = new CheckBoxFilteredTree(advancedSearchComposite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE, new PatternFilter(), true);
participantTypesTree.setLayout(new GridLayout());
- GridData chechboxTreeViewerGridData = new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1);
+ GridData chechboxTreeViewerGridData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
chechboxTreeViewerGridData.heightHint = 150;
participantTypesTree.setLayoutData(chechboxTreeViewerGridData);
participantTypesTreeViewer = (CheckboxTreeViewer)participantTypesTree.getViewer();
- participantTypesTreeViewer.setContentProvider(new ParticipantTypeContentProvider(this));
+ participantTypesTreeViewer.setContentProvider(participantTypeContentProvider);
participantTypesTreeViewer.setLabelProvider(new ParticipantTypeLabelProvider());
+ participantTypesTreeViewer.setSorter(new ViewerSorter());
+ participantTypesTreeViewer.setCheckStateProvider(new ICheckStateProvider() {
- Button btnSelectAll = new Button(grpSearchFor, SWT.PUSH);
+ public boolean isGrayed(Object element) {
+ return false;
+ }
+
+ public boolean isChecked(Object element) {
+ if(element instanceof ParticipantTypeElement) {
+
+ return ((ParticipantTypeElement)element).isChecked();
+
+ }
+ return false;
+ }
+ });
+ Composite participantManipualtionComposite = new Composite(advancedSearchComposite, SWT.NONE);
+ participantManipualtionComposite.setLayout(new GridLayout(1, false));
+ participantManipualtionComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
+
+
+
+
+ Button btnSelectSub = new Button(participantManipualtionComposite, SWT.PUSH);
+ btnSelectSub.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
+ btnSelectSub.setText(Messages.PapyrusSearchPage_14);
+ btnSelectSub.addMouseListener(new MouseAdapter() {
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ ISelection selection = participantTypesTreeViewer.getSelection();
+ if(selection instanceof IStructuredSelection) {
+ Object selectedElement = ((IStructuredSelection)selection).getFirstElement();
+
+ if(selectedElement instanceof ParticipantTypeElement) {
+ List<ParticipantTypeAttribute> attributeParentList = new ArrayList<ParticipantTypeAttribute>();
+
+ for(Object attribute : participantsList.get(selectedElement)) {
+ if(attribute instanceof ParticipantTypeAttribute) {
+ if(((ParticipantTypeAttribute)attribute).isChecked()) {
+ attributeParentList.add(((ParticipantTypeAttribute)attribute));
+ }
+
+ }
+ }
+ if(((ParticipantTypeElement)selectedElement).getElement() instanceof EClass) {
+
+ selectAllSubUML((ParticipantTypeElement)selectedElement, attributeParentList);
+
+ } else if(((ParticipantTypeElement)selectedElement).getElement() instanceof Stereotype) {
+
+ selectAllSubSter((ParticipantTypeElement)selectedElement, attributeParentList);
+
+ }
+ }
+ }
+
+ participantTypesTreeViewer.refresh();
+ }
+ });
+
+ Button btnSelectAll = new Button(participantManipualtionComposite, SWT.PUSH);
+ btnSelectAll.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
btnSelectAll.setText(Messages.PapyrusSearchPage_9);
+
btnSelectAll.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
- participantTypesTreeViewer.setAllChecked(true);
+ for(ParticipantTypeElement element : participantsList.keySet()) {
+ if(!element.isChecked()) {
+ element.setChecked(true);
+
+ for(ParticipantTypeAttribute attribute : participantsList.get(element)) {
+ attribute.setChecked(true);
+
+ }
+ }
+ }
+ participantTypesTreeViewer.refresh();
+
}
});
- Button btnDeselectAll = new Button(grpSearchFor, SWT.PUSH);
+ Button btnDeselectAll = new Button(participantManipualtionComposite, SWT.PUSH);
+ btnDeselectAll.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
btnDeselectAll.setText(Messages.PapyrusSearchPage_10);
btnDeselectAll.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
- participantTypesTreeViewer.setAllChecked(false);
+ for(ParticipantTypeElement element : participantsList.keySet()) {
+ if(element.isChecked()) {
+ element.setChecked(false);
+
+ for(ParticipantTypeAttribute attribute : participantsList.get(element)) {
+ attribute.setChecked(false);
+
+
+ }
+ }
+ }
+ participantTypesTreeViewer.refresh();
}
});
- 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() {
+
+ Button btnRefreshTypes = new Button(participantManipualtionComposite, SWT.PUSH);
+ btnRefreshTypes.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
+ btnRefreshTypes.setText(Messages.PapyrusSearchPage_15);
+ btnRefreshTypes.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
- participantTypesTreeViewer.refresh();
+
+ createAdvancedSearch();
+
+ }
+ });
+
+
+ participantTypesTreeViewer.setInput(participantsList);
+
+ // participantTypesTreeViewer.setAllChecked(true);
+ ((ICheckable)participantTypesTreeViewer).addCheckStateListener(new ICheckStateListener() {
+
+
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ if(event.getElement() instanceof ParticipantTypeElement) {
+
+
+ // If the item is checked . . .
+ if(event.getChecked()) {
+ Object selectedElement = event.getElement();
+
+ ((ParticipantTypeElement)selectedElement).setChecked(true);
+ participantTypesTreeViewer.refresh(selectedElement);
+
+ if(selectedElement instanceof ParticipantTypeAttribute) {
+ ParticipantTypeElement parent = ((ParticipantTypeAttribute)selectedElement).getParent();
+ if(parent != null) {
+ // participantTypesTreeViewer.setChecked(parent, true);
+ ((ParticipantTypeElement)parent).setChecked(true);
+ participantTypesTreeViewer.refresh(parent);
+ }
+ }
+ } else {
+ Object selectedElement = event.getElement();
+ ((ParticipantTypeElement)selectedElement).setChecked(false);
+ participantTypesTreeViewer.refresh(selectedElement);
+
+ if(((ParticipantTypeElement)selectedElement).getElement() instanceof Stereotype || ((ParticipantTypeElement)selectedElement).getElement() instanceof EClassImpl) {
+ for(Object attribute : participantTypesTreeViewer.getCheckedElements()) {
+ if(attribute instanceof ParticipantTypeAttribute) {
+ if(((ParticipantTypeAttribute)attribute).getParent().equals(selectedElement)) {
+ // participantTypesTreeViewer.setChecked(attribute, false);
+ ((ParticipantTypeElement)attribute).setChecked(false);
+ participantTypesTreeViewer.refresh(attribute);
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+ }
+ });
+ }
+
+ protected void selectAllSubSter(final ParticipantTypeElement elementParent, final List<ParticipantTypeAttribute> attributeParentList) {
+ // for(Object element : result) {
+ // if(element instanceof Stereotype) {
+ // List<Class> superTypes = ((Stereotype)element).getSuperClasses();
+ // for(Class type : superTypes) {
+ // ((Stereotype)elementParent).getName();
+ //
+ // if(((Class)type).getName().equals(((Stereotype)elementParent).getName())) {
+ // participantTypesTreeViewer.setChecked(element, true);
+ //
+ // }
+ // }
+ // }
+ // }
+ ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
+ IRunnableWithProgress computeAvailableTypes = new IRunnableWithProgress() {
+
+ public void run(IProgressMonitor thePM) throws InterruptedException {
+ for(Object element : participantsList.keySet()) {
+ if(element instanceof ParticipantTypeElement) {
+ if(((ParticipantTypeElement)element).getElement() instanceof Stereotype) {
+ List<Class> superTypes = ((Class)((ParticipantTypeElement)element).getElement()).getSuperClasses();
+
+ if(superTypes.contains(elementParent.getElement())) {
+ // participantTypesTreeViewer.setChecked(element, true);
+ ((ParticipantTypeElement)element).setChecked(true);
+
+
+ //Proceed with attributes
+ for(ParticipantTypeAttribute attributeParent : attributeParentList) {
+ for(ParticipantTypeAttribute attributeToEvaluate : participantsList.get(element)) {
+ if(attributeParent.getElement() == attributeToEvaluate.getElement()) {
+
+ attributeToEvaluate.setChecked(true);
+
+
+ }
+
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+ }
+
+ };
+
+ try {
+ dialog.run(true, true, computeAvailableTypes);
+ } catch (InvocationTargetException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ } catch (InterruptedException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ }
+
+ protected void selectAllSubUML(final ParticipantTypeElement elementParent, final List<ParticipantTypeAttribute> attributeParentList) {
+
+ ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
+ IRunnableWithProgress computeAvailableTypes = new IRunnableWithProgress() {
+
+ public void run(IProgressMonitor thePM) throws InterruptedException {
+ for(Object element : participantsList.keySet()) {
+ if(element instanceof ParticipantTypeElement) {
+ if(((ParticipantTypeElement)element).getElement() instanceof EClass) {
+ List<EClass> superTypes = ((EClass)((ParticipantTypeElement)element).getElement()).getEAllSuperTypes();
+
+ if(superTypes.contains(elementParent.getElement())) {
+ // participantTypesTreeViewer.setChecked(element, true);
+ ((ParticipantTypeElement)element).setChecked(true);
+
+
+ //Proceed with attributes
+ for(ParticipantTypeAttribute attributeParent : attributeParentList) {
+ for(ParticipantTypeAttribute attributeToEvaluate : participantsList.get(element)) {
+ if(attributeParent.getElement() == attributeToEvaluate.getElement()) {
+
+ attributeToEvaluate.setChecked(true);
+
+
+ }
+
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+ }
+
+ };
+
+ try {
+ dialog.run(true, true, computeAvailableTypes);
+ } catch (InvocationTargetException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ } catch (InterruptedException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+
+
+
+
+ // for(Object element : participantsList.keySet()) {
+ // if(element instanceof ParticipantTypeElement) {
+ // if(((ParticipantTypeElement)element).getElement() instanceof EClass) {
+ // List<EClass> superTypes = ((EClass)((ParticipantTypeElement)element).getElement()).getEAllSuperTypes();
+ //
+ // if(superTypes.contains(elementParent.getElement())) {
+ // // participantTypesTreeViewer.setChecked(element, true);
+ // ((ParticipantTypeElement)element).setChecked(true);
+ //
+ // //Proceed with attributes
+ // for(ParticipantTypeAttribute attributeParent : attributeParentList) {
+ // for(ParticipantTypeAttribute attributeToEvaluate : participantsList.get(element)) {
+ // if(attributeParent.getElement() == attributeToEvaluate.getElement()) {
+ //
+ // attributeToEvaluate.setChecked(true);
+ //
+ //
+ // }
+ //
+ // }
+ // }
+ // }
+ // }
+ // }
+ // }
+ //
+ }
+
+
+ protected void simpleSearch() {
+
+
+ Composite participantManipualtionComposite = new Composite(advancedSearchComposite, SWT.NONE);
+ participantManipualtionComposite.setLayout(new GridLayout(1, false));
+ participantManipualtionComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true, 1, 1));
+
+
+ btnSearchInName = new Button(participantManipualtionComposite, SWT.RADIO);
+ btnSearchInName.setText(Messages.PapyrusSearchPage_16);
+ btnSearchInName.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 0, 1));
+ btnSearchInName.setSelection(true);
+
+
+ btnSearchAllStringAttributes = new Button(participantManipualtionComposite, SWT.RADIO);
+ btnSearchAllStringAttributes.setText(Messages.PapyrusSearchPage_17);
+ btnSearchAllStringAttributes.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
+ }
+
+ public void initMetaClasses() {
+
+ for(EClassifier eClassifier : UMLPackage.eINSTANCE.getEClassifiers()) {
+ if(eClassifier instanceof EClass) {
+ umlMetaClasses.add(eClassifier);
+ }
+ }
+
+ }
+
+
+ protected void createOCLSearchQueryField(EObject root) {
+
+ Composite client = queryComposite;
+
+ Composite oclContextComposite = new Composite(client, SWT.NONE);
+ oclContextComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
+ oclContextComposite.setLayout(new GridLayout(2, false));
+
+ oclContext = new Text(oclContextComposite, SWT.BORDER);
+ oclContext.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ oclContext.setEnabled(false);
+ oclContext.setFocus();
+
+ Button btnSelectContext = new Button(oclContextComposite, SWT.PUSH);
+ btnSelectContext.setText(Messages.PapyrusSearchPage_18);
+ btnSelectContext.addMouseListener(new MouseAdapter() {
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+
+ LabelProviderService labelProviderService = new LabelProviderServiceImpl();
+ ILabelProvider labelProvider = labelProviderService.getLabelProvider();
+
+ ScopeEntry currentScope = getCurrentScopeEntry();
+
+ if(currentScope != null) {
+
+ try {
+ EObject root = ((UmlModel)currentScope.getModelSet().getModel(UmlModel.MODEL_ID)).lookupRoot();
+
+ ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(Display.getCurrent().getActiveShell(), labelProvider, new OCLContextContentProvider());
+ dialog.setTitle(Messages.PapyrusSearchPage_19);
+ dialog.setMessage(Messages.PapyrusSearchPage_20);
+ dialog.setInput(currentScope.getModelSet());
+ dialog.setAllowMultiple(false);
+ dialog.open();
+ Object selection = dialog.getFirstResult();
+
+ if(selection instanceof EObject) {
+
+ refreshSelection(selection);
+
+ if(contextObject instanceof NamedElement) {
+ oclContext.setText(((NamedElement)contextObject).getQualifiedName());
+ } else {
+ oclContext.setText(labelProvider.getText(contextObject));
+ }
+ }
+
+ } catch (NotFoundException notFoundException) {
+
+ Activator.log.error(Messages.PapyrusQuery_0 + currentScope.getModelSet(), notFoundException);
+ }
+ }
+
+ }
+ });
+ btnSelectContext.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
+
+ Injector injector = Activator.getInstance().getInjector(EssentialOCLPlugin.LANGUAGE_ID);
+ Composite editorComposite = client;
+ oclEditor = new EmbeddedXtextEditor(editorComposite, injector, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
+
+ oclEditor.getViewer().getTextWidget().addVerifyKeyListener(new VerifyKeyListener() {
+
+ public void verifyKey(VerifyEvent e) {
+ // System.out.println("verifyKey: " + e.keyCode);
+ if(e.keyCode == SWT.KEYPAD_CR || e.keyCode == SWT.CR) {
+ if((e.stateMask & (SWT.CTRL | SWT.SHIFT)) == 0) {
+ e.doit = false;
+ }
+ }
+ }
+ });
+
+ GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
+ data.heightHint = convertHeightInCharsToPixels(3);
+ editorComposite.setLayoutData(data);
+
+ refreshSelection(root);
+ }
+
+ protected ScopeEntry getCurrentScopeEntry() {
+ if(container.getSelectedScope() == ISearchPageContainer.SELECTION_SCOPE) {
+ Collection<IResource> scope = ScopeCollector.getInstance().computeSearchScope(container);
+
+ Collection<ScopeEntry> scopeEntries = createScopeEntries(scope);
+
+ if(scopeEntries.size() == 1) {
+ Object[] entries = scopeEntries.toArray();
+ ScopeEntry selectedResource = (ScopeEntry)entries[0];
+
+ return selectedResource;
+ }
+ }
+ return null;
+ }
+
+ public void createControl(Composite parent) {
+
+ initializeDialogUnits(parent);
+ Composite searchComposite = new Composite(parent, SWT.NONE);
+ searchComposite.setFont(parent.getFont());
+ searchComposite.setLayout(new GridLayout(2, 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.RIGHT, SWT.CENTER, true, false, 1, 1));
+ lblSearchString.setText(Messages.PapyrusSearchPage_4);
+
+ queryKind = new Combo(searchComposite, SWT.VERTICAL | SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
+ queryKind.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false, 1, 1));
+ queryKind.add(Messages.PapyrusSearchPage_21);
+ queryKind.add(Messages.PapyrusSearchPage_22);
+
+
+
+ queryKind.select(TEXT_QUERY_KIND);
+
+ queryKind.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent e) {
+ for(Control childControl : queryComposite.getChildren()) {
+ childControl.dispose();
+ }
+
+ if(queryKind.getSelectionIndex() == TEXT_QUERY_KIND) {
+ createSimpleSearchQueryField();
+
+
+
+
+ } else {
+ if(container.getSelectedScope() == ISearchPageContainer.SELECTION_SCOPE) {
+
+ ScopeEntry currentScope = getCurrentScopeEntry();
+ if(currentScope != null) {
+ if(currentScope.getModelSet() != null) {
+
+ try {
+ EObject root = ((UmlModel)currentScope.getModelSet().getModel(UmlModel.MODEL_ID)).lookupRoot();
+ createOCLSearchQueryField(root);
+
+ if(contextObject instanceof NamedElement) {
+ oclContext.setText(((NamedElement)contextObject).getQualifiedName());
+ } else {
+ LabelProviderService labelProviderService = new LabelProviderServiceImpl();
+ ILabelProvider labelProvider = labelProviderService.getLabelProvider();
+ oclContext.setText(labelProvider.getText(contextObject));
+ }
+ } catch (NotFoundException notFoundException) {
+
+ Activator.log.error(Messages.PapyrusQuery_0 + currentScope.getModelSet(), notFoundException);
+ }
+ } else {
+ MessageDialog.openWarning(Display.getCurrent().getActiveShell(), Messages.PapyrusSearchPage_23, Messages.PapyrusSearchPage_24);
+ createSimpleSearchQueryField();
+ queryKind.select(TEXT_QUERY_KIND);
+ }
+ } else {
+ MessageDialog.openWarning(Display.getCurrent().getActiveShell(), Messages.PapyrusSearchPage_25, Messages.PapyrusSearchPage_26);
+ createSimpleSearchQueryField();
+ queryKind.select(TEXT_QUERY_KIND);
+ }
+ } else {
+ MessageDialog.openWarning(Display.getCurrent().getActiveShell(), Messages.PapyrusSearchPage_27, Messages.PapyrusSearchPage_28);
+ createSimpleSearchQueryField();
+ queryKind.select(TEXT_QUERY_KIND);
+ }
+ }
+ queryComposite.layout();
}
});
- 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);
+ queryComposite = new Composite(searchComposite, SWT.NONE);
+ queryComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
+ queryComposite.setLayout(new GridLayout(1, false));
+
+ createSimpleSearchQueryField();
setControl(parent);
}
@@ -225,6 +956,54 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
}
}
+ protected void refreshSelection(final Object selected) {
+ final BaseDocument editorDocument = (BaseDocument)oclEditor.getDocument();
+ editorDocument.modify(new IUnitOfWork<Object, XtextResource>() {
+
+ public Value exec(XtextResource resource) throws Exception {
+ Object selectedObject = selected;
+ if(selectedObject instanceof IOutlineNode) {
+ if(selectedObject instanceof EObjectNode) {
+ EObjectNode selectedObjectNode = (EObjectNode)selectedObject;
+ @SuppressWarnings("unused")
+ URI eObjectURI = selectedObjectNode.getEObjectURI();
+ contextObject = null; // FIXME
+ // metaModelManager.loadResource(eObjectURI,
+ // null, null);
+ } else if(selectedObject instanceof EStructuralFeatureNode) {
+ contextObject = null;
+ } else {
+ contextObject = null;
+ }
+ } else {
+ if(selectedObject instanceof IAdaptable) {
+ selectedObject = ((IAdaptable)selectedObject).getAdapter(EObject.class);
+ }
+ if(selectedObject instanceof EObject) {
+ contextObject = (EObject)selectedObject;
+ } else {
+ contextObject = null;
+ }
+ }
+ MetaModelManager metaModelManager = getMetaModelManager(contextObject);
+ parserContext = new EObjectContext(metaModelManager, null, contextObject);
+ EssentialOCLCSResource csResource = (EssentialOCLCSResource)resource;
+ if(csResource != null) {
+ if(contextObject != null) {
+ CS2PivotResourceAdapter.getAdapter(csResource, metaModelManager);
+ }
+ ResourceSet resourceSet = oclEditor.getResourceSet();
+ if(resourceSet != null) {
+ MetaModelManagerResourceSetAdapter.getAdapter(resourceSet, metaModelManager);
+ }
+ csResource.setParserContext(parserContext);
+ }
+
+ return null;
+ }
+ });
+ }
+
/**
* Create scopeEntries based on an IResources
*
@@ -246,20 +1025,88 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
public boolean performAction() {
- if(validateRegex()) {
- Collection<IResource> scope = ScopeCollector.getInstance().computeSearchScope(container);
+ if(queryKind.getSelectionIndex() == TEXT_QUERY_KIND) {
+ if(validateRegex()) {
+ Collection<IResource> scope = ScopeCollector.getInstance().computeSearchScope(container);
- Collection<ScopeEntry> scopeEntries = createScopeEntries(scope);
+ Collection<ScopeEntry> scopeEntries = createScopeEntries(scope);
+ ISearchQuery query;
+ if(searchKind.getSelectionIndex() == SIMPLE_SEARCH) {
+ if(searchQueryText.getText().isEmpty()) {
+ MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.PapyrusSearchPage_29, Messages.PapyrusSearchPage_30);
+ return false;
+ } else {
+ initMetaClasses();
+ query = new PapyrusQuery(searchQueryText.getText(), btnCaseSensitive.getSelection(), btnRegularExpression.getSelection(), scopeEntries, umlMetaClasses.toArray(), btnSearchAllStringAttributes.getSelection());
+ }
+ } else {
- ISearchQuery query = new PapyrusQuery(searchQueryText.getText(), btnCaseSensitive.getSelection(), btnRegularExpression.getSelection(), btnSearchInStereotypeAttributes.getSelection(), scopeEntries, participantTypesTreeViewer.getCheckedElements(), btnSearchAllStringAttributes.getSelection());
- if(query.canRunInBackground()) {
- NewSearchUI.runQueryInBackground(query);
+ List<ParticipantTypeElement> participantsToEvaluate = new ArrayList<ParticipantTypeElement>();
+ for(ParticipantTypeElement element : this.participantsList.keySet()) {
+ if(element.isChecked()) {
+ participantsToEvaluate.add(element);
+ for(ParticipantTypeAttribute attributesToEvaluate : participantsList.get(element)) {
+ if(attributesToEvaluate.isChecked()) {
+ participantsToEvaluate.add(attributesToEvaluate);
+ }
+ }
+ }
+ }
+ if(participantsToEvaluate.size() == 0) {
+
+ MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.PapyrusSearchPage_31, Messages.PapyrusSearchPage_32);
+ return false;
+ } else {
+ if(searchQueryText.getText().isEmpty()) {
+ for(Object participantChecked : participantTypesTreeViewer.getCheckedElements()) {
+ if(participantChecked instanceof ParticipantTypeAttribute) {
+ MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.PapyrusSearchPage_33, Messages.PapyrusSearchPage_34);
+ return false;
+ }
+ }
+ }
+
+ query = new PapyrusAdvancedQuery(searchQueryText.getText(), btnCaseSensitive.getSelection(), btnRegularExpression.getSelection(), scopeEntries, participantsToEvaluate.toArray());
+
+ }
+
+ }
+ if(query.canRunInBackground()) {
+ NewSearchUI.runQueryInBackground(query);
+ }
+
+ return true;
+ } else {
+ MessageDialog.openError(Display.getCurrent().getActiveShell(), SEARCH_ISSUE, REGULAR_EXPRESSION_ILLFORMED);
+ return false;
}
- return true;
} else {
- MessageDialog.openError(Display.getCurrent().getActiveShell(), SEARCH_ISSUE, REGULAR_EXPRESSION_ILLFORMED);
- return false;
+
+ ScopeEntry scopeEntry = getCurrentScopeEntry();
+
+ if(scopeEntry != null) {
+
+ try {
+
+ PivotUtil.checkResourceErrors("", oclEditor.getResource()); //$NON-NLS-1$
+ ExpressionInOCL expressionInOCL = parserContext.getExpression((BaseResource)oclEditor.getResource());
+ ISearchQuery query = new PapyrusOCLQuery((BaseDocument)oclEditor.getDocument(), parserContext, getMetaModelManager(contextObject), modelManager, contextObject, scopeEntry);
+
+
+ if(query.canRunInBackground()) {
+ NewSearchUI.runQueryInBackground(query);
+ }
+ } catch (ParserException e) {
+ Object value = new InvalidValueException(e, Messages.PapyrusSearchPage_35);
+ MessageDialog.openError(Display.getCurrent().getActiveShell(), SEARCH_ISSUE, OCL_QUERY_ILLFORMED);
+ return false;
+ }
+
+ return true;
+ } else {
+ return false;
+ }
}
}
@@ -269,39 +1116,141 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
}
public boolean performReplace() {
+ if(queryKind.getSelectionIndex() == TEXT_QUERY_KIND) {
+ if(validateRegex()) {
+ if(searchQueryText.getText().isEmpty()) {
+ MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.PapyrusSearchPage_36, Messages.PapyrusSearchPage_37);
+ return false;
+ }
- if(validateRegex()) {
- Collection<IResource> scope = ScopeCollector.getInstance().computeSearchScope(container);
+ Collection<IResource> scope = ScopeCollector.getInstance().computeSearchScope(container);
- Collection<ScopeEntry> scopeEntries = createScopeEntries(scope);
+ Collection<ScopeEntry> scopeEntries = createScopeEntries(scope);
+ AbstractPapyrusQuery query;
+ if(searchKind.getSelectionIndex() == SIMPLE_SEARCH) {
+ initMetaClasses();
+
+ query = new PapyrusQuery(searchQueryText.getText(), btnCaseSensitive.getSelection(), btnRegularExpression.getSelection(), scopeEntries, umlMetaClasses.toArray(), btnSearchAllStringAttributes.getSelection());
+ } else {
+ List<ParticipantTypeElement> participantsToEvaluate = new ArrayList<ParticipantTypeElement>();
+ for(ParticipantTypeElement element : this.participantsList.keySet()) {
+ if(element.isChecked()) {
+ participantsToEvaluate.add(element);
+ if(participantsList.get(element).size() == 0) {
+ MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.PapyrusSearchPage_38, Messages.PapyrusSearchPage_39);
+ return false;
+
+ } else {
+ for(ParticipantTypeAttribute attributesToEvaluate : participantsList.get(element)) {
+ if(attributesToEvaluate.isChecked()) {
+ participantsToEvaluate.add(attributesToEvaluate);
+ Object value = element.getElement().eGet((EAttribute)attributesToEvaluate.getElement());
+ if(!(value instanceof String)) {
+ MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.PapyrusSearchPage_40, Messages.PapyrusSearchPage_41);
+ return false;
+ }
+ }
+ }
+ }
+ }
+ }
+ query = new PapyrusAdvancedQuery(searchQueryText.getText(), btnCaseSensitive.getSelection(), btnRegularExpression.getSelection(), scopeEntries, participantsToEvaluate.toArray());
- PapyrusQuery query = new PapyrusQuery(searchQueryText.getText(), btnCaseSensitive.getSelection(), btnRegularExpression.getSelection(), btnSearchInStereotypeAttributes.getSelection(), scopeEntries, participantTypesTreeViewer.getCheckedElements(), btnSearchAllStringAttributes.getSelection());
+ }
+ NewSearchUI.runQueryInForeground(container.getRunnableContext(), query);
- NewSearchUI.runQueryInForeground(container.getRunnableContext(), query);
- Display.getCurrent().syncExec(new Runnable() {
+ Display.getCurrent().syncExec(new Runnable() {
- public void run() {
- ISearchResultViewPart view = NewSearchUI.activateSearchResultView();
- if(view != null) {
- ISearchResultPage page = view.getActivePage();
+ 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();
+ if(page instanceof PapyrusSearchResultPage) {
+ PapyrusSearchResultPage resultPage = (PapyrusSearchResultPage)page;
+ ReplaceAction replaceAction = new ReplaceAction(resultPage.getSite().getShell(), resultPage, null);
+ replaceAction.run();
+ }
}
}
- }
- });
+ });
- NewSearchUI.runQueryInForeground(container.getRunnableContext(), query);
+ NewSearchUI.runQueryInForeground(container.getRunnableContext(), query);
- return true;
+ return true;
+ } else {
+ MessageDialog.openError(Display.getCurrent().getActiveShell(), SEARCH_ISSUE, REGULAR_EXPRESSION_ILLFORMED);
+ return false;
+ }
} else {
- MessageDialog.openError(Display.getCurrent().getActiveShell(), SEARCH_ISSUE, REGULAR_EXPRESSION_ILLFORMED);
+ MessageDialog.openWarning(Display.getCurrent().getActiveShell(), Messages.PapyrusSearchPage_42, Messages.PapyrusSearchPage_43);
return false;
}
}
+
+
+
+
+ public @NonNull
+ MetaModelManager getMetaModelManager(@Nullable EObject contextObject) {
+ MetaModelManager metaModelManager = contextObject != null ? PivotUtil.findMetaModelManager(contextObject) : null;
+ if(metaModelManager != null) {
+ return metaModelManager;
+ }
+ MetaModelManager nullMetaModelManager2 = nullMetaModelManager;
+ if(nullMetaModelManager2 == null) {
+ nullMetaModelManager2 = nullMetaModelManager = new MetaModelManager();
+ nullMetaModelManager2.addListener(this);
+ }
+ return nullMetaModelManager2;
+ }
+
+ public void metaModelManagerDisposed(@NonNull MetaModelManager metaModelManager) {
+ metaModelManager.removeListener(this);
+ reset();
+
+ }
+
+ protected void flushEvents() {
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ while(workbench.getDisplay().readAndDispatch());
+ }
+
+ public void reset() {
+ if(oclEditor != null) {
+ IXtextDocument document = oclEditor.getDocument();
+ MetaModelManager metaModelManager = document.modify(new IUnitOfWork<MetaModelManager, XtextResource>() { // Cancel
+
+ // validation
+
+ public MetaModelManager exec(XtextResource state) throws Exception {
+ if(state == null) {
+ return null;
+ }
+ if(state instanceof BaseResource) {
+ ((BaseResource)state).setParserContext(null);
+ }
+ return PivotUtil.findMetaModelManager(state);
+ }
+ });
+ flushEvents();
+ // editor.close(false);
+ flushEvents();
+ if(metaModelManager != null) {
+ metaModelManager.dispose();
+ }
+ }
+ if(modelManager != null) {
+ // modelManager.dispose();
+ modelManager = null;
+ }
+ if(nullMetaModelManager != null) {
+ nullMetaModelManager.dispose();
+ nullMetaModelManager = null;
+ }
+ parserContext = null;
+ contextObject = null;
+ }
}
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
index e3ed21b5fc4..dac2e439797 100644
--- 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
@@ -136,9 +136,9 @@ public class PapyrusSearchResultPage extends AbstractTextSearchViewPage {
}
}
+
@Override
protected void evaluateChangedElements(Match[] matches, Set changedElements) {
-
for(int i = 0; i < matches.length; i++) {
changedElements.add(matches[i]);
}
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
index d6195e61ea4..e63ba98135b 100644
--- 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
@@ -45,7 +45,7 @@ public class AttributeMatchLabelProvider implements IFilteredLabelProvider {
}
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$
+ return "\"" + sectionThatMatch + "\"" + Messages.AttributeMatchLabelProvider_3 + "\"" + value + "\" [" + offset + "," + lenght + "] (" + attributeName + Messages.AttributeMatchLabelProvider_8 + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
}
public String getText(Object element) {
@@ -60,17 +60,27 @@ public class AttributeMatchLabelProvider implements IFilteredLabelProvider {
String value = (String)target.eGet(source);
return printResult(value.substring(attributeMatch.getOffset(), attributeMatch.getLength()), value, attributeMatch.getOffset(), attributeMatch.getLength(), source.getName());
+ } else {
+ String value = String.valueOf(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());
+
+ Object tagValue = ((Element)target).getValue((Stereotype)containingClass, ((Property)attributeMatch.getSource()).getName());
+
if(tagValue instanceof String) {
String value = (String)tagValue;
return printResult(value.substring(attributeMatch.getOffset(), attributeMatch.getLength()), value, attributeMatch.getOffset(), attributeMatch.getLength(), source.getName());
+ } else {
+ String value = String.valueOf(tagValue);
+ return printResult(value.substring(attributeMatch.getOffset(), attributeMatch.getLength()), value, attributeMatch.getOffset(), attributeMatch.getLength(), source.getName());
}
+
}
}
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/OCLContextContentProvider.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/OCLContextContentProvider.java
new file mode 100644
index 00000000000..d99707c59a9
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/OCLContextContentProvider.java
@@ -0,0 +1,58 @@
+package org.eclipse.papyrus.uml.search.ui.providers;
+
+import java.util.ArrayList;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.NotFoundException;
+import org.eclipse.papyrus.uml.tools.model.UmlModel;
+
+
+public class OCLContextContentProvider implements ITreeContentProvider {
+
+ public void dispose() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Object[] getElements(Object inputElement) {
+ ArrayList result = new ArrayList();
+ if(inputElement instanceof ModelSet) {
+ UmlModel root = (UmlModel)((ModelSet)inputElement).getModel(UmlModel.MODEL_ID);
+ try {
+ result.add(root.lookupRoot());
+ } catch (NotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ return result.toArray();
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ ArrayList result = new ArrayList();
+ if(parentElement instanceof EObject) {
+ result.addAll(((EObject)parentElement).eContents());
+ }
+
+ return result.toArray();
+ }
+
+ public Object getParent(Object element) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ return getChildren(element).length == 0 ? false : true;
+
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ParticipantTypeAttribute.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ParticipantTypeAttribute.java
new file mode 100644
index 00000000000..05655a58040
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ParticipantTypeAttribute.java
@@ -0,0 +1,29 @@
+package org.eclipse.papyrus.uml.search.ui.providers;
+
+import org.eclipse.emf.ecore.EObject;
+
+
+public class ParticipantTypeAttribute extends ParticipantTypeElement {
+
+ ParticipantTypeElement parent;
+
+ public ParticipantTypeAttribute(EObject element, ParticipantTypeElement type) {
+ super(element);
+ this.parent = type;
+ }
+
+
+ public ParticipantTypeElement getParent() {
+ return parent;
+ }
+
+
+ public void setType(ParticipantTypeElement parent) {
+ this.parent = parent;
+ }
+
+ public String getText() {
+
+ return super.getText();
+ }
+}
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
index d2cffccc763..07b4ea93a44 100644
--- 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
@@ -14,17 +14,12 @@
package org.eclipse.papyrus.uml.search.ui.providers;
import java.util.ArrayList;
+import java.util.HashMap;
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;
/**
*
@@ -33,12 +28,18 @@ import org.eclipse.uml2.uml.UMLPackage;
*/
public class ParticipantTypeContentProvider implements ITreeContentProvider {
+
+
+
private EPackage ePackage = null;
- PapyrusSearchPage papyrusSearchPage = null;
- public ParticipantTypeContentProvider(PapyrusSearchPage papyrusSearchPage) {
- this.papyrusSearchPage = papyrusSearchPage;
+ private HashMap<ParticipantTypeElement, List<ParticipantTypeAttribute>> participantsList = new HashMap<ParticipantTypeElement, List<ParticipantTypeAttribute>>();
+
+
+
+
+ public ParticipantTypeContentProvider() {
}
public void dispose() {
@@ -46,51 +47,86 @@ public class ParticipantTypeContentProvider implements ITreeContentProvider {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
+ participantsList = (HashMap<ParticipantTypeElement, List<ParticipantTypeAttribute>>)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);
- }
- }
- }
+
+ List<Object> result = new ArrayList<Object>();
+
+ if(inputElement instanceof HashMap) {
+ return ((HashMap)inputElement).keySet().toArray();
}
+ // for(Object obj : (Collection<Object>)inputElement) {
+ // result.add(obj);
+ // }
+
+
return result.toArray();
}
public Object[] getChildren(Object parentElement) {
+ if(parentElement instanceof ParticipantTypeElement) {
+ if(!(parentElement instanceof ParticipantTypeAttribute)) {
+ return participantsList.get(parentElement).toArray();
+ }
+ }
return null;
+
+ // List<ParticipantTypeAttribute> result = new ArrayList<ParticipantTypeAttribute>();
+ // if(parentElement instanceof ParticipantTypeElement) {
+ //
+ // if(((ParticipantTypeElement)parentElement).getElement() instanceof EClass) {
+ // // result.addAll(((EClass)parentElement).getEAllAttributes());
+ // for(EObject eAttribute : ((EClass)((ParticipantTypeElement)parentElement).getElement()).getEAllAttributes()) {
+ // ParticipantTypeAttribute attribute = new ParticipantTypeAttribute(eAttribute, ((ParticipantTypeElement)parentElement));
+ //
+ // result.add(attribute);
+ //
+ // }
+ //
+ //
+ // } else if(((ParticipantTypeElement)parentElement).getElement() instanceof Stereotype) {
+ //
+ // for(Property property : ((Stereotype)((ParticipantTypeElement)parentElement).getElement()).getAllAttributes()) {
+ // if(!property.getName().startsWith("base_")) {
+ // if(property.getType() instanceof Element) {
+ //
+ // if(UMLUtil.isBoolean(property.getType()) || UMLUtil.isString(property.getType()) || UMLUtil.isInteger(property.getType()) || UMLUtil.isReal(property.getType()) || UMLUtil.isUnlimitedNatural(property.getType()) || property.getType() instanceof Enumeration) {
+ // // result.add(property);
+ // ParticipantTypeAttribute attribute = new ParticipantTypeAttribute(property, (ParticipantTypeElement)parentElement);
+ //
+ // result.add(attribute);
+ //
+ //
+ // }
+ // }
+ // }
+ // }
+ // }
+ // }
+ //
+ // return result.toArray();
}
public Object getParent(Object element) {
+
return null;
+
}
public boolean hasChildren(Object element) {
- return false;
+ if(element instanceof ParticipantTypeAttribute) {
+ return false;
+ } else {
+ if(getChildren(element).length > 0)
+ return true;
+ else
+ return false;
+ }
+
}
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ParticipantTypeElement.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ParticipantTypeElement.java
new file mode 100644
index 00000000000..d6068d6b28f
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ParticipantTypeElement.java
@@ -0,0 +1,53 @@
+package org.eclipse.papyrus.uml.search.ui.providers;
+
+import org.eclipse.emf.ecore.ENamedElement;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.uml2.uml.NamedElement;
+
+
+public class ParticipantTypeElement {
+
+ boolean isChecked;
+
+ EObject element;
+
+
+
+ public EObject getElement() {
+ return element;
+ }
+
+
+
+ public void setElement(EObject element) {
+ this.element = element;
+ }
+
+
+ public ParticipantTypeElement(EObject element) {
+ super();
+ this.element = element;
+ isChecked = false;
+ }
+
+
+ public boolean isChecked() {
+ return isChecked;
+ }
+
+
+ public void setChecked(boolean isChecked) {
+ this.isChecked = isChecked;
+ }
+
+
+ public String getText() {
+ if(element instanceof NamedElement) {
+ return ((NamedElement)element).getName();
+ } else if(element instanceof ENamedElement) {
+ return ((ENamedElement)element).getName();
+ }
+ return null;
+ }
+
+}
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
index 393b0598925..e36ba6200f0 100644
--- 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
@@ -23,16 +23,24 @@ 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$
- }
+ if(object instanceof ParticipantTypeElement)
+ if(((ParticipantTypeElement)object).getElement() instanceof ENamedElement) {
+ String imagePath = "/icons/full/obj16/" + ((ENamedElement)((ParticipantTypeElement)object).getElement()).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;
+
+ if(object instanceof ParticipantTypeElement) {
+ return ((ParticipantTypeElement)object).getText();
+ }
+
+ return ""; //$NON-NLS-1$
+ //
}
}
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
index aafaa9b5f2b..c126e5f42ef 100644
--- 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
@@ -24,7 +24,6 @@ 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;
@@ -111,10 +110,16 @@ public class ResultContentProvider implements ITreeContentProvider {
boolean found = false;
- for(Object object : children) {
+ for(Object childInMap : children) {
if(child instanceof AbstractResultEntry) {
- if(object instanceof AbstractResultEntry) {
- if(((AbstractResultEntry)object).equals((AbstractResultEntry)child)) {
+ if(childInMap instanceof AbstractResultEntry) {
+ if(((AbstractResultEntry)childInMap).equals((AbstractResultEntry)child)) {
+
+ if((!(child instanceof ResultEntry)) && (childInMap instanceof ResultEntry)) {
+
+ replaceResultEntryByRealResult((AbstractResultEntry)childInMap, (AbstractResultEntry)child);
+
+ }
found = true;
break;
@@ -128,41 +133,69 @@ public class ResultContentProvider implements ITreeContentProvider {
children.add(child);
return true;
} else {
-
return false;
}
}
+ protected void replaceResultEntryByRealResult(AbstractResultEntry toReplace, AbstractResultEntry replacement) {
+
+ //Must replace ResultEntry in the tree by RealMatch
+ for(Object childInMap : fChildrenMap.get(toReplace)) {
+ if(childInMap instanceof AbstractResultEntry) {
+ ((AbstractResultEntry)childInMap).setParent(replacement);
+ }
+ }
+
+ fChildrenMap.put(replacement, fChildrenMap.get(toReplace));
+ ((AbstractResultEntry)replacement).setParent(toReplace.getParent());
+ fChildrenMap.remove(toReplace);
+
+ for(Object key : fChildrenMap.keySet()) {
+
+ if(fChildrenMap.get(key).contains(toReplace)) {
+ fChildrenMap.get(key).remove(toReplace);
+ fChildrenMap.get(key).add(replacement);
+ }
+ }
+
+ }
+
protected Object getUpdateParent(Object child) {
Object parent = getParent(child);
+ Object existingParent = null;
+
+ //Try to find if it is already in the childrenMap
for(Object key : fChildrenMap.keySet()) {
+ //It may be the parent
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;
+ existingParent = key;
+ break;
+ }
+ }
- } else {
- parent = key;
- ((AbstractResultEntry)child).setParent(parent);
+ //or one of the children
+ for(Object childInMap : fChildrenMap.get(key)) {
+ if(childInMap instanceof AbstractResultEntry) {
+ if(((AbstractResultEntry)childInMap).equals(parent)) {
+ existingParent = childInMap;
+ break;
}
-
}
}
-
}
- return parent;
-
+ if(existingParent != null) {
+ ((AbstractResultEntry)child).setParent(existingParent);
+ return existingParent;
+ } else {
+ return parent;
+ }
}
+
protected void insert(Object child, boolean refreshViewer) {
Object parent = getUpdateParent(child);
@@ -189,9 +222,28 @@ public class ResultContentProvider implements ITreeContentProvider {
}
}
- protected boolean hasChild(Object parent, Object child, Map<Object, Set<Object>> fChildrenMap) {
+ protected boolean hasChild(Object parent, Object child) {
Set<Object> children = fChildrenMap.get(parent);
- return children != null && children.contains(child);
+
+ if(children != null) {
+ for(Object childInMap : children) {
+ if(childInMap instanceof AbstractResultEntry) {
+ if(child instanceof AbstractResultEntry) {
+ if(((AbstractResultEntry)childInMap).equals((AbstractResultEntry)child)) {
+
+ if((!(child instanceof ResultEntry)) && (childInMap instanceof ResultEntry)) {
+ replaceResultEntryByRealResult((AbstractResultEntry)childInMap, (AbstractResultEntry)child);
+ }
+
+ return true;
+ }
+ }
+ }
+ }
+ }
+
+ return false;
+ // return children != null && children.contains(child);
}
protected void removeFromSiblings(Object element, Object parent) {
@@ -233,20 +285,21 @@ public class ResultContentProvider implements ITreeContentProvider {
for(int i = 0; i < updatedElements.length; i++) {
if(updatedElements[i] instanceof AbstractResultEntry) {
+ AbstractResultEntry resultEntry = (AbstractResultEntry)updatedElements[i];
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)) {
+ Object parent = getUpdateParent(resultEntry);
+
+ if(hasChild(parent, resultEntry)) {
fViewer.update(new Object[]{ resultEntry, parent }, null);
} else {
- insert(updatedElements[i], true); //or update
+ insert(resultEntry, true); //or update
}
} else {
- remove(updatedElements[i], true);
+ remove(resultEntry, true);
}
} else {
if(fResult.getMatchCount(updatedElements[i]) > 0) {
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/AbstractPapyrusQuery.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/AbstractPapyrusQuery.java
new file mode 100644
index 00000000000..33067b3ff4a
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/AbstractPapyrusQuery.java
@@ -0,0 +1,42 @@
+/*****************************************************************************
+ * 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 org.eclipse.search.ui.ISearchQuery;
+
+/**
+ *
+ * Papyrus specific search query
+ *
+ */
+public abstract class AbstractPapyrusQuery implements ISearchQuery {
+
+ /**
+ * Getter for the text query
+ *
+ * @return the the query text
+ */
+ public abstract String getSearchQueryText();
+
+ public boolean isCaseSensitive() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isRegularExpression() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusAdvancedQuery.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusAdvancedQuery.java
new file mode 100644
index 00000000000..4f2881c69f5
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusAdvancedQuery.java
@@ -0,0 +1,435 @@
+/*****************************************************************************
+ * 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.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+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.ENamedElement;
+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.providers.ParticipantTypeAttribute;
+import org.eclipse.papyrus.uml.search.ui.providers.ParticipantTypeElement;
+import org.eclipse.papyrus.uml.search.ui.results.PapyrusSearchResult;
+import org.eclipse.papyrus.uml.search.ui.validator.ParticipantValidator;
+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.ModelElementMatch;
+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.search.ui.ISearchResult;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Enumeration;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+/**
+ *
+ * Papyrus specific search query
+ *
+ */
+public class PapyrusAdvancedQuery extends AbstractPapyrusQuery {
+
+ public boolean isCaseSensitive() {
+ return isCaseSensitive;
+ }
+
+ public boolean isRegularExpression() {
+ return isRegularExpression;
+ }
+
+ private Set<Object> sources;
+
+ private String searchQueryText;
+
+ private boolean isCaseSensitive;
+
+ private boolean isRegularExpression;
+
+ private Collection<ScopeEntry> scopeEntries;
+
+ private Object[] participantsChecked;
+
+ private PapyrusSearchResult results;
+
+ private HashMap<EObject, List<EAttribute>> participantsList;
+
+ protected Set<AbstractResultEntry> fResults = null;
+
+
+
+ private HashMap<Stereotype, ArrayList<Property>> stereotypeList;
+
+ private List<EAttribute> attributesList;
+
+ private List<Property> propertyList;
+
+
+
+
+
+ public PapyrusAdvancedQuery(String searchQueryText, boolean isCaseSensitive, boolean isRegularExpression, Collection<ScopeEntry> scopeEntries, Object[] participantsChecked) {
+ this.propertyList = new ArrayList<Property>();
+ this.sources = new HashSet<Object>();
+ this.searchQueryText = searchQueryText;
+ this.isCaseSensitive = isCaseSensitive;
+ this.isRegularExpression = isRegularExpression;
+ this.scopeEntries = scopeEntries;
+ this.participantsChecked = participantsChecked;
+ results = new PapyrusSearchResult(this);
+
+ participantsList = new HashMap<EObject, List<EAttribute>>();
+ stereotypeList = new HashMap<Stereotype, ArrayList<Property>>();
+ for(Object participant : this.participantsChecked) {
+ if(participant instanceof ParticipantTypeElement) {
+ if(((ParticipantTypeElement)participant).getElement() instanceof ENamedElement) {
+ List<EAttribute> attributesChecked = new ArrayList<EAttribute>();
+ for(Object attributesFound : this.participantsChecked) {
+ if(attributesFound instanceof ParticipantTypeAttribute) {
+ if(((ParticipantTypeAttribute)attributesFound).getParent() == participant)
+ attributesChecked.add((EAttribute)((ParticipantTypeAttribute)attributesFound).getElement());
+ }
+ }
+ participantsList.put((EObject)((ParticipantTypeElement)participant).getElement(), attributesChecked);
+
+ } else if(((ParticipantTypeElement)participant).getElement() instanceof Stereotype) {
+
+ ArrayList<Property> attributesChecked = new ArrayList<Property>();
+ for(Object attributesFound : this.participantsChecked) {
+ if(attributesFound instanceof ParticipantTypeAttribute) {
+ if(((ParticipantTypeAttribute)attributesFound).getParent() == participant)
+ attributesChecked.add((Property)((ParticipantTypeAttribute)attributesFound).getElement());
+ }
+ }
+ stereotypeList.put((Stereotype)((ParticipantTypeElement)participant).getElement(), attributesChecked);
+ }
+ }
+ }
+
+ 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, participantsList.keySet().toArray());
+
+
+ evaluate(participants, scopeEntry);
+
+ Collection<EObject> stereotypesParticipants = ParticipantValidator.getInstance().getParticipantsStereotype(root, stereotypeList.keySet().toArray());
+
+
+ evaluateStereotypes(stereotypesParticipants, 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) {
+
+ if(searchQueryText.equals("")) { //$NON-NLS-1$
+
+
+ fResults.add(new ModelElementMatch(participant, scopeEntry));
+
+ } else {
+ 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(participantsList.get(participant.eClass()).size() == 0) {
+ attributesList = participant.eClass().getEAllAttributes();
+
+
+
+
+ } else {
+
+ attributesList = participantsList.get(participant.eClass());
+
+ }
+
+ for(EAttribute attribute : attributesList) {
+
+ Object value = participant.eGet(attribute);
+
+ if(value instanceof String) {
+ String stringValue = (String)value;
+ evaluateAndAddToResult(stringValue, attribute, pattern, participant, scopeEntry);
+ } else {
+ String stringValue = String.valueOf(value);
+ evaluateAndAddToResult(stringValue, attribute, pattern, participant, scopeEntry);
+ }
+ }
+ }
+
+
+ }
+ }
+ findAndShow(scopeEntry);
+
+ }
+
+
+ protected void evaluateStereotypes(Collection<EObject> participants, ScopeEntry scopeEntry) {
+
+ for(EObject participant : participants) {
+
+ if(searchQueryText.equals("")) { //$NON-NLS-1$
+ fResults.add(new ModelElementMatch(participant, scopeEntry));
+
+ } else {
+ String query = searchQueryText;
+ if(searchQueryText.equals("")) { //$NON-NLS-1$
+ query = ".*"; //$NON-NLS-1$
+ }
+
+ Pattern pattern = PatternHelper.getInstance().createPattern(query, isCaseSensitive, isRegularExpression);
+
+ if(pattern != null) {
+ EList<Stereotype> stereotypesApplied = ((Element)participant).getAppliedStereotypes();
+ for(Stereotype stereotype : stereotypesApplied) {
+ for(Stereotype stereotypeSelected : stereotypeList.keySet()) {
+ if(stereotype.getName().equals(stereotypeSelected.getName())) {
+ if(stereotypeList.get(stereotypeSelected).size() == 0) {
+
+ propertyList = this.getStereotypesAttributes(stereotype);
+ for(Property property : propertyList) {
+
+ Object value = ((Element)participant).getValue(stereotype, property.getName());
+ if(value != null) {
+ if(value instanceof String) {
+ String stringValue = (String)value;
+ evaluateAndAddToResult(stringValue, property, pattern, participant, scopeEntry);
+ } else {
+ String stringValue = String.valueOf(value);
+ evaluateAndAddToResult(stringValue, property, pattern, participant, scopeEntry);
+ }
+ }
+ }
+ } else {
+ propertyList = this.getStereotypesAttributes(stereotype);
+ for(Property property : propertyList) {
+ for(Property property2 : (stereotypeList.get(stereotypeSelected))) {
+ if(property.getName().equals(property2.getName())) {
+ Object value = ((Element)participant).getValue(stereotype, property.getName());
+ if(value != null) {
+ if(value instanceof String) {
+ String stringValue = (String)value;
+ evaluateAndAddToResult(stringValue, property, pattern, participant, scopeEntry);
+ } else {
+ String stringValue = String.valueOf(value);
+ evaluateAndAddToResult(stringValue, property, pattern, participant, scopeEntry);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+ }
+ findAndShow(scopeEntry);
+
+ }
+
+ public List<Property> getStereotypesAttributes(Object parentElement) {
+ List<Property> result = new ArrayList<Property>();
+ if(parentElement instanceof Stereotype) {
+
+ for(Property property : ((Stereotype)parentElement).getAllAttributes()) {
+
+ if(!property.getName().startsWith("base_")) { //$NON-NLS-1$
+ if(property.getType() instanceof Element) {
+
+ if(UMLUtil.isBoolean(property.getType()) || UMLUtil.isString(property.getType()) || UMLUtil.isInteger(property.getType()) || UMLUtil.isReal(property.getType()) || UMLUtil.isUnlimitedNatural(property.getType()) || property.getType() instanceof Enumeration) {
+ result.add(property);
+
+
+ }
+ }
+ }
+ }
+
+ }
+
+
+
+ return result;
+ }
+
+ protected void findAndShow(ScopeEntry scopeEntry) {
+ //Now, find in diagram and others the elements we found
+ ViewerSearchService viewerSearcherService = new ViewerSearchService();
+ try {
+ viewerSearcherService.startService();
+
+ //Get sources elements that matched
+
+ 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/query/PapyrusOCLQuery.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusOCLQuery.java
new file mode 100644
index 00000000000..d4f7adf459c
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusOCLQuery.java
@@ -0,0 +1,456 @@
+/*****************************************************************************
+ * 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.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.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.ocl.examples.domain.evaluation.DomainModelManager;
+import org.eclipse.ocl.examples.domain.evaluation.EvaluationHaltedException;
+import org.eclipse.ocl.examples.domain.utilities.DomainUtil;
+import org.eclipse.ocl.examples.domain.values.CollectionValue;
+import org.eclipse.ocl.examples.domain.values.impl.InvalidValueException;
+import org.eclipse.ocl.examples.domain.values.util.ValuesUtil;
+import org.eclipse.ocl.examples.pivot.Environment;
+import org.eclipse.ocl.examples.pivot.EnvironmentFactory;
+import org.eclipse.ocl.examples.pivot.ExpressionInOCL;
+import org.eclipse.ocl.examples.pivot.ParserException;
+import org.eclipse.ocl.examples.pivot.context.ParserContext;
+import org.eclipse.ocl.examples.pivot.evaluation.EvaluationEnvironment;
+import org.eclipse.ocl.examples.pivot.evaluation.EvaluationVisitor;
+import org.eclipse.ocl.examples.pivot.evaluation.EvaluationVisitorImpl;
+import org.eclipse.ocl.examples.pivot.evaluation.PivotEvaluationEnvironment;
+import org.eclipse.ocl.examples.pivot.manager.MetaModelManager;
+import org.eclipse.ocl.examples.pivot.utilities.BaseResource;
+import org.eclipse.ocl.examples.pivot.utilities.PivotEnvironment;
+import org.eclipse.ocl.examples.pivot.utilities.PivotEnvironmentFactory;
+import org.eclipse.ocl.examples.pivot.utilities.PivotUtil;
+import org.eclipse.ocl.examples.xtext.console.messages.ConsoleMessages;
+import org.eclipse.ocl.examples.xtext.essentialocl.ui.model.BaseDocument;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.papyrus.uml.search.ui.Messages;
+import org.eclipse.papyrus.uml.search.ui.results.PapyrusSearchResult;
+import org.eclipse.papyrus.views.search.results.AbstractResultEntry;
+import org.eclipse.papyrus.views.search.results.ModelElementMatch;
+import org.eclipse.papyrus.views.search.results.ModelMatch;
+import org.eclipse.papyrus.views.search.scope.ScopeEntry;
+import org.eclipse.search.ui.ISearchResult;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.progress.IProgressService;
+import org.eclipse.xtext.resource.XtextResource;
+import org.eclipse.xtext.util.concurrent.IUnitOfWork;
+
+/**
+ *
+ * Papyrus specific search query
+ *
+ */
+public class PapyrusOCLQuery extends AbstractPapyrusQuery {
+
+
+ private EObject contextObject;
+
+ private PapyrusSearchResult results;
+
+ private ScopeEntry scopeEntry;
+
+ private BaseDocument queryEditorDocument;
+
+ private ParserContext parserContext;
+
+ private MetaModelManager metaModelManager;
+
+ private DomainModelManager modelManager;
+
+ protected Set<AbstractResultEntry> fResults = null;
+
+ public PapyrusOCLQuery(BaseDocument queryEditorDocument, ParserContext parserContext, MetaModelManager metaModelManager, DomainModelManager modelManager, EObject contextObject, ScopeEntry scopeEntry) {
+ this.queryEditorDocument = queryEditorDocument;
+ this.contextObject = contextObject;
+ this.scopeEntry = scopeEntry;
+ this.parserContext = parserContext;
+ this.metaModelManager = metaModelManager;
+ this.modelManager = modelManager;
+ results = new PapyrusSearchResult(this);
+ fResults = new HashSet<AbstractResultEntry>();
+ }
+
+
+ protected boolean evaluate(final String expression) {
+
+ if((expression == null) || (expression.trim().length() <= 0)) {
+ MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.PapyrusOCLQuery_0, Messages.PapyrusOCLQuery_1);
+ return false;
+ }
+
+ boolean result = true;
+ try {
+
+
+ IDocument doc = queryEditorDocument;
+
+ final BaseDocument editorDocument = queryEditorDocument;
+ Object value = null;
+ try {
+
+ value = editorDocument.readOnly(new IUnitOfWork<Object, XtextResource>() {
+
+ public Object exec(XtextResource state) throws Exception {
+ assert state != null;
+ IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
+ EvaluationRunnable runnable = new EvaluationRunnable((BaseResource)state, expression);
+ runnable.run(new NullProgressMonitor());
+ // progressService.busyCursorWhile(runnable);
+ return runnable.getValue();
+ }
+ });
+ } catch (Exception e) {
+ // MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", e.getMessage());
+ }
+ if(value instanceof InvalidValueException) {
+ InvalidValueException exception = (InvalidValueException)value;
+ // MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", exception.getMessage());
+ Throwable cause = exception.getCause();
+ if((cause != null) && (cause != exception)) {
+ // MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", cause.getMessage());
+ }
+ } else if(value != null) {
+ CollectionValue collectionValue = ValuesUtil.isCollectionValue(value);
+ if(collectionValue != null) {
+ for(Object elementValue : collectionValue.iterable()) {
+ if(elementValue instanceof EObject) {
+ ModelMatch match = new ModelElementMatch(elementValue, scopeEntry);
+ fResults.add(match);
+ }
+ // System.err.println("Found : " + ValuesUtil.stringValueOf(elementValue));
+ }
+ } else {
+ if(value instanceof EObject) {
+ ModelMatch match = new ModelElementMatch(value, scopeEntry);
+ fResults.add(match);
+ }
+ // System.err.println("Found : " + ValuesUtil.stringValueOf(value));
+ }
+ } else {
+ // MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", ValuesUtil.stringValueOf(value));
+
+ }
+
+ } catch (Exception e) {
+ result = false;
+
+ if(e.getLocalizedMessage() == null) {
+ // MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", e.getClass().getName());
+ } else {
+ // MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", e.getLocalizedMessage());
+ }
+ }
+
+ return result;
+ }
+
+ private class EvaluationRunnable implements IRunnableWithProgress {
+
+ private final @NonNull
+ BaseResource resource;
+
+ private final @NonNull
+ String expression;
+
+ private Object value = null;
+
+ public EvaluationRunnable(@NonNull BaseResource resource, @NonNull String expression) {
+ this.resource = resource;
+ this.expression = expression;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public void run(final IProgressMonitor monitor) {
+ monitor.beginTask(NLS.bind(ConsoleMessages.Progress_Title, expression), 10);
+ monitor.subTask(ConsoleMessages.Progress_Synchronising);
+ monitor.worked(1);
+
+
+ ExpressionInOCL expressionInOCL;
+ try {
+ PivotUtil.checkResourceErrors("", resource); //$NON-NLS-1$
+ expressionInOCL = parserContext.getExpression(resource);
+ } catch (ParserException e) {
+ value = new InvalidValueException(e, ConsoleMessages.Result_ParsingFailure);
+ return;
+ }
+ if(expressionInOCL != null) {
+ // monitor.worked(2);
+ monitor.subTask(ConsoleMessages.Progress_Extent);
+ PivotEnvironmentFactory envFactory = new PivotEnvironmentFactory(null, metaModelManager);
+ PivotEnvironment environment = envFactory.createEnvironment();
+ PivotEvaluationEnvironment evaluationEnvironment = envFactory.createEvaluationEnvironment();
+ Object contextValue = metaModelManager.getIdResolver().boxedValueOf(contextObject);
+ evaluationEnvironment.add(DomainUtil.nonNullModel(expressionInOCL.getContextVariable()), contextValue);
+ // if (modelManager == null) {
+ // let the evaluation environment create one
+ @NonNull
+ DomainModelManager modelManager2 = modelManager = evaluationEnvironment.createModelManager(contextObject);
+ // }
+ monitor.worked(2);
+ monitor.subTask(ConsoleMessages.Progress_Evaluating);
+ try {
+ // metaModelManager.setMonitor(monitor);
+ CancelableEvaluationVisitor evaluationVisitor = new CancelableEvaluationVisitor(monitor, environment, evaluationEnvironment, modelManager2);
+ // evaluationVisitor.setLogger(new DomainLogger() {
+ //
+ // public void append(final @NonNull String message) {
+ // OCLConsolePage.this.getControl().getDisplay().asyncExec(new Runnable() {
+ //
+ // public void run() {
+ // OCLConsolePage.this.append(message, ColorManager.DEFAULT, false);
+ // }
+ // });
+ // }
+ // });
+ value = evaluationVisitor.visitExpressionInOCL(expressionInOCL);
+ } catch (InvalidValueException e) {
+ value = e;
+ } catch (EvaluationHaltedException e) {
+ value = new InvalidValueException(ConsoleMessages.Result_EvaluationTerminated);
+ } catch (Exception e) {
+ value = new InvalidValueException(e, ConsoleMessages.Result_EvaluationFailure);
+ } finally {
+ // metaModelManager.setMonitor(null);
+ }
+ }
+ monitor.worked(4);
+ }
+ }
+
+ /**
+ * CancelableEvaluationVisitor refines the EvaluationVisitor to poll the
+ * monitor foer cancelation at a variety of significant
+ * evaluation events, such as feature vists and {@link #getValueFactory()}.
+ */
+ protected static class CancelableEvaluationVisitor extends EvaluationVisitorImpl {
+
+ private final @NonNull
+ IProgressMonitor monitor;
+
+ protected CancelableEvaluationVisitor(@NonNull IProgressMonitor monitor, @NonNull Environment env, @NonNull EvaluationEnvironment evalEnv, @NonNull DomainModelManager modelManager) {
+ super(env, evalEnv, modelManager);
+ this.monitor = monitor;
+ }
+
+ @Override
+ public @NonNull
+ EvaluationVisitor createNestedEvaluator() {
+ EnvironmentFactory factory = environment.getFactory();
+ EvaluationEnvironment nestedEvalEnv = factory.createEvaluationEnvironment(evaluationEnvironment);
+ CancelableEvaluationVisitor nestedVisitor = new CancelableEvaluationVisitor(monitor, environment, nestedEvalEnv, modelManager);
+ nestedVisitor.setLogger(getLogger());
+ return nestedVisitor;
+ }
+ }
+
+ public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
+ results.removeAll();
+ fResults.clear();
+
+ evaluate(queryEditorDocument.get().trim());
+
+ 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);
+ // }
+ // }
+
+
+ }
+
+ /**
+ * 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() {
+ if(queryEditorDocument.get().length() > 25) {
+ return queryEditorDocument.get().subSequence(0, 25) + "..."; //$NON-NLS-1$
+ } else {
+ return queryEditorDocument.get();
+ }
+ }
+
+}
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
index 02e4e8c9e69..a2605a7a347 100644
--- 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
@@ -33,6 +33,7 @@ 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.search.ui.validator.ParticipantValidator;
import org.eclipse.papyrus.uml.tools.model.UmlModel;
import org.eclipse.papyrus.views.search.regex.PatternHelper;
import org.eclipse.papyrus.views.search.results.AbstractResultEntry;
@@ -40,8 +41,6 @@ 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;
@@ -54,7 +53,7 @@ import org.eclipse.uml2.uml.UMLPackage;
* Papyrus specific search query
*
*/
-public class PapyrusQuery implements ISearchQuery {
+public class PapyrusQuery extends AbstractPapyrusQuery {
public boolean isCaseSensitive() {
return isCaseSensitive;
@@ -82,14 +81,14 @@ public class PapyrusQuery implements ISearchQuery {
private boolean searchStereotypeAttributes;
- public PapyrusQuery(String searchQueryText, boolean isCaseSensitive, boolean isRegularExpression, boolean searchStereotypeAttributes, Collection<ScopeEntry> scopeEntries, Object[] participantsTypes, boolean searchAllStringAttributes) {
+ public PapyrusQuery(String searchQueryText, boolean isCaseSensitive, boolean isRegularExpression, 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>();
}
@@ -195,20 +194,11 @@ public class PapyrusQuery implements ISearchQuery {
}
}
- } 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_")) {
+ if(!stereotypeProperty.getName().startsWith("base_")) { //$NON-NLS-1$
Object value = ((Element)participant).getValue(stereotype, stereotypeProperty.getName());
if(value != null) {
@@ -217,13 +207,23 @@ public class PapyrusQuery implements ISearchQuery {
evaluateAndAddToResult(stringValue, stereotypeProperty, 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);
+ }
}
+
}
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/results/PapyrusSearchResult.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/results/PapyrusSearchResult.java
index e68da3bd423..6dd1ef67b0e 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/results/PapyrusSearchResult.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/results/PapyrusSearchResult.java
@@ -20,7 +20,7 @@ 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.uml.search.ui.query.AbstractPapyrusQuery;
import org.eclipse.papyrus.views.search.results.AbstractResultEntry;
import org.eclipse.papyrus.views.search.scope.ScopeEntry;
import org.eclipse.papyrus.views.search.utils.MatchUtils;
@@ -40,14 +40,14 @@ public class PapyrusSearchResult extends AbstractTextSearchResult implements IEd
- private PapyrusQuery searchQuery;
+ private AbstractPapyrusQuery searchQuery;
- public PapyrusSearchResult(PapyrusQuery query) {
+ public PapyrusSearchResult(AbstractPapyrusQuery query) {
this.searchQuery = query;
possibleMatchFilter = new MatchFilter[0];
}
- public PapyrusQuery getQuery() {
+ public AbstractPapyrusQuery getQuery() {
return searchQuery;
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/validator/IParticipantValidator.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/validator/IParticipantValidator.java
new file mode 100644
index 00000000000..30e58591747
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/validator/IParticipantValidator.java
@@ -0,0 +1,38 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.search.ui.validator;
+
+import java.util.Collection;
+
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ *
+ * Interface to implement to have a specific content validator. It is used to select only the elements that will be used to find patterns.
+ *
+ */
+public interface IParticipantValidator {
+
+ /**
+ * Return the elements that will participate (i.e. the participants) in the search query based on a list of types
+ *
+ * @param root
+ * all the children and itself will be check against the list of types
+ * @param participantsTypes
+ * the types of the wanted participants
+ * @return
+ * the elements that are of wanted types
+ */
+ public Collection<? extends Object> getParticipants(EObject root, Object[] participantsTypes);
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/validator/ParticipantValidator.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/validator/ParticipantValidator.java
new file mode 100644
index 00000000000..177ff26c248
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/validator/ParticipantValidator.java
@@ -0,0 +1,101 @@
+/*****************************************************************************
+ * 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.validator;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ *
+ * A generic implementation of participant validator that works on EMF basis
+ *
+ */
+public class ParticipantValidator implements IParticipantValidator {
+
+ private static ParticipantValidator instance = null;
+
+ private ParticipantValidator() {
+ super();
+ }
+
+ public final static ParticipantValidator getInstance() {
+
+ if(ParticipantValidator.instance == null) {
+ synchronized(ParticipantValidator.class) {
+ if(ParticipantValidator.instance == null) {
+ ParticipantValidator.instance = new ParticipantValidator();
+ }
+ }
+ }
+ return ParticipantValidator.instance;
+ }
+
+ public Collection<EObject> getParticipants(EObject root, Object[] participantsTypes) {
+
+ List<Object> participantsTypesList = Arrays.asList(participantsTypes);
+ List<EObject> results = new ArrayList<EObject>();
+
+
+
+ // ... and all its content
+ TreeIterator<EObject> it = root.eAllContents();
+ while(it.hasNext()) {
+ EObject modelElement = (EObject)it.next();
+ //Check that metaclass of this element is a supported metaclass
+
+ if(participantsTypesList.contains(modelElement.eClass())) {
+ results.add(modelElement);
+ }
+ }
+
+ return results;
+ }
+
+
+ public Collection<EObject> getParticipantsStereotype(EObject root, Object[] participantsTypes) {
+
+ List<Object> participantsTypesList = Arrays.asList(participantsTypes);
+ List<EObject> results = new ArrayList<EObject>();
+
+ // Evaluate root...
+ if(participantsTypesList.contains(root.eClass())) {
+ results.add(root);
+ }
+
+ // ... and all its content
+ TreeIterator<EObject> it = root.eAllContents();
+ while(it.hasNext()) {
+ EObject modelElement = (EObject)it.next();
+ if(modelElement instanceof Element) {
+ for(Stereotype element : ((Element)modelElement).getAppliedStereotypes()) {
+ //Check that metaclass of this element is a supported metaclass
+ for(Object stereotypeToGet : participantsTypesList) {
+ if(element.getName().equals(((Stereotype)stereotypeToGet).getName())) {
+ results.add(modelElement);
+ }
+ }
+ }
+ }
+ }
+
+ return results;
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/IStereotypeCollector.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/IStereotypeCollector.java
new file mode 100644
index 00000000000..6f46977785b
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/IStereotypeCollector.java
@@ -0,0 +1,25 @@
+/*****************************************************************************
+ * 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.stereotypecollector;
+
+import java.util.Collection;
+
+import org.eclipse.search.ui.ISearchPageContainer;
+import org.eclipse.uml2.uml.Stereotype;
+
+
+public interface IStereotypeCollector {
+
+ public Collection<Stereotype> computeAvailableStereotypes(ISearchPageContainer container);
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/Messages.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/Messages.java
new file mode 100644
index 00000000000..9b7540cc1d5
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/Messages.java
@@ -0,0 +1,17 @@
+package org.eclipse.papyrus.uml.stereotypecollector;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.uml.stereotypecollector.messages"; //$NON-NLS-1$
+
+ public static String StereotypeCollector_0;
+ 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/stereotypecollector/StereotypeCollector.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/StereotypeCollector.java
new file mode 100644
index 00000000000..bf8d15d39bb
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/StereotypeCollector.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.stereotypecollector;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.infra.emf.utils.BusinessModelResolver;
+import org.eclipse.papyrus.infra.onefile.model.IPapyrusFile;
+import org.eclipse.papyrus.views.search.utils.ModelUtils;
+import org.eclipse.search.ui.ISearchPageContainer;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.ProfileApplication;
+import org.eclipse.uml2.uml.Stereotype;
+
+public class StereotypeCollector implements IStereotypeCollector {
+
+ private static StereotypeCollector instance = null;
+
+ private StereotypeCollector() {
+ super();
+ }
+
+ public final static StereotypeCollector getInstance() {
+
+ if(StereotypeCollector.instance == null) {
+ synchronized(StereotypeCollector.class) {
+ if(StereotypeCollector.instance == null) {
+ StereotypeCollector.instance = new StereotypeCollector();
+ }
+ }
+ }
+ return StereotypeCollector.instance;
+ }
+
+
+ public Collection<Stereotype> computeAvailableStereotypes(ISearchPageContainer container) {
+ Set<Stereotype> preResult = new HashSet<Stereotype>();
+
+ Set<Profile> profiles = new HashSet<Profile>();
+
+ Set<IResource> umlResources = new HashSet<IResource>();
+
+ if(container == null) {
+ //Worksapce scope
+ umlResources.addAll(createWorkspaceScope());
+
+ } else {
+ switch(container.getSelectedScope()) {
+ case ISearchPageContainer.WORKSPACE_SCOPE:
+ {
+ umlResources.addAll(createWorkspaceScope());
+ break;
+ }
+ case ISearchPageContainer.SELECTION_SCOPE:
+ {
+ ISelection selection = container.getSelection();
+
+ if(!selection.isEmpty()) {
+ if(selection instanceof IStructuredSelection) {
+ umlResources.addAll(createSelectionScope((IStructuredSelection)selection));
+ } else {
+ //Do a workspace search instead
+ umlResources.addAll(createWorkspaceScope());
+ }
+ } else {
+ //Do a workspace search instead
+ umlResources.addAll(createWorkspaceScope());
+ }
+ break;
+ }
+ case ISearchPageContainer.SELECTED_PROJECTS_SCOPE:
+ {
+ String[] projects = container.getSelectedProjectNames();
+ umlResources.addAll(createProjectsScope(projects));
+ break;
+ }
+ case ISearchPageContainer.WORKING_SET_SCOPE:
+ {
+ IWorkingSet[] workingSets = container.getSelectedWorkingSets();
+ umlResources.addAll(createWorkingSetsScope(workingSets));
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
+ }
+
+ for(IResource umlRes : umlResources) {
+ URI uri = URI.createPlatformResourceURI(umlRes.getFullPath().toString(), true);
+ ResourceSet resourceSet = new ResourceSetImpl();
+ Resource resource = resourceSet.getResource(uri, true);
+
+ TreeIterator<EObject> UMLResourceContentIterator = resource.getAllContents();
+ while(UMLResourceContentIterator.hasNext()) {
+ EObject umlElement = (EObject)UMLResourceContentIterator.next();
+
+ if(umlElement instanceof ProfileApplication) {
+ profiles.add(((ProfileApplication)umlElement).getAppliedProfile());
+ }
+
+ }
+ }
+
+ for(Profile profile : profiles) {
+ TreeIterator<EObject> profileContentIterator = profile.eAllContents();
+
+ while(profileContentIterator.hasNext()) {
+ EObject profileContent = (EObject)profileContentIterator.next();
+ if(profileContent instanceof Stereotype) {
+ preResult.add((Stereotype)profileContent);
+ }
+ }
+
+ }
+
+ Set<Stereotype> result = new HashSet<Stereotype>();
+ for(Stereotype stereo : preResult) {
+ result.add(stereo);
+ for(Classifier parent : stereo.getGenerals()) {
+ if(parent instanceof Stereotype) {
+ result.add((Stereotype)parent);
+ }
+ }
+
+ }
+
+ return result;
+
+ }
+
+ /**
+ * Create a scope when the container is ISearchPageContainer.SELECTION_SCOPE
+ *
+ * @param selection
+ * the selection of the container
+ * @return
+ * the scope
+ */
+ protected List<IResource> createSelectionScope(IStructuredSelection selection) {
+ List<IResource> results = new ArrayList<IResource>();
+
+ Iterator it = selection.iterator();
+ while(it.hasNext()) {
+ Object object = (Object)it.next();
+
+ if(object instanceof IPapyrusFile) {
+ IResource[] associatedResources = ((IPapyrusFile)object).getAssociatedResources();
+ for(IResource iResource : associatedResources) {
+ results.addAll(findUMLModels(iResource));
+ }
+
+ } else if(object instanceof IResource) {
+ results.addAll(findUMLModels((IResource)object));
+ } else {
+
+ Object element = BusinessModelResolver.getInstance().getBusinessModel(object);
+ if(element instanceof EObject) {
+ Resource eResource = ((EObject)element).eResource();
+ IFile resource = ModelUtils.getIFile(eResource);
+ if(resource != null) {
+ results.add(resource);
+
+ } else {
+ //Do a workspace search instead
+ results.addAll(createWorkspaceScope());
+ }
+
+ } else {
+ //Do a workspace search instead
+ results.addAll(createWorkspaceScope());
+ }
+
+ }
+ }
+ return results;
+ }
+
+ /**
+ * Create a scope when the container is ISearchPageContainer.SELECTED_PROJECTS_SCOPE
+ *
+ * @param projects
+ * the selected scope
+ * @return
+ * the scope
+ */
+ protected List<IResource> createProjectsScope(String[] projects) {
+ List<IResource> results = new ArrayList<IResource>();
+
+ for(String projectName : projects) {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ if(project.isOpen()) {
+ results.addAll(findUMLModels(project));
+ }
+ }
+ return results;
+ }
+
+ /**
+ * Create a scope when the container is ISearchPageContainer.WORKING_SET_SCOPE
+ *
+ * @param workingSets
+ * the selected workingSets
+ * @return
+ * the scope
+ */
+ protected List<IResource> createWorkingSetsScope(IWorkingSet[] workingSets) {
+ List<IResource> results = new ArrayList<IResource>();
+
+ if(workingSets != null && workingSets.length > 0) {
+ for(IWorkingSet iWorkingSet : workingSets) {
+ for(IAdaptable element : iWorkingSet.getElements()) {
+ Object resource = element.getAdapter(IResource.class);
+ if(resource instanceof IResource) {
+ results.addAll(findUMLModels((IResource)resource));
+ }
+ }
+ }
+ }
+
+ return results;
+ }
+
+ /**
+ * Find all Papyrus models from a specific root
+ *
+ * @param res
+ * the root
+ * @return
+ * the found Papyrus models
+ */
+ protected Collection<IResource> findUMLModels(IResource res) {
+ UMLResourceVisitor visitor = new UMLResourceVisitor();
+ try {
+ res.accept(visitor, IResource.DEPTH_INFINITE);
+ } catch (CoreException e) {
+ org.eclipse.papyrus.uml.search.ui.Activator.log.warn(Messages.StereotypeCollector_0 + res);
+ }
+
+ return visitor.getParticipants();
+ }
+
+ /**
+ * Create a scope when the container is ISearchPageContainer.WORKSPACE_SCOPE
+ *
+ * @return
+ * the scope
+ */
+ protected Collection<IResource> createWorkspaceScope() {
+
+ //Go through the workspace root
+ IResource root = ResourcesPlugin.getWorkspace().getRoot();
+
+ return findUMLModels(root);
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/UMLResourceVisitor.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/UMLResourceVisitor.java
new file mode 100644
index 00000000000..a5ca8a3f4de
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/UMLResourceVisitor.java
@@ -0,0 +1,62 @@
+/*****************************************************************************
+ * 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.stereotypecollector;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceProxy;
+import org.eclipse.core.resources.IResourceProxyVisitor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.common.util.URI;
+
+/**
+ *
+ * Implements a visitor that goes through a hierarchy of Iresource from a root and collect only those that can be processed for search
+ *
+ */
+public class UMLResourceVisitor implements IResourceProxyVisitor {
+
+ private Collection<IResource> participants;
+
+ public UMLResourceVisitor() {
+ super();
+ this.participants = new HashSet<IResource>();
+ }
+
+ public boolean visit(IResourceProxy proxy) throws CoreException {
+ switch(proxy.getType()) {
+ case IResource.FILE:
+ IResource resource = proxy.requestResource();
+
+ URI uri = URI.createPlatformResourceURI(resource.getFullPath().toString(), true);
+
+ if("uml".equals(uri.fileExtension())) { //$NON-NLS-1$
+ participants.add(resource);
+
+ }
+
+ break;
+ default:
+ break;
+ }
+ return true;
+ }
+
+ public Collection<IResource> getParticipants() {
+ return participants;
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/messages.properties b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/messages.properties
new file mode 100644
index 00000000000..3cce0c5b8b5
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/messages.properties
@@ -0,0 +1 @@
+StereotypeCollector_0=An error occured while trying to find models to search in from root :

Back to the top