]> git.argeo.org Git - gpl/argeo-jcr.git/blob - swt/org.argeo.cms.jcr.ui/src/org/argeo/cms/jcr/swt/JcrQueryTabularPart.java
Prepare next development cycle
[gpl/argeo-jcr.git] / swt / org.argeo.cms.jcr.ui / src / org / argeo / cms / jcr / swt / JcrQueryTabularPart.java
1 package org.argeo.cms.jcr.swt;
2
3 import javax.jcr.Node;
4 import javax.jcr.NodeIterator;
5 import javax.jcr.RepositoryException;
6 import javax.jcr.query.Query;
7
8 import org.argeo.cms.ux.widgets.AbstractTabularPart;
9 import org.argeo.jcr.JcrException;
10
11 public class JcrQueryTabularPart extends AbstractTabularPart<Query, Node> {
12 private int cursor = 0;
13 private NodeIterator nit = null;
14
15 @Override
16 public int getItemCount() {
17 return (int) nit.getSize();
18 }
19
20 @Override
21 public Node getData(int row) {
22 // System.out.println("Row " + row);
23 Node res;
24 if (row == cursor) {
25 res = nit.nextNode();
26 cursor++;
27 } else if (row > cursor) {
28 nit.skip(row - cursor);
29 cursor = row;
30 res = nit.nextNode();
31 cursor++;
32 } else if (row < cursor) {
33 try {
34 nit = getInput().execute().getNodes();
35 } catch (RepositoryException e) {
36 throw new JcrException("Cannot refresh query", e);
37 }
38 notifyItemCountChange();
39 nit.skip(row);
40 cursor = row;
41 res = nit.nextNode();
42 cursor++;
43 } else {
44 throw new IllegalStateException("Cursor is " + cursor + " and row is " + row);
45 }
46 return res;
47 }
48
49 @Override
50 public void refresh() {
51 cursor = 0;
52 try {
53 nit = getInput().execute().getNodes();
54 } catch (RepositoryException e) {
55 throw new JcrException("Cannot refresh query", e);
56 }
57 super.refresh();
58 }
59
60 public long getQuerySize() {
61 return nit.getSize();
62 }
63 }