1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.argeo.eclipse.ui.jcr.util;
17  
18  import javax.jcr.Node;
19  import javax.jcr.RepositoryException;
20  
21  import org.argeo.eclipse.ui.EclipseUiException;
22  import org.eclipse.jface.viewers.IElementComparer;
23  
24  
25  public class NodeViewerComparer implements IElementComparer {
26  
27  	
28  	public boolean equals(Object elementA, Object elementB) {
29  		if (!(elementA instanceof Node) || !(elementB instanceof Node)) {
30  			return elementA == null ? elementB == null : elementA
31  					.equals(elementB);
32  		} else {
33  
34  			boolean result = false;
35  			try {
36  				String idA = ((Node) elementA).getIdentifier();
37  				String idB = ((Node) elementB).getIdentifier();
38  				result = idA == null ? idB == null : idA.equals(idB);
39  			} catch (RepositoryException re) {
40  				throw new EclipseUiException("cannot compare nodes", re);
41  			}
42  
43  			return result;
44  		}
45  	}
46  
47  	public int hashCode(Object element) {
48  		
49  		return element.getClass().toString().hashCode();
50  	}
51  }