ckan-content-moderator-widget/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/HomeView.java

284 lines
7.6 KiB
Java

package org.gcube.portlets.widgets.ckancontentmoderator.client.ui;
import java.util.ArrayList;
import java.util.List;
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
import org.gcube.portlets.widgets.ckancontentmoderator.client.events.CheckBoxSelectIemsEvent;
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.table.ItemsTable.DISPLAY_FIELD;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset;
import com.github.gwtbootstrap.client.ui.CheckBox;
import com.github.gwtbootstrap.client.ui.Dropdown;
import com.github.gwtbootstrap.client.ui.Heading;
import com.github.gwtbootstrap.client.ui.NavLink;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.Widget;
// TODO: Auto-generated Javadoc
/**
* The Class HomeView.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Jun 22, 2021
*/
public class HomeView extends Composite {
private static HomeViewUiBinder uiBinder = GWT.create(HomeViewUiBinder.class);
private ContentModeratorSystemBaseView cmsPanel = new ContentModeratorSystemBaseView();
private ContentModeratorPaginatedView paginatedView;
@UiField
HTMLPanel panelContainer;
@UiField
CheckBox cbSelectAll;
@UiField
Dropdown dropdownSetStatus;
@UiField
Heading pageHeader;
@UiField
HTMLPanel confirmPanel;
private ScrollPanel confirmPanelContainer = new ScrollPanel();
private List<NavLink> setStatusOptions = new ArrayList<NavLink>();
private ItemStatus displayingItemStatus;
private HandlerManager eventBus;
private List<CatalogueDataset> selectedItems;
/**
* The Interface HomeViewUiBinder.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Jun 22, 2021
*/
interface HomeViewUiBinder extends UiBinder<Widget, HomeView> {
}
/**
* Instantiates a new home view.
*
* @param eventBus the event bus
* @param status the status
* @param displayFields the display fields
* @param sortByField the sort by field
*/
public HomeView(HandlerManager eventBus, ItemStatus status, DISPLAY_FIELD[] displayFields,
DISPLAY_FIELD sortByField) {
initWidget(uiBinder.createAndBindUi(this));
setDisplayingWithStatus(status);
this.eventBus = eventBus;
paginatedView = new ContentModeratorPaginatedView(eventBus, status, displayFields, sortByField);
cmsPanel.addToCenter(paginatedView.getCellPanel());
cmsPanel.addToBottom(paginatedView.getPagerPanel());
panelContainer.add(cmsPanel.getPanel());
setVisibleUpdateStatusAction(false);
fillSetStatusOptions();
bindEvents();
confirmPanel.add(confirmPanelContainer);
}
/**
* Fill set status options.
*/
private void fillSetStatusOptions() {
for (ItemStatus status : ItemStatus.values()) {
if (!status.equals(displayingItemStatus)) {
NavLink nl = new NavLink(status.getLabel());
dropdownSetStatus.add(nl);
setStatusOptions.add(nl);
}
}
}
private void setDisplayingWithStatus(ItemStatus status) {
this.displayingItemStatus = status;
this.pageHeader.setSubtext(status.getLabel());
}
/**
* Bind events.
*/
public void bindEvents() {
cbSelectAll.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
GWT.log("Is checked: " + cbSelectAll.getValue());
eventBus.fireEvent(new CheckBoxSelectIemsEvent<CatalogueDataset>(cbSelectAll.getValue()));
}
});
for (final NavLink navLink : setStatusOptions) {
navLink.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// selectedItems = paginatedView.getSelectItems();
// int count = selectedItems.size();
// String msg = "Going to update status of";
// if (count > 0) {
// if (count == 1) {
// msg += " one item";
// } else {
// msg += " " + count + " items";
// }
//
// msg += " from <b>" + displayingItemStatus.getLabel() + "</b> to <b>" + navLink.getText()
// + "</b>. Confirm?";
// } else
// return;
if(paginatedView.getSelectItems().size()>0) {
showConfirm(navLink);
}
}
});
}
}
/**
* Gets the panel.
*
* @return the panel
*/
public Composite getPanel() {
return this;
}
/**
* Sets the visible update status action.
*
* @param bool the new visible update status action
*/
public void setVisibleUpdateStatusAction(boolean bool) {
dropdownSetStatus.setVisible(bool);
}
/**
* Mark items as checked.
*
* @param select the select
* @param limitToPage the limit to page
*/
public void markItemsAsChecked(boolean select, boolean limitToPage) {
paginatedView.selectItems(select, limitToPage);
}
/**
* Sets the checked checkbox select all.
*
* @param bool the new checked checkbox select all
*/
public void setCheckedCheckboxSelectAll(boolean bool) {
cbSelectAll.setValue(bool);
}
/**
* Show confirm.
*
* @param msg the msg
*/
public void showConfirm(NavLink navLink) {
confirmPanelContainer.clear();
GWT.log("showConfirm clicked link: "+navLink.getText());
ItemStatus fromStatus = displayingItemStatus;
ItemStatus toStatus = null;
for (ItemStatus theStatus : ItemStatus.values()) {
if(theStatus.getLabel().compareTo(navLink.getText().trim())==0) {
toStatus = theStatus;
break;
}
}
GWT.log("Do action on from: "+fromStatus + " to: "+toStatus);
if(toStatus==null) {
return;
}
DoActionCMS doActionCMS = new DoActionCMS(fromStatus, toStatus, paginatedView.getSelectItems());
/*final AlertBlock newAlertBlock = new AlertBlock(AlertType.DEFAULT);
newAlertBlock.setAnimation(true);
newAlertBlock.setClose(true);
newAlertBlock.addClosedHandler(new ClosedHandler<AlertBase>() {
@Override
public void onClosed(ClosedEvent<AlertBase> event) {
confirmPanelContainer.clear();
}
});
Button buttActionConfirmYes = new Button(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
confirmPanelContainer.clear();
}
});
buttActionConfirmYes.getElement().getStyle().setMarginLeft(10, Unit.PX);
buttActionConfirmYes.setText("YES");
newAlertBlock.add(buttActionConfirmYes);
Button buttonActionConfirmNo = new Button(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
confirmPanelContainer.clear();
}
});
buttonActionConfirmNo.getElement().getStyle().setMarginLeft(10, Unit.PX);
buttonActionConfirmNo.setText("NO");
newAlertBlock.add(buttonActionConfirmNo);
newAlertBlock.setHTML(msg);*/
confirmPanelContainer.add(doActionCMS);
}
/**
* Load form server the items with status.
*
* @param itemStatus the item status
*/
public void loadItemsWithStatus(ItemStatus itemStatus) {
GWT.log("loadItemsWithStatus started");
setDisplayingWithStatus(itemStatus);
setCheckedCheckboxSelectAll(false);
setVisibleUpdateStatusAction(false);
try {
confirmPanelContainer.clear();
} catch (Exception e) {
GWT.log("error: " + e.getMessage() + " cause: " + e.getCause().toString());
}
paginatedView.loadItemsForStatus(itemStatus);
GWT.log("loadItemsWithStatus end");
}
}