Completed [Feature #9114] Add pagination to Workspace Explorer
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-explorer@151055 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
19b7ef4383
commit
23b8f43e87
|
@ -3,9 +3,6 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.portlets.widgets.wsexplorer.client.explore;
|
package org.gcube.portlets.widgets.wsexplorer.client.explore;
|
||||||
|
|
||||||
import static org.gcube.portlets.widgets.wsexplorer.client.explore.WorkspaceResourcesExplorerPanel.ITEMS_PER_PAGE;
|
|
||||||
import static org.gcube.portlets.widgets.wsexplorer.client.explore.WorkspaceResourcesExplorerPanel.ITEM_START_INDEX;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.portlets.widgets.wsexplorer.client.event.BreadcrumbClickEvent;
|
import org.gcube.portlets.widgets.wsexplorer.client.event.BreadcrumbClickEvent;
|
||||||
|
@ -96,6 +93,23 @@ public class WorkspaceResourcesExplorerPanelPaginated extends WorkspaceResources
|
||||||
initPanel("");
|
initPanel("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purge cache. It performs cache purge.
|
||||||
|
*/
|
||||||
|
public void purgeCache(){
|
||||||
|
wsExplorer.purgeCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hard refresh. It performs a purge of cached page and reload the folder passed in input
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public void hardRefresh() throws Exception{
|
||||||
|
wsExplorer.purgeCache();
|
||||||
|
super.refreshRootFolderView();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inits the panel.
|
* Inits the panel.
|
||||||
*
|
*
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
package org.gcube.portlets.widgets.wsexplorer.client.view;
|
package org.gcube.portlets.widgets.wsexplorer.client.view;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.portlets.widgets.wsexplorer.client.Util;
|
import org.gcube.portlets.widgets.wsexplorer.client.Util;
|
||||||
|
@ -44,10 +45,6 @@ public class WorkspaceExplorerPaginated extends WorkspaceExplorer{
|
||||||
|
|
||||||
private Boolean newLoading = false;
|
private Boolean newLoading = false;
|
||||||
|
|
||||||
private Boolean justTest = false;
|
|
||||||
|
|
||||||
//private ListDataProvider<Item> dataProvider = new ListDataProvider<Item>();
|
|
||||||
|
|
||||||
private MyCustomDataProvider<Item> dataProvider = new MyCustomDataProvider<Item>();
|
private MyCustomDataProvider<Item> dataProvider = new MyCustomDataProvider<Item>();
|
||||||
|
|
||||||
protected boolean loadGcubeProperties = false;
|
protected boolean loadGcubeProperties = false;
|
||||||
|
@ -56,6 +53,8 @@ public class WorkspaceExplorerPaginated extends WorkspaceExplorer{
|
||||||
|
|
||||||
private int serverStartIndex = 0;
|
private int serverStartIndex = 0;
|
||||||
|
|
||||||
|
private HashMap<String, SearchedFolder> cachedPage = new HashMap<String, SearchedFolder>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new workspace explorer paginated.
|
* Instantiates a new workspace explorer paginated.
|
||||||
*
|
*
|
||||||
|
@ -159,18 +158,16 @@ public class WorkspaceExplorerPaginated extends WorkspaceExplorer{
|
||||||
if(newLoading){
|
if(newLoading){
|
||||||
GWT.log("Cleaning all data...");
|
GWT.log("Cleaning all data...");
|
||||||
newStartIndex = 0;
|
newStartIndex = 0;
|
||||||
|
serverStartIndex = 0;
|
||||||
GWT.log("Store reset performed start index is: "+newStartIndex);
|
GWT.log("Store reset performed start index is: "+newStartIndex);
|
||||||
getAsycnDataProvider().updateRowCount(WorkspaceExplorerConstants.ITEMS_PER_PAGE, false);
|
getAsycnDataProvider().updateRowCount(WorkspaceExplorerConstants.ITEMS_PER_PAGE, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
perfomGetFolderChildren(item, loadGcubeProperties, newStartIndex, limit, purgeEmpyFolders, showableTypesParam);
|
perfomGetFolderChildren(item, loadGcubeProperties, newStartIndex, limit, serverStartIndex, purgeEmpyFolders, showableTypesParam);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perfom get folder children.
|
* Perfom get folder children.
|
||||||
*
|
*
|
||||||
|
@ -178,12 +175,22 @@ public class WorkspaceExplorerPaginated extends WorkspaceExplorer{
|
||||||
* @param loadGcubeProperties the load gcube properties
|
* @param loadGcubeProperties the load gcube properties
|
||||||
* @param startIdx the start idx
|
* @param startIdx the start idx
|
||||||
* @param limit the limit
|
* @param limit the limit
|
||||||
|
* @param serSI the server start index to use
|
||||||
* @param purgeEmpyFolders the purge empy folders
|
* @param purgeEmpyFolders the purge empy folders
|
||||||
* @param showableTypesParam the showable types param
|
* @param showableTypesParam the showable types param
|
||||||
*/
|
*/
|
||||||
private void perfomGetFolderChildren(final Item item, boolean loadGcubeProperties, final int startIdx, final int limit, boolean purgeEmpyFolders, List<ItemType> showableTypesParam){
|
private void perfomGetFolderChildren(final Item item, boolean loadGcubeProperties, final int startIdx, final int limit, final int serSI, boolean purgeEmpyFolders, List<ItemType> showableTypesParam){
|
||||||
GWT.log("loading workspace folder by item id from server: "+item.getId());
|
GWT.log("loading workspace folder by item id from server: "+item.getId());
|
||||||
WorkspaceExplorerConstants.workspaceNavigatorService.getFolder(item, showableTypesParam, purgeEmpyFolders, filterCriteria, loadGcubeProperties, startIdx, limit, serverStartIndex, new AsyncCallback<SearchedFolder>() {
|
|
||||||
|
SearchedFolder page = getCachePage(item, startIdx, limit);
|
||||||
|
if(page!=null){
|
||||||
|
setNewPageResult(page);
|
||||||
|
serverStartIndex = page.getServerEndIndex();
|
||||||
|
GWT.log("Using cached page, serverStartIndex: "+serverStartIndex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
WorkspaceExplorerConstants.workspaceNavigatorService.getFolder(item, showableTypesParam, purgeEmpyFolders, filterCriteria, loadGcubeProperties, startIdx, limit, serSI, new AsyncCallback<SearchedFolder>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable caught) {
|
public void onFailure(Throwable caught) {
|
||||||
|
@ -195,56 +202,112 @@ public class WorkspaceExplorerPaginated extends WorkspaceExplorer{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(SearchedFolder result) {
|
public void onSuccess(SearchedFolder result) {
|
||||||
|
setNewPageResult(result);
|
||||||
serverStartIndex = result.getServerEndIndex();
|
setCachePage(item, result);
|
||||||
|
|
||||||
if(item.getName()==null || item.getName().isEmpty())
|
|
||||||
item.setName(result.getFolder().getName());
|
|
||||||
|
|
||||||
//GWT.log("Returned "+result.getChildren().size() +" children");
|
|
||||||
//getItTables().updateItems(result.getChildren(), true);
|
|
||||||
|
|
||||||
if(newLoading){
|
|
||||||
getCellTable().setVisibleRangeAndClearData(new Range(result.getClientStartIndex(), WorkspaceExplorerConstants.ITEMS_PER_PAGE), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
SelectionModel<? super Item> sm = getCellTable().getSelectionModel();
|
|
||||||
|
|
||||||
if(sm instanceof SingleSelectionModel){
|
|
||||||
SingleSelectionModel<Item> ssm = (SingleSelectionModel<Item>) sm;
|
|
||||||
ssm.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
getAsycnDataProvider().updateRowData(result.getClientStartIndex(), result.getFolder().getChildren());
|
|
||||||
|
|
||||||
if(result.getFolder().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: "+result.getClientStartIndex() + " children size: "+result.getFolder().getChildren().size());
|
|
||||||
GWT.log("getAsycnDataProvider().getDataDisplays().size(): "+getCellTable().getRowCount());
|
|
||||||
|
|
||||||
if(result.isServerSearchFinished()){
|
|
||||||
GWT.log("Search finished!!!");
|
|
||||||
getAsycnDataProvider().updateRowCount(getCellTable().getRowCount(), true);
|
|
||||||
}
|
|
||||||
//getCellTable().setPageSize(result.getChildren().size()+1);
|
|
||||||
//getCellTable().setVisibleRange(startIdx, result.getChildren().size());
|
|
||||||
//getCellTable().redraw();
|
|
||||||
//GWT.log("cellTable size: "+getCellTable().getRowCount());
|
|
||||||
setDisplayingFolderItem(result.getFolder());
|
|
||||||
newLoading = false;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the new page result.
|
||||||
|
*
|
||||||
|
* @param result the new new page result
|
||||||
|
*/
|
||||||
|
private void setNewPageResult(SearchedFolder result){
|
||||||
|
|
||||||
|
serverStartIndex = result.getServerEndIndex();
|
||||||
|
|
||||||
|
if(result.getFolder().getName()==null || result.getFolder().getName().isEmpty())
|
||||||
|
result.getFolder().setName(result.getFolder().getName());
|
||||||
|
|
||||||
|
if(newLoading){
|
||||||
|
getCellTable().setVisibleRangeAndClearData(new Range(result.getClientStartIndex(), WorkspaceExplorerConstants.ITEMS_PER_PAGE), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
SelectionModel<? super Item> sm = getCellTable().getSelectionModel();
|
||||||
|
|
||||||
|
if(sm instanceof SingleSelectionModel){
|
||||||
|
SingleSelectionModel<Item> ssm = (SingleSelectionModel<Item>) sm;
|
||||||
|
ssm.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
getAsycnDataProvider().updateRowData(result.getClientStartIndex(), result.getFolder().getChildren());
|
||||||
|
|
||||||
|
if(result.getFolder().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: "+result.getClientStartIndex() + " children size: "+result.getFolder().getChildren().size());
|
||||||
|
GWT.log("getAsycnDataProvider().getDataDisplays().size(): "+getCellTable().getRowCount());
|
||||||
|
|
||||||
|
if(result.isServerSearchFinished()){
|
||||||
|
GWT.log("Search finished!!!");
|
||||||
|
getAsycnDataProvider().updateRowCount(getCellTable().getRowCount(), true);
|
||||||
|
}
|
||||||
|
//getCellTable().setPageSize(result.getChildren().size()+1);
|
||||||
|
//getCellTable().setVisibleRange(startIdx, result.getChildren().size());
|
||||||
|
//getCellTable().redraw();
|
||||||
|
//GWT.log("cellTable size: "+getCellTable().getRowCount());
|
||||||
|
setDisplayingFolderItem(result.getFolder());
|
||||||
|
newLoading = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cache page.
|
||||||
|
*
|
||||||
|
* @param item the item
|
||||||
|
* @param result the result
|
||||||
|
*/
|
||||||
|
private void setCachePage(Item item, SearchedFolder result){
|
||||||
|
|
||||||
|
String key = getCacheKey(item, result.getClientStartIndex(), result.getLimit());
|
||||||
|
|
||||||
|
if(key!=null){
|
||||||
|
GWT.log("Caching result with key: "+key);
|
||||||
|
cachedPage.put(key, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the cache page.
|
||||||
|
*
|
||||||
|
* @param item the item
|
||||||
|
* @param startIdx the start idx
|
||||||
|
* @param limit the limit
|
||||||
|
* @return the cache page
|
||||||
|
*/
|
||||||
|
private SearchedFolder getCachePage(Item item, int startIdx, int limit){
|
||||||
|
|
||||||
|
String key = getCacheKey(item, startIdx, limit);
|
||||||
|
|
||||||
|
return cachedPage.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the cache key.
|
||||||
|
*
|
||||||
|
* @param item the item
|
||||||
|
* @param startIdx the start idx
|
||||||
|
* @param limit the limit
|
||||||
|
* @return the cache key
|
||||||
|
*/
|
||||||
|
private String getCacheKey(Item item, int startIdx, int limit){
|
||||||
|
|
||||||
|
if(item==null || startIdx<0 || limit< 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return item.getId() + "["+startIdx + "-" +limit+"]";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inits the pagination.
|
* Inits the pagination.
|
||||||
*
|
*
|
||||||
|
@ -321,4 +384,13 @@ public class WorkspaceExplorerPaginated extends WorkspaceExplorer{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purge cache.
|
||||||
|
*/
|
||||||
|
public void purgeCache() {
|
||||||
|
cachedPage.clear();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -729,9 +729,7 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
||||||
if(currentListCount == limit || folderChildrenCount==0){
|
if(currentListCount == limit || folderChildrenCount==0){
|
||||||
logger.debug("Page completed returning "+currentListCount+ " items");
|
logger.debug("Page completed returning "+currentListCount+ " items");
|
||||||
int offset = searchStartIndex+limit;
|
int offset = searchStartIndex+limit;
|
||||||
|
Collections.sort(sf.getFolder().getChildren(), new ItemComparator());
|
||||||
//Collections.sort(sf.getFolder().getChildren(), new ItemComparator());
|
|
||||||
|
|
||||||
sf.setServerSearchFinished(offset>folderChildrenCount || folderChildrenCount == 0);
|
sf.setServerSearchFinished(offset>folderChildrenCount || folderChildrenCount == 0);
|
||||||
logger.debug("is Search finished: "+sf.isServerSearchFinished());
|
logger.debug("is Search finished: "+sf.isServerSearchFinished());
|
||||||
return sf;
|
return sf;
|
||||||
|
@ -789,12 +787,12 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
|
||||||
//String time = String.format("%d msc %d sec", endTime, TimeUnit.MILLISECONDS.toSeconds(endTime));
|
//String time = String.format("%d msc %d sec", endTime, TimeUnit.MILLISECONDS.toSeconds(endTime));
|
||||||
//logger.debug("end time - " + time);
|
//logger.debug("end time - " + time);
|
||||||
|
|
||||||
int i = 0;
|
// int i = 0;
|
||||||
for (Item item2 : sf.getFolder().getChildren()) {
|
// for (Item item2 : sf.getFolder().getChildren()) {
|
||||||
logger.debug(++i+") "+item2);
|
// logger.debug(++i+") "+item2);
|
||||||
}
|
// }
|
||||||
|
|
||||||
//Collections.sort(itemFolderToReturn.getChildren(), new ItemComparator());
|
Collections.sort(itemFolderToReturn.getChildren(), new ItemComparator());
|
||||||
logger.debug("Returning: "+sf);
|
logger.debug("Returning: "+sf);
|
||||||
return sf;
|
return sf;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue