302 lines
9.4 KiB
Java
302 lines
9.4 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.portlets.widgets.wsexplorer.client.view;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.gcube.portlets.widgets.wsexplorer.client.Util;
|
|
import org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorerConstants;
|
|
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.ItemsTable.DISPLAY_FIELD;
|
|
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.SortedCellTable;
|
|
import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria;
|
|
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
|
|
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;
|
|
|
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
|
import com.google.gwt.core.client.GWT;
|
|
import com.google.gwt.event.shared.HandlerManager;
|
|
import com.google.gwt.user.cellview.client.SimplePager;
|
|
import com.google.gwt.user.cellview.client.SimplePager.TextLocation;
|
|
import com.google.gwt.user.client.Window;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
import com.google.gwt.user.client.ui.Label;
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
import com.google.gwt.view.client.AsyncDataProvider;
|
|
import com.google.gwt.view.client.HasData;
|
|
import com.google.gwt.view.client.Range;
|
|
import com.google.gwt.view.client.SelectionModel;
|
|
import com.google.gwt.view.client.SingleSelectionModel;
|
|
|
|
|
|
/**
|
|
* The Class WorkspaceExplorerPaginated.
|
|
*
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
* Jul 5, 2017
|
|
*/
|
|
public class WorkspaceExplorerPaginated extends WorkspaceExplorer{
|
|
|
|
private VerticalPanel vPanel = new VerticalPanel();
|
|
|
|
private Boolean newLoading = false;
|
|
|
|
private Boolean justTest = false;
|
|
|
|
//private ListDataProvider<Item> dataProvider = new ListDataProvider<Item>();
|
|
|
|
private MyCustomDataProvider<Item> dataProvider = new MyCustomDataProvider<Item>();
|
|
|
|
protected boolean loadGcubeProperties = false;
|
|
|
|
protected Widget orginalLoadingIndicator = null;
|
|
|
|
/**
|
|
* Instantiates a new workspace explorer paginated.
|
|
*
|
|
* @param eventBus the event bus
|
|
* @param filterCriteria the filter criteria
|
|
* @param showableTypes the showable types
|
|
* @param selectableTypes the selectable types
|
|
* @param displayProperties the display properties
|
|
* @param showGcubeInfo the show gcube info
|
|
* @param sortByColumn the sort by column
|
|
* @param fields the fields
|
|
*/
|
|
public WorkspaceExplorerPaginated(
|
|
HandlerManager eventBus, FilterCriteria filterCriteria,
|
|
ItemType[] showableTypes, ItemType[] selectableTypes,
|
|
List<String> displayProperties, boolean showGcubeInfo,
|
|
DISPLAY_FIELD sortByColumn, DISPLAY_FIELD[] fields) {
|
|
super(eventBus, filterCriteria, showableTypes, selectableTypes, displayProperties, showGcubeInfo, sortByColumn);
|
|
initTable(dataProvider);
|
|
newLoading = true;
|
|
orginalLoadingIndicator = getCellTable().getLoadingIndicator();
|
|
}
|
|
|
|
|
|
/**
|
|
* Gets the asycn data provider.
|
|
*
|
|
* @return the asycn data provider
|
|
*/
|
|
public AsyncDataProvider<Item> getAsycnDataProvider(){
|
|
return (AsyncDataProvider<Item>) getCellTable().getDataProvider();
|
|
}
|
|
|
|
/**
|
|
* Gets the cell tale.
|
|
*
|
|
* @return the cell tale
|
|
*/
|
|
public SortedCellTable<Item> getCellTable(){
|
|
return getItTables().getCellTable();
|
|
}
|
|
|
|
|
|
/* (non-Javadoc)
|
|
* @see org.gcube.portlets.widgets.wsexplorer.client.view.WorkspaceExplorer#loadFolder(org.gcube.portlets.widgets.wsexplorer.shared.Item, boolean, int, int, boolean)
|
|
*/
|
|
public void loadFolder(final Item item, final boolean loadGcubeProperties, final int startIdx, final int limit, final boolean resetStore) throws Exception {
|
|
newLoading = resetStore;
|
|
GWT.log("loading folder data for Item: "+item.getId()+" [startIdx: "+startIdx +", limit: "+limit+", resetStore:"+resetStore+"]");
|
|
//super.loadFolder(item, loadGcubeProperties);
|
|
this.loadGcubeProperties = loadGcubeProperties;
|
|
setLoading();
|
|
if(!item.isFolder())
|
|
throw new Exception("Item is not a folder");
|
|
|
|
if(item.getId()==null || item.getId().isEmpty())
|
|
throw new Exception("Item id is null or empty");
|
|
|
|
// we make a copy of showable types
|
|
final List<ItemType> showableTypesParam = new ArrayList<ItemType>(showableTypes);
|
|
|
|
// we get sure that folders are displayed
|
|
for (ItemType folder : Util.FOLDERS) {
|
|
if (!showableTypesParam.contains(folder))
|
|
showableTypesParam.add(folder);
|
|
}
|
|
|
|
final boolean purgeEmpyFolders = !showEmptyFolders;
|
|
|
|
//IF IS INIT OR A DOUBLE CLICK
|
|
if(getDisplayingFolderItem()==null || getDisplayingFolderItem().getId()!=item.getId()){
|
|
GWT.log("Performing Get Folder Children Count ");
|
|
WorkspaceExplorerConstants.workspaceNavigatorService.getFolderChildrenCount(item, new AsyncCallback<Integer>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(final Integer result) {
|
|
GWT.log("Folder Children count: "+result);
|
|
|
|
int newStartIndex = startIdx;
|
|
getAsycnDataProvider().updateRowCount(result, true);
|
|
|
|
if(newLoading){
|
|
GWT.log("Cleaning all data...");
|
|
newStartIndex = 0;
|
|
GWT.log("Store reset performed start index is: "+newStartIndex);
|
|
}
|
|
|
|
//final Range range = display.getVisibleRange();
|
|
perfomGetFolderChildren(item, loadGcubeProperties, newStartIndex, limit, purgeEmpyFolders, showableTypesParam);
|
|
}
|
|
});
|
|
}else
|
|
perfomGetFolderChildren(item, loadGcubeProperties, startIdx, limit, purgeEmpyFolders, showableTypesParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* Perfom get folder children.
|
|
*
|
|
* @param item the item
|
|
* @param loadGcubeProperties the load gcube properties
|
|
* @param startIdx the start idx
|
|
* @param limit the limit
|
|
* @param purgeEmpyFolders the purge empy folders
|
|
* @param showableTypesParam the showable types param
|
|
*/
|
|
private void perfomGetFolderChildren(final Item item, boolean loadGcubeProperties, final int startIdx, int limit, boolean purgeEmpyFolders, List<ItemType> showableTypesParam){
|
|
GWT.log("loading workspace folder by item id from server: "+item.getId());
|
|
WorkspaceExplorerConstants.workspaceNavigatorService.getFolder(item, showableTypesParam, purgeEmpyFolders, filterCriteria, loadGcubeProperties, startIdx, limit, new AsyncCallback<Item>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
Window.alert(caught.getMessage());
|
|
setAlert(caught.getMessage(), AlertType.ERROR);
|
|
GWT.log("Error loading workspace folder from server",caught);
|
|
newLoading = false;
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(Item result) {
|
|
|
|
if(item.getName()==null || item.getName().isEmpty())
|
|
item.setName(result.getName());
|
|
|
|
//GWT.log("Returned "+result.getChildren().size() +" children");
|
|
//getItTables().updateItems(result.getChildren(), true);
|
|
|
|
if(newLoading){
|
|
getCellTable().setVisibleRangeAndClearData(new Range(startIdx, WorkspaceExplorerConstants.ITEMS_PER_PAGE), false);
|
|
}
|
|
|
|
SelectionModel<? super Item> sm = getCellTable().getSelectionModel();
|
|
|
|
if(sm instanceof SingleSelectionModel){
|
|
SingleSelectionModel ssm = (SingleSelectionModel) sm;
|
|
ssm.clear();
|
|
}
|
|
|
|
getAsycnDataProvider().updateRowData(startIdx, result.getChildren());
|
|
|
|
if(result.getChildren().size()==0){
|
|
getCellTable().setLoadingIndicator(new Label("No data"));
|
|
}else{
|
|
getCellTable().setLoadingIndicator(orginalLoadingIndicator);
|
|
}
|
|
|
|
|
|
//getCellTable().setVisibleRangeAndClearData(new Range(startIdx, result.getChildren()).), false);
|
|
//getAsycnDataProvider().getDataDisplays().
|
|
GWT.log("Updating row data startIndex: "+startIdx + " size: "+result.getChildren().size());
|
|
|
|
//getCellTable().setPageSize(result.getChildren().size()+1);
|
|
//getCellTable().setVisibleRange(startIdx, result.getChildren().size());
|
|
//getCellTable().redraw();
|
|
//GWT.log("cellTable size: "+getCellTable().getRowCount());
|
|
setDisplayingFolderItem(result);
|
|
newLoading = false;
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/**
|
|
* Inits the pagination.
|
|
*
|
|
* @param itemsPerPage the items per page
|
|
*/
|
|
public void initPagination(int itemsPerPage){
|
|
|
|
//dataProvider.updateRowCount(100, true);
|
|
// Add the cellList to the dataProvider.
|
|
//asyncDataProvider.addDataDisplay(cellTable);
|
|
// Create paging controls.
|
|
SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
|
|
SimplePager pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true);
|
|
pager.setDisplay(getCellTable());
|
|
pager.setPageSize(itemsPerPage);
|
|
vPanel.add(getCellTable());
|
|
vPanel.add(pager);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Gets the pager panel.
|
|
*
|
|
* @return the pager panel
|
|
*/
|
|
public VerticalPanel getPagerPanel(){
|
|
return vPanel;
|
|
}
|
|
|
|
|
|
/**
|
|
* A custom {@link AsyncDataProvider}.
|
|
*
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
* Jul 5, 2017
|
|
* @param <T> the generic type
|
|
*/
|
|
public class MyCustomDataProvider<T> extends AsyncDataProvider<T> {
|
|
|
|
/**
|
|
* {@link #onRangeChanged(HasData)} is called when the table requests a
|
|
* new range of data. You can push data back to the displays using
|
|
* {@link #updateRowData(int, List)}.
|
|
*
|
|
* @param display the display
|
|
*/
|
|
@Override
|
|
public void onRangeChanged(HasData<T> display) {
|
|
|
|
// Get the new range.
|
|
final Range range = display.getVisibleRange();
|
|
|
|
int start = range.getStart();
|
|
int length = range.getLength();
|
|
|
|
GWT.log("Range changed: "+start +" "+length + " visible count: "+display.getVisibleItemCount());
|
|
|
|
if(newLoading){
|
|
GWT.log("OnLoading is true.. returning");
|
|
return;
|
|
}
|
|
try {
|
|
loadFolder(getDisplayingFolderItem(), loadGcubeProperties, start, length, false);
|
|
}
|
|
catch (Exception e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|