Accueil > Eclipse Nebula, Eclipse RAP, Eclipse RCP, Nebula Pagination, Spring Data > Eclipse Nebula Pagination Control

Eclipse Nebula Pagination Control


In business application with large data, display data in a table with navigation page can be really helpful. In our XDocReport project, we need this feature in our Eclipse RCP/RAP XDocReport application for instance to select resumes to open in the Search Resume Dialog :

This last screenshot is the resume search dialog in WEB context (Eclipse RAP). Here a screenshot in fat client context (Eclipse RCP) :

After several search, it seems that there is no project which provides a SWT pagination control, which works with Eclipse RCP and RAP. So we decided to develop this control and give our code to Eclipse Nebula Project. Today Nebula Team are voting if the project will be accepted or not. Pagination control was accepted by Nebula and today it is stored on Eclipse Nebula Git.

If you are intersted you can read the original bug 367064.

Overview

The Nebula Pagination Plug-Ins gives you the capability to paginate data list in any SWT Widgets. It works with Eclipse RCP and RAP too.

Table pagination

Nebula Pagination gives you the capability for instance to manage pagination in a SWT Table :

This screen comes from org.eclipse.nebula.widgets.pagination.snippets.table.renderers.GraphicsPageableTableExample. Here the page navigation bar is drawn with SWT Graphics Context (GC), and you can change on runtime if you need the control style (or implement your own style). Here black style :

and green style :

You can use another pagination navigation bar renderer. For instance here links renderer: (see org.eclipse.nebula.widgets.pagination.snippets.table.StringPageableTableExample) :

Nebula Pagination provides another pagination renderer like Combo Page to choose the page, Scale Page to select a page, etc… Here a screenshot where you can see the whole pagination renderer (see org.eclipse.nebula.widgets.pagination.snippets.table.renderers.AllRenderersPageableTableExample) :

The whole pagination renderer are synchronized with the pagination controller. For instance if you change the selected page in a pagination renderer, the other pages renderer will be synchronized with this new selected page.

Table pagination&sort

You can manage sort with pagination like this (see org.eclipse.nebula.widgets.pagination.snippets.table.ModelSortPageableTableExample) :

Work In Process

The load of the paginated list could take time. You can observe the before/end loading of the paginated list to display a « Loading… » message. If you launch org.eclipse.nebula.widgets.pagination.snippets.table.ModelSortPageableTableWorkInProcessExample and you click on a page index (here the 2 page is selected), a « loading » message display on the bottom of the table :

The load of the paginated list takes 1 second and display at end the time of the load of the data :

Lazy loading

Nebula Pagination is able to manage lazy table to load new items when last item of the table is selected (see org.eclipse.nebula.widgets.pagination.snippets.table.lazy.LazyPageTableExample):

after selecting the last row, it load new data :

Plug-Ins

