public sealed class PagedDataSource : ICollection, IEnumerable, ITypedList
{
int page_size, current_page_index, virtual_count;
- bool allow_paging, allow_custom_paging;
+ bool allow_paging, allow_custom_paging, allow_server_paging;
IEnumerable source;
public PagedDataSource ()
public bool AllowCustomPaging {
get { return allow_custom_paging; }
- set { allow_custom_paging = value; }
+ set {
+ allow_custom_paging = value;
+#if NET_2_0
+ // AllowCustomPaging and AllowServerPaging are mutually exclusive
+ if (allow_custom_paging)
+ allow_server_paging = false;
+#endif
+ }
}
public bool AllowPaging {
if (source == null)
return 0;
- if (IsCustomPagingEnabled)
+ if (IsCustomPagingEnabled
+#if NET_2_0
+ || IsServerPagingEnabled
+#endif
+ )
return virtual_count;
if (source is ICollection)
public int FirstIndexInPage {
get {
- if (!IsPagingEnabled || IsCustomPagingEnabled || source == null)
+ if (!IsPagingEnabled || IsCustomPagingEnabled ||
+#if NET_2_0
+ IsServerPagingEnabled ||
+#endif
+ source == null)
return 0;
return current_page_index * page_size;
get { return IsPagingEnabled && allow_custom_paging; }
}
+#if NET_2_0
+ public bool IsServerPagingEnabled {
+ get { return IsPagingEnabled && allow_server_paging; }
+ }
+#endif
+
public bool IsFirstPage {
get {
if (!allow_paging)
get {
if (source == null)
return 0;
-
+
if (!IsPagingEnabled || DataSourceCount == 0 || page_size == 0)
return 1;
-
+
return (DataSourceCount + page_size - 1) / page_size;
}
}
set { virtual_count = value; }
}
#if NET_2_0
- [MonoTODO]
public bool AllowServerPaging {
get {
- throw new NotImplementedException ();
- }
- set {
- throw new NotImplementedException ();
- }
- }
-
- [MonoTODO]
- public DataSourceSelectArguments DataSourceSelectArguments {
- get {
- throw new NotImplementedException ();
+ return allow_server_paging;
}
set {
- throw new NotImplementedException ();
+ allow_server_paging = value;
+ // AllowCustomPaging and AllowServerPaging are mutually exclusive
+ if (allow_server_paging)
+ allow_custom_paging = false;
}
}
- [MonoTODO]
- public DataSourceView DataSourceView {
- get {
- throw new NotImplementedException ();
- }
- set {
- throw new NotImplementedException ();
- }
- }
-
- [MonoTODO]
- public void SetItemCountFromPageIndex (int highestPageIndex)
- {
- throw new NotImplementedException ();
- }
#endif
public void CopyTo (Array array, int index)
return String.Empty; // as documented
}
+#if TARGET_JVM
+ internal class ListEnum : IEnumerator
+ {
+ int start;
+ int end;
+ int ind;
+ IList list;
+
+ internal ListEnum(IList list, int start, int end)
+ {
+ this.list = list;
+ this.start = start;
+ this.end = end;
+ this.ind = start - 1;
+ }
+
+ public bool MoveNext()
+ {
+ ind++;
+ return (ind < end);
+ }
+
+ public void Reset() { ind = start - 1; }
+ public object Current { get { return list[ind]; }}
+ }
+
private IEnumerator GetListEnum (IList list, int start, int end)
{
if (!allow_paging)
end = list.Count;
+ return new ListEnum(list, start, end);
+ }
+
+ internal class EnumeratorEnum : IEnumerator
+ {
+ int start;
+ int end;
+ int ind;
+ IEnumerator en;
+ PagedDataSource parent;
+
+ internal EnumeratorEnum(PagedDataSource parent, IEnumerator en, int start, int end)
+ {
+ this.parent = parent;
+ this.en = en;
+ this.start = start;
+ this.end = end;
+ this.ind = start - 1;
+ for (int i = 0; i < start; i++)
+ en.MoveNext ();
+ }
+
+ public bool MoveNext()
+ {
+ ind++;
+ return (!parent.allow_paging || ind < end) && en.MoveNext ();
+ }
+
+ public void Reset()
+ {
+ throw new NotSupportedException();
+ }
+
+ public object Current { get { return en.Current; }}
+ }
+
+ private IEnumerator GetEnumeratorEnum (IEnumerator e, int start, int end)
+ {
+ return new EnumeratorEnum(this, e, start, end);
+ }
+#else
+ private IEnumerator GetListEnum (IList list, int start, int end)
+ {
+ if (!AllowPaging)
+ end = list.Count;
else if (start >= list.Count)
yield break;
for (int i = start; (!allow_paging || i < end) && e.MoveNext (); i++)
yield return e.Current;
}
+#endif
}
}