]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/ResultItemsComparer.java
Fix SWT resource leak
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui / src / main / java / org / argeo / slc / client / ui / model / ResultItemsComparer.java
1 package org.argeo.slc.client.ui.model;
2
3 import javax.jcr.RepositoryException;
4
5 import org.argeo.slc.SlcException;
6 import org.eclipse.jface.viewers.IElementComparer;
7
8 /**
9 * Override default behaviour to insure that 2 distincts results that have the
10 * same name will be correctly and distincly returned by corresponding
11 * TreeViewer.getSelection() method.
12 *
13 */
14 public class ResultItemsComparer implements IElementComparer {
15 // private final static Log log =
16 // LogFactory.getLog(ResultItemsComparer.class);
17
18 public boolean equals(Object a, Object b) {
19 if (b == null)
20 return a == null ? true : false;
21
22 if (a.hashCode() != b.hashCode() || !a.getClass().equals(b.getClass()))
23 return false;
24 else if (a instanceof SingleResultNode) {
25 try {
26 String ida = ((SingleResultNode) a).getNode().getIdentifier();
27
28 String idb = ((SingleResultNode) b).getNode().getIdentifier();
29
30 if (ida.equals(idb))
31 return true;
32 else
33 return false;
34
35 } catch (RepositoryException e) {
36 throw new SlcException("Cannot compare single reult nodes", e);
37 }
38 } else
39 return true;
40 }
41
42 public int hashCode(Object element) {
43 return element.hashCode();
44 }
45
46 }