From 5be1d922915376ad5570cafc8b7835005779c86a Mon Sep 17 00:00:00 2001
From: Simon Barner <barner@fortiss.org>
Date: Fri, 12 Oct 2018 17:13:25 +0200
Subject: [PATCH] Move HierarchicalNameViewerComparator to kernel.ui

* Generalize interface to IModelElement
* Use anonymous class in GenericAnnotationView to adapt AnnotationEntry
  elements

Issue-Ref: 3223
Issue-Url: https://af3-developer.fortiss.org/issues/3223

Signed-off-by: Simon Barner <barner@fortiss.org>
---
 .../base/ui/annotation/view/generic/.ratings     |  3 +--
 .../view/generic/GenericAnnotationView.java      | 16 +++++++++++++++-
 .../org/fortiss/tooling/kernel/ui/util/.ratings  |  1 +
 .../util}/HierarchicalNameViewerComparator.java  | 13 ++++++-------
 4 files changed, 23 insertions(+), 10 deletions(-)
 rename {org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic => org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/util}/HierarchicalNameViewerComparator.java (80%)

diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/.ratings
index d9bd0b9aa..aed51645e 100644
--- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/.ratings
+++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/.ratings
@@ -1,3 +1,2 @@
 ColumnHandle.java 8fc5f04cbb0127e5df8c7a9e3b2620502bf93716 GREEN
-GenericAnnotationView.java 9ece325e33056bc866aa842a7be5e0be3db84fe0 GREEN
-HierarchicalNameViewerComparator.java c12e9216387618c518f7e7c15d21179a86aad472 GREEN
+GenericAnnotationView.java 0fea0eafedcf1d24ea9faa34d84f3044443f951f YELLOW
diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/GenericAnnotationView.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/GenericAnnotationView.java
index 9ece325e3..0fea0eafe 100644
--- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/GenericAnnotationView.java
+++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/GenericAnnotationView.java
@@ -17,6 +17,7 @@ package org.fortiss.tooling.base.ui.annotation.view.generic;
 
 import static org.fortiss.tooling.base.ui.annotation.editingsupport.EditingSupportFactory.createEditingSupport;
 import static org.fortiss.tooling.base.ui.annotation.labelprovider.LabelProviderFactory.createLabelProvider;
+import static org.fortiss.tooling.kernel.utils.HierarchicalNameComparator.compareByNameIdHashCode;
 
 import java.lang.reflect.Method;
 import java.util.Collection;
@@ -41,6 +42,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 +83,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 +507,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 compareByNameIdHashCode(o1, o2);
+			}
+		});
 
 		tableViewer.setComparer(new IElementComparer() {
 
diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/util/.ratings b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/util/.ratings
index 7b9ae0f73..c80414eb7 100644
--- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/util/.ratings
+++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/util/.ratings
@@ -4,6 +4,7 @@ CopyPasteUtils.java bbc5cf9c9dc03ebf8dc75d42c919fe6eb60b388e GREEN
 DataBindingUtils.java 6ae66457694227b69c13c092ef62babdd4a2a137 GREEN
 DragAndDropUtils.java 7aab91518aa12d76533a345bf6ed0be9ac7ff0e5 GREEN
 EObjectSelectionUtils.java 128cf8f96c6b9478171dff3deda662d5934f5f44 GREEN
+HierarchicalNameViewerComparator.java f9a2a8add3ea2bedfa40bcde25b35389cb2dd005 YELLOW
 KernelUIUtils.java 46d3279ef3523b104f89a6c526109f72d36f72f2 GREEN
 ObservableUtils.java 34abfd1dfaf9c0acbb31caf1f525e7b39416c116 GREEN
 PropertiesConstantUtils.java 59b1a1e4d594bb98db3aa396f2ff6474ba405920 GREEN
diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/HierarchicalNameViewerComparator.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/util/HierarchicalNameViewerComparator.java
similarity index 80%
rename from org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/HierarchicalNameViewerComparator.java
rename to org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/util/HierarchicalNameViewerComparator.java
index c12e92163..f9a2a8add 100644
--- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/HierarchicalNameViewerComparator.java
+++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/util/HierarchicalNameViewerComparator.java
@@ -13,20 +13,20 @@
 | See the License for the specific language governing permissions and      |
 | limitations under the License.                                           |
 +--------------------------------------------------------------------------*/
-package org.fortiss.tooling.base.ui.annotation.view.generic;
+package org.fortiss.tooling.kernel.ui.util;
 
 import static org.fortiss.tooling.kernel.utils.HierarchicalNameComparator.compareByNameIdHashCode;
 
 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.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,9 +38,8 @@ 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());
+		if(o1 instanceof EObject && o2 instanceof EObject) {
+			return comp.compare((EObject)o1, (EObject)o2);
 		}
 
 		return compareByNameIdHashCode(o1, o2);
-- 
GitLab