]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/lists/RowViewerComparator.java
ffd065599b50f1dcec692d602797db4630de6cb6
1 package org
.argeo
.eclipse
.ui
.jcr
.lists
;
4 import javax
.jcr
.RepositoryException
;
5 import javax
.jcr
.query
.Row
;
7 import org
.argeo
.eclipse
.ui
.EclipseUiException
;
8 import org
.eclipse
.jface
.viewers
.Viewer
;
11 * Base comparator to enable ordering on Table or Tree viewer that display Jcr
14 public class RowViewerComparator
extends NodeViewerComparator
{
15 private static final long serialVersionUID
= 7020939505172625113L;
16 protected String selectorName
;
18 public RowViewerComparator() {
22 * e1 and e2 must both be Jcr rows.
30 public int compare(Viewer viewer
, Object e1
, Object e2
) {
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
);
43 * Corresponding JCR type
45 * name of the property to use.
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 // Same column as last sort; toggle the direction
53 setDirection(1 - getDirection());
55 // New column; do a descending sort
56 setPropertyType(propertyType
);
57 setPropertyName(propertyName
);
58 this.selectorName
= selectorName
;
59 setDirection(NodeViewerComparator
.ASCENDING
);