Nebula Pagination contribution provides 7 Plug-Ins :

  • org.eclipse.nebula.widgets.pagination : Eclipse Nebula Pagination which provides abstract class to manage pagination and implementation of thoses classes with PageResult pagination structure. Eclipse Nebula Pagination defines an IPageContentProvider to work with any Pagination structure (by default it works with Nebula PageResult, but you can use Spring Data Page structure if you wish (see org.eclipse.nebula.widgets.pagination.springdata).
  • org.eclipse.nebula.widgets.pagination.snippets : snippets with table pagination sample by using Nebula Pagination.
  • org.eclipse.nebula.widgets.pagination.tests : tests of Eclipse Nebula Pagination.
  • org.eclipse.nebula.widgets.pagination.example : example which adds a tab demo with table pagination in the global Nebula demo.

And if you wish use Spring Data pagination structure :

  • org.eclipse.nebula.widgets.pagination.springdata : defines an IpageContentProvider to works with Spring Data Page, Pageable.
  • org.eclipse.nebula.widgets.pagination.example.springdata : same sample than org.eclipse.nebula.widgets.pagination.example but works with Spring Data structure.
  • org.springframework.data.domain-only : Spring Data with just Pagination structure.
  • org.springframework.data.domain.collections : Spring Data domain Collections support.

Nebula Pagination API (without Spring Data)

To manage pagination with SWT table, Nebula Pagination provides a SWT Composite org.eclipse.nebula.widgets.pagination.PageableTable. The use of PageableTable is very easy but before explaining how to use it, it’s interesting to manage pagination at hand with the Nebula Pagination API (page controller etc) to understand more how to work PageableTable. The Nebula Pagination API could be used to manage pagination with another thing like Tree, NatTable, etc.

Pagination in Table at hand

This explanation is based on the sample org.eclipse.nebula.widgets.pagination.example.table.renderers.OneRendererPaginationTableAtHandExample :

Nebula Pagination works with a pagination controller which hold information about pagination and send events when information changes. The pagination controller is used to store information about pagination :

  • the current page index: index of the selected page.
  • the page size: number items to display per page.
  • the total elements: the total elements of the paginated list.
  • the current sort information: the property name and direction of the sort.

The controller fire events as soon as pagination information changes (ex: a new page is selected, sort change,etc). Those information can be observed by adding org.eclipse.nebula.widgets.pagination..IPageChangedListener to the controller. The pagination controller is designed with the class org.eclipse.nebula.widgets.pagination.PageableController which plays the role of the pagination request.

  1. At first you must create a pagination controller like this:
    int pageSize = 10;
    final PageableController controller = new PageableController(pageSize);
  2. For pagination table, a listener is added to the pagination controller to refresh the table with paginated list. To load paginated list, you must implement org.eclipse.nebula.widgets.pagination.IPageLoader :
    package org.eclipse.nebula.widgets.pagination;
    
    import java.util.List;
    
    import org.eclipse.nebula.widgets.pagination.collections.PageResultLoaderList;
    import org.eclipse.nebula.widgets.pagination.collections.PageResult;
    
    /**
     * Classes which implement this interface provide methods which load paginated
     * list by using information about pagination (sort, page index etc) coming from
     * the {@link PageableController}.
     * 
     * <p>
     * If you wish to manage pagination with Java {@link List} in memory you can use
     * {@link PageResultLoaderList}.
     * 
     * </p>
     * <p>
     * For better design {@link IPageLoader} should be implemented by the Service
     * Layer or DAO (Repository) layer. If you wish to manage pagination with JPA,
     * Spring Data JPA can be very helpful.
     * </p>
     * 
     * @see http://www.springsource.org/spring-data
     */
    public interface IPageLoader<T> {
    
      /**
       * Load the paginated list by using the {@link PageableController}
       * information about pagination (sort, page index etc) and returns a page
       * result which contains the paginated list and the total elements (ex:
       * {@link PageResult}, Spring Data Page, etc).
       * 
       * @param controller
       *            information about pagination.
       * @return a pagination structure which contains the paginated list and the
       *         total elements.
       */
      T loadPage(PageableController controller);
    
    }

    The implementation of this interface must return the page result structure. Nebula Pagination provides a basic pagination page result org.eclipse.nebula.widgets.pagination.collections.PageResult which works with Java list :

    package org.eclipse.nebula.widgets.pagination.collections;
    
    import java.util.List;
    
    /**
     * 
     * Page result used to store pagination result information :
     * 
     * <ul>
     * <li>the total elements</li>
     * <li>the paginated list</li>
     * </ul>
     * 
     * @param <T>
     *            the type item of the paginated list.
     */
    public class PageResult<T> {
    
    	private final List<T> content;
    	private final long totalElements;
    
    	/**
    	 * Constructor with the given paginated list and total elements.
    	 * 
    	 * @param content
    	 * @param totalElements
    	 */
    	public PageResult(List<T> content, long totalElements) {
    		this.totalElements = totalElements;
    		this.content = content;
    	}
    
    	/**
    	 * Returns the total amount of elements.
    	 * 
    	 * @return the total amount of elements
    	 */
    	public long getTotalElements() {
    		return totalElements;
    	}
    
    	/**
    	 * Returns the page content as {@link List}.
    	 * 
    	 * @return
    	 */
    	public List<T> getContent() {
    		return content;
    	}
    }

    So you can create a page loader like this:

    final List items = ...;
    final IPageLoader<PageResult> pageLoader = new PageResultLoaderList(items);

    If you use Spring Data JPA, the page result structure can be org.springframework.data.domain.Page and implementation of the IPageLoader can call directly a repository interface (ex: Page findAllPageable(Pageable pageable)). If you wish use Nebula Pagination with Spring Data, please read Nebula Pagination API (with Spring Data).

  3. You can create your TableViewer with classic mean and synchronyse it with controller and pageLoader like this :
    Table table = new Table(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    ...
    TableViewer viewer = new TableViewer(table);
    controller.addPageChangedListener(PageLoaderStrategyHelper.createLoadPageAndReplaceItemsListener(controller, viewer, pageLoader, PageResultContentProvider.getInstance(), null));
    

    Here when controller changes (ex: page index changes, sort changes, etc), it call the pageloader which returns paginated list in the PageResult and the viewer is refreshed (viewer.setInput(page.gecontent()) with the sublist coming from the PageResult#getContent(). PageResultContentProvider.getInstance() is the org.eclipse.nebula.widgets.pagination.IPageContentProvider to tell that you wish works with page result org.eclipse.nebula.widgets.pagination.PageResult.

    Now if you do :

    controller.setCurrentPage(0)

    to set the current page index to 0, the controller will send an event to notify that page index has changed. In this case, page loader will be called to load paginated list and refresh the viewer.

  4. At this step we can display navigation page with a renderer :
    ResultAndNavigationPageLinksRenderer resultAndPageLinksDecorator = new ResultAndNavigationPageLinksRenderer(parent, SWT.NONE, controller);
  5. At this step, page links are drawn and you can click on page links to navigate to page and refresh the table. Now you can create columns and add sort by adding SortTableColumnSelectionListener to the column:
    TableViewerColumn viewerColumn = new TableViewerColumn(viewer,
    SWT.NONE);
    ...
    viewerColumn.getColumn().addSelectionListener(new SortTableColumnSelectionListener("name", controller));
    

    The constructor org.eclipse.nebula.widgets.pagination.table.SortTableColumnSelectionListener is called with « name » property to sort to Person#getName() property.

  6. Here the full code :

    package org.eclipse.nebula.widgets.pagination.example.table.renderers;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import org.eclipse.jface.viewers.ArrayContentProvider;
    import org.eclipse.jface.viewers.ColumnLabelProvider;
    import org.eclipse.jface.viewers.LabelProvider;
    import org.eclipse.jface.viewers.TableViewer;
    import org.eclipse.jface.viewers.TableViewerColumn;
    import org.eclipse.nebula.widgets.pagination.IPageLoader;
    import org.eclipse.nebula.widgets.pagination.PageLoaderStrategyHelper;
    import org.eclipse.nebula.widgets.pagination.PageableController;
    import org.eclipse.nebula.widgets.pagination.collections.PageResult;
    import org.eclipse.nebula.widgets.pagination.collections.PageResultContentProvider;
    import org.eclipse.nebula.widgets.pagination.collections.PageResultLoaderList;
    import org.eclipse.nebula.widgets.pagination.example.model.Address;
    import org.eclipse.nebula.widgets.pagination.example.model.Person;
    import org.eclipse.nebula.widgets.pagination.renderers.navigation.ResultAndNavigationPageLinksRenderer;
    import org.eclipse.nebula.widgets.pagination.table.SortTableColumnSelectionListener;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.layout.GridData;
    import org.eclipse.swt.layout.GridLayout;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.widgets.Table;
    import org.eclipse.swt.widgets.TableColumn;
    
    /**
     * This sample display a list of model {@link Person} in a SWT Table with
     * pagination banner displayed with Page Results+Page Links on the top of the
     * SWT Table. The 2 columns which display the list of {@link Person} can be
     * clicked to sort the paginated list.
     * 
     */
    public class OneRendererPaginationTableAtHandExample {
    
    	public static void main(String[] args) {
    
    		Display display = new Display();
    		Shell shell = new Shell(display);
    		GridLayout layout = new GridLayout(1, false);
    		shell.setLayout(layout);
    
    		final List items = createList();
    
    		Composite parent = new Composite(shell, SWT.NONE);
    		parent.setLayoutData(new GridData(GridData.FILL_BOTH));
    		parent.setLayout(new GridLayout());
    
    		// Left panel
    		Table table = new Table(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL
    				| SWT.V_SCROLL);
    		table.setLayoutData(new GridData(GridData.FILL_BOTH));
    
    		// 2) Initialize the table viewer + SWT Table
    		TableViewer viewer = new TableViewer(table);
    		viewer.setContentProvider(ArrayContentProvider.getInstance());
    		viewer.setLabelProvider(new LabelProvider());
    
    		table.setHeaderVisible(true);
    		table.setLinesVisible(true);
    
    		// 3) Create Table columns with sort of paginated list.
    		int pageSize = 10;
    		final PageableController controller = new PageableController(pageSize);
    		final IPageLoader<PageResult> pageLoader = new PageResultLoaderList(
    				items);
    		controller.addPageChangedListener(PageLoaderStrategyHelper
    				.createLoadPageAndReplaceItemsListener(controller, viewer,
    						pageLoader, PageResultContentProvider.getInstance(),
    						null));
    
    		// Create navigation page links
    		ResultAndNavigationPageLinksRenderer resultAndPageLinksDecorator = new ResultAndNavigationPageLinksRenderer(
    				parent, SWT.NONE, controller);
    		resultAndPageLinksDecorator.setLayoutData(new GridData(
    				GridData.FILL_HORIZONTAL));
    
    		createColumns(viewer, controller);
    		// 3) Set current page to 0 to refresh the table
    
    		controller.setCurrentPage(0);
    
    		shell.setSize(350, 250);
    		shell.open();
    		while (!shell.isDisposed()) {
    			if (!display.readAndDispatch())
    				display.sleep();
    		}
    		display.dispose();
    	}
    
    	private static void createColumns(final TableViewer viewer,
    			PageableController controller) {
    
    		// First column is for the first name
    		TableViewerColumn col = createTableViewerColumn(viewer, "Name", 150);
    		col.setLabelProvider(new ColumnLabelProvider() {
    			@Override
    			public String getText(Object element) {
    				String p = (String) element;
    				return p;
    			}
    		});
    		col.setLabelProvider(new ColumnLabelProvider() {
    			@Override
    			public String getText(Object element) {
    				Person p = (Person) element;
    				return p.getName();
    			}
    		});
    		col.getColumn().addSelectionListener(
    				new SortTableColumnSelectionListener("name", controller));
    
    		// Second column is for the adress
    		col = createTableViewerColumn(viewer, "Adress", 150);
    		col.setLabelProvider(new ColumnLabelProvider() {
    			@Override
    			public String getText(Object element) {
    				Person p = (Person) element;
    				Address address = p.getAddress();
    				if (address == null) {
    					return "";
    				}
    				return address.getName();
    			}
    		});
    		col.getColumn()
    				.addSelectionListener(
    						new SortTableColumnSelectionListener("address.name",
    								controller));
    	}
    
    	private static List createList() {
    		List names = new ArrayList();
    		for (int i = 1; i < 100; i++) {
    			names.add(new Person(&quot;Name &quot; + i, i < 25 ? &quot;Adress &quot;
    					+ Math.random() : null));
    		}
    		return names;
    	}
    
    	private static TableViewerColumn createTableViewerColumn(
    			TableViewer viewer, String title, int bound) {
    		final TableViewerColumn viewerColumn = new TableViewerColumn(viewer,
    				SWT.NONE);
    		final TableColumn column = viewerColumn.getColumn();
    		column.setText(title);
    		column.setWidth(bound);
    		column.setResizable(true);
    		column.setMoveable(true);
    		return viewerColumn;
    	}
    
    }

    Pagination in Table with PageableTable

    You can simplify the previous code by using org.eclipse.nebula.widgets.pagination.table.PageableTable. This explanation is based on the sample org.eclipse.nebula.widgets.pagination.examples.table.OneRendererPaginationTableWithPageableTableExample.

    Here the code which create the SWT Table, the Pagination controller, the TableViewer:

    final PageableTable pageableTable = new PageableTable(shell, SWT.BORDER, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL, pageSize, null,
    ResultAndNavigationPageLinksRendererFactory.getFactory());
    

    This code create the SWT Table, viewer and add on the bottom an instance of ResultAndNavigationPageLinksRenderer.

    PageLoader must be set like this:

    pageableTable.setPageLoader(new PageResultLoaderList(items));
    

    Here the full code :

    package org.eclipse.nebula.widgets.pagination.example.table.renderers;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import org.eclipse.jface.viewers.ArrayContentProvider;
    import org.eclipse.jface.viewers.ColumnLabelProvider;
    import org.eclipse.jface.viewers.LabelProvider;
    import org.eclipse.jface.viewers.TableViewer;
    import org.eclipse.jface.viewers.TableViewerColumn;
    import org.eclipse.nebula.widgets.pagination.PageableController;
    import org.eclipse.nebula.widgets.pagination.collections.PageResultContentProvider;
    import org.eclipse.nebula.widgets.pagination.collections.PageResultLoaderList;
    import org.eclipse.nebula.widgets.pagination.example.model.Address;
    import org.eclipse.nebula.widgets.pagination.example.model.Person;
    import org.eclipse.nebula.widgets.pagination.renderers.navigation.ResultAndNavigationPageLinksRendererFactory;
    import org.eclipse.nebula.widgets.pagination.table.PageableTable;
    import org.eclipse.nebula.widgets.pagination.table.SortTableColumnSelectionListener;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.layout.GridData;
    import org.eclipse.swt.layout.GridLayout;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.widgets.Table;
    import org.eclipse.swt.widgets.TableColumn;
    
    /**
     * This sample display a list of model {@link Person} in a SWT Table with
     * pagination banner displayed with Page Results+Page Links on the top of the
     * SWT Table. The 2 columns which display the list of {@link Person} can be
     * clicked to sort the paginated list.
     * 
     */
    public class OneRendererPaginationTableWithPageableTableExample {
    
    	public static void main(String[] args) {
    
    		Display display = new Display();
    		Shell shell = new Shell(display);
    		GridLayout layout = new GridLayout(1, false);
    		shell.setLayout(layout);
    
    		final List items = createList();
    
    		int pageSize = 10;
    		final PageableTable pageableTable = new PageableTable(shell,
    				SWT.BORDER, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL
    						| SWT.V_SCROLL, pageSize,
    				PageResultContentProvider.getInstance(), null,
    				ResultAndNavigationPageLinksRendererFactory.getFactory());
    		pageableTable.setLayoutData(new GridData(GridData.FILL_BOTH));
    		pageableTable.setPageLoader(new PageResultLoaderList(items));
    
    		// 2) Initialize the table viewer + SWT Table
    		TableViewer viewer = pageableTable.getViewer();
    		viewer.setContentProvider(ArrayContentProvider.getInstance());
    		viewer.setLabelProvider(new LabelProvider());
    
    		Table table = viewer.getTable();
    		table.setHeaderVisible(true);
    		table.setLinesVisible(true);
    
    		PageableController controller = pageableTable.getController();
    		createColumns(viewer, controller);
    		// 3) Set current page to 0 to refresh the table
    
    		controller.setCurrentPage(0);
    
    		shell.setSize(350, 250);
    		shell.open();
    		while (!shell.isDisposed()) {
    			if (!display.readAndDispatch())
    				display.sleep();
    		}
    		display.dispose();
    	}
    
    	private static void createColumns(final TableViewer viewer,
    			PageableController controller) {
    
    		// First column is for the first name
    		TableViewerColumn col = createTableViewerColumn(viewer, "Name", 150);
    		col.setLabelProvider(new ColumnLabelProvider() {
    			@Override
    			public String getText(Object element) {
    				String p = (String) element;
    				return p;
    			}
    		});
    		col.setLabelProvider(new ColumnLabelProvider() {
    			@Override
    			public String getText(Object element) {
    				Person p = (Person) element;
    				return p.getName();
    			}
    		});
    		col.getColumn().addSelectionListener(
    				new SortTableColumnSelectionListener("name", controller));
    
    		// Second column is for the adress
    		col = createTableViewerColumn(viewer, "Adress", 150);
    		col.setLabelProvider(new ColumnLabelProvider() {
    			@Override
    			public String getText(Object element) {
    				Person p = (Person) element;
    				Address address = p.getAddress();
    				if (address == null) {
    					return "";
    				}
    				return address.getName();
    			}
    		});
    		col.getColumn()
    				.addSelectionListener(
    						new SortTableColumnSelectionListener("address.name",
    								controller));
    	}
    
    	private static List createList() {
    		List names = new ArrayList();
    		for (int i = 1; i < 100; i++) {
    			names.add(new Person(&quot;Name &quot; + i, i < 25 ? &quot;Adress &quot;
    					+ Math.random() : null));
    		}
    		return names;
    	}
    
    	private static TableViewerColumn createTableViewerColumn(
    			TableViewer viewer, String title, int bound) {
    		final TableViewerColumn viewerColumn = new TableViewerColumn(viewer,
    				SWT.NONE);
    		final TableColumn column = viewerColumn.getColumn();
    		column.setText(title);
    		column.setWidth(bound);
    		column.setResizable(true);
    		column.setMoveable(true);
    		return viewerColumn;
    	}
    
    }
    

    Nebula Pagination API (with Spring Data)

    By default the pagination structure used in the page loader is org.eclipse.nebula.widgets.pagination.PageResult. But it’s possible to use Spring Data pagination structure org.springframework.data.domain.Page with Nebula Pagination. We do that in our Eclipse RCP/RAP XDocReport.
    :

    Before explaining how to use Spring Data with Nebula Pagination, here some interesting information:

    • No need to add Spring dependencies to use Spring Data pagination structure.
    • If you wish paginate :
      • list stored in memory, I suggest to use Spring Data domain Collections.
      • list stored in database I suggest you to use Spring Data JPA or Spring Data JDBC Extensions.
      • If you don’t know Spring Data, I suggets you to study it. You can just write your repository (dao) interface with name convention to manage JPA or JDBC like manage pagination in for Person list:
        Page finadAll(Pageable pagable)

        and that’s all!

    Why Spring Data?

    Why org.springframework.data.domain-only?

    The big problem with Spring Data Core is that it dependends to Spring Core, Spring AOP etc. That’s why we have created org.springframework.data.domain-only which contains only the source of org.springframework.data.domain with pagination structure :

    We have intention to tell about this problem to Spring Data Team and see if those bundles could exist?

    If you wish to manage JPA (like we have done with our XDocReport demo), Spring Data JPA is very helpfull. In this case no need to use org.springframework.data.domain-only because Spring Data JPA requires Spring Core, AOP etc. The only case where org.springframework.data.domain-only is intersesting with JPA is when you have Eclipse RCP client (client side) which calls services with remoting which uses JPA (server side). The client side doesn’t call directly JPA, so no need to have in the Target Platform the Spring Data Core.

    Why org.springframework.data.domain.collections?

    In a business application, pagination is done generally with list coming from database. But sometimes list could coming from java list stored in memory. This is the case for our XDocReport application wich works with DAO layer (Data Access Object) :

    • with JPA (it’s our JPA DAO).
    • or with java list stored in memory (it’s our mock DAO).

For our mock DAO, we need to create Spring Data Page structure coming from a Java list (and not from JPA). Spring Data manages JPA, JDBC but not Java list in memory. The org.springframework.data.domain.collections is able to create Page implementation coming from Java list and Pageable pagination criteria like this :

List persons =...
Pageable pageable =...
Page paginatedPersons = PageListHelper.createPage(items, pageable)

How to use Spring Data with Nebula Pagination?

If you wish use Spring Data Page structure with Nebula Pagination you must add org.eclipse.nebula.widgets.pagination.springdata in your project and :

  • use org.eclipse.nebula.widgets.pagination.springdata.SpringDataPageableController instead of using org.eclipse.nebula.widgets.pagination.PageableController.
  • use org.eclipse.nebula.widgets.pagination.springdata.SpringDataPageContentProvider.getInstance() instead of using org.eclipse.nebula.widgets.pagination.PageResultContentProvider.getInstance().

If you wish use pagination with Java list in memory (and not Spring Data JPA or Spring Data JDBC).

  • use org.eclipse.nebula.widgets.pagination.springdata.SpringDataPageLoaderList instead of org.eclipse.nebula.widgets.pagination.collections.PageResultLoaderList.

Pagination in Table at hand

Here the « Pagination in Table at hand » with Spring Data (see org.eclipse.nebula.widgets.pagination.springdata.examples.renderer.OneRendererPaginationTableAtHandExample) :

final PageableController controller = new SpringDataPageableController(pageSize);
final IPageLoader pageLoader = new SpringDataPageLoaderList(items);
controller.addPageChangedListener(PageLoaderStrategyHelper.createLoadPageAndReplaceItemsListener(controller, viewer,pageLoader,	SpringDataPageContentProvider.getInstance(), null));

Pagination in Table with PageableTable

Here the « Pagination in Table with PageableTable » with Spring Data (see org.eclipse.nebula.widgets.pagination.springdata.examples.renderer.OneRendererPaginationTableWithPageableTableExample) :

final PageableTable pageableTable = new PageableTable(shell,	SWT.BORDER, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL, pageSize, SpringDataPageContentProvider.getInstance(), null, ResultAndNavigationPageLinksRendererFactory.getFactory());
pageableTable.setLayoutData(new GridData(GridData.FILL_BOTH));
pageableTable.setPageLoader(new SpringDataPageLoaderList(items));
  1. janvier 7, 2012 à 11:20

    Very well done! I hope this is accepted into the Nebula project.
    One question: when loading extra data, that is mostly done with a Job. Is it possible to display the monitor progress bar in the view as well, just like in a Wizard dialog?

    • janvier 7, 2012 à 3:38

      Hi Maarten

      Thank a lot for your comment.
      For your question, it seems that you wish to use IProgressMonitor I suppose. I think it’s possible but perhaps Nebula Pagniation should provide an abstract class of IPageLoader to works with monitor to help developer to use monitor. But I thnik you can do that if you wish (never tested). If you see https://angelozerr.wordpress.com/2012/01/06/nebula_pagination/#ModelSortPageableTableWorkInProcessExample (Work In Process) you can see that you can observe the start/end loading of data.

      If you provide me a sample that you wish to do, I could help you and perhaps improve Nebula Pagination if need.

      Regards Angelo

  2. Cristiano
    mars 14, 2012 à 12:28

    Hi,

    I have a doubt.

    Should all data be retrieve from datasource before widget be displayed ?

    Or can I setup anyway to retrieve data lazily ?

    regards

    • mars 14, 2012 à 1:09

      Hi,

      > Should all data be retrieve from datasource before widget be displayed ?
      No!

      >Or can I setup anyway to retrieve data lazily ?
      Yes sure!

      The samples with PaginationControl is very basic. It paginate a java List. However you can implement your own pagination like we have done in our demo with XDocReport which uses Spring Data JPA to use JPA pagination.

      Regards Angelo

  3. Sandz
    juin 26, 2013 à 10:33

    Hi,

    I have implemented pagination using org.eclipse.nebula.widgets.pagination.table.PageableTable.

    But I am stucked at a point. Lets say we have loaded some pages with inital data,. but now I want to update the data. Then that data is updated in table but the pagination links are not updating. Can you provide some information how to use pageableTable.totalElementsChanged(…);. I think it is method which I am suppose to use.

    Currently I am using org.eclipse.nebula.widgets.pagination_1.0.0.201306151114.jar

    • juin 26, 2013 à 11:14

      Hi Sandz,

      Hi perhaps it’s the same bug than https://bugs.eclipse.org/bugs/show_bug.cgi?id=400526 ?
      If you have a problem, I suggest you to create a new bug (Product=Nebula, Component=PaginationControl) with your problem
      and a Java main sample which causes the problem will help me (but I’m very busy for the moment).

      And any contribution are welcome!

      Regards Angelo

  4. matameko
    février 5, 2017 à 9:04

    Where can I download a jar containing
    org.eclipse.nebula.widgets.pagination.springdata ?

  1. janvier 7, 2012 à 6:41
  2. janvier 7, 2012 à 12:52
  3. avril 15, 2012 à 10:26
  4. avril 16, 2012 à 1:23
  5. avril 16, 2012 à 10:11

Laisser un commentaire