diff options
author | Shuai Li | 2015-02-25 09:39:55 +0000 |
---|---|---|
committer | Shuai Li | 2015-03-11 17:06:16 +0000 |
commit | 9173f56602ecbc75928f3ea01fc5c9d3289109f0 (patch) | |
tree | b44e262d94998e94bb30c1bff68055824c217029 /plugins/views | |
parent | 65ba5cee2bc3554c2f615a2b1bbfa989d08823b5 (diff) | |
download | org.eclipse.papyrus-9173f56602ecbc75928f3ea01fc5c9d3289109f0.tar.gz org.eclipse.papyrus-9173f56602ecbc75928f3ea01fc5c9d3289109f0.tar.xz org.eclipse.papyrus-9173f56602ecbc75928f3ea01fc5c9d3289109f0.zip |
Bug 461819 - [Search] Results should be displayed as flat
Bug 461821 - [Search] Attributes matches aren't displayed correctly
- Display qualified name for semantic elements in results
- Do not display whole hierarchy for an element in results
- Fix result text of non-string attribute matches
- Fix different attribute matches not showing if they have the same
offset, length due to collision in HashSet
Change-Id: Ice3909d113537fc8ba1c6d6303652438e3f80dfd
Signed-off-by: Shuai Li <shuai.li@cea.fr>
Diffstat (limited to 'plugins/views')
2 files changed, 305 insertions, 289 deletions
diff --git a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/AttributeMatch.java b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/AttributeMatch.java index 95b5b9c0b8e..3331139faab 100644 --- a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/AttributeMatch.java +++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/AttributeMatch.java @@ -1,190 +1,208 @@ -/*****************************************************************************
- * 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.views.search.results;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.services.openelement.service.OpenElementService;
-import org.eclipse.papyrus.views.search.scope.ScopeEntry;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.uml2.uml.Stereotype;
-
-/**
- *
- * A match raised by the value of an attribute
- *
- */
-public class AttributeMatch extends ModelMatch {
-
- /**
- * The element containing the value of the attribute that matches
- */
-
-
-
- protected Object attribute;
-
- private Stereotype stereotype;
-
-
-
- /**
- * Similar to {@link AbstractResultEntry} but adds an information about which attribute raised the match and which element contains the value of
- * the attribute that matches
- *
- * @param offset
- * @param lenght
- * @param target
- * the element containing the value of the attribute that matches
- * @param scopeEntry
- * @param attribute
- * the attribute that raised the match
- */
- public AttributeMatch(int offset, int lenght, Object target, ScopeEntry scopeEntry, Object attribute, Stereotype stereotype) {
- super(offset, lenght, target, scopeEntry);
- this.attribute = attribute;
- this.stereotype = stereotype;
-
- // if(target instanceof EObject) {
- // this.uriSource = EcoreUtil.getURI((EObject)target);
- // }
- this.parent = new ResultEntry(target, scopeEntry);
- recursiveHierarchy((AbstractResultEntry) parent);
- }
-
- /**
- * Create an attribute-match in a parent result entry that already exists.
- *
- * @param parent
- * the parent result entry
- * @param offset
- * @param lengtt
- * @param target
- * the element containing the value of the attribute that matches
- * @param attribute
- * the attribute that raised the match
- */
- public AttributeMatch(AbstractResultEntry parent, int offset, int length, Object target, Object attribute, Stereotype stereotype) {
- super(offset, length, target, (ScopeEntry) parent.getElement());
-
- this.attribute = attribute;
- this.stereotype = stereotype;
- this.parent = parent;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#equals(java.lang.Object)
- * In addition, it checks if target is the same as well.
- *
- * @param obj
- * @return
- */
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof AttributeMatch) {
- if (super.equals(obj)) {
- if (((AttributeMatch) obj).getSource() instanceof EObject && this.getSource() instanceof EObject) {
- if (EcoreUtil.equals((EObject) ((AttributeMatch) obj).getSource(), (EObject) this.getSource())) {
- return true;
- }
- } else {
- if (((AttributeMatch) obj).getSource().equals(this.getSource())) {
- return true;
- }
- }
- }
- return false;
-
- } else {
- return false;
- }
- }
-
- // public Object getTarget() {
- // // ResourceSet resSet = new ResourceSetImpl();
- // if(this.uriSource != null) {
- // ResourceSet resSet = ((ScopeEntry)this.getElement()).getModelSet();
- // return resSet.getEObject(this.uriSource, true);
- // }
- // return null;
- //
- // }
- //
- // public void setTarget(Object target) {
- // if(target instanceof EObject) {
- // this.uriSource = EcoreUtil.getURI((EObject)target);
- // }
- //
- // }
-
- /**
- *
- * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#elementToDisplay()
- *
- * @return
- */
- @Override
- public Object elementToDisplay() {
- return this;
-
- }
-
- /**
- *
- * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#elementToCheckFilterFor()
- *
- * @return
- */
- @Override
- public Object elementToCheckFilterFor() {
- return this.getSource();
- }
-
- /**
- *
- * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#openElement()
- *
- * @return
- */
- @Override
- public Object openElement(OpenElementService service) throws ServiceException, PartInitException {
- if (this.getSource() instanceof EObject) {
- return service.openSemanticElement((EObject) this.getSource());
- }
- return null;
- }
-
- public Object getMetaAttribute() {
- // TODO Auto-generated method stub
- return this.attribute;
- }
-
- public Stereotype getStereotype() {
- return stereotype;
- }
-
-
- public void setStereotype(Stereotype stereotype) {
- this.stereotype = stereotype;
- }
-
- public URI getURISource() {
-
- return uriSource;
- }
-
-}
+/***************************************************************************** + * 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.views.search.results; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.services.openelement.service.OpenElementService; +import org.eclipse.papyrus.views.search.scope.ScopeEntry; +import org.eclipse.ui.PartInitException; +import org.eclipse.uml2.uml.Stereotype; + +/** + * + * A match raised by the value of an attribute + * + */ +public class AttributeMatch extends ModelMatch { + + /** + * The element containing the value of the attribute that matches + */ + + + + protected Object attribute; + + private Stereotype stereotype; + + + + /** + * Similar to {@link AbstractResultEntry} but adds an information about which attribute raised the match and which element contains the value of + * the attribute that matches + * + * @param offset + * @param lenght + * @param target + * the element containing the value of the attribute that matches + * @param scopeEntry + * @param attribute + * the attribute that raised the match + */ + public AttributeMatch(int offset, int lenght, Object target, ScopeEntry scopeEntry, Object attribute, Stereotype stereotype) { + super(offset, lenght, target, scopeEntry); + this.attribute = attribute; + this.stereotype = stereotype; + + // if(target instanceof EObject) { + // this.uriSource = EcoreUtil.getURI((EObject)target); + // } + this.parent = new ResultEntry(target, scopeEntry); + ((ResultEntry) this.parent).setParent(new ResultEntry(scopeEntry.getResourceURI(), scopeEntry)); + + // recursiveHierarchy((AbstractResultEntry) parent); + } + + /** + * Create an attribute-match in a parent result entry that already exists. + * + * @param parent + * the parent result entry + * @param offset + * @param lengtt + * @param target + * the element containing the value of the attribute that matches + * @param attribute + * the attribute that raised the match + */ + public AttributeMatch(AbstractResultEntry parent, int offset, int length, Object target, Object attribute, Stereotype stereotype) { + super(offset, length, target, (ScopeEntry) parent.getElement()); + + this.attribute = attribute; + this.stereotype = stereotype; + this.parent = parent; + } + + /** + * + * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#equals(java.lang.Object) + * In addition, it checks if target is the same as well. + * + * @param obj + * @return + */ + @Override + public boolean equals(Object obj) { + if (obj instanceof AttributeMatch) { + if (super.equals(obj)) { + if (((AttributeMatch) obj).getSource() instanceof EObject && this.getSource() instanceof EObject) { + if (EcoreUtil.equals((EObject) ((AttributeMatch) obj).getSource(), (EObject) this.getSource())) { + if (obj.hashCode() == this.hashCode()) { + return true; + } + } + } else { + if (((AttributeMatch) obj).getSource().equals(this.getSource())) { + if (obj.hashCode() == this.hashCode()) { + return true; + } + } + } + } + return false; + + } else { + return false; + } + } + + /** + * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#hashCode() + * + * Adds the identity hash since two instances of match with same offset and length will have + * the same hash code, although they should not if they are two different attributes. + * + */ + @Override + public int hashCode() { + return super.hashCode() + System.identityHashCode(this); + } + + // public Object getTarget() { + // // ResourceSet resSet = new ResourceSetImpl(); + // if(this.uriSource != null) { + // ResourceSet resSet = ((ScopeEntry)this.getElement()).getModelSet(); + // return resSet.getEObject(this.uriSource, true); + // } + // return null; + // + // } + // + // public void setTarget(Object target) { + // if(target instanceof EObject) { + // this.uriSource = EcoreUtil.getURI((EObject)target); + // } + // + // } + + /** + * + * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#elementToDisplay() + * + * @return + */ + @Override + public Object elementToDisplay() { + return this; + + } + + /** + * + * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#elementToCheckFilterFor() + * + * @return + */ + @Override + public Object elementToCheckFilterFor() { + return this.getSource(); + } + + /** + * + * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#openElement() + * + * @return + */ + @Override + public Object openElement(OpenElementService service) throws ServiceException, PartInitException { + if (this.getSource() instanceof EObject) { + return service.openSemanticElement((EObject) this.getSource()); + } + return null; + } + + public Object getMetaAttribute() { + // TODO Auto-generated method stub + return this.attribute; + } + + public Stereotype getStereotype() { + return stereotype; + } + + + public void setStereotype(Stereotype stereotype) { + this.stereotype = stereotype; + } + + public URI getURISource() { + + return uriSource; + } + +} diff --git a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/ModelElementMatch.java b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/ModelElementMatch.java index d32ceed375e..bef174d07e1 100644 --- a/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/ModelElementMatch.java +++ b/plugins/views/org.eclipse.papyrus.views.search/src/org/eclipse/papyrus/views/search/results/ModelElementMatch.java @@ -1,99 +1,97 @@ -/*****************************************************************************
- * 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.views.search.results;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.services.openelement.service.OpenElementService;
-import org.eclipse.papyrus.views.search.scope.ScopeEntry;
-import org.eclipse.ui.PartInitException;
-
-/**
- *
- * A match raised by an element in a model
- *
- */
-public class ModelElementMatch extends ModelMatch {
-
-
-
- public ModelElementMatch(Object source, ScopeEntry scopeEntry) {
- super(UNSPECIFIED, UNSPECIFIED, source, scopeEntry);
- recursiveHierarchy(this);
-
-
- // this.parent = new ResultEntry(scopeEntry.getResource(), scopeEntry);
- }
-
- @Override
- public boolean equals(Object obj) {
-
- return super.equals(obj);
- }
-
- /**
- *
- * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#elementToDisplay()
- *
- * @return
- */
- @Override
- public Object elementToDisplay() {
- // return this.getSource();
- if (this.uriSource != null) {
- ResourceSet resSet = ((ScopeEntry) this.getElement()).getModelSet();
- return resSet.getEObject(this.uriSource, true);
- }
- return null;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#elementToCheckFilterFor()
- *
- * @return
- */
- @Override
- public Object elementToCheckFilterFor() {
- return this.getSource();
- }
-
- // @Override
- // public Object getSource() {
- //
- // if(this.uriSource != null) {
- // ResourceSet resSet = ((ScopeEntry)this.getElement()).getModelSet();
- // return resSet.getEObject(this.uriSource, true);
- // }
- // return null;
- //
- //
- // }
-
- /**
- *
- * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#openElement()
- *
- * @return
- */
- @Override
- public Object openElement(OpenElementService service) throws ServiceException, PartInitException {
- if (this.getSource() instanceof EObject) {
-
- return service.openSemanticElement((EObject) this.getSource());
- }
- return null;
- }
-}
+/***************************************************************************** + * 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.views.search.results; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.services.openelement.service.OpenElementService; +import org.eclipse.papyrus.views.search.scope.ScopeEntry; +import org.eclipse.ui.PartInitException; + +/** + * + * A match raised by an element in a model + * + */ +public class ModelElementMatch extends ModelMatch { + + + + public ModelElementMatch(Object source, ScopeEntry scopeEntry) { + super(UNSPECIFIED, UNSPECIFIED, source, scopeEntry); + this.setParent(new ResultEntry(scopeEntry.getResourceURI(), scopeEntry)); + // recursiveHierarchy(this); + } + + @Override + public boolean equals(Object obj) { + + return super.equals(obj); + } + + /** + * + * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#elementToDisplay() + * + * @return + */ + @Override + public Object elementToDisplay() { + // return this.getSource(); + if (this.uriSource != null) { + ResourceSet resSet = ((ScopeEntry) this.getElement()).getModelSet(); + return resSet.getEObject(this.uriSource, true); + } + return null; + } + + /** + * + * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#elementToCheckFilterFor() + * + * @return + */ + @Override + public Object elementToCheckFilterFor() { + return this.getSource(); + } + + // @Override + // public Object getSource() { + // + // if(this.uriSource != null) { + // ResourceSet resSet = ((ScopeEntry)this.getElement()).getModelSet(); + // return resSet.getEObject(this.uriSource, true); + // } + // return null; + // + // + // } + + /** + * + * @see org.eclipse.papyrus.views.search.results.AbstractResultEntry#openElement() + * + * @return + */ + @Override + public Object openElement(OpenElementService service) throws ServiceException, PartInitException { + if (this.getSource() instanceof EObject) { + + return service.openSemanticElement((EObject) this.getSource()); + } + return null; + } +} |