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.DataTea;
import com.es.app.model.DataTeaDescripcion;
import com.es.app.model.GroupsData;
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.annotations.StyleSheet;
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;
@StyleSheet("styles_Control.css")
public class DataInsert extends CustomComponent {
private static final long serialVersionUID = 1584890206409722029L;
@AutoGenerated
private GridLayout mainLayout;
String id;
private MainComponent mainComponent;
/** Control de Instancias de la ventana **/
public int hashCode() {
return this.id.hashCode();
}
public void setId(String id) {
this.id = id;
}
/** Controles de Ventana **/
private cstMenu menuDescrip;
private cstMenu menuTEA;
private cstMenu menuGroups;
private Table tblDescrip;
private Table tblTEA;
private Table tblGroups;
private beansInsert beanInv = new beansInsert();
/** Controles de Tabla **/
TableControls controls = new TableControls();
public DataInsert(MainComponent mainComponent, String id) {
this.setMainComponent(mainComponent);
setId(id);
buildMainLayout();
setCompositionRoot(mainLayout);
addListeners();
}
private void addListeners() {
addListMenuActions();
addListMenuTea();
addListMenuGroup();
tblDescrip.addActionHandler(controls.new ActEstab());
tblDescrip.setTableFieldFactory(controls.new TableFactory());
tblTEA.addActionHandler(controls.new ActEstab());
tblTEA.setTableFieldFactory(controls.new TableFactory());
tblGroups.addActionHandler(controls.new ActEstab());
tblGroups.setTableFieldFactory(controls.new TableFactory());
}
private void updDescrip() {
try {
getTblDescrip().setContainerDataSource(
beanInv.getDescriptionsForTEA());
} catch (Exception e) {
}
getTblDescrip().setVisibleColumns(
GstFormat.setOrdCol(getTblDescrip(), 5, 2));
getTblDescrip().setColumnHeaders("Descripcion", "Fecha Ingreso");
}
private void addListMenuActions() {
menuDescrip.getBtnEdit().addClickListener(new ClickListener() {
private static final long serialVersionUID = -778260493481658721L;
@Override
public void buttonClick(ClickEvent event) {
tblDescrip.setEditable(true);
}
});
menuDescrip.getBtnCancel().addClickListener(new ClickListener() {
private static final long serialVersionUID = -1757886248973962019L;
@Override
public void buttonClick(ClickEvent event) {
tblDescrip.setEditable(false);
updDescrip();
}
});
menuDescrip.getBtnSave().addClickListener(new ClickListener() {
private static final long serialVersionUID = -1442506026472679058L;
@Override
public void buttonClick(ClickEvent event) {
if (saveTables(tblDescrip)) {
GstFormat.showNotifiSave(true);
updDescrip();
}
try {
tblDescrip.setEditable(false);
} catch (Exception e) {
}
}
});
menuDescrip.getBtnRefresh().addClickListener(new ClickListener() {
private static final long serialVersionUID = -990394689393381670L;
@Override
public void buttonClick(ClickEvent event) {
updDescrip();
tblDescrip.refreshRowCache();
}
});
}
private void updTea() {
try {
getTblTEA().setContainerDataSource(beanInv.getdataTEA());
} catch (Exception e) {
}
getTblTEA().setVisibleColumns(
GstFormat.setOrdCol(getTblTEA(), 8, 2, 4, 1, 6, 9));
getTblTEA().setColumnHeaders("Tratemiento", "Descripcion", "Gain",
"Cost. Unitario", "Lower", "Upper");
}
private void updGroup() {
try {
getTblGroups().setContainerDataSource(beanInv.getGroupData());
} catch (Exception e) {
}
getTblGroups().setVisibleColumns(
GstFormat.setOrdCol(getTblGroups(), 4, 1));
getTblGroups().setColumnHeaders("Nombre Grupo", "Fecha Ingreso");
}
private void addListMenuTea() {
menuTEA.getBtnEdit().addClickListener(new ClickListener() {
private static final long serialVersionUID = 833276341151683019L;
@Override
public void buttonClick(ClickEvent event) {
tblTEA.setEditable(true);
}
});
menuTEA.getBtnCancel().addClickListener(new ClickListener() {
/**
*
*/
private static final long serialVersionUID = -1442506026472679058L;
@Override
public void buttonClick(ClickEvent event) {
tblTEA.setEditable(false);
updTea();
}
});
menuTEA.getBtnSave().addClickListener(new ClickListener() {
/**
*
*/
private static final long serialVersionUID = -990394689393381670L;
@Override
public void buttonClick(ClickEvent event) {
if (saveTables(tblTEA)) {
GstFormat.showNotifiSave(true);
updTea();
}
try {
tblTEA.setEditable(false);
} catch (Exception e) {
}
}
});
menuTEA.getBtnRefresh().addClickListener(new ClickListener() {
/**
*
*/
private static final long serialVersionUID = -4176153875292566821L;
@Override
public void buttonClick(ClickEvent event) {
updTea();
getTblTEA().refreshRowCache();
}
});
}
private void addListMenuGroup() {
menuGroups.getBtnEdit().addClickListener(new ClickListener() {
private static final long serialVersionUID = 3933202741919764225L;
@Override
public void buttonClick(ClickEvent event) {
getTblGroups().setEditable(true);
}
});
menuGroups.getBtnCancel().addClickListener(new ClickListener() {
private static final long serialVersionUID = -6685345178806445697L;
@Override
public void buttonClick(ClickEvent event) {
getTblGroups().setEditable(false);
updGroup();
}
});
menuGroups.getBtnSave().addClickListener(new ClickListener() {
private static final long serialVersionUID = -53731398021731445L;
@Override
public void buttonClick(ClickEvent event) {
if (saveTables(getTblGroups())) {
GstFormat.showNotifiSave(true);
updGroup();
}
try {
getTblGroups().setEditable(false);
} catch (Exception e) {
}
}
});
menuGroups.getBtnRefresh().addClickListener(new ClickListener() {
private static final long serialVersionUID = -5998405794926974485L;
@Override
public void buttonClick(ClickEvent event) {
updGroup();
getTblGroups().refreshRowCache();
}
});
}
/** 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 == getTblTEA()) {
for (Object item : table.getContainerDataSource().getItemIds()) {
DataTea s = (DataTea) item;
if (s.isNew())
objSave.add(s);
else
objUpdate.add(s);
}
} else if (table == getTblDescrip()) {
for (Object item : table.getContainerDataSource().getItemIds()) {
DataTeaDescripcion s = (DataTeaDescripcion) item;
if (s.isNew())
objSave.add(s);
else
objUpdate.add(s);
}
} else if (table == getTblGroups()) {
for (Object item : table.getContainerDataSource().getItemIds()) {
GroupsData s = (GroupsData) 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;
}
@AutoGenerated
private void buildMainLayout() {
// the main layout and components will be created here
mainLayout = new GridLayout();
mainLayout.setMargin(true);
mainLayout.setSpacing(true);
// Descrip
menuDescrip = new cstMenu();
menuDescrip.setCaption("DESCRIPCIONES");
mainLayout.addComponent(menuDescrip);
mainLayout.addComponent(buildGrlDescrip());
// TEA
menuTEA = new cstMenu();
menuTEA.setCaption("TEA");
mainLayout.addComponent(menuTEA);
mainLayout.addComponent(buildGrlTEA());
// GROUPS
menuGroups = new cstMenu();
menuGroups.setCaption("GRUPOS");
mainLayout.addComponent(menuGroups);
mainLayout.addComponent(buildGrlGROUP());
}
private GridLayout buildGrlTEA() {
GridLayout grlTEA = new GridLayout();
grlTEA.setWidth("100%");
grlTEA.setHeight("-1px");
// btn_tea = new Button("TEA");
// grlTEA.addComponent(btn_tea);
tblTEA = new Table();
tblTEA.setImmediate(true);
tblTEA.setSelectable(true);
// tblTEA.setWidth("-1px");
tblTEA.setPageLength(13);
updTea();
grlTEA.addComponent(tblTEA);
return grlTEA;
}
private GridLayout buildGrlGROUP() {
GridLayout grlGroup = new GridLayout();
grlGroup.setWidth("100%");
grlGroup.setHeight("-1px");
// btn_tea = new Button("TEA");
// grlTEA.addComponent(btn_tea);
tblGroups = new Table();
tblGroups.setImmediate(true);
tblGroups.setSelectable(true);
// tblTEA.setWidth("-1px");
tblGroups.setPageLength(13);
updGroup();
grlGroup.addComponent(tblGroups);
return grlGroup;
}
private GridLayout buildGrlDescrip() {
GridLayout grlDescrip = new GridLayout();
grlDescrip.setWidth("100%");
grlDescrip.setHeight("-1px");
tblDescrip = new Table();
tblDescrip.setImmediate(true);
tblDescrip.setSelectable(true);
// tblACTIONS.setWidth("-1px");
tblDescrip.setPageLength(13);
updDescrip();
grlDescrip.addComponent(tblDescrip);
return grlDescrip;
}
public MainComponent getMainComponent() {
return mainComponent;
}
public void setMainComponent(MainComponent mainComponent) {
this.mainComponent = mainComponent;
}
public Table getTblTEA() {
return tblTEA;
}
public void setTblTEA(Table tblTEA) {
this.tblTEA = tblTEA;
}
public Table getTblDescrip() {
return tblDescrip;
}
public void setTblDescrip(Table tblDescrip) {
this.tblDescrip = tblDescrip;
}
/**
* @return the tblGroups
*/
public Table getTblGroups() {
return tblGroups;
}
/**
* @param tblGroups
* the tblGroups to set
*/
public void setTblGroups(Table tblGroups) {
this.tblGroups = tblGroups;
}
}