first commit
This commit is contained in:
@@ -3,6 +3,7 @@ package prueba.aadd.swing;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.swing.DefaultListCellRenderer;
|
||||
import javax.swing.DefaultListModel;
|
||||
@@ -15,12 +16,10 @@ import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import org.palomafp.aadd.inm.dao.IContinenteDAO;
|
||||
import org.palomafp.aadd.inm.dao.IPaisDAO;
|
||||
import org.palomafp.aadd.inm.dao.impl.ContinenteDaoCSV;
|
||||
import org.palomafp.aadd.inm.dao.impl.PaisDaoText;
|
||||
import org.palomafp.aadd.inm.model.Continente;
|
||||
import org.palomafp.aadd.inm.model.Pais;
|
||||
import org.palomafp.aadd.dta.dao.IContinenteDAO;
|
||||
import org.palomafp.aadd.dta.dao.IPaisDAO;
|
||||
import org.palomafp.aadd.dta.model.Continente;
|
||||
import org.palomafp.aadd.dta.model.Pais;
|
||||
|
||||
public class VentanaContinentesPaises extends JFrame {
|
||||
/**
|
||||
@@ -45,9 +44,12 @@ public class VentanaContinentesPaises extends JFrame {
|
||||
setSize(500, 350);
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
// Inicializar DAO
|
||||
continenteDAO = new ContinenteDaoCSV();
|
||||
paisDAO = new PaisDaoText(continenteDAO);
|
||||
// Carga por reflexión
|
||||
try {
|
||||
cargarImplementaciones();
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("No se pudieron cargar los DAO", e);
|
||||
}
|
||||
|
||||
// Componentes
|
||||
comboContinentes = new JComboBox<>();
|
||||
@@ -103,11 +105,43 @@ public class VentanaContinentesPaises extends JFrame {
|
||||
// Cargar continentes al iniciar
|
||||
cargarContinentes();
|
||||
}
|
||||
|
||||
// Método para cargar por reflexión
|
||||
private void cargarImplementaciones() throws Exception {
|
||||
|
||||
Properties config = new Properties();
|
||||
|
||||
try (var in = VentanaContinentesPaises.class.getResourceAsStream("/application.properties")) {
|
||||
|
||||
if (in == null) {
|
||||
throw new IllegalStateException("No se encontró application.properties en el classpath");
|
||||
}
|
||||
|
||||
config.load(in);
|
||||
}
|
||||
|
||||
String claseContinente = config.getProperty("continente.implementacion.clase");
|
||||
String clasePais = config.getProperty("pais.implementacion.clase");
|
||||
|
||||
if (claseContinente == null || clasePais == null) {
|
||||
throw new IllegalStateException("Las propiedades de clase no se encuentran en application.properties");
|
||||
}
|
||||
|
||||
// Reflexión para continenteDAO
|
||||
continenteDAO = (IContinenteDAO) Class.forName(claseContinente.trim())
|
||||
.getDeclaredConstructor()
|
||||
.newInstance();
|
||||
|
||||
// Reflexión para paisDAO
|
||||
paisDAO = (IPaisDAO) Class.forName(clasePais.trim())
|
||||
.getDeclaredConstructor(IContinenteDAO.class)
|
||||
.newInstance(continenteDAO);
|
||||
}
|
||||
|
||||
private void cargarContinentes() {
|
||||
|
||||
// Sustituir por el nombre real del método de tu DAO
|
||||
List<Continente> continentes = continenteDAO.obtenerListaContinentes();
|
||||
List<Continente> continentes = continenteDAO.obtenerTodos();
|
||||
|
||||
comboContinentes.removeAllItems();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user