1 package org.argeo.eclipse.ui.jcr.lists;
2
3 import javax.jcr.Node;
4 import javax.jcr.RepositoryException;
5 import javax.jcr.query.Row;
6
7 import org.argeo.eclipse.ui.EclipseUiException;
8 import org.eclipse.jface.viewers.Viewer;
9
10
11
12
13
14 public class RowViewerComparator extends NodeViewerComparator {
15 private static final long serialVersionUID = 7020939505172625113L;
16 protected String selectorName;
17
18 public RowViewerComparator() {
19 }
20
21
22
23
24
25
26
27
28
29 @Override
30 public int compare(Viewer viewer, Object e1, Object e2) {
31 try {
32 Node n1 = ((Row) e1).getNode(selectorName);
33 Node n2 = ((Row) e2).getNode(selectorName);
34 return super.compare(viewer, n1, n2);
35 } catch (RepositoryException re) {
36 throw new EclipseUiException("Unexpected error "
37 + "while comparing nodes", re);
38 }
39 }
40
41
42
43
44
45
46
47 public void setColumn(int propertyType, String selectorName,
48 String propertyName) {
49 if (this.selectorName != null && getPropertyName() != null
50 && this.selectorName.equals(selectorName)
51 && this.getPropertyName().equals(propertyName)) {
52
53 setDirection(1 - getDirection());
54 } else {
55
56 setPropertyType(propertyType);
57 setPropertyName(propertyName);
58 this.selectorName = selectorName;
59 setDirection(NodeViewerComparator.ASCENDING);
60 }
61 }
62 }