performfish-analytics-portlet/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/AnnualListKPIView.java

234 lines
6.5 KiB
Java

/**
*
*/
package org.gcube.portlets.user.performfishanalytics.client.viewannualbinder;
import java.util.List;
import java.util.Map;
import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant;
import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant.POPULATION_LEVEL;
import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsServiceAsync;
import org.gcube.portlets.user.performfishanalytics.client.controllers.PerformFishAnalyticsController;
import org.gcube.portlets.user.performfishanalytics.client.event.AddedBatchIdEvent;
import org.gcube.portlets.user.performfishanalytics.client.view.LoaderIcon;
import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVFile;
import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVRow;
import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishResponse;
import com.github.gwtbootstrap.client.ui.Alert;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
// TODO: Auto-generated Javadoc
/**
* The Class BatchIDAndListKPIView.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Feb 28, 2019
*/
public class AnnualListKPIView extends Composite {
/** The ui binder. */
private static BatchIDAndListKPIViewUiBinder uiBinder =
GWT.create(BatchIDAndListKPIViewUiBinder.class);
/**
* The Interface BatchIDAndListKPIViewUiBinder.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Feb 28, 2019
*/
interface BatchIDAndListKPIViewUiBinder
extends UiBinder<Widget, AnnualListKPIView> {
}
/** The the panel container. */
@UiField
VerticalPanel the_panel_container;
/** The the panel error. */
@UiField
HorizontalPanel the_panel_error;
/** The perform fish response. */
private PerformFishResponse performFishResponse;
/** The map parameters. */
private Map<String, List<String>> mapParameters;
/**
* Instantiates a new batch id and list kpi view.
*/
public AnnualListKPIView() {
initWidget(uiBinder.createAndBindUi(this));
}
/**
* Adds the.
*
* @param w the w
*/
public void add(Widget w){
the_panel_container.add(w);
}
/**
* Manage perform fish service response.
*
* @param performFishResponse the perform fish response
* @param mapParameters the map parameters
* @param level the level
*/
public void managePerformFishServiceResponse(
PerformFishResponse performFishResponse,
Map<String, List<String>> mapParameters, final POPULATION_LEVEL level) {
this.performFishResponse = performFishResponse;
this.mapParameters = mapParameters;
GWT.log("PerformFish Response: "+performFishResponse);
String fileURL = performFishResponse.getMapParameters().get(PerformFishAnalyticsConstant.BATCHES_TABLE_INTERNAL);
GWT.log("BatchesTable_internal is: "+fileURL);
//Managing the Perform Fish Service Response
if(fileURL==null){
showAlert("No select found for "+PerformFishAnalyticsConstant.BATCHES_TABLE_INTERNAL, AlertType.ERROR, false, the_panel_error);
}else{
final LoaderIcon loader = new LoaderIcon("Loading Values...");
the_panel_container.insert(loader, 1);
PerformFishAnalyticsServiceAsync.Util.getInstance().readCSVFile(fileURL, new AsyncCallback<CSVFile>() {
@Override
public void onFailure(Throwable caught) {
loader.setVisible(false);
the_panel_container.remove(loader);
Window.alert(caught.getMessage());
}
@Override
public void onSuccess(CSVFile result) {
loader.setVisible(false);
the_panel_container.remove(loader);
if(result==null){
showAlert("No value found for "+PerformFishAnalyticsConstant.BATCHES_TABLE_INTERNAL, AlertType.ERROR, false, the_panel_error);
return;
}
//IT CAN BE "BATCH", "FARM", etc.
String theScalePParamValue = level.name();
int indexOfTheScaleValue = result.getHeaderRow().getListValues().indexOf(theScalePParamValue);
if(indexOfTheScaleValue>-1){
List<CSVRow> rows = result.getValueRows();
if(rows==null || rows.isEmpty()){
PerformFishAnalyticsController.eventBus.fireEvent(new AddedBatchIdEvent());
return;
}
for (CSVRow row : rows) {
String valuePerScaleP = row.getListValues().get(indexOfTheScaleValue);
//field_list_focus_id_dea.addItem(valuePerScaleP, valuePerScaleP);
// uib_list_batch_id.addItem(valuePerScaleP, valuePerScaleP);
// listBatchesID.add(valuePerScaleP);
}
// uib_list_batch_id.addItem(PerformFishAnalyticsConstant.DM_FOCUS_ID_ALL_VALUE, PerformFishAnalyticsConstant.DM_FOCUS_ID_ALL_VALUE);
// listBatchesID.add(PerformFishAnalyticsConstant.DM_FOCUS_ID_ALL_VALUE);
PerformFishAnalyticsController.eventBus.fireEvent(new AddedBatchIdEvent());
}
}
});
}
}
/**
* Show alert.
*
* @param error the error
* @param type the type
* @param closable the closable
* @param panel the panel
*/
private void showAlert(String error, AlertType type, boolean closable, ComplexPanel panel){
panel.clear();
Alert alert = new Alert(error);
alert.setType(type);
alert.setClose(closable);
alert.getElement().getStyle().setMargin(10, Unit.PX);
panel.add(alert);
}
/**
* Show alert.
*
* @param error the error
* @param type the type
* @param closable the closable
*/
public void showAlert(String error, AlertType type, boolean closable){
showAlert(error, type, closable, the_panel_error);
}
/**
* Show selection ok.
*
* @param msg the msg
* @param closable the closable
*/
public void showSelectionOK(String msg, boolean closable){
showAlert(msg, AlertType.INFO, closable, the_panel_error);
}
/**
* Gets the perform fish response.
*
* @return the performFishResponse
*/
public PerformFishResponse getPerformFishResponse() {
return performFishResponse;
}
/**
* Gets the map parameters.
*
* @return the mapParameters
*/
public Map<String, List<String>> getMapParameters() {
return mapParameters;
}
}