/*******************************************************************************
* Copyright (C) 2011 Angelo Zerr <angelo.zerr@gmail.com>, Pascal Leclercq <pascal.leclercq@gmail.com>
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo ZERR - initial API and implementation
* Pascal Leclercq - initial API and implementation
*******************************************************************************/
package fr.opensagres.mongodb.ide.ui.viewers.gridfs;
import java.util.List;
import org.eclipse.nebula.widgets.pagination.IPageLoader;
import org.eclipse.nebula.widgets.pagination.PageableController;
import com.mongodb.gridfs.GridFS;
import com.mongodb.tools.driver.pagination.Page;
import com.mongodb.tools.shell.ShellCommandManager;
/**
* Implementation of {@link IPageLoader} with java {@link List}.
*
*/
public class GridFSFilesPageResultLoader<T> implements IPageLoader<Page<T>> {
private final GridFS gridFS;
private final ShellCommandManager shellCommandManager;
public GridFSFilesPageResultLoader(GridFS collection,
ShellCommandManager shellCommandManager) {
this.gridFS = collection;
this.shellCommandManager = shellCommandManager;
}
public Page<T> loadPage(PageableController controller) {
int pageNumber = controller.getCurrentPage();
int itemsPerPage = controller.getPageSize();
return shellCommandManager.paginate(gridFS, pageNumber,
itemsPerPage);
}
}