Skip to content
Snippets Groups Projects
Commit ae963620 authored by Alexander Diewald's avatar Alexander Diewald
Browse files

Merge branch '3223' into 'master'

3223: Refactorying of hierarchical name (viewer) comparator

See merge request !29
parents bbe5695b c01d8a60
No related branches found
No related tags found
1 merge request!293223: Refactorying of hierarchical name (viewer) comparator
Showing
with 47 additions and 34 deletions
HierarchicalNameComparator.java 479dc1a3da772e551d15cbfb0d820cce87c15d63 GREEN
......@@ -5,7 +5,7 @@ EditingSupportFactory.java 03123559abc2952e417e6180b9364c2f5ecff4a3 GREEN
ElementCommentEditingSupport.java 4be366924a040caf3f80e35b383e796e84aedcac GREEN
ElementEditingSupportBase.java a6360f99ee149276f0fbd299820ebd1c9731ea97 GREEN
ElementNameEditingSupport.java 0dcaecf4ba5f8ddefa3ccb7d6f4e4506f7f09b26 GREEN
LabelValueMapping.java 54bf09ebd23039827a72dfbe9edb3d117f2db607 GREEN
LabelValueMapping.java 51fa603929b0e89f5fb2d757761746bd773ba371 GREEN
MultiSelectionCellEditor.java cac4a63137203ea90777b8ff971c945a457165c2 GREEN
MultiSelectionEditingSupport.java c9d45d09c2d64518d58e6e62254804608638a0ed GREEN
TextEditingSupport.java e761ea393816f23ca41157f2a9a9a8d8ef30b858 GREEN
......@@ -38,10 +38,10 @@ import org.eclipse.emf.ecore.EReference;
import org.fortiss.tooling.base.annotation.valueprovider.EStructuralFeatureDescriptor;
import org.fortiss.tooling.base.annotation.valueprovider.EStructuralFeatureDescriptor.EReferenceScope;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.ui.annotation.HierarchicalNameComparator;
import org.fortiss.tooling.kernel.model.IIdLabeled;
import org.fortiss.tooling.kernel.model.INamedElement;
import org.fortiss.tooling.kernel.model.IProjectRootElement;
import org.fortiss.tooling.kernel.utils.HierarchicalNameComparator;
/**
* Translates between the labels shown in a GUI and actual model elements (=values) (e.g.,
......
ColumnHandle.java 8fc5f04cbb0127e5df8c7a9e3b2620502bf93716 GREEN
GenericAnnotationView.java 9ece325e33056bc866aa842a7be5e0be3db84fe0 GREEN
HierarchicalNameViewerComparator.java 393f888a671d788c05650d17c937b76dda8a0f43 GREEN
GenericAnnotationView.java 3986c6ab6f1b5f9ec04780c3d6256e7c70b91c1d GREEN
......@@ -41,6 +41,7 @@ import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.jface.window.ToolTip;
import org.eclipse.swt.SWT;
......@@ -81,6 +82,7 @@ import org.fortiss.tooling.base.ui.annotation.view.generic.filter.AnnotationFilt
import org.fortiss.tooling.base.ui.dialog.MultiFieldInputDialog;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.service.IPersistencyService;
import org.fortiss.tooling.kernel.ui.util.HierarchicalNameViewerComparator;
/**
* <p>
......@@ -504,7 +506,18 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
fixedColumnCount = createFixedModelElementColumns();
columnWidthCache = new HashMap<String, Integer>();
tableViewer.setComparator(new HierarchicalNameViewerComparator());
tableViewer.setComparator(new HierarchicalNameViewerComparator() {
/** {@inheritDoc} */
@Override
public int compare(Viewer viewer, Object o1, Object o2) {
if(o1 instanceof AnnotationEntry && o2 instanceof AnnotationEntry) {
return super.compare(viewer, ((AnnotationEntry)o1).getModelElement(),
((AnnotationEntry)o2).getModelElement());
}
return super.compare(viewer, o1, o2);
}
});
tableViewer.setComparer(new IElementComparer() {
......
ChildrenContentProvider.java d5aa8d8d16f453be39d97a7ba2e1955e3e1582a0 GREEN
SameTypeContentProvider.java dc923f33aaf70b1f833d388837536e9e303d55c1 GREEN
SameTypeContentProvider.java 67d62fa5cb568e396062025baab7bf34c2c35a45 GREEN
......@@ -36,11 +36,11 @@ public class SameTypeContentProvider<T extends IHierarchicElement & INamedElemen
extends DynamicTreeContentProviderBase<T> {
/** EObject type to check against. */
EClass type;
private EClass eClass;
/** Constructor. */
public SameTypeContentProvider(EClass type) {
this.type = type;
public SameTypeContentProvider(EClass eClass) {
this.eClass = eClass;
}
/** {@inheritDoc} */
......@@ -51,7 +51,7 @@ public class SameTypeContentProvider<T extends IHierarchicElement & INamedElemen
// @CodeFormatterOff
Collection<? extends T> children = (Collection<? extends T>)
filterStream(current.getContainedElements(), e -> e instanceof INamedElement)
.filter(e -> (e.getClass().equals(type)) || (type.isInstance(e)))
.filter(e -> eClass.isInstance(e))
.collect(Collectors.toList());
// @CodeFormatterOn
return children;
......
......@@ -4,6 +4,7 @@ CopyPasteUtils.java bbc5cf9c9dc03ebf8dc75d42c919fe6eb60b388e GREEN
DataBindingUtils.java 6ae66457694227b69c13c092ef62babdd4a2a137 GREEN
DragAndDropUtils.java 7aab91518aa12d76533a345bf6ed0be9ac7ff0e5 GREEN
EObjectSelectionUtils.java 128cf8f96c6b9478171dff3deda662d5934f5f44 GREEN
HierarchicalNameViewerComparator.java 199d82e392d4e437810cc65c0fc521dab52038e0 GREEN
KernelUIUtils.java 46d3279ef3523b104f89a6c526109f72d36f72f2 GREEN
ObservableUtils.java 34abfd1dfaf9c0acbb31caf1f525e7b39416c116 GREEN
PropertiesConstantUtils.java 59b1a1e4d594bb98db3aa396f2ff6474ba405920 GREEN
......
......@@ -13,20 +13,18 @@
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.annotation.view.generic;
import static org.fortiss.tooling.base.ui.annotation.HierarchicalNameComparator.compareByNameIdHashCode;
package org.fortiss.tooling.kernel.ui.util;
import java.util.Comparator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.fortiss.tooling.base.annotation.AnnotationEntry;
import org.fortiss.tooling.base.ui.annotation.HierarchicalNameComparator;
import org.fortiss.tooling.kernel.utils.HierarchicalNameComparator;
/**
* {@link ViewerComparator} that sorts rows according to hierarchy level. Elements within one
* hierarchy level are sorted by name.
* {@link ViewerComparator} whose {@link #compare(Viewer, Object, Object)} method sorts
* {@link EObject} model elements by wrapping {@link HierarchicalNameComparator}).
*
* @author barner
*/
......@@ -38,11 +36,6 @@ public class HierarchicalNameViewerComparator extends ViewerComparator {
/** {@inheritDoc} */
@Override
public int compare(Viewer viewer, Object o1, Object o2) {
if(o1 instanceof AnnotationEntry && o2 instanceof AnnotationEntry) {
return comp.compare(((AnnotationEntry)o1).getModelElement(),
((AnnotationEntry)o2).getModelElement());
}
return compareByNameIdHashCode(o1, o2);
return comp.compare(o1, o2);
}
}
......@@ -4,9 +4,10 @@ EMFResourceUtils.java 979d0e1f4f66a2b3e715d2da0ebef6493f547fd7 GREEN
EcoreSerializerBase.java 0a0c2969d793d2e68094c55c8f7b0a662ef6e5d5 GREEN
EcoreUtils.java ffb428de083b536cd06e875e75484706f2149c2a GREEN
ExtensionPointUtils.java 7ce63242b49eb9a7cd4eaadd223f5ebce1dfd75b GREEN
HierarchicalNameComparator.java 6face1b673126701a0721af48ead2f9766c17d46 GREEN
IdentifierUtils.java fff43dc4e84cdd89c3ece4f5d9d89aec4b0749c2 GREEN
JavaUtils.java 65cdadfb9137a240ad59992eacf53a15b7f20804 GREEN
KernelModelElementUtils.java a7fa0e2596e06195634e3163b23fa376b2420920 GREEN
KernelModelElementUtils.java 56c86fe9afb23053f50d7279809afd2a5bb10eba GREEN
LoggingUtils.java a982f7c3371e72feb8658510b5b0358876281a12 GREEN
PrototypesUtils.java ec75bed75cfc5103f1f38e3a29df86f729428775 GREEN
ResourceUtils.java 698c7db34acb4f1a258a1953e6afcca9823763a8 GREEN
......
......@@ -13,7 +13,7 @@
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.annotation;
package org.fortiss.tooling.kernel.utils;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getModelElementAncestor;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getModelElementLevel;
......@@ -23,12 +23,13 @@ import org.fortiss.tooling.kernel.model.IIdLabeled;
import org.fortiss.tooling.kernel.model.INamedElement;
/**
* Comparator that sorts rows according to hierarchy level. Elements within one hierarchy level
* are sorted by name.
* Comparator whose {@link #compare(Object, Object)} method sorts model elements
* according to hierarchy level (in case they are {@link EObject}s. Elements within one hierarchy
* level (or non-{@link EObject}s) are sorted by name, ID, and hash code.
*
* @author eder, diewald, barner
*/
public class HierarchicalNameComparator implements java.util.Comparator<EObject> {
public class HierarchicalNameComparator implements java.util.Comparator<Object> {
/**
* Compare two {@link Object}s by
......@@ -38,7 +39,7 @@ public class HierarchicalNameComparator implements java.util.Comparator<EObject>
* <li>Hash code (otherwise)</li>
* </ul>
*/
public static int compareByNameIdHashCode(Object o1, Object o2) {
private int compareByNameIdHashCode(Object o1, Object o2) {
// Compare elements by name if they are INamedElements
if(o1 instanceof INamedElement && o2 instanceof INamedElement) {
// Elements are at the same level -> compare by name
......@@ -65,14 +66,20 @@ public class HierarchicalNameComparator implements java.util.Comparator<EObject>
/** {@inheritDoc} */
@Override
public int compare(EObject modelElement1, EObject modelElement2) {
public int compare(Object o1, Object o2) {
int modelElement1Level = getModelElementLevel(modelElement1);
int modelElement2Level = getModelElementLevel(modelElement2);
if(!(o1 instanceof EObject) || !(o2 instanceof EObject)) {
return compareByNameIdHashCode(o1, o2);
}
EObject modelElement1 = (EObject)o1;
EObject modelElement2 = (EObject)o2;
EObject e1 = modelElement1;
EObject e2 = modelElement2;
int modelElement1Level = getModelElementLevel(modelElement1);
int modelElement2Level = getModelElementLevel(modelElement2);
if(modelElement1Level < modelElement2Level) {
// Element1 is higher than element2: Get ancestor of element2 that is at the
// level as the element1.
......
......@@ -150,8 +150,8 @@ public final class KernelModelElementUtils {
while(currentElement != null && !(currentElement instanceof IProjectRootElement)) {
if(targetClass.isAssignableFrom(currentElement.getClass())) {
retList.add((T)currentElement);
currentElement = currentElement.eContainer();
}
currentElement = currentElement.eContainer();
}
return retList;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment