}
}
+ /**
+ * Retrieve a {@link PropertyType#DATE} property as an {@link Instant}.
+ *
+ * @return the property value, or <code>null</code> if not found.
+ */
+ public static Instant getAsInstant(Node node, String property) {
+ try {
+ if (!node.hasProperty(property))
+ return null;
+ Calendar calendar = node.getProperty(property).getDate();
+ return calendar.getTime().toInstant();
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot get property " + property + " of " + node + " as an instant.", e);
+ }
+
+ }
+
/**
* Get a multiple property as a list, doing a best effort to cast it as the
* target list.
--- /dev/null
+package org.argeo.cms.jcr.swt;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.query.Query;
+
+import org.argeo.cms.ux.widgets.AbstractTabularPart;
+import org.argeo.jcr.JcrException;
+
+public class JcrQueryTabularPart extends AbstractTabularPart<Query, Node> {
+ private int cursor = 0;
+ private NodeIterator nit = null;
+
+ @Override
+ public int getItemCount() {
+ return (int) nit.getSize();
+ }
+
+ @Override
+ public Node getData(int row) {
+ // System.out.println("Row " + row);
+ Node res;
+ if (row == cursor) {
+ res = nit.nextNode();
+ cursor++;
+ } else if (row > cursor) {
+ nit.skip(row - cursor);
+ cursor = row;
+ res = nit.nextNode();
+ cursor++;
+ } else if (row < cursor) {
+ try {
+ nit = getInput().execute().getNodes();
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot refresh query", e);
+ }
+ notifyItemCountChange();
+ nit.skip(row);
+ cursor = row;
+ res = nit.nextNode();
+ cursor++;
+ } else {
+ throw new IllegalStateException("Cursor is " + cursor + " and row is " + row);
+ }
+ return res;
+ }
+
+ @Override
+ public void refresh() {
+ cursor = 0;
+ try {
+ nit = getInput().execute().getNodes();
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot refresh query", e);
+ }
+ super.refresh();
+ }
+
+ public long getQuerySize() {
+ return nit.getSize();
+ }
+}
--- /dev/null
+package org.argeo.cms.jcr.swt;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.query.Query;
+
+import org.argeo.cms.ux.widgets.AbstractTabularPart;
+import org.argeo.jcr.JcrException;
+
+public class PagedJcrQueryTabularPart extends AbstractTabularPart<Query, Node> {
+ private int pageSize = 100;
+ private int cursor = 0;
+ private int nextUpperBound = pageSize;
+ private NodeIterator nit = null;
+
+ @Override
+ public int getItemCount() {
+ return (nextUpperBound - pageSize) + (int) nit.getSize();
+ }
+
+ @Override
+ public Node getData(int row) {
+ // System.out.println("Row " + row);
+ if (row == cursor) {
+ cursor++;
+ Node res = nit.nextNode();
+ if (cursor == nextUpperBound) {
+ getInput().setOffset(cursor);
+ nextUpperBound = cursor + pageSize;
+ try {
+ nit = getInput().execute().getNodes();
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot refresh query", e);
+ }
+ notifyItemCountChange();
+ }
+ return res;
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public void refresh() {
+ getInput().setOffset(0);
+ getInput().setLimit(pageSize);
+ cursor = 0;
+ nextUpperBound = pageSize;
+ try {
+ nit = getInput().execute().getNodes();
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot refresh query", e);
+ }
+ super.refresh();
+ }
+
+}