You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.5 KiB
Java
112 lines
3.5 KiB
Java
/**
|
|
*
|
|
*/
|
|
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<KPI> populationTypeProvider = new ListDataProvider<KPI>();
|
|
|
|
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 <T> 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<String> dataProvider = new ListDataProvider<String>();
|
|
dataProvider.getList().add("KPIs");
|
|
TextCell textCell = new TextCell();
|
|
return new DefaultNodeInfo<String>(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<KPI> dataProvider = new ListDataProvider<KPI>();
|
|
// dataProvider.getList().addAll(listOfKpi);
|
|
//List<KPI> listOfKpi = ((PopulationType) value).getListKPI();
|
|
KPICell kpi = new KPICell(null);
|
|
PopulationType populationType = (PopulationType) value;
|
|
GWT.log("populationType: "+populationType);
|
|
List<KPI> listOfKpi = populationType.getListKPI();
|
|
populationTypeProvider.getList().addAll(listOfKpi);
|
|
return new DefaultNodeInfo<KPI>(populationTypeProvider, kpi);
|
|
|
|
}
|
|
else if (value instanceof KPI) {
|
|
// LEVEL 2 - LEAF.
|
|
// We want the children of the KPI. Return them.
|
|
KPI kpiValue = (KPI) value;
|
|
List<KPI> listOfKpi = kpiValue.getListKPI();
|
|
//populationTypeProvider.getList().addAll(listOfKpi);
|
|
//GWT.log("KPI type listOfKpi: " + listOfKpi.toString());
|
|
ListDataProvider<KPI> kpiProvider = new ListDataProvider<KPI>(listOfKpi);
|
|
AbstractCell<KPI> cell = null;
|
|
if(kpiValue.isLeaf()){
|
|
List<HasCell<KPI, ?>> hasCells = new ArrayList<HasCell<KPI, ?>>();
|
|
cell = new LeafCell(hasCells);
|
|
}else{
|
|
cell = new KPICell(null);
|
|
}
|
|
|
|
return new DefaultNodeInfo<KPI>(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;
|
|
}
|
|
|
|
}
|