package com.es.app.ui;
import java.util.ArrayList;
import com.es.app.customs.cstMenu;
import com.es.app.data.GstData;
import com.es.app.data.GstFormat;
import com.es.app.model.DataInventario;
import com.es.app.model.ProyectoVia;
import com.es.app.ui.component.TableControls;
import com.es.app.ui.data.beansInsert;
import com.es.universalwebframe.composite.MainComponent;
import com.vaadin.annotations.AutoGenerated;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;
public class ViewProyec extends CustomComponent {
private static final long serialVersionUID = 6512924276168770339L;
@AutoGenerated
private VerticalLayout mainLayout;
private MainComponent mainComponent;
private String id;
/** Controles de Tabla **/
TableControls controls = new TableControls();
/** Gestor de datos **/
private beansInsert beanInv = new beansInsert();
private ProyectoVia proyectoVia;
/** Controles de Ventana **/
private cstMenu menuInvent;
private Table tblInvent;
private GridLayout grlInventori;
/** Control de Instancias de la ventana **/
public int hashCode() {
return this.id.hashCode();
}
private void addListeners() {
addListMenuInvnt();
tblInvent.addActionHandler(controls.new ActEstab());
tblInvent.setTableFieldFactory(controls.new TableFactory());
}
public ViewProyec(MainComponent mainComponent, String id) {
this.setMainComponent(mainComponent);
setId(id);
buildMainLayout();
setCompositionRoot(mainLayout);
addListeners();
loadData();
}
private void loadData() {
if (proyectoVia == null) {
} else {
updInvent();
}
}
// private Window dataInv() {
// final Window window = new Window("Window");
// final VerticalLayout content = new VerticalLayout();
// //
// window.setCaption("Datos de Inventario");
// GridLayout comp = new GridLayout();
// comp.setColumns(2);
// comp.setMargin(true);
// //
// Object s = GstData.getSingleObject("Select a From DataInventario a",
// true);
// DataInventario invs = s == null ? new DataInventario()
// : (DataInventario) s;
// //
// comp.addComponent(new cstMenu(), 0, 0, 1, 0);
// comp.addComponent(GstFormat.etiqueta("Condición:"));
// comp.addComponent(new TextField("", invs.getCondicion() + ""));
// comp.addComponent(GstFormat.etiqueta("Grupo:"));
// comp.addComponent(new TextField("", invs.getGrupo()));
// comp.addComponent(GstFormat.etiqueta("LixQij:"));
// comp.addComponent(new TextField("", invs.getLixqij() + ""));
// comp.addComponent(GstFormat.etiqueta("MinLos:"));
// comp.addComponent(new TextField("", invs.getMinLos() + ""));
// comp.addComponent(GstFormat.etiqueta("Segmento:"));
// comp.addComponent(new TextField("", invs.getNombSegmento()));
// comp.addComponent(GstFormat.etiqueta("Size:"));
// comp.addComponent(new TextField("", invs.getSize() + ""));
// //
// content.addComponent(comp);
// window.setContent(content);
// window.center();
// window.setModal(true);
// return window;
// }
// private Window dataTea() {
// final Window window = new Window("Window");
// final VerticalLayout content = new VerticalLayout();
// content.setSizeUndefined();
// window.setCaption("Datos de TEA");
// GridLayout comp = new GridLayout();
// comp.setColumns(2);
// comp.setMargin(true);
// //
// DataTea tea = (DataTea) GstData.getSingleObject(
// "Select a From DataTea a", true);
// //
// comp.addComponent(new cstMenu(), 0, 0, 1, 0);
// comp.addComponent(GstFormat.etiqueta("Cost Unitary:"));
// comp.addComponent(new TextField("", tea.getCostUnitary() + ""));
// comp.addComponent(GstFormat.etiqueta("Gain:"));
// comp.addComponent(new TextField("", tea.getGain() + ""));
// comp.addComponent(GstFormat.etiqueta("Lower:"));
// comp.addComponent(new TextField("", tea.getLower() + ""));
// comp.addComponent(GstFormat.etiqueta("Tratamiento:"));
// comp.addComponent(new TextField("", tea.getTratamiento() + ""));
// comp.addComponent(GstFormat.etiqueta("Upper:"));
// comp.addComponent(new TextField("", tea.getUpper() + ""));
// comp.addComponent(GstFormat.etiqueta("DataTea:"));
// comp.addComponent(new ComboBox());
// comp.addComponent(GstFormat.etiqueta("DataTea - Descripcion:"));
// comp.addComponent(new ComboBox());
// //
// content.addComponent(comp);
// window.setContent(content);
// window.center();
// window.setModal(true);
// return window;
// }
@AutoGenerated
private void buildMainLayout() {
// the main layout and components will be created here
mainLayout = new VerticalLayout();
mainLayout.setMargin(true);
mainLayout.setSpacing(true);
// Seleccionar Proyecto Vial
mainLayout.addComponent(buildGrlProyecto());
// Informacion Contenedora de Proyecto
mainLayout.addComponent(buildGrlInvent());
}
private GridLayout buildGrlProyecto() {
return new GridLayout();
}
private GridLayout buildGrlInvent() {
grlInventori = new GridLayout();
grlInventori.setWidth("100%");
grlInventori.setHeight("-1px");
// Inventario
menuInvent = new cstMenu();
menuInvent.setCaption("INVENTARIO");
grlInventori.addComponent(menuInvent);
tblInvent = new Table();
tblInvent.setImmediate(true);
tblInvent.setSelectable(true);
// tblInvent.setWidth("-1px");
tblInvent.setPageLength(13);
grlInventori.addComponent(tblInvent);
return grlInventori;
}
private void addListMenuInvnt() {
menuInvent.getBtnEdit().addClickListener(new ClickListener() {
private static final long serialVersionUID = 3519194415421317767L;
@Override
public void buttonClick(ClickEvent event) {
try {
tblInvent.setEditable(true);
} catch (Exception e) {
}
}
});
menuInvent.getBtnCancel().addClickListener(new ClickListener() {
private static final long serialVersionUID = -778260493481658721L;
@Override
public void buttonClick(ClickEvent event) {
tblInvent.setEditable(false);
updInvent();
}
});
menuInvent.getBtnSave().addClickListener(new ClickListener() {
private static final long serialVersionUID = 833276341151683019L;
@Override
public void buttonClick(ClickEvent event) {
if (saveTables(tblInvent)) {
GstFormat.showNotifiSave(true);
updInvent();
}
try {
tblInvent.setEditable(false);
} catch (Exception e) {
}
}
});
}
private void updInvent() {
try {
getTblInvent().setContainerDataSource(beanInv.getdataInv());
} catch (Exception e) {
}
getTblInvent().setVisibleColumns(
GstFormat.setOrdCol(getTblInvent(), 8, 7, 9, 2, 1, 5, 4));
getTblInvent().setColumnHeaders("Proyecto", "Segment name", "Size",
"Group", "Condition", "Min LOS", "Li x Qij");
}
/** Grabar datos de tablas **/
private boolean saveTables(Table table) {
ArrayList<Object> objSave = new ArrayList<Object>();
ArrayList<Object> objUpdate = new ArrayList<Object>();
boolean bn;
if (table == getTblInvent()) {
for (Object item : table.getContainerDataSource().getItemIds()) {
DataInventario s = (DataInventario) item;
if (s.isNew())
objSave.add(s);
else
objUpdate.add(s);
}
}
bn = GstData.saveObject(objSave);
if (objUpdate.size() > 0)
bn = GstData.updateObject(objUpdate);
return bn;
}
/**
* @return the mainComponent
*/
public MainComponent getMainComponent() {
return mainComponent;
}
/**
* @param mainComponent
* the mainComponent to set
*/
public void setMainComponent(MainComponent mainComponent) {
this.mainComponent = mainComponent;
}
/**
* @return the id
*/
public String getId() {
return id;
}
/**
* @param id
* the id to set
*/
public void setId(String id) {
this.id = id;
}
/**
* @return the tblInvent
*/
public Table getTblInvent() {
return tblInvent;
}
/**
* @param tblInvent
* the tblInvent to set
*/
public void setTblInvent(Table tblInvent) {
this.tblInvent = tblInvent;
}
}