Cambiado el egresotablemodel para que acepte un egreso como modelo para llenar la tabla
This commit is contained in:
@@ -57,12 +57,7 @@ public class CajaController {
|
||||
private void fillEgresosTable() {
|
||||
for(Egreso egreso: this.egresoDAO.findAll()){
|
||||
TipoEgreso tipoEgreso = tipoEgresoDAO.findById(egreso.getTipo()).get(0);
|
||||
view.getEgresosTableModel().addRow(new String[]{
|
||||
egreso.getNro(),
|
||||
egreso.getDescripcion(),
|
||||
String.valueOf(egreso.getValor()),
|
||||
tipoEgreso.getNombre()
|
||||
});
|
||||
view.getEgresosTableModel().addRow(egreso);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,15 +67,10 @@ public class CajaController {
|
||||
String descripcion = this.view.getDescripcionField().getText();
|
||||
String valor = this.view.getValorField().getText();
|
||||
TipoEgreso tipo = (TipoEgreso) this.view.getTipoCombo().getSelectedItem();
|
||||
this.addToTable(nro, descripcion, valor, tipo.getNombre());
|
||||
this.createEgreso(nro, descripcion, valor, tipo.getId());
|
||||
Egreso egreso = this.createEgreso(nro, descripcion, valor, tipo.getId());
|
||||
this.view.getEgresosTableModel().addRow(egreso);
|
||||
this.updateTotalEgresos();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void addToTable(String nro, String descripcion, String valor, String tipo){
|
||||
view.getEgresosTableModel().addRow(new String[]{nro,descripcion,valor,tipo});
|
||||
}
|
||||
|
||||
private void updateTotalEgresos(){
|
||||
@@ -88,13 +78,14 @@ public class CajaController {
|
||||
this.view.getTotalEgresosField().setText(String.valueOf(total));
|
||||
}
|
||||
|
||||
private void createEgreso(String nro, String descripcion, String valor, int tipo){
|
||||
private Egreso createEgreso(String nro, String descripcion, String valor, int tipo){
|
||||
Egreso egreso = new Egreso();
|
||||
egreso.setValor(Integer.valueOf(valor));
|
||||
egreso.setDescripcion(descripcion);
|
||||
egreso.setNro(nro);
|
||||
egreso.setTipo(tipo);
|
||||
egresoDAO.insertEgreso(egreso);
|
||||
return egreso;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -24,12 +24,19 @@
|
||||
|
||||
package danielcortes.xyz.views.components;
|
||||
|
||||
public class EgresosTableModel extends TableModel {
|
||||
import danielcortes.xyz.models.Egreso;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class EgresosTableModel extends AbstractTableModel {
|
||||
private String[] columns;
|
||||
private ArrayList<Egreso> rows;
|
||||
|
||||
public EgresosTableModel(){
|
||||
super();
|
||||
this.columns = new String[]{"N°", "Descripcion", "Valor", "Tipo"};
|
||||
this.rows = new ArrayList<>();
|
||||
}
|
||||
|
||||
public String getColumnName(int col) {
|
||||
@@ -39,4 +46,27 @@ public class EgresosTableModel extends TableModel {
|
||||
public int getColumnCount() {
|
||||
return columns.length;
|
||||
}
|
||||
|
||||
public int getRowCount() {
|
||||
return rows.size();
|
||||
}
|
||||
|
||||
public void addRow(Egreso egreso) {
|
||||
rows.add(egreso);
|
||||
this.fireTableRowsInserted(0,getRowCount()-1);
|
||||
}
|
||||
|
||||
public Object getValueAt(int row, int col) {
|
||||
switch (col){
|
||||
case 0:
|
||||
return rows.get(row).getNro();
|
||||
case 1:
|
||||
return rows.get(row).getDescripcion();
|
||||
case 2:
|
||||
return rows.get(row).getValor();
|
||||
case 3:
|
||||
return rows.get(row).getTipo();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 Daniel Cortes
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package danielcortes.xyz.views.components;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class TableModel extends AbstractTableModel {
|
||||
private ArrayList<String[]> rows = new ArrayList<>();
|
||||
|
||||
public int getRowCount() {
|
||||
return rows.size();
|
||||
}
|
||||
|
||||
public void addRow(String[] data){
|
||||
rows.add(data);
|
||||
this.fireTableRowsInserted(0,getRowCount()-1);
|
||||
}
|
||||
|
||||
public Object getValueAt(int row, int col) {
|
||||
return rows.get(row)[col];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user