accounting-dashboard/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/ReportAreaView.java

168 lines
4.7 KiB
Java

package org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.logging.Logger;
import javax.inject.Inject;
import org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart;
import org.gcube.portlets.user.accountingdashboard.client.resources.AppResources;
import org.gcube.portlets.user.accountingdashboard.shared.data.ReportData;
import org.gcube.portlets.user.accountingdashboard.shared.data.ReportElementData;
import com.github.gwtbootstrap.client.ui.Tab;
import com.github.gwtbootstrap.client.ui.TabPanel;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;
import com.gwtplatform.mvp.client.ViewWithUiHandlers;
/**
*
* @author Giancarlo Panichi
*
*/
public class ReportAreaView extends ViewWithUiHandlers<ReportAreaPresenter>
implements ReportAreaPresenter.ReportAreaView {
private static Logger logger = java.util.logging.Logger.getLogger("");
interface Binder extends UiBinder<Widget, ReportAreaView> {
}
@UiField
HTMLPanel reportPanel;
private AppResources resources;
@Inject
ReportAreaView(Binder uiBinder, AppResources resources) {
this.resources = resources;
init();
initWidget(uiBinder.createAndBindUi(this));
/*
RecordData recordData1 = new RecordData();
recordData1.setX("Gennaio");
recordData1.setY(3d);
RecordData recordData2 = new RecordData();
recordData2.setX("Febbraio");
recordData2.setY(2d);
RecordData recordData3 = new RecordData();
recordData3.setX("Marzo");
recordData3.setY(4d);
RecordData[] dataRow1 = new RecordData[2];
dataRow1[0] = recordData1;
dataRow1[1] = recordData2;
dataRow1[2] = recordData3;
RecordData recordData4 = new RecordData();
recordData4.setX("Gennaio");
recordData4.setY(1d);
RecordData recordData5 = new RecordData();
recordData5.setX("Febbraio");
recordData5.setY(5d);
RecordData recordData6 = new RecordData();
recordData6.setX("Marzo");
recordData6.setY(2d);
RecordData[] dataRow2 = new RecordData[2];
dataRow2[0] = recordData4;
dataRow2[1] = recordData5;
dataRow2[2] = recordData6;
SeriesData seriesData1 = new SeriesData();
seriesData1.setLabel("Series1");
seriesData1.setDataRow(dataRow1);
SeriesData seriesData2 = new SeriesData();
seriesData2.setLabel("Series2");
seriesData2.setDataRow(dataRow2);
SeriesData[] serieses = new SeriesData[2];
serieses[0] = seriesData1;
serieses[1] = seriesData2;
ReportData rData = new ReportData();
ArrayList<ReportElementData> elements = new ArrayList<>();
ReportElementData reportElementData1 = new ReportElementData();
reportElementData1.setxAxis("XAxis");
reportElementData1.setyAxis("YAxis");
reportElementData1.setCategory("Category");
reportElementData1.setLabel("Label1");
reportElementData1.setSerieses(serieses);
elements.add(reportElementData1);
ReportElementData reportElementData2 = new ReportElementData();
reportElementData2.setxAxis("XAxis");
reportElementData2.setyAxis("YAxis");
reportElementData2.setCategory("Category");
reportElementData2.setLabel("Label2");
reportElementData2.setSerieses(serieses);
elements.add(reportElementData2);
rData.setElements(elements);
displayReportData(rData);*/
}
private void init() {
}
/**
* LABEL | | _ yaxis | _ | | | | || |_ | | || | |
* ---------------------------------------------------
*
*
* *Series_label1 *Series_label2 *Series_label3
*
* xAxis
*
*/
@Override
public void displayReportData(ReportData reportData) {
if (reportData == null) {
reportPanel.clear();
} else {
reportPanel.clear();
HashMap<String, ArrayList<Chart>> categories=new HashMap<>();
for (int i = 0; i < reportData.getElements().size(); i++) {
ReportElementData reportElementData=reportData.getElements().get(i);
ArrayList<Chart> category;
if(categories.containsKey(reportElementData.getCategory())){
category=categories.get(reportElementData.getCategory());
} else {
category=new ArrayList<>();
}
Chart chart = new Chart(resources, "report_" + i, reportElementData);
category.add(chart);
}
TabPanel tabPanel=new TabPanel();
for(String category:categories.keySet()){
Tab tab=new Tab();
HTMLPanel tabContent=new HTMLPanel("");
for(Chart chart:categories.get(category)){
tabContent.add(chart);
}
tab.add(tabContent);
tabPanel.add(tab);
}
reportPanel.add(tabPanel);
}
}
}