Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShuai Li2015-02-10 10:27:41 +0000
committerShuai Li2015-03-11 16:59:45 +0000
commit0964d5a20f8f5cab6cd650c533b0b58e10a3c103 (patch)
treeda7b128ff90f69897d4f53786003f0c70c2d837e
parent91f8210cd95adbd6ea8074c9ba31f76d3525973d (diff)
downloadorg.eclipse.papyrus-0964d5a20f8f5cab6cd650c533b0b58e10a3c103.tar.gz
org.eclipse.papyrus-0964d5a20f8f5cab6cd650c533b0b58e10a3c103.tar.xz
org.eclipse.papyrus-0964d5a20f8f5cab6cd650c533b0b58e10a3c103.zip
Bug 459425 - [Search] In advanced search, selecting an element should
select all of its attributes by default - Checking an element checks all of its attributes - Unchecking the last attribute of an element, unchecks the element - The behaviors are also respected in filtered mode. E.g. checking a filtered element, with its attributes hidden, also checks the attributes - Behavior of search is adapted for this change Change-Id: I33a34a51818e5479441f31f857eee983db2df5f1 Signed-off-by: Shuai Li <shuai.li@cea.fr>
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/listeners/ParticipantTypesTreeViewerCheckStateListener.java97
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/messages.properties2
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/pages/PapyrusSearchPage.java129
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/providers/AttributeMatchLabelProvider.java13
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusAdvancedQuery.java10
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/validator/ParticipantValidator.java209
6 files changed, 231 insertions, 229 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/listeners/ParticipantTypesTreeViewerCheckStateListener.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/listeners/ParticipantTypesTreeViewerCheckStateListener.java
new file mode 100644
index 00000000000..41b9d7ae53e
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/listeners/ParticipantTypesTreeViewerCheckStateListener.java
@@ -0,0 +1,97 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST and others.
+ *
+ * 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
+ * Shuai Li (CEA LIST)
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.search.ui.listeners;
+
+import java.util.HashMap;
+import java.util.List;
+
+import org.eclipse.emf.ecore.impl.EClassImpl;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.papyrus.uml.search.ui.providers.ParticipantTypeAttribute;
+import org.eclipse.papyrus.uml.search.ui.providers.ParticipantTypeElement;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * CheckStateListener for checkbox selections in types and stereotypes treeviewers
+ *
+ */
+public class ParticipantTypesTreeViewerCheckStateListener implements ICheckStateListener {
+
+ private CheckboxTreeViewer participantTypesTreeViewer;
+ private HashMap<ParticipantTypeElement, List<ParticipantTypeAttribute>> participantsList;
+
+ public ParticipantTypesTreeViewerCheckStateListener(CheckboxTreeViewer participantTypesTreeViewer, HashMap<ParticipantTypeElement, List<ParticipantTypeAttribute>> participantsList) {
+ this.participantTypesTreeViewer = participantTypesTreeViewer;
+ this.participantsList = participantsList;
+ }
+
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ if (participantTypesTreeViewer != null && participantsList != null) {
+ 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 && !parent.isChecked()) {
+ parent.setChecked(true);
+ participantTypesTreeViewer.refresh(parent);
+ }
+ } else if (((ParticipantTypeElement) selectedElement).getElement() instanceof Stereotype || ((ParticipantTypeElement) selectedElement).getElement() instanceof EClassImpl) {
+ for (ParticipantTypeAttribute attribute : participantsList.get(selectedElement)) {
+ attribute.setChecked(true);
+ participantTypesTreeViewer.refresh(attribute);
+ }
+ }
+ } else {
+ Object selectedElement = event.getElement();
+ ((ParticipantTypeElement) selectedElement).setChecked(false);
+ participantTypesTreeViewer.refresh(selectedElement);
+
+ if (selectedElement instanceof ParticipantTypeAttribute) {
+ ParticipantTypeElement parent = ((ParticipantTypeAttribute) selectedElement).getParent();
+
+ if (parent != null && parent.isChecked()) {
+ boolean hasCheckedChildren = false;
+
+ for (ParticipantTypeAttribute attribute : participantsList.get(parent)) {
+ if (attribute.isChecked()) {
+ hasCheckedChildren = true;
+ break;
+ }
+ }
+
+ if (!hasCheckedChildren) {
+ parent.setChecked(false);
+ participantTypesTreeViewer.refresh(parent);
+ }
+ }
+ } else if (((ParticipantTypeElement) selectedElement).getElement() instanceof Stereotype || ((ParticipantTypeElement) selectedElement).getElement() instanceof EClassImpl) {
+ for (ParticipantTypeAttribute attribute : participantsList.get(selectedElement)) {
+ attribute.setChecked(false);
+ participantTypesTreeViewer.refresh(attribute);
+ }
+ }
+ }
+ }
+ }
+ }
+
+}
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 30ae8cd75f6..86a5989ac54 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
@@ -54,7 +54,7 @@ PapyrusSearchPage_44=UML Elements
PapyrusSearchPage_45=Stereotypes applied in model(s)
PapyrusSearchPage_46=Select All Stereotypes
PapyrusSearchPage_47=Deselect All Stereotypes
-PapyrusSearchPage_47=String (leave empty in advanced search mode to search for element types only)
+PapyrusSearchPage_48=String (leave empty in advanced search mode to search for element types only)
PapyrusSearchPage_5=Case sensitive
PapyrusSearchPage_6=Regular expression
PapyrusSearchPage_7=Search kind:
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 583f61d73aa..780019bd1e0 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
@@ -68,6 +68,7 @@ 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.listeners.ParticipantTypesTreeViewerCheckStateListener;
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;
@@ -110,6 +111,7 @@ 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.swt.widgets.TreeItem;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
@@ -332,8 +334,7 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
}
}
}
-
-
+
// Find available stereotypes
availableStereotypes = StereotypeCollector.getInstance().computeAppliedStereotypes(container);
for (Stereotype stereotype : availableStereotypes) {
@@ -355,11 +356,7 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
}
stereotypeParticipantsList.put(parentElement, attributeList);
-
-
}
-
-
}
};
@@ -592,97 +589,10 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
});
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);
- 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);
- }
- }
- }
- }
- }
- }
-
-
- }
- });
+ ((ICheckable) participantTypesTreeViewer).addCheckStateListener(new ParticipantTypesTreeViewerCheckStateListener(participantTypesTreeViewer, participantsList));
participantStereotypesTreeViewer.setInput(stereotypeParticipantsList);
- //TODO refactor
- ((ICheckable) participantStereotypesTreeViewer).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);
- participantStereotypesTreeViewer.refresh(selectedElement);
-
- if (selectedElement instanceof ParticipantTypeAttribute) {
- ParticipantTypeElement parent = ((ParticipantTypeAttribute) selectedElement).getParent();
- if (parent != null) {
- // participantTypesTreeViewer.setChecked(parent, true);
- parent.setChecked(true);
- participantStereotypesTreeViewer.refresh(parent);
- }
- }
- } else {
- Object selectedElement = event.getElement();
- ((ParticipantTypeElement) selectedElement).setChecked(false);
- participantStereotypesTreeViewer.refresh(selectedElement);
-
- if (((ParticipantTypeElement) selectedElement).getElement() instanceof Stereotype || ((ParticipantTypeElement) selectedElement).getElement() instanceof EClassImpl) {
- for (Object attribute : participantStereotypesTreeViewer.getCheckedElements()) {
- if (attribute instanceof ParticipantTypeAttribute) {
- if (((ParticipantTypeAttribute) attribute).getParent().equals(selectedElement)) {
- // participantTypesTreeViewer.setChecked(attribute, false);
- ((ParticipantTypeElement) attribute).setChecked(false);
- participantStereotypesTreeViewer.refresh(attribute);
- }
- }
- }
- }
- }
- }
- }
- });
+ ((ICheckable) participantStereotypesTreeViewer).addCheckStateListener(new ParticipantTypesTreeViewerCheckStateListener(participantStereotypesTreeViewer, stereotypeParticipantsList));
//TODO Better solution than this empty label to fill last row 1, col 3 with empty space
emptyLabel2 = new Label(advancedSearchComposite, SWT.NONE);
@@ -1158,9 +1068,12 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
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 (searchQueryText.getText().length() > 0) {
+ for (ParticipantTypeAttribute attributesToEvaluate : participantsList.get(element)) {
+ if (attributesToEvaluate.isChecked()) {
+ participantsToEvaluate.add(attributesToEvaluate);
+ }
}
}
}
@@ -1169,31 +1082,23 @@ public class PapyrusSearchPage extends DialogPage implements ISearchPage, IRepla
for (ParticipantTypeElement element : this.stereotypeParticipantsList.keySet()) {
if (element.isChecked()) {
participantsToEvaluate.add(element);
- for (ParticipantTypeAttribute attributesToEvaluate : stereotypeParticipantsList.get(element)) {
- if (attributesToEvaluate.isChecked()) {
- participantsToEvaluate.add(attributesToEvaluate);
+
+ if (searchQueryText.getText().length() > 0) {
+ for (ParticipantTypeAttribute attributesToEvaluate : stereotypeParticipantsList.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().length() == 0) {
- for (Object participantChecked : participantTypesTreeViewer.getCheckedElements()) {
- if (participantChecked instanceof ParticipantTypeAttribute) {
- MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.PapyrusSearchPage_33, Messages.PapyrusSearchPage_34);
- return false;
- }
- }
- }
-
QueryInfo info = new QueryInfo(searchQueryText.getText(), btnCaseSensitive.getSelection(), btnRegularExpression.getSelection(), participantsToEvaluate, scope, fBtnSearchForAllSelected.getSelection());
query = CompositePapyrusQueryProvider.getInstance().createAdvancedSearchQuery(info);
-
}
}
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 7cb1524c850..ed37f9781a1 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,8 +45,8 @@ public class AttributeMatchLabelProvider implements IFilteredLabelProvider {
return null;
}
- private String printResult(String sectionThatMatch, String value, int offset, int length, String attributeName) {
- return "\"" + sectionThatMatch + "\"" + Messages.AttributeMatchLabelProvider_3 + "\"" + value + "\" [" + (offset + 1) + "," + (offset + length) + "] (" + 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$
+ private String printResult(String value, int offset, int length, String attributeName) {
+ return "\"" + value.substring(offset, offset + length) + "\"" + Messages.AttributeMatchLabelProvider_3 + "\"" + value + "\" [" + (offset + 1) + "," + (offset + length) + "] (" + 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) {
@@ -59,12 +59,10 @@ public class AttributeMatchLabelProvider implements IFilteredLabelProvider {
EAttribute source = (EAttribute) attributeMatch.getMetaAttribute();
if (target.eGet(source) instanceof String) {
String value = (String) target.eGet(source);
- int end = attributeMatch.getOffset() + attributeMatch.getLength();
- return printResult(value.substring(attributeMatch.getOffset(), end), value, attributeMatch.getOffset(), attributeMatch.getLength(), source.getName());
+ return printResult(value, attributeMatch.getOffset(), attributeMatch.getLength(), source.getName());
} else {
String value = String.valueOf(target.eGet(source));
- int end = attributeMatch.getOffset() + attributeMatch.getLength();
- return printResult(value.substring(attributeMatch.getOffset(), end), value, attributeMatch.getOffset(), attributeMatch.getOffset(), source.getName());
+ return printResult(value, attributeMatch.getOffset(), attributeMatch.getOffset(), source.getName());
}
} else if (attributeMatch.getMetaAttribute() instanceof Property) {
@@ -73,8 +71,7 @@ public class AttributeMatchLabelProvider implements IFilteredLabelProvider {
if (containingClass instanceof Stereotype) {
if (target instanceof Element) {
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());
-
+ return printResult(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/query/PapyrusAdvancedQuery.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/query/PapyrusAdvancedQuery.java
index 9a3b0da9c3c..0c646ef6f23 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
@@ -164,21 +164,23 @@ 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());
+ Collection<EObject> stereotypedParticipants = ParticipantValidator.getInstance().getParticipantsStereotype(root, stereotypeList.keySet().toArray());
if (searchForAllSter) {
if (participantsList.keySet().size() == 0) {
- stereotypesParticipants = getElementsWithAllSter(stereotypesParticipants);
- evaluateStereotypes(stereotypesParticipants, scopeEntry);
+ stereotypedParticipants = getElementsWithAllSter(stereotypedParticipants);
+ evaluate(stereotypedParticipants, scopeEntry);
+ evaluateStereotypes(stereotypedParticipants, scopeEntry);
} else {
participants = getElementsWithAllSter(participants);
evaluate(participants, scopeEntry);
+ evaluateStereotypes(participants, scopeEntry);
}
} else {
evaluate(participants, scopeEntry);
- evaluateStereotypes(stereotypesParticipants, scopeEntry);
+ evaluateStereotypes(stereotypedParticipants, scopeEntry);
}
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
index 19931b30e3f..d652c7641eb 100644
--- 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
@@ -1,104 +1,105 @@
-/*****************************************************************************
- * 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.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-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 = it.next();
-
- // Check that metaclass of this element is a supported metaclass
- @SuppressWarnings("unused") EClass e = modelElement.eClass();
- 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 = it.next();
- if (modelElement instanceof Element) {
- for (Stereotype appliedStereotype : ((Element) modelElement).getAppliedStereotypes()) {
- // Check that metaclass of this element is a supported metaclass
- for (Object stereotypeToGet : participantsTypesList) {
- if (EcoreUtil.equals(appliedStereotype, (EObject) stereotypeToGet)) {
- results.add(modelElement);
- }
- }
- }
- }
- }
-
- return results;
- }
-}
+/*****************************************************************************
+ * 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.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+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 = it.next();
+
+ // Check that metaclass of this element is a supported metaclass
+ @SuppressWarnings("unused") EClass e = modelElement.eClass();
+ 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 = it.next();
+ if (modelElement instanceof Element) {
+ for (Stereotype appliedStereotype : ((Element) modelElement).getAppliedStereotypes()) {
+ // Check that metaclass of this element is a supported metaclass
+ for (Object stereotypeToGet : participantsTypesList) {
+ if (EcoreUtil.equals(appliedStereotype, (EObject) stereotypeToGet)) {
+ results.add(modelElement);
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ return results;
+ }
+}

Back to the top