]> git.argeo.org Git - lgpl/argeo-commons.git/blob - jcr/org.argeo.cms.ui/src/org/argeo/eclipse/ui/jcr/util/NodeViewerComparer.java
Change ScrolledPage package
[lgpl/argeo-commons.git] / jcr / org.argeo.cms.ui / src / org / argeo / eclipse / ui / jcr / util / NodeViewerComparer.java
1 package org.argeo.eclipse.ui.jcr.util;
2
3 import javax.jcr.Node;
4 import javax.jcr.RepositoryException;
5
6 import org.argeo.eclipse.ui.EclipseUiException;
7 import org.eclipse.jface.viewers.IElementComparer;
8
9 /** Compare JCR nodes based on their JCR identifiers, for use in JFace viewers. */
10 public class NodeViewerComparer implements IElementComparer {
11
12 // force comparison on Node IDs only.
13 public boolean equals(Object elementA, Object elementB) {
14 if (!(elementA instanceof Node) || !(elementB instanceof Node)) {
15 return elementA == null ? elementB == null : elementA
16 .equals(elementB);
17 } else {
18
19 boolean result = false;
20 try {
21 String idA = ((Node) elementA).getIdentifier();
22 String idB = ((Node) elementB).getIdentifier();
23 result = idA == null ? idB == null : idA.equals(idB);
24 } catch (RepositoryException re) {
25 throw new EclipseUiException("cannot compare nodes", re);
26 }
27
28 return result;
29 }
30 }
31
32 public int hashCode(Object element) {
33 // TODO enhanced this method.
34 return element.getClass().toString().hashCode();
35 }
36 }