]> git.argeo.org Git - lgpl/argeo-commons.git/blob - eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/utils/NodeViewerComparer.java
Slightly modify the class to enable easy introduction of sorter on column headers...
[lgpl/argeo-commons.git] / eclipse / runtime / org.argeo.eclipse.ui.jcr / src / main / java / org / argeo / eclipse / ui / jcr / utils / NodeViewerComparer.java
1 package org.argeo.eclipse.ui.jcr.utils;
2
3 import javax.jcr.Node;
4 import javax.jcr.RepositoryException;
5
6 import org.argeo.ArgeoException;
7 import org.eclipse.jface.viewers.IElementComparer;
8
9 public class NodeViewerComparer implements IElementComparer {
10
11 // force comparison on Node IDs only.
12 public boolean equals(Object elementA, Object elementB) {
13 if (!(elementA instanceof Node) || !(elementB instanceof Node)) {
14 return elementA == null ? elementB == null : elementA
15 .equals(elementB);
16 } else {
17
18 boolean result = false;
19 try {
20 String idA = ((Node) elementA).getIdentifier();
21 String idB = ((Node) elementB).getIdentifier();
22 result = idA == null ? idB == null : idA.equals(idB);
23 } catch (RepositoryException re) {
24 throw new ArgeoException("cannot compare nodes", re);
25 }
26
27 return result;
28 }
29 }
30
31 public int hashCode(Object element) {
32 // TODO enhanced this method.
33 return element.getClass().toString().hashCode();
34 }
35 }