Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Noyrit2013-12-20 16:36:46 +0000
committerFlorian Noyrit2013-12-20 16:36:46 +0000
commit4a9f359e3739e41c0d34e39072f52b14a66f1772 (patch)
tree50ae1aa6e76775c79cdb41707e1c19de0e3da4dc /plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org
parent91f76f6759821005495bcaed00f4cd2410155d98 (diff)
downloadorg.eclipse.papyrus-4a9f359e3739e41c0d34e39072f52b14a66f1772.tar.gz
org.eclipse.papyrus-4a9f359e3739e41c0d34e39072f52b14a66f1772.tar.xz
org.eclipse.papyrus-4a9f359e3739e41c0d34e39072f52b14a66f1772.zip
Update search to support "AND" semantics on stereotype application of
selected stereotypes. Replace is now based on refactoring framework.
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/Messages.java12
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/ReplaceAction.java11
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/ReplaceTransformationOnElement.java141
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/dialogs/ReplaceRefactoring.java151
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/manager/PapyrusSearchTextManager.java101
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/messages.properties6
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchPage.java185
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/AttributeMatchLabelProvider.java26
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ParticipantTypeContentProvider.java43
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ResultLabelProvider.java1
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusAdvancedQuery.java71
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusOCLQuery.java168
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusQuery.java19
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/QueryInfo.java14
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/WorkspaceQueryProvider.java2
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/results/PapyrusSearchResult.java32
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/StereotypeCollector.java3
17 files changed, 817 insertions, 169 deletions
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 a429c3d292e..9a1cd027295 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
@@ -51,6 +51,8 @@ public class Messages extends NLS {
public static String PapyrusSearchPage_12;
+ public static String PapyrusSearchPage_13;
+
public static String PapyrusSearchPage_14;
public static String PapyrusSearchPage_15;
@@ -151,6 +153,16 @@ public class Messages extends NLS {
public static String ReplaceDialog_4;
+ public static String ReplaceRefactoring_0;
+
+ public static String ReplaceRefactoring_1;
+
+ public static String ReplaceRefactoring_2;
+
+ public static String ReplaceRefactoring_3;
+
+ public static String ReplaceRefactoring_4;
+
public static String ResultContentProvider_0;
public static String ResultContentProvider_10;
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/ReplaceAction.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/ReplaceAction.java
index 5cde7e08c7f..acc8bd97fc8 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/ReplaceAction.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/ReplaceAction.java
@@ -14,7 +14,8 @@
package org.eclipse.papyrus.uml.search.ui.actions;
import org.eclipse.jface.action.Action;
-import org.eclipse.papyrus.uml.search.ui.dialogs.ReplaceDialog;
+import org.eclipse.papyrus.infra.refactoring.core.PapyrusRefactoringOperation;
+import org.eclipse.papyrus.uml.search.ui.dialogs.ReplaceRefactoring;
import org.eclipse.papyrus.uml.search.ui.pages.PapyrusSearchResultPage;
import org.eclipse.swt.widgets.Shell;
@@ -24,8 +25,6 @@ public class ReplaceAction extends Action {
private final Object[] fSelection;
- private final Shell fShell;
-
/**
* Creates the replace action to be
*
@@ -38,7 +37,6 @@ public class ReplaceAction extends Action {
* the selected entries or <code>null</code> to replace all
*/
public ReplaceAction(Shell shell, PapyrusSearchResultPage resultPage, Object[] selection) {
- fShell = shell;
fResultPage = resultPage;
fSelection = selection;
}
@@ -51,9 +49,10 @@ public class ReplaceAction extends Action {
@Override
public void run() {
- ReplaceDialog replaceDialog = new ReplaceDialog(fShell, fResultPage, fSelection);
- replaceDialog.open();
+ ReplaceRefactoring replaceRef = new ReplaceRefactoring(fResultPage, fSelection);
+ PapyrusRefactoringOperation refactoringOperation = new PapyrusRefactoringOperation(replaceRef);
+ refactoringOperation.run();
}
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/ReplaceTransformationOnElement.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/ReplaceTransformationOnElement.java
new file mode 100644
index 00000000000..c38b44f5a59
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/actions/ReplaceTransformationOnElement.java
@@ -0,0 +1,141 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.search.ui.actions;
+
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.papyrus.infra.refactoring.refactoringOnElement.ITransformationOnElement;
+import org.eclipse.papyrus.uml.search.ui.query.AbstractPapyrusQuery;
+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.uml2.uml.Class;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+
+
+public class ReplaceTransformationOnElement implements ITransformationOnElement {
+
+ /**
+ * The {@link AbstractResultEntry} list representing textual matches with the String pattern to be replaced.
+ */
+ private Set<AbstractResultEntry> fAttributeMatchList;
+
+ /**
+ * The {@link AbstractPapyrusQuery} representing the search of matches.
+ */
+ private AbstractPapyrusQuery fQuery;
+
+ /**
+ * The string that should replace the String pattern to be replaced.
+ */
+ private String fNewString;
+
+
+ public ReplaceTransformationOnElement(Set<AbstractResultEntry> toProcess, AbstractPapyrusQuery query, String newString) {
+ fAttributeMatchList = toProcess;
+ fQuery = query;
+ fNewString = newString;
+ }
+
+
+ public void transformationToExecute(EObject element) {
+ for(AbstractResultEntry match : fAttributeMatchList) {
+ if(match.getSource() instanceof EObject && match instanceof AttributeMatch){
+ AttributeMatch attributeMatch=(AttributeMatch) match;
+ if(EcoreUtil.equals(element, (EObject)match.getSource())) {
+
+ if(attributeMatch.getMetaAttribute() instanceof EAttribute) {
+ Object value = element.eGet((EAttribute)attributeMatch.getMetaAttribute());
+ if(value != null) {
+ if(value instanceof String) {
+ String originalvalue = (String)value;
+ Pattern pattern = PatternHelper.getInstance().createPattern(fQuery.getSearchQueryText(), fQuery.isCaseSensitive(), fQuery.isRegularExpression());
+
+ String newValue = computeReplacementString(pattern, originalvalue, fNewString);
+
+ element.eSet((EAttribute)attributeMatch.getMetaAttribute(), newValue);
+
+ }
+ }
+ }
+
+ else if(attributeMatch.getMetaAttribute() instanceof Property) {
+ Property source = (Property)attributeMatch.getMetaAttribute();
+ Class containingClass = source.getClass_();
+ if(containingClass instanceof Stereotype) {
+ if(element instanceof Element) {
+ Stereotype stereotype = ((Element)element).getAppliedStereotype(containingClass.getQualifiedName());
+ Object tagValue = ((Element)element).getValue(stereotype, source.getName());
+ if(tagValue instanceof String) {
+ Object value = tagValue;
+
+ if(value != null) {
+ if(value instanceof String) {
+ String originalvalue = (String)value;
+ Pattern pattern = PatternHelper.getInstance().createPattern(fQuery.getSearchQueryText(), fQuery.isCaseSensitive(), fQuery.isRegularExpression());
+
+ String newValue = computeReplacementString(pattern, originalvalue, fNewString);
+
+ ((Element)element).setValue(stereotype, source.getName(), newValue);
+
+ }
+ }
+
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Compute the replacement.
+ * @param pattern The pattern that we will us to compute the replacement.
+ * @param originalText The String to be modified.
+ * @param replacementText The String to append.
+ * @return The new String.
+ */
+ private String computeReplacementString(Pattern pattern, String originalText, String replacementText) throws PatternSyntaxException {
+ if(pattern != null) {
+ try {
+
+ Matcher matcher = pattern.matcher(originalText);
+ StringBuffer sb = new StringBuffer();
+ matcher.reset();
+ if(matcher.find()) {
+ matcher.appendReplacement(sb, replacementText);
+ } else {
+ return null;
+ }
+ matcher.appendTail(sb);
+ return sb.toString();
+ } catch (IndexOutOfBoundsException ex) {
+ throw new PatternSyntaxException(ex.getLocalizedMessage(), replacementText, -1);
+ }
+ }
+ return replacementText;
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/dialogs/ReplaceRefactoring.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/dialogs/ReplaceRefactoring.java
new file mode 100644
index 00000000000..51a8d4f79b6
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/dialogs/ReplaceRefactoring.java
@@ -0,0 +1,151 @@
+package org.eclipse.papyrus.uml.search.ui.dialogs;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.papyrus.infra.refactoring.refactoringOnElement.AbstractTransformationOnElement;
+import org.eclipse.papyrus.infra.refactoring.refactoringOnElement.ITransformationOnElement;
+import org.eclipse.papyrus.uml.search.ui.Messages;
+import org.eclipse.papyrus.uml.search.ui.actions.ReplaceTransformationOnElement;
+import org.eclipse.papyrus.uml.search.ui.pages.PapyrusSearchResultPage;
+import org.eclipse.papyrus.uml.search.ui.query.AbstractPapyrusQuery;
+import org.eclipse.papyrus.views.search.results.AbstractResultEntry;
+import org.eclipse.papyrus.views.search.results.AttributeMatch;
+import org.eclipse.papyrus.views.search.utils.MatchUtils;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+
+public class ReplaceRefactoring extends AbstractTransformationOnElement {
+
+ private Text fNewValueText;
+
+ private Text fOldValueText;
+
+ private PapyrusSearchResultPage fResultPage;
+
+ private AbstractPapyrusQuery fQuery;
+
+ private Object[] fSelection;
+
+ private Set<AbstractResultEntry> fListMatch;
+
+
+
+ public ReplaceRefactoring(PapyrusSearchResultPage resultPage, Object[] selection) {
+ super(Messages.ReplaceRefactoring_0);
+ fResultPage = resultPage;
+ fSelection = selection;
+ fQuery = (AbstractPapyrusQuery)fResultPage.getInput().getQuery();
+ initListMatches();
+
+
+ }
+
+
+ private Text createNameField(Composite result) {
+ Text field = new Text(result, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
+ field.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ return field;
+ }
+
+
+
+ @Override
+ public RefactoringStatus checkFinalConditions() {
+ RefactoringStatus status = new RefactoringStatus();
+ if(fNewValueText.getText().isEmpty()) {
+ status.merge(RefactoringStatus.createFatalErrorStatus(Messages.ReplaceRefactoring_1));
+ } else if(fNewValueText.getText().equals(fQuery.getSearchQueryText())) {
+ status.merge(RefactoringStatus.createFatalErrorStatus(Messages.ReplaceRefactoring_2));
+
+ }
+ return status;
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+
+
+ GridLayout layout = new GridLayout();
+
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ layout.numColumns = 2;
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
+
+ setControl(composite);
+
+ Label label = new Label(composite, SWT.NONE);
+ label.setText(Messages.ReplaceRefactoring_3);
+ fOldValueText = createNameField(composite);
+ fOldValueText.setFocus();
+ fOldValueText.setText(fQuery.getSearchQueryText());
+ fOldValueText.setEnabled(false);
+
+
+ label = new Label(composite, SWT.NONE);
+ label.setText(Messages.ReplaceRefactoring_4);
+
+ fNewValueText = createNameField(composite);
+
+ GridData data = new GridData();
+ data.horizontalAlignment = SWT.END;
+
+ }
+
+
+
+ private void initListMatches() {
+ fListMatch = new HashSet<AbstractResultEntry>();
+ if(fSelection == null) {
+ for(AbstractResultEntry resultEntry : MatchUtils.getMatches(fResultPage.getInput(), false)) {
+ if(resultEntry instanceof AttributeMatch) {
+ fListMatch.add((AttributeMatch)resultEntry);
+ }
+ }
+ } else {
+ for(Object selected : Arrays.asList(fSelection)) {
+ if(selected instanceof AttributeMatch) {
+ fListMatch.add((AttributeMatch)selected);
+ }
+ }
+
+ }
+
+ }
+
+ @Override
+ public Collection<EObject> getElementsListToTransform() {
+ List<EObject> toProcess = new ArrayList<EObject>();
+ for(AbstractResultEntry match : fListMatch) {
+ if(match.getSource() instanceof EObject) {
+ if(!toProcess.contains(match.getSource())) {
+ toProcess.add((EObject)match.getSource());
+ }
+
+ }
+ }
+ return toProcess;
+ }
+
+ @Override
+ public ITransformationOnElement getTransformationOnElement() {
+
+ return new ReplaceTransformationOnElement(fListMatch, fQuery, fNewValueText.getText());
+
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/manager/PapyrusSearchTextManager.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/manager/PapyrusSearchTextManager.java
new file mode 100644
index 00000000000..de6b4f62df3
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/manager/PapyrusSearchTextManager.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.manager;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+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.query.PapyrusAdvancedQuery;
+import org.eclipse.papyrus.uml.search.ui.query.PapyrusQuery;
+import org.eclipse.papyrus.views.search.scope.ScopeEntry;
+import org.eclipse.search.ui.ISearchQuery;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ *Manage the search depending on user choices.
+ *
+ */
+public class PapyrusSearchTextManager {
+
+ private Collection<ScopeEntry> fScopeEntries;
+
+ private boolean fIsCaseSensitive;
+
+ private boolean fIsRegularExpression;
+
+ private String fQueryText;
+
+ public PapyrusSearchTextManager(Collection<ScopeEntry> scopeEntries, boolean isCaseSensitive, boolean isRegularExpression, String queryText) {
+ fScopeEntries = scopeEntries;
+ fIsCaseSensitive = isCaseSensitive;
+ fIsRegularExpression = isRegularExpression;
+ fQueryText = queryText;
+ }
+
+ public ISearchQuery manageSimpleSearch(boolean searchAllStrings, Object[] umlMetaClassesArray) {
+ if(fQueryText.isEmpty()) {
+ MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.PapyrusSearchPage_29, Messages.PapyrusSearchPage_30);
+ return null;
+ } else {
+ PapyrusQuery query = new PapyrusQuery(fQueryText, fIsCaseSensitive, fIsRegularExpression, fScopeEntries, umlMetaClassesArray, searchAllStrings);
+ return query;
+ }
+
+ }
+
+ public ISearchQuery manageAdvancedSearch(HashMap<ParticipantTypeElement, List<ParticipantTypeAttribute>> participantsList, Object[] checkedElements, boolean searchForAllSter) {
+ List<ParticipantTypeElement> participantsToEvaluate = getParticipantsToEvaluate(participantsList);
+
+
+ if(participantsToEvaluate.size() == 0) {
+
+ MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.PapyrusSearchPage_31, Messages.PapyrusSearchPage_32);
+ return null;
+ } else {
+ if(fQueryText.isEmpty()) {
+ for(Object participantChecked : checkedElements) {
+ if(participantChecked instanceof ParticipantTypeAttribute) {
+ MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.PapyrusSearchPage_33, Messages.PapyrusSearchPage_34);
+ return null;
+ }
+ }
+ }
+
+ PapyrusAdvancedQuery query = new PapyrusAdvancedQuery(fQueryText, fIsCaseSensitive, fIsRegularExpression, fScopeEntries, participantsToEvaluate.toArray(), searchForAllSter);
+ return query;
+ }
+ }
+
+ private List<ParticipantTypeElement> getParticipantsToEvaluate(HashMap<ParticipantTypeElement, List<ParticipantTypeAttribute>> participantsList) {
+ List<ParticipantTypeElement> participantsToEvaluate = new ArrayList<ParticipantTypeElement>();
+
+ for(ParticipantTypeElement element : participantsList.keySet()) {
+ if(element.isChecked()) {
+ participantsToEvaluate.add(element);
+ for(ParticipantTypeAttribute attributesToEvaluate : participantsList.get(element)) {
+ if(attributesToEvaluate.isChecked()) {
+ participantsToEvaluate.add(attributesToEvaluate);
+ }
+ }
+ }
+ }
+ return participantsToEvaluate;
+ }
+}
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 2f19d527713..3fcc2a68c0d 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
@@ -16,6 +16,7 @@ PapyrusSearchPage_1=Query issue
PapyrusSearchPage_10=Deselect All
PapyrusSearchPage_11=Simple search
PapyrusSearchPage_12=Advanced search
+PapyrusSearchPage_13=Search for elements with exactly all the specified stereotypes
PapyrusSearchPage_14=Select subelements
PapyrusSearchPage_15=Refresh types
PapyrusSearchPage_16=Search only in name attribute
@@ -73,6 +74,11 @@ 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\:
+ReplaceRefactoring_0=Replace
+ReplaceRefactoring_1=Please indicate the new value which should replace the original.
+ReplaceRefactoring_2=Original and new strings are same.
+ReplaceRefactoring_3=&Replace:
+ReplaceRefactoring_4=&With:
ResultContentProvider_0=The plug-in
ResultContentProvider_10=The plug-in
ResultContentProvider_11=\ contributed an invalid extension for
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 044a4a815e7..46e7cfc58f2 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
@@ -19,7 +19,9 @@ 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.runtime.IAdaptable;
@@ -140,10 +142,6 @@ import com.google.inject.Injector;
*/
public class PapyrusSearchPage extends DialogPage implements ISearchPage, IReplacePage, MetaModelManagerListener {
- public PapyrusSearchPage() {
- }
-
-
private HashMap<ParticipantTypeElement, List<ParticipantTypeAttribute>> participantsList = new HashMap<ParticipantTypeElement, List<ParticipantTypeAttribute>>();
private Collection<Stereotype> availableStereotypes;
@@ -154,10 +152,6 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
private static final String SEARCH_ISSUE = Messages.PapyrusSearchPage_1;
- private static final String SEARCH_IN_ALL_STRINGS = Messages.PapyrusSearchPage_2;
-
- private static final String SEARCH_IN_STEREOTYPE_ATTRIBUTES = Messages.PapyrusSearchPage_3;
-
private Text searchQueryText;
private Text oclContext;
@@ -191,8 +185,6 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
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;
@@ -205,17 +197,13 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
protected Composite textQueryComposite;
- protected Composite textQueryComposite2;
-
-
-
private Composite advancedSearchComposite;
- protected Group grpSearchFor;
-
private Composite textQueryFieldsComposite;
- protected ParticipantTypeContentProvider participantTypeContentProvider = new ParticipantTypeContentProvider();
+
+ private Button fBtnSearchForAllSelected;
+
@@ -270,7 +258,7 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
- grpSearchFor = new Group(textQueryComposite, SWT.NONE);
+ Group 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);
@@ -296,9 +284,9 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
}
if(searchKind.getSelectionIndex() == ADVANCED_SEARCH) {
- if(participantsList.size() == 0) {
+ participantsList.clear();
createResultList();
- }
+
createAdvancedSearch();
} else {
simpleSearch();
@@ -391,7 +379,7 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
participantTypesTree.setLayoutData(chechboxTreeViewerGridData);
participantTypesTreeViewer = (CheckboxTreeViewer)participantTypesTree.getViewer();
- participantTypesTreeViewer.setContentProvider(participantTypeContentProvider);
+ participantTypesTreeViewer.setContentProvider(new ParticipantTypeContentProvider());
participantTypesTreeViewer.setLabelProvider(new ParticipantTypeLabelProvider());
participantTypesTreeViewer.setSorter(new ViewerSorter());
participantTypesTreeViewer.setCheckStateProvider(new ICheckStateProvider() {
@@ -504,6 +492,8 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
@Override
public void mouseUp(MouseEvent e) {
+ participantsList.clear();
+ createResultList();
createAdvancedSearch();
@@ -557,33 +547,47 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
}
});
+
+ fBtnSearchForAllSelected = new Button(advancedSearchComposite, SWT.CHECK);
+ fBtnSearchForAllSelected.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
+ fBtnSearchForAllSelected.setText(Messages.PapyrusSearchPage_13);
}
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) {
+ checkAllSubSter((ParticipantTypeElement)element, elementParent, attributeParentList);
+
+ }
+ }
+
+
+ }
+
+ };
+
+
+ try {
+ dialog.run(true, true, computeAvailableTypes);
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+
+ }
+
+ protected void checkAllSubSter(ParticipantTypeElement element, ParticipantTypeElement elementParent, List<ParticipantTypeAttribute> attributeParentList) {
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);
@@ -602,10 +606,20 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
}
}
}
- }
+ 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) {
+ checkAllSubUML((ParticipantTypeElement)element, elementParent, attributeParentList);
}
+ }
+ }
};
@@ -621,14 +635,8 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
}
- 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) {
+ protected void checkAllSubUML(ParticipantTypeElement element, ParticipantTypeElement elementParent, List<ParticipantTypeAttribute> attributeParentList) {
if(((ParticipantTypeElement)element).getElement() instanceof EClass) {
List<EClass> superTypes = ((EClass)((ParticipantTypeElement)element).getElement()).getEAllSuperTypes();
@@ -651,23 +659,7 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
}
}
}
- }
- }
-
-
- }
-
- };
- 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();
- }
}
@@ -691,6 +683,19 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
}
+ public Object[] getMetaClassesList() {
+ Set<EObject> umlMetaClasses= new HashSet<EObject>();
+
+ for(EClassifier eClassifier : UMLPackage.eINSTANCE.getEClassifiers()) {
+ if(eClassifier instanceof EClass) {
+ umlMetaClasses.add(eClassifier);
+ }
+ }
+ return umlMetaClasses.toArray();
+
+ }
+
+
protected void createOCLSearchQueryField(EObject root) {
Composite client = queryComposite;
@@ -719,7 +724,7 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
if(currentScope != null) {
try {
- EObject root = ((UmlModel)currentScope.getModelSet().getModel(UmlModel.MODEL_ID)).lookupRoot();
+ ((UmlModel)currentScope.getModelSet().getModel(UmlModel.MODEL_ID)).lookupRoot();
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(Display.getCurrent().getActiveShell(), labelProvider, new OCLContextContentProvider());
dialog.setTitle(Messages.PapyrusSearchPage_19);
@@ -757,6 +762,7 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
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;
@@ -913,8 +919,7 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
if(selectedObject instanceof IOutlineNode) {
if(selectedObject instanceof EObjectNode) {
EObjectNode selectedObjectNode = (EObjectNode)selectedObject;
- @SuppressWarnings("unused")
- URI eObjectURI = selectedObjectNode.getEObjectURI();
+ selectedObjectNode.getEObjectURI();
contextObject = null; // FIXME
// metaModelManager.loadResource(eObjectURI,
// null, null);
@@ -952,6 +957,37 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
});
}
+
+ private Collection<ScopeEntry> createScopeEntries(Collection<URI> scope) {
+ Collection<ScopeEntry> results = new HashSet<ScopeEntry>();
+
+ for(URI resource : scope) {
+
+ ScopeEntry scopeEntry = new ScopeEntry(resource);
+
+ results.add(scopeEntry);
+
+ }
+
+ return results;
+ }
+
+ private List<ParticipantTypeElement> getParticipantsToEvaluate(HashMap<ParticipantTypeElement, List<ParticipantTypeAttribute>> participantsList) {
+ List<ParticipantTypeElement> participantsToEvaluate = new ArrayList<ParticipantTypeElement>();
+
+ for(ParticipantTypeElement element : participantsList.keySet()) {
+ if(element.isChecked()) {
+ participantsToEvaluate.add(element);
+ for(ParticipantTypeAttribute attributesToEvaluate : participantsList.get(element)) {
+ if(attributesToEvaluate.isChecked()) {
+ participantsToEvaluate.add(attributesToEvaluate);
+ }
+ }
+ }
+ }
+ return participantsToEvaluate;
+ }
+
public boolean performAction() {
if(queryKind.getSelectionIndex() == TEXT_QUERY_KIND) {
@@ -994,7 +1030,7 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
}
}
- QueryInfo info = new QueryInfo(searchQueryText.getText(), btnCaseSensitive.getSelection(), btnRegularExpression.getSelection(), participantsToEvaluate, scope);
+ QueryInfo info = new QueryInfo(searchQueryText.getText(), btnCaseSensitive.getSelection(), btnRegularExpression.getSelection(), participantsToEvaluate, scope, fBtnSearchForAllSelected.getSelection());
query = CompositePapyrusQueryProvider.getInstance().createAdvancedSearchQuery(info);
}
@@ -1045,6 +1081,7 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
public boolean performReplace() {
if(queryKind.getSelectionIndex() == TEXT_QUERY_KIND) {
+ if(container.getSelectedScope() == ISearchPageContainer.SELECTION_SCOPE) {
if(validateRegex()) {
if(searchQueryText.getText().length() == 0) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.PapyrusSearchPage_36, Messages.PapyrusSearchPage_37);
@@ -1070,8 +1107,19 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
for(ParticipantTypeAttribute attributesToEvaluate : participantsList.get(element)) {
if(attributesToEvaluate.isChecked()) {
participantsToEvaluate.add(attributesToEvaluate);
+ boolean canDoReplace = false;
+ if(attributesToEvaluate.getElement() instanceof EAttribute) {
Object value = element.getElement().eGet((EAttribute)attributesToEvaluate.getElement());
- if(!(value instanceof String)) {
+ if(value instanceof String) {
+ canDoReplace = true;
+ }
+ } else if(attributesToEvaluate.getElement() instanceof Property) {
+ Property property = (Property)attributesToEvaluate.getElement();
+ if(UMLUtil.isString(property.getType())) {
+ canDoReplace = true;
+ }
+ }
+ if(!canDoReplace) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.PapyrusSearchPage_40, Messages.PapyrusSearchPage_41);
return false;
}
@@ -1080,7 +1128,7 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
}
}
}
- QueryInfo info = new QueryInfo(searchQueryText.getText(), btnCaseSensitive.getSelection(), btnRegularExpression.getSelection(), participantsToEvaluate, scope);
+ QueryInfo info = new QueryInfo(searchQueryText.getText(), btnCaseSensitive.getSelection(), btnRegularExpression.getSelection(), participantsToEvaluate, scope, fBtnSearchForAllSelected.getSelection());
query = CompositePapyrusQueryProvider.getInstance().createAdvancedSearchQuery(info);
}
@@ -1104,14 +1152,17 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
}
});
- NewSearchUI.runQueryInForeground(container.getRunnableContext(), query);
-
+ NewSearchUI.removeQuery(query);
return true;
} else {
MessageDialog.openError(Display.getCurrent().getActiveShell(), SEARCH_ISSUE, REGULAR_EXPRESSION_ILLFORMED);
return false;
}
} else {
+ MessageDialog.openWarning(Display.getCurrent().getActiveShell(), Messages.PapyrusSearchPage_27, Messages.PapyrusSearchPage_28);
+ return false;
+ }
+ } else {
MessageDialog.openWarning(Display.getCurrent().getActiveShell(), Messages.PapyrusSearchPage_42, Messages.PapyrusSearchPage_43);
return false;
}
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 d133e3adf43..2182ad93585 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
@@ -26,6 +26,7 @@ import org.eclipse.papyrus.views.search.results.AttributeMatch;
import org.eclipse.swt.graphics.Image;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.EnumerationLiteral;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Stereotype;
@@ -72,18 +73,8 @@ public class AttributeMatchLabelProvider implements IFilteredLabelProvider {
Class containingClass = source.getClass_();
if(containingClass instanceof Stereotype) {
if(target instanceof Element) {
-
- Object tagValue = ((Element)target).getValue((Stereotype)containingClass, ((Property)attributeMatch.getMetaAttribute()).getName());
-
- if(tagValue instanceof String) {
- String value = (String)tagValue;
- int end = attributeMatch.getOffset() + attributeMatch.getLength();
- return printResult(value.substring(attributeMatch.getOffset(), end), value, attributeMatch.getOffset(), attributeMatch.getLength(), source.getName());
- } else {
- String value = String.valueOf(tagValue);
- int end = attributeMatch.getOffset() + attributeMatch.getLength();
- return printResult(value.substring(attributeMatch.getOffset(), end), value, attributeMatch.getOffset(), attributeMatch.getLength(), source.getName());
- }
+ String value = getStringValueOfProperty(((Element)target), (Stereotype)containingClass, (Property)attributeMatch.getMetaAttribute());
+ return printResult(value.substring(attributeMatch.getOffset(), attributeMatch.getLength()), value, attributeMatch.getOffset(), attributeMatch.getLength(), source.getName());
}
}
@@ -120,4 +111,15 @@ public class AttributeMatchLabelProvider implements IFilteredLabelProvider {
return false;
}
+ private String getStringValueOfProperty(Element element, Stereotype stereotype, Property property) {
+ Object value = element.getValue(stereotype, property.getName());
+ if(value instanceof String) {
+ return (String)value;
+ } else if(value instanceof EnumerationLiteral) {
+ return ((EnumerationLiteral)value).getName();
+ } else {
+ return String.valueOf(value);
+ }
+ }
+
}
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 07b4ea93a44..90747d62b36 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
@@ -31,9 +31,6 @@ public class ParticipantTypeContentProvider implements ITreeContentProvider {
- private EPackage ePackage = null;
-
-
private HashMap<ParticipantTypeElement, List<ParticipantTypeAttribute>> participantsList = new HashMap<ParticipantTypeElement, List<ParticipantTypeAttribute>>();
@@ -59,11 +56,7 @@ public class ParticipantTypeContentProvider implements ITreeContentProvider {
return ((HashMap)inputElement).keySet().toArray();
}
- // for(Object obj : (Collection<Object>)inputElement) {
- // result.add(obj);
- // }
-
-
+
return result.toArray();
}
@@ -75,40 +68,6 @@ public class ParticipantTypeContentProvider implements ITreeContentProvider {
}
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) {
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ResultLabelProvider.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ResultLabelProvider.java
index 989ede3387c..1ceb4662045 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ResultLabelProvider.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/ResultLabelProvider.java
@@ -42,7 +42,6 @@ public class ResultLabelProvider extends LabelProvider {
if(element instanceof AbstractResultEntry) {
return labelProviderService.getLabelProvider().getText(((AbstractResultEntry)element).elementToDisplay());
}
-
return ""; //$NON-NLS-1$
}
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
index a0309c2fd13..32fcbbcd602 100644
--- 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
@@ -52,6 +52,7 @@ 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.EnumerationLiteral;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.util.UMLUtil;
@@ -97,11 +98,13 @@ public class PapyrusAdvancedQuery extends AbstractPapyrusQuery {
private List<Property> propertyList;
+ private boolean searchForAllSter;
- public PapyrusAdvancedQuery(String searchQueryText, boolean isCaseSensitive, boolean isRegularExpression, Collection<ScopeEntry> scopeEntries, Object[] participantsChecked) {
+
+ public PapyrusAdvancedQuery(String searchQueryText, boolean isCaseSensitive, boolean isRegularExpression, Collection<ScopeEntry> scopeEntries, Object[] participantsChecked, boolean searchForAllSter) {
this.propertyList = new ArrayList<Property>();
this.sources = new HashSet<Object>();
this.searchQueryText = searchQueryText;
@@ -109,6 +112,7 @@ public class PapyrusAdvancedQuery extends AbstractPapyrusQuery {
this.isRegularExpression = isRegularExpression;
this.scopeEntries = scopeEntries;
this.participantsChecked = participantsChecked;
+ this.searchForAllSter = searchForAllSter;
results = new PapyrusSearchResult(this);
participantsList = new HashMap<EObject, List<EAttribute>>();
@@ -156,14 +160,26 @@ public class PapyrusAdvancedQuery extends AbstractPapyrusQuery {
EObject root = umlModel.lookupRoot();
Collection<EObject> participants = ParticipantValidator.getInstance().getParticipants(root, participantsList.keySet().toArray());
+ Collection<EObject> stereotypesParticipants = ParticipantValidator.getInstance().getParticipantsStereotype(root, stereotypeList.keySet().toArray());
+ if(searchForAllSter) {
+
+ if(participantsList.keySet().size() == 0) {
+ stereotypesParticipants = getElementsWithAllSter(stereotypesParticipants);
+ evaluateStereotypes(stereotypesParticipants, scopeEntry);
+ } else {
+ participants = getElementsWithAllSter(participants);
+ evaluate(participants, scopeEntry);
+ }
+
+ } else {
+ evaluate(participants, scopeEntry);
+ evaluateStereotypes(stereotypesParticipants, scopeEntry);
+ }
- 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);
@@ -174,6 +190,29 @@ public class PapyrusAdvancedQuery extends AbstractPapyrusQuery {
return Status.OK_STATUS;
}
+ private Collection<EObject> getElementsWithAllSter(Collection<EObject> initialParticipants) {
+ Collection<EObject> participantsToKeep = new ArrayList<EObject>();
+ for(EObject participants : initialParticipants) {
+ if(participants instanceof Element) {
+ int numberOfStereotypeToBeApplied = stereotypeList.size();
+ int numberOfStereotypeMatching = 0;
+ if(numberOfStereotypeToBeApplied == ((Element)participants).getAppliedStereotypes().size()) {
+ for(Stereotype stereotypeToBeApplied : stereotypeList.keySet()) {
+ for(Stereotype stereotypeApplied : ((Element)participants).getAppliedStereotypes()) {
+ if(EcoreUtil.equals(stereotypeToBeApplied, stereotypeApplied)) {
+ numberOfStereotypeMatching++;
+ }
+ }
+ }
+ if(numberOfStereotypeMatching == numberOfStereotypeToBeApplied) {
+ participantsToKeep.add(participants);
+ }
+ }
+ }
+ }
+ return participantsToKeep;
+ }
+
/**
* Evaluate if the value matches the pattern
*
@@ -321,15 +360,11 @@ public class PapyrusAdvancedQuery extends AbstractPapyrusQuery {
for(Property property : propertyList) {
for(Property property2 : (stereotypeList.get(stereotypeSelected))) {
if(EcoreUtil.equals(property, property2)) {
- Object value = ((Element)participant).getValue(stereotype, property.getName());
+
+ String value = getStringValueOfProperty((Element)participant, stereotype, property);
+
if(value != null) {
- if(value instanceof String) {
- String stringValue = (String)value;
- evaluateAndAddToResult(stringValue, property, pattern, participant, scopeEntry, stereotype);
- } else {
- String stringValue = String.valueOf(value);
- evaluateAndAddToResult(stringValue, property, pattern, participant, scopeEntry, stereotype);
- }
+ evaluateAndAddToResult(value, property, pattern, participant, scopeEntry, stereotype);
}
}
}
@@ -343,10 +378,22 @@ public class PapyrusAdvancedQuery extends AbstractPapyrusQuery {
}
+
findInDiagram(scopeEntry);
}
+ private String getStringValueOfProperty(Element element, Stereotype stereotype, Property property) {
+ Object value = element.getValue(stereotype, property.getName());
+ if(value instanceof String) {
+ return (String)value;
+ } else if(value instanceof EnumerationLiteral) {
+ return ((EnumerationLiteral)value).getName();
+ } else {
+ return String.valueOf(value);
+ }
+ }
+
public List<Property> getStereotypesAttributes(Object parentElement) {
List<Property> result = new ArrayList<Property>();
if(parentElement instanceof Stereotype) {
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
index 3dd729e5aac..6e9a377efed 100644
--- 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
@@ -17,6 +17,8 @@ import java.util.ArrayList;
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;
@@ -51,7 +53,6 @@ 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.Activator;
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;
@@ -128,16 +129,19 @@ public class PapyrusOCLQuery extends AbstractPapyrusQuery {
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) {
- Activator.log.error(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);
@@ -147,25 +151,28 @@ public class PapyrusOCLQuery extends AbstractPapyrusQuery {
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;
- Activator.log.error(e);
-
- // if(e.getLocalizedMessage() == null) {
- // // MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", e.getClass().getName());
- // } else {
- // // MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", e.getLocalizedMessage());
- // }
+ if(e.getLocalizedMessage() == null) {
+ // MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", e.getClass().getName());
+ } else {
+ // MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", e.getLocalizedMessage());
+ }
}
return result;
@@ -222,6 +229,17 @@ public class PapyrusOCLQuery extends AbstractPapyrusQuery {
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;
@@ -274,6 +292,138 @@ public class PapyrusOCLQuery extends AbstractPapyrusQuery {
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;
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 d65a2827e10..ec6dfd20d77 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
@@ -133,7 +133,7 @@ public class PapyrusQuery extends AbstractPapyrusQuery {
* @param scopeEntry
* the scopeEntry that contains the participant
*/
- protected void evaluateAndAddToResult(String value, Object attribute, Pattern pattern, Object participant, ScopeEntry scopeEntry) {
+ protected void evaluateAndAddToResult(String value, Object attribute, Pattern pattern, Object participant, ScopeEntry scopeEntry, Stereotype stereotype) {
value = value != null ? value : ""; //$NON-NLS-1$
@@ -143,7 +143,7 @@ public class PapyrusQuery extends AbstractPapyrusQuery {
if(m.matches()) {
int start = m.start();
int end = m.end();
- ModelMatch match = new AttributeMatch(start, end, participant, scopeEntry, attribute, null);
+ ModelMatch match = new AttributeMatch(start, end, participant, scopeEntry, attribute, stereotype);
fResults.add(match);
}
@@ -151,7 +151,7 @@ public class PapyrusQuery extends AbstractPapyrusQuery {
while(m.find()) {
int start = m.start();
int end = m.end();
- AttributeMatch match = new AttributeMatch(start, end, participant, scopeEntry, attribute, null);
+ AttributeMatch match = new AttributeMatch(start, end, participant, scopeEntry, attribute, stereotype);
fResults.add(match);
}
}
@@ -190,7 +190,7 @@ public class PapyrusQuery extends AbstractPapyrusQuery {
if(value instanceof String) {
String stringValue = (String)value;
- evaluateAndAddToResult(stringValue, attribute, pattern, participant, scopeEntry);
+ evaluateAndAddToResult(stringValue, attribute, pattern, participant, scopeEntry, null);
}
}
@@ -203,7 +203,7 @@ public class PapyrusQuery extends AbstractPapyrusQuery {
if(value instanceof String) {
String stringValue = (String)value;
- evaluateAndAddToResult(stringValue, stereotypeProperty, pattern, participant, scopeEntry);
+ evaluateAndAddToResult(stringValue, stereotypeProperty, pattern, participant, scopeEntry, stereotype);
}
}
}
@@ -215,7 +215,7 @@ public class PapyrusQuery extends AbstractPapyrusQuery {
String umlElementName = ((NamedElement)participant).getName();
umlElementName = umlElementName != null ? umlElementName : ""; //$NON-NLS-1$
- evaluateAndAddToResult(umlElementName, UMLPackage.eINSTANCE.getNamedElement_Name(), pattern, participant, scopeEntry);
+ evaluateAndAddToResult(umlElementName, UMLPackage.eINSTANCE.getNamedElement_Name(), pattern, participant, scopeEntry, null);
}
}
@@ -255,12 +255,17 @@ public class PapyrusQuery extends AbstractPapyrusQuery {
}
}
+
+ public Set<AbstractResultEntry> getResults() {
+ return fResults;
+ }
+
public String getLabel() {
return Messages.PapyrusQuery_6;
}
public boolean canRerun() {
- return true;
+ return false;
}
public boolean canRunInBackground() {
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/QueryInfo.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/QueryInfo.java
index 1f0251bcec8..9f1d79c69d5 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/QueryInfo.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/QueryInfo.java
@@ -32,6 +32,8 @@ public class QueryInfo {
private boolean searchAllStringAttributes;
private Collection<? extends ParticipantTypeElement> participantTypes;
+
+ private boolean searchForAllSter;
private Collection<URI> scope;
@@ -53,6 +55,7 @@ public class QueryInfo {
public QueryInfo(String queryText, boolean caseSensitive, boolean regularExpression, boolean searchAllStringAttributes, Collection<URI> scope) {
super();
+
this.queryText = queryText;
this.caseSensitive = caseSensitive;
this.regularExpression = regularExpression;
@@ -72,10 +75,12 @@ public class QueryInfo {
* whether the {@code queryText} is to be taken as a regular expression
* @param participantTypes
* the participant types (identifying specific metaclasses and/or attributes) to include in the search
+ * @param searchForAllSter
+ * stereotype application must all applied or not
* @param scope
* the domain-specific search scope
*/
- public QueryInfo(String queryText, boolean caseSensitive, boolean regularExpression, Collection<? extends ParticipantTypeElement> participantTypes, Collection<URI> scope) {
+ public QueryInfo(String queryText, boolean caseSensitive, boolean regularExpression, Collection<? extends ParticipantTypeElement> participantTypes, Collection<URI> scope,boolean searchForAllSter) {
super();
this.queryText = queryText;
@@ -84,6 +89,7 @@ public class QueryInfo {
this.searchAllStringAttributes = false;
this.participantTypes = participantTypes;
this.scope = scope;
+ this.searchForAllSter = searchForAllSter;
}
/**
@@ -97,6 +103,7 @@ public class QueryInfo {
this.regularExpression = original.regularExpression;
this.searchAllStringAttributes = original.searchAllStringAttributes;
this.participantTypes = original.participantTypes;
+ this.searchForAllSter = original.searchForAllSter;
this.scope = scope;
}
@@ -123,6 +130,11 @@ public class QueryInfo {
public Collection<URI> getScope() {
return scope;
}
+
+ public boolean isSearchForAllSter() {
+ return searchForAllSter;
+ }
+
/**
* Creates a new instance encapsulating query parameters for the specified partition (strict subset) of my {@linkplain #getScope() scope}.
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/WorkspaceQueryProvider.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/WorkspaceQueryProvider.java
index 18318084408..5296eec748d 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/WorkspaceQueryProvider.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/WorkspaceQueryProvider.java
@@ -51,7 +51,7 @@ public class WorkspaceQueryProvider implements IPapyrusQueryProvider {
public AbstractPapyrusQuery createAdvancedSearchQuery(QueryInfo queryInfo) {
Collection<ScopeEntry> scopeEntries = createScopeEntries(queryInfo.getScope());
- return new PapyrusAdvancedQuery(queryInfo.getQueryText(), queryInfo.isCaseSensitive(), queryInfo.isRegularExpression(), scopeEntries, queryInfo.getParticipantTypes().toArray());
+ return new PapyrusAdvancedQuery(queryInfo.getQueryText(), queryInfo.isCaseSensitive(), queryInfo.isRegularExpression(), scopeEntries, queryInfo.getParticipantTypes().toArray(),queryInfo.isSearchForAllSter());
}
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 b64c82da64c..0afcb88d95d 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
@@ -28,6 +28,7 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.papyrus.infra.core.utils.EditorUtils;
import org.eclipse.papyrus.uml.search.ui.Activator;
@@ -49,7 +50,9 @@ import org.eclipse.search.ui.text.MatchFilter;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.ide.ResourceUtil;
import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.EnumerationLiteral;
import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
import com.google.common.base.Objects;
import com.swtdesigner.ResourceManager;
@@ -167,22 +170,20 @@ public class PapyrusSearchResult extends AbstractTextSearchResult implements IEd
if(match instanceof AbstractResultEntry) {
if(((AbstractResultEntry)match).getSource() != null) {
if(match instanceof AttributeMatch) {
-
+ Object attribute = ((AttributeMatch)match).getMetaAttribute();
String value = null;
EObject target = (EObject)((AbstractResultEntry)match).getSource();
- if(((AttributeMatch)match).getMetaAttribute() instanceof EAttribute) {
+ if(attribute instanceof EAttribute) {
- EAttribute attribute = (EAttribute)((AttributeMatch)match).getMetaAttribute();
- value = String.valueOf(target.eGet(attribute));
- } else if(((AttributeMatch)match).getMetaAttribute() instanceof Property) {
+ value = String.valueOf(target.eGet((EStructuralFeature)attribute));
+ } else if(attribute instanceof Property) {
- Property attribute = (Property)((AttributeMatch)match).getMetaAttribute();
- value = (String)((Element)((AbstractResultEntry)match).getSource()).getValue(((AttributeMatch)match).getStereotype(), attribute.getName());
+ value = getStringValueOfProperty((Element)((AbstractResultEntry)match).getSource(), ((AttributeMatch)match).getStereotype(), ((Property)attribute));
}
if(value != null && !this.getQuery().isRegularExpression()) {
- if(value.length() >= match.getOffset() + match.getLength()) {
+ if(value.length() >= match.getLength() - match.getOffset()) {
int end = match.getOffset() + match.getLength();
value = value.substring(match.getOffset(), end);
if(this.searchQuery.isCaseSensitive()) {
@@ -226,7 +227,7 @@ public class PapyrusSearchResult extends AbstractTextSearchResult implements IEd
}
}
}
- // Now get Viewers
+ // Now get Viewer
for(Match match : matchList) {
if(match instanceof ViewerMatch) {
Object source = ((ViewerMatch)match).getSemanticElement();
@@ -238,7 +239,8 @@ public class PapyrusSearchResult extends AbstractTextSearchResult implements IEd
}
return (Match[])matchToKeep.toArray(new Match[matchToKeep.size()]);
-
+ // return ((PapyrusQuery)searchQuery).getfResults().toArray(new Match[matchToKeep.size()]);
+ //
}
public Match[] computeContainedMatches(AbstractTextSearchResult result, IEditorPart editor) {
@@ -274,6 +276,16 @@ public class PapyrusSearchResult extends AbstractTextSearchResult implements IEd
return count;
}
+ private String getStringValueOfProperty(Element element, Stereotype stereotype, Property property) {
+ Object value = element.getValue(stereotype, property.getName());
+ if(value instanceof String) {
+ return (String)value;
+ } else if(value instanceof EnumerationLiteral) {
+ return ((EnumerationLiteral)value).getName();
+ } else {
+ return String.valueOf(value);
+ }
+ }
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/StereotypeCollector.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/StereotypeCollector.java
index 09e2def3e46..ab63bc3a987 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/StereotypeCollector.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/stereotypecollector/StereotypeCollector.java
@@ -35,6 +35,7 @@ import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.emf.utils.BusinessModelResolver;
import org.eclipse.papyrus.infra.onefile.model.IPapyrusFile;
import org.eclipse.search.ui.ISearchPageContainer;
@@ -111,7 +112,7 @@ public class StereotypeCollector implements IStereotypeCollector {
}
for(URI uri : umlResources) {
- ResourceSet resourceSet = new ResourceSetImpl();
+ ModelSet resourceSet = new ModelSet();
Resource resource = resourceSet.getResource(uri, true);
TreeIterator<EObject> UMLResourceContentIterator = resource.getAllContents();

Back to the top