123 lines
3.0 KiB
Java
123 lines
3.0 KiB
Java
|
/**
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
package org.gcube.portlets.user.performfishanalytics.client.view.totest;
|
||
|
|
||
|
import java.util.List;
|
||
|
|
||
|
import org.gcube.portlets.user.performfishanalytics.client.controllers.PerformFishAnalyticsController;
|
||
|
import org.gcube.portlets.user.performfishanalytics.client.event.SelectedKPIEvent;
|
||
|
import org.gcube.portlets.user.performfishanalytics.client.view.KPICell;
|
||
|
import org.gcube.portlets.user.performfishanalytics.shared.KPI;
|
||
|
|
||
|
import com.google.gwt.cell.client.Cell;
|
||
|
import com.google.gwt.cell.client.CheckboxCell;
|
||
|
import com.google.gwt.cell.client.CompositeCell;
|
||
|
import com.google.gwt.cell.client.FieldUpdater;
|
||
|
import com.google.gwt.cell.client.HasCell;
|
||
|
import com.google.gwt.core.client.GWT;
|
||
|
import com.google.gwt.dom.client.Element;
|
||
|
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
||
|
import com.google.gwt.view.client.SingleSelectionModel;
|
||
|
|
||
|
/**
|
||
|
* The Class LeafCell.
|
||
|
*
|
||
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||
|
* Mar 4, 2019
|
||
|
*/
|
||
|
public class LeafCell extends CompositeCell<KPI> {
|
||
|
|
||
|
private final SingleSelectionModel<KPI> multiSelectionModel =
|
||
|
new SingleSelectionModel<KPI>();
|
||
|
private List<HasCell<KPI, ?>> hasCells;
|
||
|
|
||
|
/**
|
||
|
* @param hasCells
|
||
|
*/
|
||
|
public LeafCell(List<HasCell<KPI, ?>> hasCells) {
|
||
|
|
||
|
super(hasCells);
|
||
|
this.hasCells = hasCells;
|
||
|
|
||
|
hasCells.add(new HasCell<KPI, Boolean>() {
|
||
|
|
||
|
private CheckboxCell cell = new CheckboxCell(true, true);
|
||
|
|
||
|
public Cell<Boolean> getCell() {
|
||
|
|
||
|
return cell;
|
||
|
}
|
||
|
|
||
|
public FieldUpdater<KPI, Boolean> getFieldUpdater() {
|
||
|
|
||
|
return new FieldUpdater<KPI, Boolean>() {
|
||
|
|
||
|
@Override
|
||
|
public void update(int index, KPI object, Boolean value) {
|
||
|
|
||
|
// TODO Auto-generated method stub
|
||
|
GWT.log("Checked: " + object.getName() + " value: " +
|
||
|
value);
|
||
|
PerformFishAnalyticsController.eventBus.fireEvent(new SelectedKPIEvent(
|
||
|
null, object, value));
|
||
|
// cell.set(value);
|
||
|
// dataGrid.redraw();
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
public Boolean getValue(KPI object) {
|
||
|
|
||
|
return multiSelectionModel.isSelected(object);
|
||
|
}
|
||
|
});
|
||
|
hasCells.add(new HasCell<KPI, KPI>() {
|
||
|
|
||
|
private KPICell cell = new KPICell(null);
|
||
|
|
||
|
public Cell<KPI> getCell() {
|
||
|
|
||
|
return cell;
|
||
|
}
|
||
|
|
||
|
public FieldUpdater<KPI, KPI> getFieldUpdater() {
|
||
|
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
public KPI getValue(KPI object) {
|
||
|
|
||
|
return object;
|
||
|
}
|
||
|
});
|
||
|
// TODO Auto-generated constructor stub
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void render(Context context, KPI value, SafeHtmlBuilder sb) {
|
||
|
|
||
|
sb.appendHtmlConstant("<table><tbody><tr>");
|
||
|
sb.appendHtmlConstant(value.getName());
|
||
|
sb.appendHtmlConstant("</tr></tbody></table>");
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected Element getContainerElement(Element parent) {
|
||
|
|
||
|
// Return the first TR element in the table.
|
||
|
return parent.getFirstChildElement().getFirstChildElement().getFirstChildElement();
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected <X> void render(
|
||
|
Context context, KPI value, SafeHtmlBuilder sb, HasCell<KPI, X> hasCell) {
|
||
|
|
||
|
Cell<X> cell = hasCell.getCell();
|
||
|
sb.appendHtmlConstant("<td>");
|
||
|
cell.render(context, hasCell.getValue(value), sb);
|
||
|
sb.appendHtmlConstant("</td>");
|
||
|
}
|
||
|
}
|