/** * */ package org.gcube.portlets.user.performfishanalytics.client.view.totest; import java.util.ArrayList; import java.util.List; import org.gcube.portlets.user.performfishanalytics.client.view.KPICell; import org.gcube.portlets.user.performfishanalytics.shared.KPI; import org.gcube.portlets.user.performfishanalytics.shared.PopulationType; import com.google.gwt.cell.client.AbstractCell; import com.google.gwt.cell.client.HasCell; import com.google.gwt.cell.client.TextCell; import com.google.gwt.core.shared.GWT; import com.google.gwt.view.client.ListDataProvider; import com.google.gwt.view.client.TreeViewModel; /** * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * Mar 4, 2019 */ public class NewCustomTreeModel implements TreeViewModel { private ListDataProvider populationTypeProvider = new ListDataProvider(); public void setNewBatchType(PopulationType populationType) { //GWT.log("Displayng KPI for: " + populationType.toString()); if (this.populationTypeProvider != null) { //removing all data from base data provider this.populationTypeProvider.getList().clear(); this.populationTypeProvider.getList().addAll(populationType.getListKPI()); } } /** * Get the {@link NodeInfo} that provides the children of the specified * value. */ public NodeInfo getNodeInfo(T value) { GWT.log("Get Node Info fired: " + value); if (value == null) { // LEVEL 0. // We passed null as the root value. Create a fake root KPIs PopulationType rootKPI = new PopulationType("", "KPIs", "", "", null); rootKPI.setListKPI(rootKPI.getListKPI()); ListDataProvider dataProvider = new ListDataProvider(); dataProvider.getList().add("KPIs"); TextCell textCell = new TextCell(); return new DefaultNodeInfo(dataProvider, textCell); } else if (value instanceof PopulationType) { // LEVEL 1. // We want the children of PopulationType. Getting its list of KPI. // //PopulationTypeCell populatioCell = new PopulationTypeCell(null); // ListDataProvider dataProvider = new ListDataProvider(); // dataProvider.getList().addAll(listOfKpi); //List listOfKpi = ((PopulationType) value).getListKPI(); KPICell kpi = new KPICell(null); PopulationType populationType = (PopulationType) value; GWT.log("populationType: "+populationType); List listOfKpi = populationType.getListKPI(); populationTypeProvider.getList().addAll(listOfKpi); return new DefaultNodeInfo(populationTypeProvider, kpi); } else if (value instanceof KPI) { // LEVEL 2 - LEAF. // We want the children of the KPI. Return them. KPI kpiValue = (KPI) value; List listOfKpi = kpiValue.getListKPI(); //populationTypeProvider.getList().addAll(listOfKpi); //GWT.log("KPI type listOfKpi: " + listOfKpi.toString()); ListDataProvider kpiProvider = new ListDataProvider(listOfKpi); AbstractCell cell = null; if(kpiValue.isLeaf()){ List> hasCells = new ArrayList>(); cell = new LeafCell(hasCells); }else{ cell = new KPICell(null); } return new DefaultNodeInfo(kpiProvider, cell); } return null; } /** * Check if the specified value represents a leaf node. Leaf nodes cannot be * opened. */ public boolean isLeaf(Object value) { // The leaf nodes are the songs, which are Strings. if (value instanceof KPI) { KPI toKPI = (KPI) value; return toKPI.isLeaf(); } return false; } }