Mh, ListDataProvider is in wicket-core, but (I)SortableDataProvider is in wicket-extensions.
So my suggestion doesn't work :/.

Please open a Jira issue, we'll see what the other devs think about an additional convenience class.

Regards
Sven

On 08.06.2015 10:36, Ernesto Reinaldo Barreiro wrote:
Sven,

On Mon, Jun 8, 2015 at 10:07 AM, Sven Meier <[email protected]> wrote:

Hi,

my only objection would be that this SortableListDataProvider doesn't
actually sort anything.

AFAIK this does no harm though, so why not let the current
ListDataProvider implement ISortableDataProvider?

That's also posible. All I want is not having to roll out my own over an
over... :-)


Have fun
Sven



On 08.06.2015 08:50, Ernesto Reinaldo Barreiro wrote:

On many project I just need to show a list of beans on an AJAX default
datatable... There is already a ListDataProvider... but this component
require a Sortable version... and I always end up rolling out something
like the class bellow. Would it make sense to include a similar class on
wicket code base?

/**
   *  Sortable version of ListDataProvider.

   */

public class SortableListDataProvider<T extends Serializable, S>
extends SortableDataProvider<T, S> {

      private static final long serialVersionUID = 1L;

      /** reference to the list used as dataprovider for the dataview */
      private final List<T> list;

      /**
       * Constructs an empty provider. Useful for lazy loading together
with {@linkplain #getData()}
       */
      public SortableListDataProvider()
      {
          this(Collections.<T> emptyList());
      }

      /**
       *
       * @param list
       *            the list used as dataprovider for the dataview
       */
      public SortableListDataProvider(List<T> list)
      {
          if (list == null)
          {
              throw new IllegalArgumentException("argument [list] cannot
be null");
          }

          this.list = list;
      }

      /**
       * Subclass to lazy load the list
       *
       * @return The list
       */
      protected List<T> getData()
      {
          return list;
      }

      @Override
      public Iterator<? extends T> iterator(final long first, final long
count)
      {
          List<T> list = getData();

          long toIndex = first + count;
          if (toIndex > list.size())
          {
              toIndex = list.size();
          }
          return list.subList((int)first, (int)toIndex).listIterator();
      }

      /**
       * @see IDataProvider#size()
       */
      @Override
      public long size()
      {
          return getData().size();
      }

      /**
       * @see IDataProvider#model(Object)
       */
      @Override
      public IModel<T> model(T object)
      {
          return new Model<T>(object);
      }

      /**
       * @see org.apache.wicket.model.IDetachable#detach()
       */
      @Override
      public void detach()
      {
      }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]





---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to