task_21363 #1
|
@ -4,10 +4,12 @@ import java.util.List;
|
|||
|
||||
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset;
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.shared.SearchedData;
|
||||
|
||||
import com.google.gwt.user.client.rpc.RemoteService;
|
||||
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The client side stub for the RPC service.
|
||||
*
|
||||
|
@ -63,8 +65,20 @@ public interface CkanContentModeratorService extends RemoteService {
|
|||
* @param limit the limit
|
||||
* @param offset the offset
|
||||
* @return the list items for status
|
||||
* @throws Exception
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public List<CatalogueDataset> getListItemsForStatus(ItemStatus theStatus, int limit, int offset) throws Exception;
|
||||
|
||||
/**
|
||||
* Gets the data for status.
|
||||
*
|
||||
* @param status the status
|
||||
* @param startIndex the start index
|
||||
* @param lenght the lenght
|
||||
* @param serverIndex the server index
|
||||
* @return the data for status
|
||||
* @throws Exception
|
||||
*/
|
||||
SearchedData getDataForStatus(ItemStatus status, int startIndex, int lenght, int serverIndex) throws Exception;
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
|
||||
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset;
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.shared.SearchedData;
|
||||
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
|
||||
|
@ -70,4 +71,8 @@ public interface CkanContentModeratorServiceAsync {
|
|||
void getListItemsForStatus(ItemStatus theStatus, int limit, int offset,
|
||||
AsyncCallback<List<CatalogueDataset>> callback);
|
||||
|
||||
void getDataForStatus(ItemStatus status, int startIndex, int lenght, int serverIndex,
|
||||
AsyncCallback<SearchedData> asyncCallback);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +1,14 @@
|
|||
package org.gcube.portlets.widgets.ckancontentmoderator.client;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.ContentModeratorSystemPanel;
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.table.ItemsTable;
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.ContentModeratorPaginatedView;
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.ContentModeratorSystemBaseView;
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.table.ItemsTable.DISPLAY_FIELD;
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.user.client.Command;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.view.client.ListDataProvider;
|
||||
|
||||
/**
|
||||
* The Class CkanContentModeratorWidget.
|
||||
|
@ -23,12 +19,13 @@ import com.google.gwt.view.client.ListDataProvider;
|
|||
*/
|
||||
public class CkanContentModeratorWidget {
|
||||
|
||||
public final CkanContentModeratorServiceAsync contentModeratorService = GWT
|
||||
public final static CkanContentModeratorServiceAsync contentModeratorService = GWT
|
||||
.create(CkanContentModeratorService.class);
|
||||
|
||||
private ItemsTable<CatalogueDataset> itemsTable;
|
||||
private ContentModeratorSystemPanel cmsPanel = new ContentModeratorSystemPanel();
|
||||
// private ItemsTable<CatalogueDataset> itemsTable;
|
||||
private ContentModeratorSystemBaseView cmsPanel = new ContentModeratorSystemBaseView();
|
||||
private Boolean isContentModeratorEnabled = null;
|
||||
private ContentModeratorPaginatedView paginatedView;
|
||||
|
||||
/**
|
||||
* Instantiates a new ckan content moderator widget.
|
||||
|
@ -36,46 +33,51 @@ public class CkanContentModeratorWidget {
|
|||
* @param displayFields the display fields
|
||||
* @param sortByField the sort by field
|
||||
*/
|
||||
public CkanContentModeratorWidget(DISPLAY_FIELD[] displayFields, DISPLAY_FIELD sortByField) {
|
||||
itemsTable = new ItemsTable<CatalogueDataset>(null, displayFields, sortByField);
|
||||
itemsTable.initTable(null, null, new ListDataProvider<CatalogueDataset>());
|
||||
cmsPanel.add(itemsTable.getCellTable());
|
||||
public CkanContentModeratorWidget(ItemStatus status, DISPLAY_FIELD[] displayFields, DISPLAY_FIELD sortByField) {
|
||||
// itemsTable = new ItemsTable<CatalogueDataset>(null, displayFields, sortByField);
|
||||
// itemsTable.initTable(null, null, new ListDataProvider<CatalogueDataset>());
|
||||
// cmsPanel.add(itemsTable.getCellTable());
|
||||
|
||||
paginatedView = new ContentModeratorPaginatedView(status, displayFields, sortByField);
|
||||
//cmsPanel.addToTop(new LoadingPanel(new HTML("Loading...")));
|
||||
cmsPanel.addToCenter(paginatedView.getCellPanel());
|
||||
cmsPanel.addToBottom(paginatedView.getPagerPanel());
|
||||
}
|
||||
|
||||
/**
|
||||
* Load items for status.
|
||||
*
|
||||
* @param status the status
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public void loadItemsForStatus(ItemStatus status) throws Exception {
|
||||
|
||||
if (isContentModeratorEnabled == null)
|
||||
throw new Exception("Please, first check if the content moderator is enabled in this context");
|
||||
|
||||
if (!isContentModeratorEnabled)
|
||||
throw new Exception("Content Moderator is not enabled in this context");
|
||||
|
||||
cmsPanel.showLoading(true);
|
||||
contentModeratorService.getListItemsForStatus(status, ContentModeratorWidgetConstants.ITEMS_PER_PAGE,
|
||||
ContentModeratorWidgetConstants.ITEM_START_INDEX, new AsyncCallback<List<CatalogueDataset>>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(List<CatalogueDataset> result) {
|
||||
cmsPanel.showLoading(false);
|
||||
itemsTable.updateItems(result, true);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
cmsPanel.showLoading(false);
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
// /**
|
||||
// * Load items for status.
|
||||
// *
|
||||
// * @param status the status
|
||||
// * @throws Exception the exception
|
||||
// */
|
||||
// public void loadItemsForStatus(ItemStatus status) throws Exception {
|
||||
//
|
||||
// if (isContentModeratorEnabled == null)
|
||||
// throw new Exception("Please, first check if the content moderator is enabled in this context");
|
||||
//
|
||||
// if (!isContentModeratorEnabled)
|
||||
// throw new Exception("Content Moderator is not enabled in this context");
|
||||
//
|
||||
// cmsPanel.showLoading(true);
|
||||
// contentModeratorService.getListItemsForStatus(status, ContentModeratorWidgetConstants.ITEMS_PER_PAGE,
|
||||
// ContentModeratorWidgetConstants.ITEM_START_INDEX, new AsyncCallback<List<CatalogueDataset>>() {
|
||||
//
|
||||
// @Override
|
||||
// public void onSuccess(List<CatalogueDataset> result) {
|
||||
// cmsPanel.showLoading(false);
|
||||
// itemsTable.updateItems(result, true);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onFailure(Throwable caught) {
|
||||
// cmsPanel.showLoading(false);
|
||||
// // TODO Auto-generated method stub
|
||||
//
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// }
|
||||
|
||||
/**
|
||||
* Checks if is content moderator enabled.
|
||||
|
|
|
@ -11,6 +11,6 @@ public class ContentModeratorWidgetConstants {
|
|||
|
||||
public static final String NO_DATA = "No data";
|
||||
|
||||
public static int ITEMS_PER_PAGE = 20;
|
||||
public static int ITEMS_PER_PAGE = 10;
|
||||
public static int ITEM_START_INDEX = 0;
|
||||
}
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
package org.gcube.portlets.widgets.ckancontentmoderator.client.ui;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.uibinder.client.UiBinder;
|
||||
import com.google.gwt.uibinder.client.UiField;
|
||||
import com.google.gwt.uibinder.client.UiHandler;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.HasText;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
public class ConentModeratorSystemBasePanel extends Composite implements HasText {
|
||||
|
||||
private static ConentModeratorSystemBasePanelUiBinder uiBinder = GWT
|
||||
.create(ConentModeratorSystemBasePanelUiBinder.class);
|
||||
|
||||
interface ConentModeratorSystemBasePanelUiBinder extends UiBinder<Widget, ConentModeratorSystemBasePanel> {
|
||||
}
|
||||
|
||||
public ConentModeratorSystemBasePanel() {
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
}
|
||||
|
||||
@UiField
|
||||
Button button;
|
||||
|
||||
public ConentModeratorSystemBasePanel(String firstName) {
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
button.setText(firstName);
|
||||
}
|
||||
|
||||
@UiHandler("button")
|
||||
void onClick(ClickEvent e) {
|
||||
Window.alert("Hello!");
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
button.setText(text);
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return button.getText();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
|
||||
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
|
||||
xmlns:g="urn:import:com.google.gwt.user.client.ui">
|
||||
<ui:style>
|
||||
.important {
|
||||
font-weight: bold;
|
||||
}
|
||||
</ui:style>
|
||||
<g:HTMLPanel>
|
||||
<g:DockPanel>
|
||||
|
||||
</g:DockPanel>
|
||||
<g:ScrollPanel ui:field="theCenterPanel">
|
||||
|
||||
</g:ScrollPanel>
|
||||
</g:HTMLPanel>
|
||||
</ui:UiBinder>
|
|
@ -0,0 +1,270 @@
|
|||
package org.gcube.portlets.widgets.ckancontentmoderator.client.ui;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.client.CkanContentModeratorWidget;
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.client.ContentModeratorWidgetConstants;
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.table.ItemsTable;
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.table.ItemsTable.DISPLAY_FIELD;
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.table.SortedCellTable;
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.util.LoadingPanel;
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset;
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.shared.SearchedData;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.user.cellview.client.SimplePager;
|
||||
import com.google.gwt.user.cellview.client.SimplePager.TextLocation;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
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;
|
||||
|
||||
public class ContentModeratorPaginatedView {
|
||||
|
||||
private static final int ITEM_START_INDEX = ContentModeratorWidgetConstants.ITEM_START_INDEX;
|
||||
|
||||
private static final int ITEMS_PER_PAGE = ContentModeratorWidgetConstants.ITEMS_PER_PAGE;
|
||||
|
||||
private VerticalPanel vPanel = new VerticalPanel();
|
||||
|
||||
private FlowPanel pagerPanel = new FlowPanel();
|
||||
|
||||
private Boolean newLoading = false;
|
||||
private ItemsTable<CatalogueDataset> itemsTable;
|
||||
private MyCustomDataProvider<CatalogueDataset> dataProvider = new MyCustomDataProvider<CatalogueDataset>();
|
||||
protected Widget orginalLoadingIndicator = null;
|
||||
private LoadingPanel loadingPanel = new LoadingPanel(new HTML("Loading data..."));
|
||||
// private int serverStartIndex = 0;
|
||||
|
||||
private ItemStatus itemStatus;
|
||||
|
||||
private int serverStartIndex;
|
||||
|
||||
public ContentModeratorPaginatedView(ItemStatus theStatus, DISPLAY_FIELD[] displayFields,
|
||||
DISPLAY_FIELD sortByField) {
|
||||
this.itemStatus = theStatus;
|
||||
this.newLoading = true;
|
||||
itemsTable = new ItemsTable<CatalogueDataset>(null, displayFields, sortByField);
|
||||
itemsTable.initTable(null, null, dataProvider);
|
||||
|
||||
orginalLoadingIndicator = itemsTable.getCellTable().getLoadingIndicator();
|
||||
initPagination(ITEMS_PER_PAGE);
|
||||
loadNewPage(ITEM_START_INDEX, ITEMS_PER_PAGE,false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the asycn data provider.
|
||||
*
|
||||
* @return the asycn data provider
|
||||
*/
|
||||
public AsyncDataProvider<CatalogueDataset> getAsycnDataProvider() {
|
||||
return (AsyncDataProvider<CatalogueDataset>) getCellTable().getDataProvider();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cell tale.
|
||||
*
|
||||
* @return the cell tale
|
||||
*/
|
||||
private SortedCellTable<CatalogueDataset> getCellTable() {
|
||||
return itemsTable.getCellTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Inits the pagination.
|
||||
*
|
||||
* @param itemsPerPage the items per page
|
||||
*/
|
||||
public void initPagination(int itemsPerPage) {
|
||||
|
||||
SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
|
||||
SimplePager pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true);
|
||||
pager.setDisplay(getCellTable());
|
||||
pager.setPageSize(itemsPerPage);
|
||||
pager.getElement().getStyle().setProperty("margin", "auto");
|
||||
vPanel.add(loadingPanel);
|
||||
vPanel.add(getCellTable());
|
||||
vPanel.getElement().addClassName("vPanel");
|
||||
pagerPanel.add(pager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the pager panel.
|
||||
*
|
||||
* @return the pager panel
|
||||
*/
|
||||
public VerticalPanel getCellPanel() {
|
||||
return vPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the panel in loading mode.
|
||||
*/
|
||||
protected void showLoading(boolean show) {
|
||||
loadingPanel.setVisible(show);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the pager panel.
|
||||
*
|
||||
* @return the pager panel
|
||||
*/
|
||||
public FlowPanel getPagerPanel() {
|
||||
return pagerPanel;
|
||||
}
|
||||
|
||||
/*
|
||||
* (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 loadNewPage(final int startIdx, final int limit, final boolean resetStore) {
|
||||
newLoading = resetStore;
|
||||
GWT.log("loading data with parameters [startIdx: "+startIdx+", limit: " + limit + ", resetStore:" + resetStore + "]");
|
||||
// showLoading(true);
|
||||
|
||||
int newStartIndex = startIdx;
|
||||
|
||||
if (newLoading) {
|
||||
GWT.log("Cleaning all data...");
|
||||
newStartIndex = 0;
|
||||
serverStartIndex = 0;
|
||||
GWT.log("Store reset performed start index is: " + newStartIndex);
|
||||
getAsycnDataProvider().updateRowCount(ITEMS_PER_PAGE, false);
|
||||
//newLoading = false;
|
||||
}
|
||||
|
||||
loadItemsForStatus(itemStatus, newStartIndex, limit, serverStartIndex);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
if (newLoading) {
|
||||
GWT.log("OnLoading is true.. returning");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
GWT.log("Range changed: " + start + " " + length + " visible count: " + display.getVisibleItemCount());
|
||||
// GWT.log("Server start index: " + serverStartIndex);
|
||||
// int newStart = start < serverStartIndex? serverStartIndex : start;
|
||||
// GWT.log("newStart index: "+newStart);
|
||||
loadNewPage(start, length, false);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the new page result.
|
||||
*
|
||||
* @param result the new new page result
|
||||
*/
|
||||
private void setNewPageResult(SearchedData result){
|
||||
|
||||
serverStartIndex = result.getServerEndIndex();
|
||||
|
||||
if(newLoading){
|
||||
getCellTable().setVisibleRangeAndClearData(new Range(result.getClientStartIndex(), ITEMS_PER_PAGE), false);
|
||||
}
|
||||
|
||||
SelectionModel<? super CatalogueDataset> sm = getCellTable().getSelectionModel();
|
||||
|
||||
if(sm instanceof SingleSelectionModel){
|
||||
SingleSelectionModel<CatalogueDataset> ssm = (SingleSelectionModel<CatalogueDataset>) sm;
|
||||
ssm.clear();
|
||||
}
|
||||
|
||||
getAsycnDataProvider().updateRowCount((int) result.getTotalItems(), true);
|
||||
getAsycnDataProvider().updateRowData(result.getClientStartIndex(), result.getData());
|
||||
|
||||
if(result.getData().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.getData().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());
|
||||
newLoading = false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Load items for status.
|
||||
*
|
||||
* @param status the status
|
||||
* @param offset
|
||||
* @param limit
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
private void loadItemsForStatus(ItemStatus status, int offset, int limit, int serverIndex) {
|
||||
showLoading(true);
|
||||
|
||||
//TODO implement new method
|
||||
GWT.log("calling getDataForStatus with parameters [startIndex: "+offset+", limit: " + limit + ", serverIndex:" + serverIndex + "]");
|
||||
CkanContentModeratorWidget.contentModeratorService.getDataForStatus(status, offset, limit, serverIndex,
|
||||
new AsyncCallback<SearchedData>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(SearchedData result) {
|
||||
showLoading(false);
|
||||
setNewPageResult(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
showLoading(false);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package org.gcube.portlets.widgets.ckancontentmoderator.client.ui;
|
||||
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.ScrollPanel;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class ContentModeratorSystemBaseView.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Jun 16, 2021
|
||||
*/
|
||||
public class ContentModeratorSystemBaseView {
|
||||
|
||||
private BaseViewTemplate baseViewTemplate = new BaseViewTemplate();
|
||||
private ScrollPanel centerPanel = new ScrollPanel();
|
||||
|
||||
/**
|
||||
* Instantiates a new content moderator system base view.
|
||||
*/
|
||||
public ContentModeratorSystemBaseView() {
|
||||
baseViewTemplate.addToMiddle(centerPanel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the to top.
|
||||
*
|
||||
* @param w the w
|
||||
*/
|
||||
public void addToTop(Widget w) {
|
||||
baseViewTemplate.addToTop(w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the to center.
|
||||
*
|
||||
* @param w the w
|
||||
*/
|
||||
public void addToCenter(Widget w) {
|
||||
centerPanel.add(w);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the to bottom.
|
||||
*
|
||||
* @param w the w
|
||||
*/
|
||||
public void addToBottom(Widget w) {
|
||||
baseViewTemplate.addToBottom(w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the panel.
|
||||
*
|
||||
* @return the panel
|
||||
*/
|
||||
public Composite getPanel() {
|
||||
return baseViewTemplate;
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
package org.gcube.portlets.widgets.ckancontentmoderator.client.ui;
|
||||
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.client.resources.ContentModeratorWidgetResources;
|
||||
|
||||
import com.google.gwt.dom.client.Style.Unit;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
import com.google.gwt.user.client.ui.ScrollPanel;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
|
||||
/**
|
||||
* The Class ContentModeratorSystemPanel.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Jun 15, 2021
|
||||
*/
|
||||
public class ContentModeratorSystemPanel {
|
||||
|
||||
|
||||
private BaseViewTemplate baseViewTemplate = new BaseViewTemplate();
|
||||
private ScrollPanel centerPanel = new ScrollPanel();
|
||||
|
||||
protected static final HorizontalPanel LOADING_PANEL = new HorizontalPanel();
|
||||
protected static final Image LOADING_IMAGE = ContentModeratorWidgetResources.getIconLoading().createImage();
|
||||
|
||||
static {
|
||||
LOADING_PANEL.getElement().getStyle().setMargin(5.0, Unit.PX);
|
||||
// LOADING_PANEL.setSpacing(3);
|
||||
LOADING_PANEL.add(LOADING_IMAGE);
|
||||
HTML loading = new HTML("Loading...");
|
||||
loading.getElement().getStyle().setPaddingLeft(5.0, Unit.PX);
|
||||
LOADING_PANEL.add(loading);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public ContentModeratorSystemPanel(){
|
||||
baseViewTemplate.addToTop(LOADING_PANEL);
|
||||
baseViewTemplate.addToMiddle(centerPanel);
|
||||
}
|
||||
|
||||
public void showLoading(boolean show) {
|
||||
LOADING_PANEL.setVisible(show);
|
||||
centerPanel.setVisible(!show);
|
||||
}
|
||||
|
||||
public void add(Widget w){
|
||||
centerPanel.add(w);
|
||||
}
|
||||
|
||||
public Composite getPanel(){
|
||||
return baseViewTemplate;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package org.gcube.portlets.widgets.ckancontentmoderator.client.ui.util;
|
||||
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.client.resources.ContentModeratorWidgetResources;
|
||||
|
||||
import com.google.gwt.dom.client.Style.Unit;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
|
||||
|
||||
/**
|
||||
* The Class LoadingPanel.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Jun 16, 2021
|
||||
*/
|
||||
public class LoadingPanel extends HorizontalPanel {
|
||||
|
||||
protected final Image LOADING_IMAGE = ContentModeratorWidgetResources.getIconLoading().createImage();
|
||||
|
||||
/**
|
||||
* Instantiates a new loading panel.
|
||||
*
|
||||
* @param html the html
|
||||
*/
|
||||
public LoadingPanel(HTML html) {
|
||||
this.getElement().getStyle().setMargin(5.0, Unit.PX);
|
||||
// LOADING_PANEL.setSpacing(3);
|
||||
this.add(LOADING_IMAGE);
|
||||
if (html != null) {
|
||||
HTML loadingText = new HTML("Loading...");
|
||||
loadingText.getElement().getStyle().setPaddingLeft(5.0, Unit.PX);
|
||||
this.add(loadingText);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -10,6 +10,7 @@ import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
|
|||
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset;
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.client.CkanContentModeratorService;
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset;
|
||||
import org.gcube.portlets.widgets.ckancontentmoderator.shared.SearchedData;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -37,10 +38,19 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list items for status.
|
||||
*
|
||||
* @param theStatus the the status
|
||||
* @param offset the offset
|
||||
* @param limit the limit
|
||||
* @return the list items for status
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Override
|
||||
public List<CatalogueDataset> getListItemsForStatus(ItemStatus theStatus, int limit, int offset) throws Exception {
|
||||
LOG.info("called getListItemsForStatus with [status: " + theStatus + "], [limit: " + limit + "], [offset: "
|
||||
+ offset + "]");
|
||||
public List<CatalogueDataset> getListItemsForStatus(ItemStatus theStatus, int offset, int limit) throws Exception {
|
||||
LOG.info("called getListItemsForStatus with [status: " + theStatus + ", offset: " + offset + "], [limit: "
|
||||
+ limit + "]");
|
||||
List<CatalogueDataset> datasetList = null;
|
||||
try {
|
||||
|
||||
|
@ -89,4 +99,80 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
|
|||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchedData getDataForStatus(ItemStatus status, int offset, int limit, int serverStartIndex) throws Exception {
|
||||
LOG.info("called getDataForStatus [status: "+status+", offset: "+offset+", limit: "+limit+", serverIndex: "+serverStartIndex);
|
||||
|
||||
try {
|
||||
String scope = WsUtil.getCurrentScope(this.getThreadLocalRequest());
|
||||
GCubeUser user = WsUtil.getCurrentUser(this.getThreadLocalRequest());
|
||||
String token = WsUtil.getCurrentToken(scope, user.getUsername());
|
||||
ScopeProvider.instance.set(scope);
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
//int searchStartIndex = limit < serverStartIndex? serverStartIndex : offset;
|
||||
|
||||
int searchStartIndex = offset;
|
||||
|
||||
CatalogueContentModeratorSystem cmsInstance = CatalogueCMSFactory.getFactory().getCMSPerScope(scope);
|
||||
SearchedData searchedData = new SearchedData(offset, limit, searchStartIndex, false);
|
||||
long totalItemsForStatus = cmsInstance.countListItemsForStatus(status);
|
||||
LOG.info("totalItemsForStatus "+status+" are : "+totalItemsForStatus);
|
||||
List<CatalogueDataset> listDataset = new ArrayList<CatalogueDataset>();
|
||||
try {
|
||||
LOG.debug("getListItemsForStatus with searchStartIndex: "+searchStartIndex+", limit: "+limit);
|
||||
listDataset = getListItemsForStatus(status, searchStartIndex, limit);
|
||||
}catch (Exception e) {
|
||||
LOG.error("Error occurred on gettin items for status: "+status,e);
|
||||
}
|
||||
|
||||
int listDatasetSize = listDataset.size();
|
||||
LOG.debug("Returned "+listDatasetSize+" with above parameters");
|
||||
searchedData.setData(listDataset);
|
||||
searchedData.setTotalItems(totalItemsForStatus);
|
||||
|
||||
if(listDatasetSize == limit || listDatasetSize==0){
|
||||
LOG.debug("Page completed returning "+listDatasetSize+ " items");
|
||||
int newOffset = searchStartIndex+offset;
|
||||
searchedData.setServerSearchFinished(newOffset>totalItemsForStatus || listDatasetSize == 0);
|
||||
LOG.debug("is Search finished: "+searchedData.isServerSearchFinished());
|
||||
return searchedData;
|
||||
}
|
||||
|
||||
/*int offsetStartIndex = searchStartIndex;
|
||||
boolean pageOffsetOut = false;
|
||||
while(listDatasetSize < offset && !searchedData.isServerSearchFinished() && !pageOffsetOut){ //&& SEARCH NOT ULTIMATED
|
||||
LOG.debug("MyLg new WHILE Items count: "+totalItemsForStatus+" is less than limit..");
|
||||
|
||||
int newOffsetStartIndex = offsetStartIndex+limit+1;
|
||||
LOG.debug("MyLg NewStartIndex is startIndex+limit: "+newOffsetStartIndex);
|
||||
|
||||
//THERE ARE OTHER CHILDREN OVER NEW START INDEX
|
||||
if(newOffsetStartIndex < totalItemsForStatus){
|
||||
//newLimit = limit - childrenToReturn.size();
|
||||
LOG.debug("MyLg getting items with index start: "+newOffsetStartIndex + ", limit: "+offset);
|
||||
|
||||
int diff = (int) (offset - totalItemsForStatus); //How items are remaining
|
||||
//int offset = 0;
|
||||
LOG.debug("MyLg new search start: "+newOffsetStartIndex + ", diff: "+diff+ ", retrieved: "+listDatasetSize);
|
||||
if(diff >= listDatasetSize){
|
||||
}else{
|
||||
pageOffsetOut = true;
|
||||
}
|
||||
offsetStartIndex = newOffsetStartIndex;
|
||||
LOG.debug("MyLg items count is: "+totalItemsForStatus + " serverEndIndex: "+offsetStartIndex);
|
||||
searchedData.setServerEndIndex(offsetStartIndex);
|
||||
}else{
|
||||
LOG.debug("New start index (oldStartIndex+limit) is grather than total items count, search is finished");
|
||||
searchedData.setServerSearchFinished(true);
|
||||
}
|
||||
}*/
|
||||
LOG.debug("Returning: "+searchedData);
|
||||
return searchedData;
|
||||
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error during folder retrieving", e);
|
||||
throw new Exception("Sorry, an error occurred on loading items");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,181 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.widgets.ckancontentmoderator.shared;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* The Class SearchedFolder.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Jun 16, 2021
|
||||
*/
|
||||
public class SearchedData implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 6800997954077785719L;
|
||||
private List<CatalogueDataset> data;
|
||||
private int clientStartIndex = 0;
|
||||
private int limit;
|
||||
private int serverEndIndex = 0;
|
||||
private boolean isServerSearchFinished = false;
|
||||
private long totalItems;
|
||||
|
||||
/**
|
||||
* Instantiates a new searched folder.
|
||||
*/
|
||||
public SearchedData() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new searched data.
|
||||
*
|
||||
* @param clientStartIndex the client start index
|
||||
* @param limit the limit
|
||||
* @param serverEndIndex the server end index
|
||||
* @param isServerSearchFinished the is server search finished
|
||||
*/
|
||||
public SearchedData(int clientStartIndex, int limit, int serverEndIndex, boolean isServerSearchFinished) {
|
||||
|
||||
this.clientStartIndex = clientStartIndex;
|
||||
this.limit = limit;
|
||||
this.serverEndIndex = serverEndIndex;
|
||||
this.isServerSearchFinished = isServerSearchFinished;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data.
|
||||
*
|
||||
* @return the data
|
||||
*/
|
||||
public List<CatalogueDataset> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the client start index.
|
||||
*
|
||||
* @return the client start index
|
||||
*/
|
||||
public int getClientStartIndex() {
|
||||
return clientStartIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the limit.
|
||||
*
|
||||
* @return the limit
|
||||
*/
|
||||
public int getLimit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server end index.
|
||||
*
|
||||
* @return the server end index
|
||||
*/
|
||||
public int getServerEndIndex() {
|
||||
return serverEndIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is server search finished.
|
||||
*
|
||||
* @return true, if is server search finished
|
||||
*/
|
||||
public boolean isServerSearchFinished() {
|
||||
return isServerSearchFinished;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the data.
|
||||
*
|
||||
* @param data the new data
|
||||
*/
|
||||
public void setData(List<CatalogueDataset> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the client start index.
|
||||
*
|
||||
* @param clientStartIndex the new client start index
|
||||
*/
|
||||
public void setClientStartIndex(int clientStartIndex) {
|
||||
this.clientStartIndex = clientStartIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the limit.
|
||||
*
|
||||
* @param limit the new limit
|
||||
*/
|
||||
public void setLimit(int limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the server end index.
|
||||
*
|
||||
* @param serverEndIndex the new server end index
|
||||
*/
|
||||
public void setServerEndIndex(int serverEndIndex) {
|
||||
this.serverEndIndex = serverEndIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the server search finished.
|
||||
*
|
||||
* @param isServerSearchFinished the new server search finished
|
||||
*/
|
||||
public void setServerSearchFinished(boolean isServerSearchFinished) {
|
||||
this.isServerSearchFinished = isServerSearchFinished;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the total items.
|
||||
*
|
||||
* @return the total items
|
||||
*/
|
||||
public long getTotalItems() {
|
||||
return totalItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the total items.
|
||||
*
|
||||
* @param totalItems the new total items
|
||||
*/
|
||||
public void setTotalItems(long totalItems) {
|
||||
this.totalItems = totalItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("SearchedData [data=");
|
||||
builder.append(data);
|
||||
builder.append(", clientStartIndex=");
|
||||
builder.append(clientStartIndex);
|
||||
builder.append(", limit=");
|
||||
builder.append(limit);
|
||||
builder.append(", serverEndIndex=");
|
||||
builder.append(serverEndIndex);
|
||||
builder.append(", isServerSearchFinished=");
|
||||
builder.append(isServerSearchFinished);
|
||||
builder.append(", totalItems=");
|
||||
builder.append(totalItems);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue