Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 15be56a

Browse files
committed
Listar y dar de altas tiendas terminado
1 parent dca8f4e commit 15be56a

File tree

5 files changed

+106
-3
lines changed

5 files changed

+106
-3
lines changed

‎HolaDb4o/grancasas.db4o

801 Bytes
Binary file not shown.

‎HolaDb4o/src/org/sfaci/holadb4o/gui/HolaDb4o.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class HolaDb4o {
5959

6060
private JScrollPane scrollPane;
6161
private JScrollPane scrollPane_1;
62-
private JTable tablaTiendas;
62+
private JTablaTiendas tablaTiendas;
6363
private JTable tablaCentros;
6464

6565
/**
@@ -92,6 +92,7 @@ public HolaDb4o() {
9292
private void inicializar() {
9393

9494
conectar();
95+
tablaTiendas.listar();
9596
}
9697

9798
/**
@@ -163,6 +164,7 @@ public void windowClosing(WindowEvent arg0) {
163164
frmHolaDbo.getContentPane().add(getToolBar(), BorderLayout.NORTH);
164165
frmHolaDbo.getContentPane().add(getTab(), BorderLayout.CENTER);
165166
frmHolaDbo.setJMenuBar(getMenuBar());
167+
frmHolaDbo.setLocationRelativeTo(null);
166168
}
167169

168170
public JLabel getTfEstado() {
@@ -281,7 +283,7 @@ public JScrollPane getScrollPane_1() {
281283
}
282284
public JTable getTablaTiendas() {
283285
if (tablaTiendas == null) {
284-
tablaTiendas = new JTable();
286+
tablaTiendas = new JTablaTiendas();
285287
}
286288
return tablaTiendas;
287289
}
Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,83 @@
11
package org.sfaci.holadb4o.gui;
22

3-
public class JTablaTiendas {
3+
import java.util.List;
4+
5+
import javax.swing.JTable;
6+
import javax.swing.table.DefaultTableModel;
7+
8+
import org.sfaci.holadb4o.base.Tienda;
9+
import org.sfaci.holadb4o.util.Constantes;
10+
import org.sfaci.holadb4o.util.Util;
11+
12+
/**
13+
* Tabla que lista datos de Tiendas
14+
* @author Santiago Faci
15+
* @version 1.0
16+
*
17+
*/
18+
public class JTablaTiendas extends JTable {
19+
20+
private DefaultTableModel modeloDatos;
21+
22+
public JTablaTiendas() {
23+
super();
24+
25+
inicializar();
26+
}
27+
28+
/**
29+
* Inicializa la tabla, creando las columnas
30+
*/
31+
private void inicializar() {
32+
33+
modeloDatos = new DefaultTableModel() {
34+
@Override
35+
public boolean isCellEditable(int fila, int columna) {
36+
return false;
37+
}
38+
};
39+
40+
modeloDatos.addColumn(Constantes.NOMBRE);
41+
modeloDatos.addColumn(Constantes.DESCRIPCION);
42+
modeloDatos.addColumn(Constantes.NUMERO_LOCAL);
43+
modeloDatos.addColumn(Constantes.FECHA_APERTURA);
44+
45+
setModel(modeloDatos);
46+
}
47+
48+
/**
49+
* Lista todas las tiendas en la tabla
50+
*/
51+
public void listar() {
52+
53+
List<Tienda> tiendas = Util.db.query(Tienda.class);
54+
cargarFilas(tiendas);
55+
}
56+
57+
/*
58+
* 'Pinta' los datos en el JTable
59+
*/
60+
private void cargarFilas(List<Tienda> tiendas) {
61+
62+
modeloDatos.setNumRows(0);
63+
64+
for (Tienda tienda : tiendas) {
65+
Object[] fila = new Object[]{
66+
tienda.getNombre(),
67+
tienda.getDescripcion(),
68+
String.valueOf(tienda.getNumeroLocal()),
69+
tienda.getFechaApertura().toString()};
70+
71+
modeloDatos.addRow(fila);
72+
}
73+
}
74+
75+
/**
76+
* Elimina todo el contenido del control JTable
77+
*/
78+
public void vaciar() {
79+
80+
modeloDatos.setNumRows(0);
81+
}
482

583
}

‎HolaDb4o/src/org/sfaci/holadb4o/gui/JTienda.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import org.sfaci.holadb4o.util.Util.Accion;
1515

1616
import com.toedter.calendar.JDateChooser;
17+
import java.awt.event.ActionListener;
18+
import java.awt.event.ActionEvent;
1719

1820
/**
1921
* Ventana para recogida de datos de Tiendas
@@ -69,12 +71,17 @@ private void aceptar() {
6971
tfNumeroLocal.setText("0");
7072
tienda.setNumeroLocal(Integer.parseInt(tfNumeroLocal.getText()));
7173
tienda.setFechaApertura(dcFechaApertura.getDate());
74+
75+
accion = Accion.ACEPTAR;
76+
setVisible(false);
7277
}
7378

7479
private void cancelar() {
7580

7681
tienda = null;
7782
accion = Accion.CANCELAR;
83+
84+
setVisible(false);
7885
}
7986

8087
/**
@@ -102,16 +109,27 @@ public JTienda() {
102109
getContentPane().add(buttonPane, BorderLayout.SOUTH);
103110
{
104111
JButton okButton = new JButton("OK");
112+
okButton.addActionListener(new ActionListener() {
113+
public void actionPerformed(ActionEvent e) {
114+
aceptar();
115+
}
116+
});
105117
okButton.setActionCommand("OK");
106118
buttonPane.add(okButton);
107119
getRootPane().setDefaultButton(okButton);
108120
}
109121
{
110122
JButton cancelButton = new JButton("Cancel");
123+
cancelButton.addActionListener(new ActionListener() {
124+
public void actionPerformed(ActionEvent e) {
125+
cancelar();
126+
}
127+
});
111128
cancelButton.setActionCommand("Cancel");
112129
buttonPane.add(cancelButton);
113130
}
114131
}
132+
setLocationRelativeTo(null);
115133
}
116134
public JLabel getLblNewLabel() {
117135
if (lblNewLabel == null) {

‎HolaDb4o/src/org/sfaci/holadb4o/util/Constantes.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ public class Constantes {
1212

1313
public static final int TIENDA = 0;
1414
public static final int CENTRO_COMERCIAL = 1;
15+
16+
public static final String NOMBRE = "Nombre";
17+
public static final String DESCRIPCION = "Descripción";
18+
public static final String NUMERO_LOCAL = "Núm. Local";
19+
public static final String FECHA_APERTURA = "Fecha Apertura";
1520
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /