package net.helipilot50.stocktrade.client;
import java.util.ArrayList;
import java.util.List;
import net.helipilot50.stocktrade.model.Holding;
import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.data.BeanModelFactory;
import com.extjs.gxt.ui.client.data.BeanModelLookup;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.layout.FormData;
public class CustomerHoldingsPanel extends FormPanel {
ListStore<Holding> holdings;
private Grid<Holding> grid;
public CustomerHoldingsPanel() {
setSize("300px", "195px");
holdings = new ListStore<Holding>();
holdings.setMonitorChanges(true);
// final NumberFormat currency = NumberFormat.getCurrencyFormat();
// final NumberFormat number = NumberFormat.getFormat("0.00");
// final NumberCellRenderer<Grid<Holding>> numberRenderer = new NumberCellRenderer<Grid<Holding>>(currency);
//
// GridCellRenderer<Holding> change = new GridCellRenderer<Holding>() {
// public String render(Stock model, String property, ColumnData config, int rowIndex, int colIndex,
// ListStore<Holding> store, Grid<Holding> grid) {
// double val = (Double) model.get(property);
// String style = val < 0 ? "red" : GXT.isHighContrastMode ? "#00ff5a" : "green";
// String v = number.format(val);
//
// return "<span qtitle='" + cm.getColumnById(property).getHeader() + "' qtip='" + v
// + "' style='font-weight: bold;color:" + style + "'>" + v + "</span>";
// }
// };
setHeading("Holdings");
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
ColumnConfig clmncnfgStockName = new ColumnConfig("stockName", "Stock", 150);
configs.add(clmncnfgStockName);
ColumnConfig clmncnfgQuantity = new ColumnConfig("quantity", "Quantity", 60);
configs.add(clmncnfgQuantity);
ColumnConfig clmncnfgPrice = new ColumnConfig("price", "Price", 60);
configs.add(clmncnfgPrice);
ColumnModel cm = new ColumnModel(configs);
grid = new Grid<Holding>(holdings, cm);
add(grid, new FormData("-5 -10"));
grid.setSize("", "");
grid.setBorders(true);
}
public void setHoldings(List<Holding> holdings){
this.holdings.removeAll();
this.holdings.add(holdings);
}
public Holding getSelectedHolding(){
return this.grid.getSelectionModel().getSelectedItem();
}
}