]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/eclipse/ui/jcr/NodeElementComparer.java
Working UUID factory
[lgpl/argeo-commons.git] / org.argeo.cms.ui / src / org / argeo / eclipse / ui / jcr / NodeElementComparer.java
1 package org.argeo.eclipse.ui.jcr;
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 /** Element comparer for JCR node, to be used in JFace viewers. */
10 public class NodeElementComparer implements IElementComparer {
11
12 public boolean equals(Object a, Object b) {
13 try {
14 if ((a instanceof Node) && (b instanceof Node)) {
15 Node nodeA = (Node) a;
16 Node nodeB = (Node) b;
17 return nodeA.getIdentifier().equals(nodeB.getIdentifier());
18 } else {
19 return a.equals(b);
20 }
21 } catch (RepositoryException e) {
22 throw new EclipseUiException("Cannot compare nodes", e);
23 }
24 }
25
26 public int hashCode(Object element) {
27 try {
28 if (element instanceof Node)
29 return ((Node) element).getIdentifier().hashCode();
30 return element.hashCode();
31 } catch (RepositoryException e) {
32 throw new EclipseUiException("Cannot get hash code", e);
33 }
34 }
35
36 }