2018-07-05 18:29:38 +02:00
|
|
|
package org.gcube.portlets.user.accountingdashboard.client.application.mainarea.filter;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
2018-07-09 19:08:52 +02:00
|
|
|
import org.gcube.portlets.user.accountingdashboard.client.application.event.RequestReportEvent;
|
|
|
|
import org.gcube.portlets.user.accountingdashboard.client.application.event.RequestReportEvent.RequestReportEventHandler;
|
2018-07-05 18:29:38 +02:00
|
|
|
import org.gcube.portlets.user.accountingdashboard.client.application.mainarea.filter.scopetree.ScopeTreeModel;
|
|
|
|
import org.gcube.portlets.user.accountingdashboard.client.resources.AppResources;
|
|
|
|
import org.gcube.portlets.user.accountingdashboard.client.resources.ScopeTreeResources;
|
2018-07-10 17:50:37 +02:00
|
|
|
import org.gcube.portlets.user.accountingdashboard.shared.data.RequestReportData;
|
2018-07-05 18:29:38 +02:00
|
|
|
import org.gcube.portlets.user.accountingdashboard.shared.data.ScopeData;
|
2020-04-07 17:56:56 +02:00
|
|
|
import org.gcube.portlets.user.accountingdashboard.shared.options.TreeOptions;
|
2018-07-05 18:29:38 +02:00
|
|
|
|
|
|
|
import com.github.gwtbootstrap.client.ui.ListBox;
|
2020-04-07 19:00:10 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.RadioButton;
|
2018-07-05 18:29:38 +02:00
|
|
|
import com.google.gwt.core.client.GWT;
|
2018-07-17 19:15:10 +02:00
|
|
|
import com.google.gwt.event.dom.client.ChangeEvent;
|
|
|
|
import com.google.gwt.event.dom.client.ChangeHandler;
|
2020-04-07 17:56:56 +02:00
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
2018-07-05 18:29:38 +02:00
|
|
|
import com.google.gwt.i18n.client.DateTimeFormat;
|
|
|
|
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
|
|
|
|
import com.google.gwt.i18n.client.LocaleInfo;
|
|
|
|
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
|
import com.google.gwt.uibinder.client.UiField;
|
|
|
|
import com.google.gwt.user.cellview.client.CellTree;
|
2018-07-09 19:08:52 +02:00
|
|
|
import com.google.gwt.user.cellview.client.TreeNode;
|
2018-07-05 18:29:38 +02:00
|
|
|
import com.google.gwt.user.client.ui.HTMLPanel;
|
|
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
import com.google.gwt.view.client.ListDataProvider;
|
|
|
|
import com.gwtplatform.mvp.client.ViewWithUiHandlers;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author Giancarlo Panichi
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class FilterAreaView extends ViewWithUiHandlers<FilterAreaPresenter>
|
|
|
|
implements FilterAreaPresenter.FilterAreaView {
|
|
|
|
|
|
|
|
private static Logger logger = java.util.logging.Logger.getLogger("");
|
|
|
|
|
|
|
|
interface Binder extends UiBinder<Widget, FilterAreaView> {
|
|
|
|
}
|
|
|
|
|
|
|
|
@UiField
|
|
|
|
HTMLPanel periodPanel;
|
|
|
|
|
|
|
|
@UiField
|
|
|
|
HTMLPanel explorePanel;
|
|
|
|
|
|
|
|
@UiField(provided = true)
|
|
|
|
ListBox yearStart;
|
|
|
|
|
|
|
|
@UiField(provided = true)
|
|
|
|
ListBox monthStart;
|
|
|
|
|
|
|
|
@UiField(provided = true)
|
|
|
|
ListBox yearEnd;
|
|
|
|
|
|
|
|
@UiField(provided = true)
|
|
|
|
ListBox monthEnd;
|
|
|
|
|
2020-04-07 17:56:56 +02:00
|
|
|
@UiField(provided = true)
|
2020-04-07 19:00:10 +02:00
|
|
|
RadioButton btnShowDetachedREs;
|
2020-04-07 17:56:56 +02:00
|
|
|
|
|
|
|
@UiField(provided = true)
|
2020-04-07 19:00:10 +02:00
|
|
|
RadioButton btnHideDetachedREs;
|
2020-04-07 17:56:56 +02:00
|
|
|
|
2018-07-05 18:29:38 +02:00
|
|
|
@UiField(provided = true)
|
|
|
|
CellTree scopeTree;
|
|
|
|
|
2018-07-06 17:48:46 +02:00
|
|
|
private ListDataProvider<ScopeData> dataProvider;
|
2018-07-17 19:15:10 +02:00
|
|
|
private ScopeTreeModel scopeTreeModel;
|
|
|
|
|
2018-07-06 17:48:46 +02:00
|
|
|
@SuppressWarnings("unused")
|
2018-07-05 18:29:38 +02:00
|
|
|
private AppResources resources;
|
|
|
|
|
2018-07-10 17:50:37 +02:00
|
|
|
private ScopeData scopeData;
|
|
|
|
|
2018-07-05 18:29:38 +02:00
|
|
|
@Inject
|
|
|
|
FilterAreaView(Binder uiBinder, AppResources resources) {
|
|
|
|
this.resources = resources;
|
|
|
|
init();
|
|
|
|
initWidget(uiBinder.createAndBindUi(this));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void init() {
|
|
|
|
yearStart = new ListBox();
|
|
|
|
yearStart.setMultipleSelect(false);
|
|
|
|
|
|
|
|
yearEnd = new ListBox();
|
|
|
|
yearEnd.setMultipleSelect(false);
|
2018-07-09 19:08:52 +02:00
|
|
|
|
|
|
|
Date now = new Date();
|
|
|
|
String currentYear = DateTimeFormat.getFormat(PredefinedFormat.YEAR).format(now);
|
2018-07-05 18:29:38 +02:00
|
|
|
logger.log(Level.FINE, "Current year: " + currentYear);
|
2018-07-09 19:08:52 +02:00
|
|
|
int year = Integer.parseInt(currentYear);
|
|
|
|
for (int i = 2015; i <= year; i++) {
|
2018-07-05 18:29:38 +02:00
|
|
|
yearStart.addItem(String.valueOf(i));
|
|
|
|
yearEnd.addItem(String.valueOf(i));
|
|
|
|
}
|
2018-07-19 19:17:57 +02:00
|
|
|
|
|
|
|
String yearStartDefaultValue;
|
|
|
|
if(year==2015){
|
|
|
|
yearStartDefaultValue="2015";
|
|
|
|
} else {
|
|
|
|
yearStartDefaultValue=String.valueOf(year-1);
|
|
|
|
}
|
|
|
|
yearStart.setSelectedValue(yearStartDefaultValue);
|
2018-07-16 18:56:04 +02:00
|
|
|
yearEnd.setSelectedValue(String.valueOf(year));
|
2018-07-17 19:15:10 +02:00
|
|
|
|
|
|
|
yearStart.addChangeHandler(new ChangeHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChange(ChangeEvent event) {
|
|
|
|
requestReport();
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
yearEnd.addChangeHandler(new ChangeHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChange(ChangeEvent event) {
|
|
|
|
requestReport();
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
2018-07-09 19:08:52 +02:00
|
|
|
|
2018-07-05 18:29:38 +02:00
|
|
|
// returns a String array with localized names of the months
|
|
|
|
String[] months = LocaleInfo.getCurrentLocale().getDateTimeFormatInfo().monthsFull();
|
|
|
|
logger.log(Level.FINE, "Months: " + months.length);
|
|
|
|
monthStart = new ListBox();
|
|
|
|
monthStart.setMultipleSelect(false);
|
|
|
|
|
|
|
|
monthEnd = new ListBox();
|
|
|
|
monthEnd.setMultipleSelect(false);
|
2018-07-19 17:59:37 +02:00
|
|
|
|
2018-07-05 18:29:38 +02:00
|
|
|
for (int i = 0; i < months.length; i++) {
|
|
|
|
monthStart.addItem(months[i]);
|
|
|
|
monthEnd.addItem(months[i]);
|
|
|
|
}
|
2018-07-09 19:08:52 +02:00
|
|
|
|
2018-07-16 18:56:04 +02:00
|
|
|
String currentMonth = DateTimeFormat.getFormat(PredefinedFormat.MONTH).format(now);
|
2018-07-17 19:15:10 +02:00
|
|
|
|
2018-07-19 19:17:57 +02:00
|
|
|
monthStart.setSelectedValue(currentMonth);
|
2018-07-16 18:56:04 +02:00
|
|
|
monthEnd.setSelectedValue(currentMonth);
|
2018-07-17 19:15:10 +02:00
|
|
|
|
|
|
|
monthStart.addChangeHandler(new ChangeHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChange(ChangeEvent event) {
|
|
|
|
requestReport();
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
monthEnd.addChangeHandler(new ChangeHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChange(ChangeEvent event) {
|
|
|
|
requestReport();
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-04-07 17:56:56 +02:00
|
|
|
|
|
|
|
logger.log(Level.FINE, "Configuring buttons DetachedREs");
|
2020-04-07 19:00:10 +02:00
|
|
|
btnShowDetachedREs=new RadioButton("radioDetachedREs");
|
2020-04-07 17:56:56 +02:00
|
|
|
btnShowDetachedREs.addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
TreeOptions treeOptions=new TreeOptions(true);
|
|
|
|
getUiHandlers().updateTreeOptions(treeOptions);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-04-07 19:00:10 +02:00
|
|
|
btnHideDetachedREs=new RadioButton("radioDetachedREs");
|
|
|
|
btnHideDetachedREs.setValue(true);
|
2020-04-07 17:56:56 +02:00
|
|
|
btnHideDetachedREs.addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
TreeOptions treeOptions=new TreeOptions(false);
|
|
|
|
getUiHandlers().updateTreeOptions(treeOptions);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
logger.log(Level.FINE, "Configuring DataProvider");
|
2018-07-06 17:48:46 +02:00
|
|
|
dataProvider = new ListDataProvider<ScopeData>();
|
2018-07-09 19:08:52 +02:00
|
|
|
|
2018-07-10 17:50:37 +02:00
|
|
|
RequestReportEventHandler handler = new RequestReportEventHandler() {
|
|
|
|
|
2018-07-09 19:08:52 +02:00
|
|
|
@Override
|
|
|
|
public void onData(RequestReportEvent event) {
|
2018-07-10 17:50:37 +02:00
|
|
|
scopeData = event.getScopeData();
|
|
|
|
requestReport();
|
|
|
|
|
2018-07-09 19:08:52 +02:00
|
|
|
}
|
|
|
|
};
|
2018-07-10 17:50:37 +02:00
|
|
|
|
2018-07-17 19:15:10 +02:00
|
|
|
scopeTreeModel = new ScopeTreeModel(dataProvider, handler);
|
2018-07-05 18:29:38 +02:00
|
|
|
ScopeTreeResources scopeTreeResources = GWT.create(ScopeTreeResources.class);
|
2018-07-09 19:08:52 +02:00
|
|
|
scopeTree = new CellTree(scopeTreeModel, null, scopeTreeResources);
|
2018-07-25 12:57:37 +02:00
|
|
|
scopeTree.setDefaultNodeSize(500);
|
2020-04-07 17:56:56 +02:00
|
|
|
|
|
|
|
logger.log(Level.FINE, "FilterAreaView init end");
|
2018-07-05 18:29:38 +02:00
|
|
|
}
|
|
|
|
|
2018-07-06 17:48:46 +02:00
|
|
|
@Override
|
|
|
|
public void displayScopeData(ScopeData scopeData) {
|
2020-04-07 17:56:56 +02:00
|
|
|
logger.log(Level.FINE, "displayScopeData()");
|
2018-07-09 19:08:52 +02:00
|
|
|
ArrayList<ScopeData> scopeDataList = new ArrayList<>();
|
2018-07-06 17:48:46 +02:00
|
|
|
scopeDataList.add(scopeData);
|
2018-07-17 19:15:10 +02:00
|
|
|
this.scopeData = scopeData;
|
2018-07-06 17:48:46 +02:00
|
|
|
dataProvider.setList(scopeDataList);
|
|
|
|
dataProvider.refresh();
|
|
|
|
dataProvider.flush();
|
2018-07-09 19:08:52 +02:00
|
|
|
TreeNode root = scopeTree.getRootTreeNode();
|
|
|
|
root.setChildOpen(root.getIndex(), true);
|
2018-07-17 19:15:10 +02:00
|
|
|
scopeTreeModel.setSelected(scopeData, true);
|
2018-07-16 18:56:04 +02:00
|
|
|
requestReport();
|
2018-07-10 17:50:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void requestReport() {
|
2020-04-07 17:56:56 +02:00
|
|
|
logger.log(Level.FINE, "requestReport()");
|
2018-07-19 17:59:37 +02:00
|
|
|
String[] months = LocaleInfo.getCurrentLocale().getDateTimeFormatInfo().monthsFull();
|
|
|
|
logger.log(Level.FINE, "Months: " + months.length);
|
|
|
|
|
2018-07-10 17:50:37 +02:00
|
|
|
String yearS = yearStart.getValue();
|
|
|
|
String monthS = monthStart.getValue();
|
2018-07-19 17:59:37 +02:00
|
|
|
|
|
|
|
String monthSN=null;
|
|
|
|
for(int i=0; i<months.length; i++){
|
|
|
|
if(months[i].compareTo(monthS)==0){
|
|
|
|
int v=i+1;
|
|
|
|
if(v>9){
|
|
|
|
monthSN=""+v;
|
|
|
|
} else {
|
|
|
|
monthSN="0"+v;
|
|
|
|
}
|
|
|
|
}
|
2018-07-10 17:50:37 +02:00
|
|
|
}
|
2018-07-19 17:59:37 +02:00
|
|
|
|
|
|
|
String dateStart = yearS + "-" + monthSN + "-01";
|
|
|
|
logger.fine("DateStart: " + dateStart);
|
|
|
|
|
2018-07-10 17:50:37 +02:00
|
|
|
String yearE = yearEnd.getValue();
|
|
|
|
String monthE = monthEnd.getValue();
|
2018-07-17 19:15:10 +02:00
|
|
|
|
2018-07-19 17:59:37 +02:00
|
|
|
String monthEN=null;
|
|
|
|
for(int i=0; i<months.length; i++){
|
|
|
|
if(months[i].compareTo(monthE)==0){
|
|
|
|
int v=i+1;
|
|
|
|
if(v>9){
|
|
|
|
monthEN=""+v;
|
|
|
|
} else {
|
|
|
|
monthEN="0"+v;
|
|
|
|
}
|
|
|
|
}
|
2018-07-10 17:50:37 +02:00
|
|
|
}
|
2018-07-19 17:59:37 +02:00
|
|
|
|
|
|
|
String dateEnd = yearE + "-" + monthEN + "-01";
|
|
|
|
logger.fine("DateEnd: " + dateEnd);
|
2018-07-17 19:15:10 +02:00
|
|
|
|
|
|
|
RequestReportData requestReportData = new RequestReportData(scopeData, dateStart, dateEnd);
|
2018-07-10 17:50:37 +02:00
|
|
|
getUiHandlers().getReport(requestReportData);
|
2018-07-17 19:15:10 +02:00
|
|
|
|
2018-07-06 17:48:46 +02:00
|
|
|
}
|
|
|
|
|
2018-07-05 18:29:38 +02:00
|
|
|
}
|