Direceccion para clientes, distribuidors y trabajadores
This commit is contained in:
@@ -22,6 +22,10 @@ import xyz.danielcortes.controllers.cliente.correo.ClienteCorreoCreateController
|
||||
import xyz.danielcortes.controllers.cliente.correo.ClienteCorreoSearchController;
|
||||
import xyz.danielcortes.controllers.cliente.correo.ClienteCorreoUpdateController;
|
||||
import xyz.danielcortes.controllers.cliente.correo.ClienteCorreoViewController;
|
||||
import xyz.danielcortes.controllers.cliente.direccion.ClienteDireccionCreateController;
|
||||
import xyz.danielcortes.controllers.cliente.direccion.ClienteDireccionSearchController;
|
||||
import xyz.danielcortes.controllers.cliente.direccion.ClienteDireccionUpdateController;
|
||||
import xyz.danielcortes.controllers.cliente.direccion.ClienteDireccionViewController;
|
||||
import xyz.danielcortes.controllers.distribuidor.DistribuidorCreateController;
|
||||
import xyz.danielcortes.controllers.distribuidor.DistribuidorSearchController;
|
||||
import xyz.danielcortes.controllers.distribuidor.DistribuidorUpdateController;
|
||||
@@ -30,6 +34,10 @@ import xyz.danielcortes.controllers.distribuidor.correo.DistribuidorCorreoCreate
|
||||
import xyz.danielcortes.controllers.distribuidor.correo.DistribuidorCorreoSearchController;
|
||||
import xyz.danielcortes.controllers.distribuidor.correo.DistribuidorCorreoUpdateController;
|
||||
import xyz.danielcortes.controllers.distribuidor.correo.DistribuidorCorreoViewController;
|
||||
import xyz.danielcortes.controllers.distribuidor.direccion.DistribuidorDireccionCreateController;
|
||||
import xyz.danielcortes.controllers.distribuidor.direccion.DistribuidorDireccionSearchController;
|
||||
import xyz.danielcortes.controllers.distribuidor.direccion.DistribuidorDireccionUpdateController;
|
||||
import xyz.danielcortes.controllers.distribuidor.direccion.DistribuidorDireccionViewController;
|
||||
import xyz.danielcortes.controllers.editorial.EditorialCreateController;
|
||||
import xyz.danielcortes.controllers.editorial.EditorialSearchController;
|
||||
import xyz.danielcortes.controllers.editorial.EditorialUpdateController;
|
||||
@@ -54,10 +62,10 @@ import xyz.danielcortes.controllers.trabajador.correo.TrabajadorCorreoCreateCont
|
||||
import xyz.danielcortes.controllers.trabajador.correo.TrabajadorCorreoSearchController;
|
||||
import xyz.danielcortes.controllers.trabajador.correo.TrabajadorCorreoUpdateController;
|
||||
import xyz.danielcortes.controllers.trabajador.correo.TrabajadorCorreoViewController;
|
||||
import xyz.danielcortes.controllers.trabajador.direccion.DireccionCreateController;
|
||||
import xyz.danielcortes.controllers.trabajador.direccion.DireccionSearchController;
|
||||
import xyz.danielcortes.controllers.trabajador.direccion.DireccionUpdateController;
|
||||
import xyz.danielcortes.controllers.trabajador.direccion.DireccionViewController;
|
||||
import xyz.danielcortes.controllers.trabajador.direccion.TrabajadorDireccionCreateController;
|
||||
import xyz.danielcortes.controllers.trabajador.direccion.TrabajadorDireccionSearchController;
|
||||
import xyz.danielcortes.controllers.trabajador.direccion.TrabajadorDireccionUpdateController;
|
||||
import xyz.danielcortes.controllers.trabajador.direccion.TrabajadorDireccionViewController;
|
||||
import xyz.danielcortes.controllers.trabajador.telefono.TelefonoCreateController;
|
||||
import xyz.danielcortes.controllers.trabajador.telefono.TelefonoSearchController;
|
||||
import xyz.danielcortes.controllers.trabajador.telefono.TelefonoUpdateController;
|
||||
@@ -210,10 +218,20 @@ public class LaunchController {
|
||||
this.controllers.put(PanelName.TELEFONO_CREATE, new TelefonoCreateController(new TelefonoCreatePanel(), this));
|
||||
this.controllers.put(PanelName.TELEFONO_UPDATE, new TelefonoUpdateController(new TelefonoUpdatePanel(), this));
|
||||
|
||||
this.controllers.put(PanelName.DIRECCION_SEARCH, new DireccionSearchController(new DireccionSearchPanel(), this));
|
||||
this.controllers.put(PanelName.DIRECCION_VIEW, new DireccionViewController(new DireccionViewPanel(), this));
|
||||
this.controllers.put(PanelName.DIRECCION_CREATE, new DireccionCreateController(new DireccionCreatePanel(), this));
|
||||
this.controllers.put(PanelName.DIRECCION_UPDATE, new DireccionUpdateController(new DireccionUpdatePanel(), this));
|
||||
this.controllers.put(PanelName.TRABAJADOR_DIRECCION_SEARCH, new TrabajadorDireccionSearchController(new DireccionSearchPanel(), this));
|
||||
this.controllers.put(PanelName.TRABAJADOR_DIRECCION_VIEW, new TrabajadorDireccionViewController(new DireccionViewPanel(), this));
|
||||
this.controllers.put(PanelName.TRABAJADOR_DIRECCION_CREATE, new TrabajadorDireccionCreateController(new DireccionCreatePanel(), this));
|
||||
this.controllers.put(PanelName.TRABAJADOR_DIRECCION_UPDATE, new TrabajadorDireccionUpdateController(new DireccionUpdatePanel(), this));
|
||||
|
||||
this.controllers.put(PanelName.CLIENTE_DIRECCION_SEARCH, new ClienteDireccionSearchController(new DireccionSearchPanel(), this));
|
||||
this.controllers.put(PanelName.CLIENTE_DIRECCION_VIEW, new ClienteDireccionViewController(new DireccionViewPanel(), this));
|
||||
this.controllers.put(PanelName.CLIENTE_DIRECCION_CREATE, new ClienteDireccionCreateController(new DireccionCreatePanel(), this));
|
||||
this.controllers.put(PanelName.CLIENTE_DIRECCION_UPDATE, new ClienteDireccionUpdateController(new DireccionUpdatePanel(), this));
|
||||
|
||||
this.controllers.put(PanelName.DISTRIBUIDOR_DIRECCION_SEARCH, new DistribuidorDireccionSearchController(new DireccionSearchPanel(), this));
|
||||
this.controllers.put(PanelName.DISTRIBUIDOR_DIRECCION_VIEW, new DistribuidorDireccionViewController(new DireccionViewPanel(), this));
|
||||
this.controllers.put(PanelName.DISTRIBUIDOR_DIRECCION_CREATE, new DistribuidorDireccionCreateController(new DireccionCreatePanel(), this));
|
||||
this.controllers.put(PanelName.DISTRIBUIDOR_DIRECCION_UPDATE, new DistribuidorDireccionUpdateController(new DireccionUpdatePanel(), this));
|
||||
|
||||
for (PanelName name : this.controllers.keySet()) {
|
||||
BaseController controller = this.controllers.get(name);
|
||||
|
||||
@@ -9,9 +9,9 @@ import xyz.danielcortes.views.direccion.DireccionCreatePanel;
|
||||
|
||||
public abstract class AbstractDireccionCreateController extends BaseController {
|
||||
|
||||
private DireccionCreatePanel view;
|
||||
private DireccionRepository repository;
|
||||
private DireccionValidator validator;
|
||||
protected DireccionCreatePanel view;
|
||||
protected DireccionRepository repository;
|
||||
protected DireccionValidator validator;
|
||||
|
||||
public AbstractDireccionCreateController(DireccionCreatePanel view, LaunchController parentController) {
|
||||
super(parentController);
|
||||
|
||||
@@ -13,9 +13,9 @@ import xyz.danielcortes.views.direccion.DireccionSearchPanel;
|
||||
|
||||
public abstract class AbstractDireccionSearchController extends BaseController {
|
||||
|
||||
private DireccionSearchPanel view;
|
||||
private DireccionRepository direccionRepository;
|
||||
private DireccionValidator validator;
|
||||
protected DireccionSearchPanel view;
|
||||
protected DireccionRepository direccionRepository;
|
||||
protected DireccionValidator validator;
|
||||
|
||||
public AbstractDireccionSearchController(DireccionSearchPanel view, LaunchController parent) {
|
||||
super(parent);
|
||||
@@ -64,12 +64,12 @@ public abstract class AbstractDireccionSearchController extends BaseController {
|
||||
|
||||
protected abstract void loadDireccionesTable();
|
||||
|
||||
private void loadDireccionesTable(List<Direccion> direccions) {
|
||||
protected void loadDireccionesTable(List<Direccion> direccions) {
|
||||
BaseTableModel<Direccion> model = this.view.getDireccionModel();
|
||||
model.setRows(direccions);
|
||||
}
|
||||
|
||||
private Direccion getSelectedDireccion() {
|
||||
protected Direccion getSelectedDireccion() {
|
||||
int selectedRow = this.view.getDireccionesTable().getSelectedRow();
|
||||
if (selectedRow == -1) {
|
||||
JOptionPane.showMessageDialog(
|
||||
|
||||
@@ -11,10 +11,10 @@ import xyz.danielcortes.views.direccion.DireccionUpdatePanel;
|
||||
|
||||
public abstract class AbstractDireccionUpdateController extends BaseController {
|
||||
|
||||
private Direccion direccion;
|
||||
private DireccionUpdatePanel view;
|
||||
private DireccionRepository repository;
|
||||
private DireccionValidator validator;
|
||||
protected Direccion direccion;
|
||||
protected DireccionUpdatePanel view;
|
||||
protected DireccionRepository repository;
|
||||
protected DireccionValidator validator;
|
||||
|
||||
public AbstractDireccionUpdateController(DireccionUpdatePanel view, LaunchController parentController) {
|
||||
super(parentController);
|
||||
@@ -49,13 +49,13 @@ public abstract class AbstractDireccionUpdateController extends BaseController {
|
||||
this.view.getNumeroField().setText(this.direccion.getNumero());
|
||||
}
|
||||
|
||||
private void setupListeners() {
|
||||
protected void setupListeners() {
|
||||
this.view.getNumeroField().addActionListener(e -> this.update());
|
||||
this.view.getActualizarButton().addActionListener(e -> this.update());
|
||||
this.view.getVolverButton().addActionListener(e -> this.volver());
|
||||
}
|
||||
|
||||
private void update() {
|
||||
protected void update() {
|
||||
String calle = this.view.getCalleField().getText();
|
||||
String numero = this.view.getNumeroField().getText();
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ import xyz.danielcortes.views.direccion.DireccionViewPanel;
|
||||
|
||||
public abstract class AbstractDireccionViewController extends BaseController {
|
||||
|
||||
private Direccion direccion;
|
||||
private DireccionViewPanel view;
|
||||
protected Direccion direccion;
|
||||
protected DireccionViewPanel view;
|
||||
|
||||
public AbstractDireccionViewController(DireccionViewPanel view, LaunchController parentController) {
|
||||
super(parentController);
|
||||
|
||||
@@ -3,6 +3,7 @@ package xyz.danielcortes.controllers.cliente;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.controllers.cliente.correo.ClienteCorreoSearchController;
|
||||
import xyz.danielcortes.controllers.cliente.direccion.ClienteDireccionSearchController;
|
||||
import xyz.danielcortes.framework.BaseController;
|
||||
import xyz.danielcortes.framework.BasePanel;
|
||||
import xyz.danielcortes.framework.PanelName;
|
||||
@@ -33,15 +34,16 @@ public class ClienteViewController extends BaseController {
|
||||
this.view.getVolverButton().addActionListener(e -> this.getParentController().showCard(PanelName.CLIENTE_SEARCH));
|
||||
this.view.getCorreosButton().addActionListener(e -> this.gotoCorreosView());
|
||||
// this.view.getTelefonosButton().addActionListener(e -> this.gotoTelefonoView());
|
||||
// this.view.getDireccionesButton().addActionListener(e -> this.gotoDireccionView());
|
||||
this.view.getDireccionesButton().addActionListener(e -> this.gotoDireccionView());
|
||||
}
|
||||
|
||||
private void gotoDireccionView() {
|
||||
ClienteDireccionSearchController controller = (ClienteDireccionSearchController) this.getParentController()
|
||||
.getCard(PanelName.CLIENTE_DIRECCION_SEARCH);
|
||||
controller.setCliente(this.cliente);
|
||||
this.getParentController().showCard(PanelName.CLIENTE_DIRECCION_SEARCH);
|
||||
}
|
||||
|
||||
// private void gotoDireccionView() {
|
||||
// AbstractDireccionSearchController controller = (AbstractDireccionSearchController) this.getParentController().getCard(PanelName.DIRECCION_SEARCH);
|
||||
// controller.setCliente(cliente);
|
||||
// this.getParentController().showCard(PanelName.DIRECCION_SEARCH);
|
||||
// }
|
||||
//
|
||||
// private void gotoTelefonoView() {
|
||||
// AbstractTelefonoSearchController controller = (AbstractTelefonoSearchController) this.getParentController().getCard(PanelName.TELEFONO_SEARCH);
|
||||
// controller.setCliente(cliente);
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package xyz.danielcortes.controllers.cliente.direccion;
|
||||
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.controllers.abstract_direccion.AbstractDireccionCreateController;
|
||||
import xyz.danielcortes.framework.PanelName;
|
||||
import xyz.danielcortes.framework.ValidationResult;
|
||||
import xyz.danielcortes.models.Cliente;
|
||||
import xyz.danielcortes.models.Direccion;
|
||||
import xyz.danielcortes.views.direccion.DireccionCreatePanel;
|
||||
|
||||
public class ClienteDireccionCreateController extends AbstractDireccionCreateController {
|
||||
|
||||
private Cliente cliente;
|
||||
|
||||
public ClienteDireccionCreateController(DireccionCreatePanel view, LaunchController parentController) {
|
||||
super(view, parentController);
|
||||
}
|
||||
|
||||
public void setCliente(Cliente cliente) {
|
||||
this.cliente = cliente;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void save() {
|
||||
String calle = this.view.getCalleField().getText();
|
||||
String numero = this.view.getNumeroField().getText();
|
||||
|
||||
ValidationResult direccionValidation = this.validator.validateCalle(calle);
|
||||
if (direccionValidation.hasError()) {
|
||||
direccionValidation.showErrorDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
ValidationResult numeroValidation = this.validator.validateNumero(numero);
|
||||
if (numeroValidation.hasError()) {
|
||||
numeroValidation.showErrorDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
Direccion direccion = new Direccion();
|
||||
direccion.setCalle(calle);
|
||||
direccion.setNumero(numero);
|
||||
direccion.getClientes().add(this.cliente);
|
||||
|
||||
this.repository.save(direccion);
|
||||
this.cliente.getDirecciones().add(direccion);
|
||||
|
||||
this.volver();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void volver() {
|
||||
ClienteDireccionSearchController controller = (ClienteDireccionSearchController) this.getParentController()
|
||||
.getCard(PanelName.CLIENTE_DIRECCION_SEARCH);
|
||||
controller.setCliente(this.cliente);
|
||||
this.getParentController().showCard(PanelName.CLIENTE_DIRECCION_SEARCH);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package xyz.danielcortes.controllers.cliente.direccion;
|
||||
|
||||
import java.util.List;
|
||||
import javax.swing.JOptionPane;
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.controllers.abstract_direccion.AbstractDireccionSearchController;
|
||||
import xyz.danielcortes.controllers.cliente.ClienteViewController;
|
||||
import xyz.danielcortes.framework.PanelName;
|
||||
import xyz.danielcortes.models.Cliente;
|
||||
import xyz.danielcortes.models.Direccion;
|
||||
import xyz.danielcortes.views.direccion.DireccionSearchPanel;
|
||||
|
||||
public class ClienteDireccionSearchController extends AbstractDireccionSearchController {
|
||||
|
||||
private Cliente cliente;
|
||||
|
||||
public ClienteDireccionSearchController(DireccionSearchPanel view, LaunchController parent) {
|
||||
super(view, parent);
|
||||
}
|
||||
|
||||
public void setCliente(Cliente cliente) {
|
||||
this.cliente = cliente;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void create() {
|
||||
ClienteDireccionCreateController controller = (ClienteDireccionCreateController) this.getParentController()
|
||||
.getCard(PanelName.CLIENTE_DIRECCION_CREATE);
|
||||
controller.setCliente(this.cliente);
|
||||
this.getParentController().showCard(PanelName.CLIENTE_DIRECCION_CREATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void edit() {
|
||||
Direccion direccion = this.getSelectedDireccion();
|
||||
if (direccion != null) {
|
||||
ClienteDireccionUpdateController controller = (ClienteDireccionUpdateController) this.getParentController()
|
||||
.getCard(PanelName.CLIENTE_DIRECCION_UPDATE);
|
||||
controller.setCliente(this.cliente);
|
||||
controller.setDireccion(direccion);
|
||||
this.getParentController().showCard(PanelName.CLIENTE_DIRECCION_UPDATE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void delete() {
|
||||
Direccion direccion = this.getSelectedDireccion();
|
||||
if (direccion == null)
|
||||
return;
|
||||
|
||||
int option = JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
"¿Estas seguro de que deseas eliminar la direccion?",
|
||||
"Confirmacion",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE
|
||||
);
|
||||
if (option == JOptionPane.NO_OPTION)
|
||||
return;
|
||||
|
||||
this.direccionRepository.delete(direccion);
|
||||
this.cliente.getDirecciones().remove(direccion);
|
||||
this.reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void view() {
|
||||
Direccion direccion = this.getSelectedDireccion();
|
||||
if (direccion != null) {
|
||||
ClienteDireccionViewController controller = (ClienteDireccionViewController) this.getParentController()
|
||||
.getCard(PanelName.CLIENTE_DIRECCION_VIEW);
|
||||
controller.setDireccion(direccion);
|
||||
controller.setCliente(this.cliente);
|
||||
this.getParentController().showCard(PanelName.CLIENTE_DIRECCION_VIEW);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void search() {
|
||||
String term = this.view.getSearchField().getText();
|
||||
List<Direccion> direccion = this.direccionRepository.search(term, this.cliente);
|
||||
this.loadDireccionesTable(direccion);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void volver() {
|
||||
ClienteViewController controller = (ClienteViewController) this.getParentController().getCard(PanelName.CLIENTE_VIEW);
|
||||
controller.setCliente(this.cliente);
|
||||
this.getParentController().showCard(PanelName.CLIENTE_VIEW);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadDireccionesTable() {
|
||||
List<Direccion> direccions = this.cliente.getDirecciones();
|
||||
this.loadDireccionesTable(direccions);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package xyz.danielcortes.controllers.cliente.direccion;
|
||||
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.controllers.abstract_direccion.AbstractDireccionUpdateController;
|
||||
import xyz.danielcortes.framework.PanelName;
|
||||
import xyz.danielcortes.models.Cliente;
|
||||
import xyz.danielcortes.views.direccion.DireccionUpdatePanel;
|
||||
|
||||
public class ClienteDireccionUpdateController extends AbstractDireccionUpdateController {
|
||||
|
||||
private Cliente cliente;
|
||||
|
||||
public ClienteDireccionUpdateController(DireccionUpdatePanel view, LaunchController parentController) {
|
||||
super(view, parentController);
|
||||
}
|
||||
|
||||
public void setCliente(Cliente cliente) {
|
||||
this.cliente = cliente;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void volver() {
|
||||
ClienteDireccionSearchController controller = (ClienteDireccionSearchController) this.getParentController()
|
||||
.getCard(PanelName.CLIENTE_DIRECCION_SEARCH);
|
||||
controller.setCliente(this.cliente);
|
||||
this.getParentController().showCard(PanelName.CLIENTE_DIRECCION_SEARCH);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package xyz.danielcortes.controllers.cliente.direccion;
|
||||
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.controllers.abstract_direccion.AbstractDireccionViewController;
|
||||
import xyz.danielcortes.framework.PanelName;
|
||||
import xyz.danielcortes.models.Cliente;
|
||||
import xyz.danielcortes.views.direccion.DireccionViewPanel;
|
||||
|
||||
public class ClienteDireccionViewController extends AbstractDireccionViewController {
|
||||
|
||||
private Cliente cliente;
|
||||
|
||||
public ClienteDireccionViewController(DireccionViewPanel view, LaunchController parentController) {
|
||||
super(view, parentController);
|
||||
}
|
||||
|
||||
public void setCliente(Cliente cliente) {
|
||||
this.cliente = cliente;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void volver() {
|
||||
ClienteDireccionSearchController controller = (ClienteDireccionSearchController) this.getParentController()
|
||||
.getCard(PanelName.CLIENTE_DIRECCION_SEARCH);
|
||||
controller.setCliente(this.cliente);
|
||||
this.getParentController().showCard(PanelName.CLIENTE_DIRECCION_SEARCH);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package xyz.danielcortes.controllers.distribuidor;
|
||||
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.controllers.distribuidor.correo.DistribuidorCorreoSearchController;
|
||||
import xyz.danielcortes.controllers.distribuidor.direccion.DistribuidorDireccionSearchController;
|
||||
import xyz.danielcortes.framework.BaseController;
|
||||
import xyz.danielcortes.framework.BasePanel;
|
||||
import xyz.danielcortes.framework.PanelName;
|
||||
@@ -32,14 +33,16 @@ public class DistribuidorViewController extends BaseController {
|
||||
this.view.getVolverButton().addActionListener(e -> this.getParentController().showCard(PanelName.DISTRIBUIDOR_SEARCH));
|
||||
this.view.getCorreosButton().addActionListener(e -> this.gotoCorreosView());
|
||||
// this.view.getTelefonosButton().addActionListener(e -> this.gotoTelefonoView());
|
||||
// this.view.getDireccionesButton().addActionListener(e -> this.gotoDireccionView());
|
||||
this.view.getDireccionesButton().addActionListener(e -> this.gotoDireccionView());
|
||||
}
|
||||
|
||||
private void gotoDireccionView() {
|
||||
DistribuidorDireccionSearchController controller = (DistribuidorDireccionSearchController) this.getParentController()
|
||||
.getCard(PanelName.DISTRIBUIDOR_DIRECCION_SEARCH);
|
||||
controller.setDistribuidor(this.distribuidor);
|
||||
this.getParentController().showCard(PanelName.DISTRIBUIDOR_DIRECCION_SEARCH);
|
||||
}
|
||||
|
||||
// private void gotoDireccionView() {
|
||||
// AbstractDireccionSearchController controller = (AbstractDireccionSearchController) this.getParentController().getCard(PanelName.DIRECCION_SEARCH);
|
||||
// controller.setCliente(distribuidor);
|
||||
// this.getParentController().showCard(PanelName.DIRECCION_SEARCH);
|
||||
// }
|
||||
//
|
||||
// private void gotoTelefonoView() {
|
||||
// AbstractTelefonoSearchController controller = (AbstractTelefonoSearchController) this.getParentController().getCard(PanelName.TELEFONO_SEARCH);
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package xyz.danielcortes.controllers.distribuidor.direccion;
|
||||
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.controllers.abstract_direccion.AbstractDireccionCreateController;
|
||||
import xyz.danielcortes.framework.PanelName;
|
||||
import xyz.danielcortes.framework.ValidationResult;
|
||||
import xyz.danielcortes.models.Direccion;
|
||||
import xyz.danielcortes.models.Distribuidor;
|
||||
import xyz.danielcortes.views.direccion.DireccionCreatePanel;
|
||||
|
||||
public class DistribuidorDireccionCreateController extends AbstractDireccionCreateController {
|
||||
|
||||
private Distribuidor distribuidor;
|
||||
|
||||
public DistribuidorDireccionCreateController(DireccionCreatePanel view, LaunchController parentController) {
|
||||
super(view, parentController);
|
||||
}
|
||||
|
||||
public void setDistribuidor(Distribuidor distribuidor) {
|
||||
this.distribuidor = distribuidor;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void save() {
|
||||
String calle = this.view.getCalleField().getText();
|
||||
String numero = this.view.getNumeroField().getText();
|
||||
|
||||
ValidationResult direccionValidation = this.validator.validateCalle(calle);
|
||||
if (direccionValidation.hasError()) {
|
||||
direccionValidation.showErrorDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
ValidationResult numeroValidation = this.validator.validateNumero(numero);
|
||||
if (numeroValidation.hasError()) {
|
||||
numeroValidation.showErrorDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
Direccion direccion = new Direccion();
|
||||
direccion.setCalle(calle);
|
||||
direccion.setNumero(numero);
|
||||
direccion.getDistribuidores().add(this.distribuidor);
|
||||
|
||||
this.repository.save(direccion);
|
||||
this.distribuidor.getDirecciones().add(direccion);
|
||||
|
||||
this.volver();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void volver() {
|
||||
DistribuidorDireccionSearchController controller = (DistribuidorDireccionSearchController) this.getParentController()
|
||||
.getCard(PanelName.DISTRIBUIDOR_DIRECCION_SEARCH);
|
||||
controller.setDistribuidor(this.distribuidor);
|
||||
this.getParentController().showCard(PanelName.DISTRIBUIDOR_DIRECCION_SEARCH);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package xyz.danielcortes.controllers.distribuidor.direccion;
|
||||
|
||||
import java.util.List;
|
||||
import javax.swing.JOptionPane;
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.controllers.abstract_direccion.AbstractDireccionSearchController;
|
||||
import xyz.danielcortes.controllers.distribuidor.DistribuidorViewController;
|
||||
import xyz.danielcortes.framework.PanelName;
|
||||
import xyz.danielcortes.models.Direccion;
|
||||
import xyz.danielcortes.models.Distribuidor;
|
||||
import xyz.danielcortes.views.direccion.DireccionSearchPanel;
|
||||
|
||||
public class DistribuidorDireccionSearchController extends AbstractDireccionSearchController {
|
||||
|
||||
private Distribuidor distribuidor;
|
||||
|
||||
public DistribuidorDireccionSearchController(DireccionSearchPanel view, LaunchController parent) {
|
||||
super(view, parent);
|
||||
}
|
||||
|
||||
public void setDistribuidor(Distribuidor distribuidor) {
|
||||
this.distribuidor = distribuidor;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void create() {
|
||||
DistribuidorDireccionCreateController controller = (DistribuidorDireccionCreateController) this.getParentController()
|
||||
.getCard(PanelName.DISTRIBUIDOR_DIRECCION_CREATE);
|
||||
controller.setDistribuidor(this.distribuidor);
|
||||
this.getParentController().showCard(PanelName.DISTRIBUIDOR_DIRECCION_CREATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void edit() {
|
||||
Direccion direccion = this.getSelectedDireccion();
|
||||
if (direccion != null) {
|
||||
DistribuidorDireccionUpdateController controller = (DistribuidorDireccionUpdateController) this.getParentController()
|
||||
.getCard(PanelName.DISTRIBUIDOR_DIRECCION_UPDATE);
|
||||
controller.setDistribuidor(this.distribuidor);
|
||||
controller.setDireccion(direccion);
|
||||
this.getParentController().showCard(PanelName.DISTRIBUIDOR_DIRECCION_UPDATE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void delete() {
|
||||
Direccion direccion = this.getSelectedDireccion();
|
||||
if (direccion == null)
|
||||
return;
|
||||
|
||||
int option = JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
"¿Estas seguro de que deseas eliminar la direccion?",
|
||||
"Confirmacion",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE
|
||||
);
|
||||
if (option == JOptionPane.NO_OPTION)
|
||||
return;
|
||||
|
||||
this.direccionRepository.delete(direccion);
|
||||
this.distribuidor.getDirecciones().remove(direccion);
|
||||
this.reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void view() {
|
||||
Direccion direccion = this.getSelectedDireccion();
|
||||
if (direccion != null) {
|
||||
DistribuidorDireccionViewController controller = (DistribuidorDireccionViewController) this.getParentController()
|
||||
.getCard(PanelName.DISTRIBUIDOR_DIRECCION_VIEW);
|
||||
controller.setDireccion(direccion);
|
||||
controller.setDistribuidor(this.distribuidor);
|
||||
this.getParentController().showCard(PanelName.DISTRIBUIDOR_DIRECCION_VIEW);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void search() {
|
||||
String term = this.view.getSearchField().getText();
|
||||
List<Direccion> direccion = this.direccionRepository.search(term, this.distribuidor);
|
||||
this.loadDireccionesTable(direccion);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void volver() {
|
||||
DistribuidorViewController controller = (DistribuidorViewController) this.getParentController().getCard(PanelName.DISTRIBUIDOR_VIEW);
|
||||
controller.setDistribuidor(this.distribuidor);
|
||||
this.getParentController().showCard(PanelName.DISTRIBUIDOR_VIEW);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadDireccionesTable() {
|
||||
List<Direccion> direccions = this.distribuidor.getDirecciones();
|
||||
this.loadDireccionesTable(direccions);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package xyz.danielcortes.controllers.distribuidor.direccion;
|
||||
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.controllers.abstract_direccion.AbstractDireccionUpdateController;
|
||||
import xyz.danielcortes.framework.PanelName;
|
||||
import xyz.danielcortes.models.Distribuidor;
|
||||
import xyz.danielcortes.views.direccion.DireccionUpdatePanel;
|
||||
|
||||
public class DistribuidorDireccionUpdateController extends AbstractDireccionUpdateController {
|
||||
|
||||
private Distribuidor distribuidor;
|
||||
|
||||
public DistribuidorDireccionUpdateController(DireccionUpdatePanel view, LaunchController parentController) {
|
||||
super(view, parentController);
|
||||
}
|
||||
|
||||
public void setDistribuidor(Distribuidor distribuidor) {
|
||||
this.distribuidor = distribuidor;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void volver() {
|
||||
DistribuidorDireccionSearchController controller = (DistribuidorDireccionSearchController) this.getParentController()
|
||||
.getCard(PanelName.DISTRIBUIDOR_DIRECCION_SEARCH);
|
||||
controller.setDistribuidor(this.distribuidor);
|
||||
this.getParentController().showCard(PanelName.DISTRIBUIDOR_DIRECCION_SEARCH);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package xyz.danielcortes.controllers.distribuidor.direccion;
|
||||
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.controllers.abstract_direccion.AbstractDireccionViewController;
|
||||
import xyz.danielcortes.framework.PanelName;
|
||||
import xyz.danielcortes.models.Distribuidor;
|
||||
import xyz.danielcortes.views.direccion.DireccionViewPanel;
|
||||
|
||||
public class DistribuidorDireccionViewController extends AbstractDireccionViewController {
|
||||
|
||||
private Distribuidor distribuidor;
|
||||
|
||||
public DistribuidorDireccionViewController(DireccionViewPanel view, LaunchController parentController) {
|
||||
super(view, parentController);
|
||||
}
|
||||
|
||||
public void setDistribuidor(Distribuidor distribuidor) {
|
||||
this.distribuidor = distribuidor;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void volver() {
|
||||
DistribuidorDireccionSearchController controller = (DistribuidorDireccionSearchController) this.getParentController()
|
||||
.getCard(PanelName.DISTRIBUIDOR_DIRECCION_SEARCH);
|
||||
controller.setDistribuidor(this.distribuidor);
|
||||
this.getParentController().showCard(PanelName.DISTRIBUIDOR_DIRECCION_SEARCH);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package xyz.danielcortes.controllers.trabajador;
|
||||
import javax.swing.JOptionPane;
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.controllers.trabajador.correo.TrabajadorCorreoSearchController;
|
||||
import xyz.danielcortes.controllers.trabajador.direccion.DireccionSearchController;
|
||||
import xyz.danielcortes.controllers.trabajador.direccion.TrabajadorDireccionSearchController;
|
||||
import xyz.danielcortes.controllers.trabajador.telefono.TelefonoSearchController;
|
||||
import xyz.danielcortes.controllers.trabajador.usuario.UsuarioCreateController;
|
||||
import xyz.danielcortes.controllers.trabajador.usuario.UsuarioViewController;
|
||||
@@ -42,9 +42,10 @@ public class TrabajadorViewController extends BaseController {
|
||||
}
|
||||
|
||||
private void gotoDireccionView() {
|
||||
DireccionSearchController controller = (DireccionSearchController) this.getParentController().getCard(PanelName.DIRECCION_SEARCH);
|
||||
TrabajadorDireccionSearchController controller = (TrabajadorDireccionSearchController) this.getParentController()
|
||||
.getCard(PanelName.TRABAJADOR_DIRECCION_SEARCH);
|
||||
controller.setTrabajador(this.trabajador);
|
||||
this.getParentController().showCard(PanelName.DIRECCION_SEARCH);
|
||||
this.getParentController().showCard(PanelName.TRABAJADOR_DIRECCION_SEARCH);
|
||||
}
|
||||
|
||||
private void gotoTelefonoView() {
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
package xyz.danielcortes.controllers.trabajador.direccion;
|
||||
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.framework.BaseController;
|
||||
import xyz.danielcortes.framework.BasePanel;
|
||||
import xyz.danielcortes.framework.PanelName;
|
||||
import xyz.danielcortes.framework.ValidationResult;
|
||||
import xyz.danielcortes.models.Direccion;
|
||||
import xyz.danielcortes.models.Trabajador;
|
||||
import xyz.danielcortes.repository.DireccionRepository;
|
||||
import xyz.danielcortes.validator.DireccionValidator;
|
||||
import xyz.danielcortes.views.direccion.DireccionCreatePanel;
|
||||
|
||||
public class DireccionCreateController extends BaseController {
|
||||
|
||||
private Trabajador trabajador;
|
||||
private DireccionCreatePanel view;
|
||||
private DireccionRepository repository;
|
||||
private DireccionValidator validator;
|
||||
|
||||
public DireccionCreateController(DireccionCreatePanel view, LaunchController parentController) {
|
||||
super(parentController);
|
||||
this.view = view;
|
||||
this.repository = new DireccionRepository();
|
||||
this.validator = new DireccionValidator(this.repository);
|
||||
this.setupListeners();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LaunchController getParentController() {
|
||||
return this.parentController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
this.view.getCalleField().requestFocus();
|
||||
this.view.getCalleField().setText("");
|
||||
this.view.getNumeroField().setText("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BasePanel getView() {
|
||||
return this.view;
|
||||
}
|
||||
|
||||
public void setTrabajador(Trabajador trabajador) {
|
||||
this.trabajador = trabajador;
|
||||
}
|
||||
|
||||
private void setupListeners() {
|
||||
this.view.getGuardarButton().addActionListener(e -> this.save());
|
||||
this.view.getNumeroField().addActionListener(e -> this.save());
|
||||
this.view.getVolverButton().addActionListener(e -> this.volver());
|
||||
}
|
||||
|
||||
private void save() {
|
||||
String calle = this.view.getCalleField().getText();
|
||||
String numero = this.view.getNumeroField().getText();
|
||||
|
||||
ValidationResult direccionValidation = this.validator.validateCalle(calle);
|
||||
if (direccionValidation.hasError()) {
|
||||
direccionValidation.showErrorDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
ValidationResult numeroValidation = this.validator.validateNumero(numero);
|
||||
if (numeroValidation.hasError()) {
|
||||
numeroValidation.showErrorDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
Direccion direccion = new Direccion();
|
||||
direccion.setCalle(calle);
|
||||
direccion.setNumero(numero);
|
||||
direccion.getTrabajadores().add(this.trabajador);
|
||||
|
||||
this.repository.save(direccion);
|
||||
this.trabajador.getDirecciones().add(direccion);
|
||||
|
||||
this.volver();
|
||||
}
|
||||
|
||||
private void volver() {
|
||||
DireccionSearchController controller = (DireccionSearchController) this.getParentController().getCard(PanelName.DIRECCION_SEARCH);
|
||||
controller.setTrabajador(this.trabajador);
|
||||
this.getParentController().showCard(PanelName.DIRECCION_SEARCH);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,143 +0,0 @@
|
||||
package xyz.danielcortes.controllers.trabajador.direccion;
|
||||
|
||||
import java.util.List;
|
||||
import javax.swing.JOptionPane;
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.controllers.trabajador.TrabajadorViewController;
|
||||
import xyz.danielcortes.framework.BaseController;
|
||||
import xyz.danielcortes.framework.BasePanel;
|
||||
import xyz.danielcortes.framework.BaseTableModel;
|
||||
import xyz.danielcortes.framework.PanelName;
|
||||
import xyz.danielcortes.models.Direccion;
|
||||
import xyz.danielcortes.models.Trabajador;
|
||||
import xyz.danielcortes.repository.DireccionRepository;
|
||||
import xyz.danielcortes.validator.DireccionValidator;
|
||||
import xyz.danielcortes.views.direccion.DireccionSearchPanel;
|
||||
|
||||
public class DireccionSearchController extends BaseController {
|
||||
|
||||
private Trabajador trabajador;
|
||||
private DireccionSearchPanel view;
|
||||
private DireccionRepository direccionRepository;
|
||||
private DireccionValidator validator;
|
||||
|
||||
public DireccionSearchController(DireccionSearchPanel view, LaunchController parent) {
|
||||
super(parent);
|
||||
this.view = view;
|
||||
this.direccionRepository = new DireccionRepository();
|
||||
this.validator = new DireccionValidator(this.direccionRepository);
|
||||
this.setupListeners();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
this.reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BasePanel getView() {
|
||||
return this.view;
|
||||
}
|
||||
|
||||
public void setTrabajador(Trabajador trabajador) {
|
||||
this.trabajador = trabajador;
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
this.loadDireccionesTable();
|
||||
this.view.getDireccionesTable().clearSelection();
|
||||
}
|
||||
|
||||
private void setupListeners() {
|
||||
this.view.getCrearButton().addActionListener(e -> this.create());
|
||||
this.view.getSearchField().addActionListener(e -> this.search());
|
||||
this.view.getBuscarButton().addActionListener(e -> this.search());
|
||||
this.view.getVerButton().addActionListener(e -> this.view());
|
||||
this.view.getEditarButton().addActionListener(e -> this.edit());
|
||||
this.view.getEliminarButton().addActionListener(e -> this.delete());
|
||||
this.view.getVolverButton().addActionListener(e -> this.volver());
|
||||
}
|
||||
|
||||
private void create() {
|
||||
DireccionCreateController controller = (DireccionCreateController) this.getParentController().getCard(PanelName.DIRECCION_CREATE);
|
||||
controller.setTrabajador(this.trabajador);
|
||||
this.getParentController().showCard(PanelName.DIRECCION_CREATE);
|
||||
}
|
||||
|
||||
private void edit() {
|
||||
Direccion direccion = this.getSelectedDireccion();
|
||||
if (direccion != null) {
|
||||
DireccionUpdateController controller = (DireccionUpdateController) this.getParentController().getCard(PanelName.DIRECCION_UPDATE);
|
||||
controller.setTrabajador(this.trabajador);
|
||||
controller.setDireccion(direccion);
|
||||
this.getParentController().showCard(PanelName.DIRECCION_UPDATE);
|
||||
}
|
||||
}
|
||||
|
||||
private void delete() {
|
||||
Direccion direccion = this.getSelectedDireccion();
|
||||
if (direccion == null)
|
||||
return;
|
||||
|
||||
int option = JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
"¿Estas seguro de que deseas eliminar la abstract_direccion?",
|
||||
"Confirmacion",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE
|
||||
);
|
||||
if (option == JOptionPane.NO_OPTION)
|
||||
return;
|
||||
|
||||
this.direccionRepository.delete(direccion);
|
||||
this.trabajador.getDirecciones().remove(direccion);
|
||||
this.reload();
|
||||
}
|
||||
|
||||
private void view() {
|
||||
Direccion direccion = this.getSelectedDireccion();
|
||||
if (direccion != null) {
|
||||
DireccionViewController controller = (DireccionViewController) this.getParentController().getCard(PanelName.DIRECCION_VIEW);
|
||||
controller.setDireccion(direccion);
|
||||
controller.setTrabajador(this.trabajador);
|
||||
this.getParentController().showCard(PanelName.DIRECCION_VIEW);
|
||||
}
|
||||
}
|
||||
|
||||
private void search() {
|
||||
String term = this.view.getSearchField().getText();
|
||||
List<Direccion> direccion = this.direccionRepository.search(term, this.trabajador);
|
||||
this.loadDireccionesTable(direccion);
|
||||
}
|
||||
|
||||
private void volver() {
|
||||
TrabajadorViewController controller = (TrabajadorViewController) this.getParentController().getCard(PanelName.TRABAJADOR_VIEW);
|
||||
controller.setTrabajador(this.trabajador);
|
||||
this.getParentController().showCard(PanelName.TRABAJADOR_VIEW);
|
||||
}
|
||||
|
||||
private void loadDireccionesTable() {
|
||||
List<Direccion> direccions = this.trabajador.getDirecciones();
|
||||
this.loadDireccionesTable(direccions);
|
||||
}
|
||||
|
||||
private void loadDireccionesTable(List<Direccion> direccions) {
|
||||
BaseTableModel<Direccion> model = this.view.getDireccionModel();
|
||||
model.setRows(direccions);
|
||||
}
|
||||
|
||||
private Direccion getSelectedDireccion() {
|
||||
int selectedRow = this.view.getDireccionesTable().getSelectedRow();
|
||||
if (selectedRow == -1) {
|
||||
JOptionPane.showMessageDialog(
|
||||
null,
|
||||
"No hay abstract_direccion seleccionada",
|
||||
"Error",
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.view.getDireccionModel().getRow(selectedRow);
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
package xyz.danielcortes.controllers.trabajador.direccion;
|
||||
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.framework.BaseController;
|
||||
import xyz.danielcortes.framework.BasePanel;
|
||||
import xyz.danielcortes.framework.PanelName;
|
||||
import xyz.danielcortes.framework.ValidationResult;
|
||||
import xyz.danielcortes.models.Direccion;
|
||||
import xyz.danielcortes.models.Trabajador;
|
||||
import xyz.danielcortes.repository.DireccionRepository;
|
||||
import xyz.danielcortes.validator.DireccionValidator;
|
||||
import xyz.danielcortes.views.direccion.DireccionUpdatePanel;
|
||||
|
||||
public class DireccionUpdateController extends BaseController {
|
||||
|
||||
private Trabajador trabajador;
|
||||
private Direccion direccion;
|
||||
private DireccionUpdatePanel view;
|
||||
private DireccionRepository repository;
|
||||
private DireccionValidator validator;
|
||||
|
||||
public DireccionUpdateController(DireccionUpdatePanel view, LaunchController parentController) {
|
||||
super(parentController);
|
||||
this.view = view;
|
||||
this.repository = new DireccionRepository();
|
||||
this.validator = new DireccionValidator(this.repository);
|
||||
this.setupListeners();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LaunchController getParentController() {
|
||||
return this.parentController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
this.view.getCalleField().requestFocus();
|
||||
this.fillDireccion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BasePanel getView() {
|
||||
return this.view;
|
||||
}
|
||||
|
||||
public void setTrabajador(Trabajador trabajador) {
|
||||
this.trabajador = trabajador;
|
||||
}
|
||||
|
||||
public void setDireccion(Direccion direccion) {
|
||||
this.direccion = direccion;
|
||||
}
|
||||
|
||||
public void fillDireccion() {
|
||||
this.view.getCalleField().setText(this.direccion.getCalle());
|
||||
this.view.getNumeroField().setText(this.direccion.getNumero());
|
||||
}
|
||||
|
||||
private void setupListeners() {
|
||||
this.view.getNumeroField().addActionListener(e -> this.update());
|
||||
this.view.getActualizarButton().addActionListener(e -> this.update());
|
||||
this.view.getVolverButton().addActionListener(e -> this.volver());
|
||||
}
|
||||
|
||||
private void update() {
|
||||
String calle = this.view.getCalleField().getText();
|
||||
String numero = this.view.getNumeroField().getText();
|
||||
|
||||
ValidationResult originalValidation = this.validator.validateOriginal(this.direccion);
|
||||
if (originalValidation.hasError()) {
|
||||
originalValidation.showErrorDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
ValidationResult direccionValidation = this.validator.validateCalle(calle);
|
||||
if (direccionValidation.hasError()) {
|
||||
direccionValidation.showErrorDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
ValidationResult numeroValidation = this.validator.validateNumero(numero);
|
||||
if (numeroValidation.hasError()) {
|
||||
numeroValidation.showErrorDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
this.direccion.setCalle(calle);
|
||||
this.direccion.setNumero(numero);
|
||||
this.repository.update(this.direccion);
|
||||
|
||||
this.volver();
|
||||
}
|
||||
|
||||
private void volver() {
|
||||
DireccionSearchController controller = (DireccionSearchController) this.getParentController().getCard(PanelName.DIRECCION_SEARCH);
|
||||
controller.setTrabajador(this.trabajador);
|
||||
this.getParentController().showCard(PanelName.DIRECCION_SEARCH);
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package xyz.danielcortes.controllers.trabajador.direccion;
|
||||
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.framework.BaseController;
|
||||
import xyz.danielcortes.framework.BasePanel;
|
||||
import xyz.danielcortes.framework.PanelName;
|
||||
import xyz.danielcortes.models.Direccion;
|
||||
import xyz.danielcortes.models.Trabajador;
|
||||
import xyz.danielcortes.views.direccion.DireccionViewPanel;
|
||||
|
||||
public class DireccionViewController extends BaseController {
|
||||
|
||||
private Trabajador trabajador;
|
||||
private Direccion direccion;
|
||||
private DireccionViewPanel view;
|
||||
|
||||
public DireccionViewController(DireccionViewPanel view, LaunchController parentController) {
|
||||
super(parentController);
|
||||
this.view = view;
|
||||
this.setupListeners();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LaunchController getParentController() {
|
||||
return this.parentController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
this.fillDireccion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BasePanel getView() {
|
||||
return this.view;
|
||||
}
|
||||
|
||||
public void setTrabajador(Trabajador trabajador) {
|
||||
this.trabajador = trabajador;
|
||||
}
|
||||
|
||||
public void setDireccion(Direccion direccion) {
|
||||
this.direccion = direccion;
|
||||
}
|
||||
|
||||
public void fillDireccion() {
|
||||
this.view.getCalleField().setText(this.direccion.getCalle());
|
||||
this.view.getNumeroField().setText(this.direccion.getNumero());
|
||||
}
|
||||
|
||||
private void setupListeners() {
|
||||
this.view.getVolverButton().addActionListener(e -> this.volver());
|
||||
}
|
||||
|
||||
private void volver() {
|
||||
DireccionSearchController controller = (DireccionSearchController) this.getParentController().getCard(PanelName.DIRECCION_SEARCH);
|
||||
controller.setTrabajador(this.trabajador);
|
||||
this.getParentController().showCard(PanelName.DIRECCION_SEARCH);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package xyz.danielcortes.controllers.trabajador.direccion;
|
||||
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.controllers.abstract_direccion.AbstractDireccionCreateController;
|
||||
import xyz.danielcortes.framework.PanelName;
|
||||
import xyz.danielcortes.framework.ValidationResult;
|
||||
import xyz.danielcortes.models.Direccion;
|
||||
import xyz.danielcortes.models.Trabajador;
|
||||
import xyz.danielcortes.views.direccion.DireccionCreatePanel;
|
||||
|
||||
public class TrabajadorDireccionCreateController extends AbstractDireccionCreateController {
|
||||
|
||||
private Trabajador trabajador;
|
||||
|
||||
public TrabajadorDireccionCreateController(DireccionCreatePanel view, LaunchController parentController) {
|
||||
super(view, parentController);
|
||||
}
|
||||
|
||||
public void setTrabajador(Trabajador trabajador) {
|
||||
this.trabajador = trabajador;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void save() {
|
||||
String calle = this.view.getCalleField().getText();
|
||||
String numero = this.view.getNumeroField().getText();
|
||||
|
||||
ValidationResult direccionValidation = this.validator.validateCalle(calle);
|
||||
if (direccionValidation.hasError()) {
|
||||
direccionValidation.showErrorDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
ValidationResult numeroValidation = this.validator.validateNumero(numero);
|
||||
if (numeroValidation.hasError()) {
|
||||
numeroValidation.showErrorDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
Direccion direccion = new Direccion();
|
||||
direccion.setCalle(calle);
|
||||
direccion.setNumero(numero);
|
||||
direccion.getTrabajadores().add(this.trabajador);
|
||||
|
||||
this.repository.save(direccion);
|
||||
this.trabajador.getDirecciones().add(direccion);
|
||||
|
||||
this.volver();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void volver() {
|
||||
TrabajadorDireccionSearchController controller = (TrabajadorDireccionSearchController) this.getParentController()
|
||||
.getCard(PanelName.TRABAJADOR_DIRECCION_SEARCH);
|
||||
controller.setTrabajador(this.trabajador);
|
||||
this.getParentController().showCard(PanelName.TRABAJADOR_DIRECCION_SEARCH);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package xyz.danielcortes.controllers.trabajador.direccion;
|
||||
|
||||
import java.util.List;
|
||||
import javax.swing.JOptionPane;
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.controllers.abstract_direccion.AbstractDireccionSearchController;
|
||||
import xyz.danielcortes.controllers.trabajador.TrabajadorViewController;
|
||||
import xyz.danielcortes.framework.PanelName;
|
||||
import xyz.danielcortes.models.Direccion;
|
||||
import xyz.danielcortes.models.Trabajador;
|
||||
import xyz.danielcortes.views.direccion.DireccionSearchPanel;
|
||||
|
||||
public class TrabajadorDireccionSearchController extends AbstractDireccionSearchController {
|
||||
|
||||
private Trabajador trabajador;
|
||||
|
||||
public TrabajadorDireccionSearchController(DireccionSearchPanel view, LaunchController parent) {
|
||||
super(view, parent);
|
||||
}
|
||||
|
||||
public void setTrabajador(Trabajador trabajador) {
|
||||
this.trabajador = trabajador;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void create() {
|
||||
TrabajadorDireccionCreateController controller = (TrabajadorDireccionCreateController) this.getParentController()
|
||||
.getCard(PanelName.TRABAJADOR_DIRECCION_CREATE);
|
||||
controller.setTrabajador(this.trabajador);
|
||||
this.getParentController().showCard(PanelName.TRABAJADOR_DIRECCION_CREATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void edit() {
|
||||
Direccion direccion = this.getSelectedDireccion();
|
||||
if (direccion != null) {
|
||||
TrabajadorDireccionUpdateController controller = (TrabajadorDireccionUpdateController) this.getParentController()
|
||||
.getCard(PanelName.TRABAJADOR_DIRECCION_UPDATE);
|
||||
controller.setTrabajador(this.trabajador);
|
||||
controller.setDireccion(direccion);
|
||||
this.getParentController().showCard(PanelName.TRABAJADOR_DIRECCION_UPDATE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void delete() {
|
||||
Direccion direccion = this.getSelectedDireccion();
|
||||
if (direccion == null)
|
||||
return;
|
||||
|
||||
int option = JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
"¿Estas seguro de que deseas eliminar la direccion?",
|
||||
"Confirmacion",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE
|
||||
);
|
||||
if (option == JOptionPane.NO_OPTION)
|
||||
return;
|
||||
|
||||
this.direccionRepository.delete(direccion);
|
||||
this.trabajador.getDirecciones().remove(direccion);
|
||||
this.reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void view() {
|
||||
Direccion direccion = this.getSelectedDireccion();
|
||||
if (direccion != null) {
|
||||
TrabajadorDireccionViewController controller = (TrabajadorDireccionViewController) this.getParentController()
|
||||
.getCard(PanelName.TRABAJADOR_DIRECCION_VIEW);
|
||||
controller.setDireccion(direccion);
|
||||
controller.setTrabajador(this.trabajador);
|
||||
this.getParentController().showCard(PanelName.TRABAJADOR_DIRECCION_VIEW);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void search() {
|
||||
String term = this.view.getSearchField().getText();
|
||||
List<Direccion> direccion = this.direccionRepository.search(term, this.trabajador);
|
||||
this.loadDireccionesTable(direccion);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void volver() {
|
||||
TrabajadorViewController controller = (TrabajadorViewController) this.getParentController().getCard(PanelName.TRABAJADOR_VIEW);
|
||||
controller.setTrabajador(this.trabajador);
|
||||
this.getParentController().showCard(PanelName.TRABAJADOR_VIEW);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadDireccionesTable() {
|
||||
List<Direccion> direccions = this.trabajador.getDirecciones();
|
||||
this.loadDireccionesTable(direccions);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package xyz.danielcortes.controllers.trabajador.direccion;
|
||||
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.controllers.abstract_direccion.AbstractDireccionUpdateController;
|
||||
import xyz.danielcortes.framework.PanelName;
|
||||
import xyz.danielcortes.models.Trabajador;
|
||||
import xyz.danielcortes.views.direccion.DireccionUpdatePanel;
|
||||
|
||||
public class TrabajadorDireccionUpdateController extends AbstractDireccionUpdateController {
|
||||
|
||||
private Trabajador trabajador;
|
||||
|
||||
public TrabajadorDireccionUpdateController(DireccionUpdatePanel view, LaunchController parentController) {
|
||||
super(view, parentController);
|
||||
}
|
||||
|
||||
public void setTrabajador(Trabajador trabajador) {
|
||||
this.trabajador = trabajador;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void volver() {
|
||||
TrabajadorDireccionSearchController controller = (TrabajadorDireccionSearchController) this.getParentController()
|
||||
.getCard(PanelName.TRABAJADOR_DIRECCION_SEARCH);
|
||||
controller.setTrabajador(this.trabajador);
|
||||
this.getParentController().showCard(PanelName.TRABAJADOR_DIRECCION_SEARCH);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package xyz.danielcortes.controllers.trabajador.direccion;
|
||||
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.controllers.abstract_direccion.AbstractDireccionViewController;
|
||||
import xyz.danielcortes.framework.PanelName;
|
||||
import xyz.danielcortes.models.Trabajador;
|
||||
import xyz.danielcortes.views.direccion.DireccionViewPanel;
|
||||
|
||||
public class TrabajadorDireccionViewController extends AbstractDireccionViewController {
|
||||
|
||||
private Trabajador trabajador;
|
||||
|
||||
public TrabajadorDireccionViewController(DireccionViewPanel view, LaunchController parentController) {
|
||||
super(view, parentController);
|
||||
}
|
||||
|
||||
public void setTrabajador(Trabajador trabajador) {
|
||||
this.trabajador = trabajador;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void volver() {
|
||||
TrabajadorDireccionSearchController controller = (TrabajadorDireccionSearchController) this.getParentController()
|
||||
.getCard(PanelName.TRABAJADOR_DIRECCION_SEARCH);
|
||||
controller.setTrabajador(this.trabajador);
|
||||
this.getParentController().showCard(PanelName.TRABAJADOR_DIRECCION_SEARCH);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -72,10 +72,20 @@ public enum PanelName {
|
||||
TELEFONO_CREATE,
|
||||
TELEFONO_UPDATE,
|
||||
|
||||
DIRECCION_VIEW,
|
||||
DIRECCION_SEARCH,
|
||||
DIRECCION_CREATE,
|
||||
DIRECCION_UPDATE,
|
||||
TRABAJADOR_DIRECCION_VIEW,
|
||||
TRABAJADOR_DIRECCION_SEARCH,
|
||||
TRABAJADOR_DIRECCION_CREATE,
|
||||
TRABAJADOR_DIRECCION_UPDATE,
|
||||
|
||||
DISTRIBUIDOR_DIRECCION_VIEW,
|
||||
DISTRIBUIDOR_DIRECCION_SEARCH,
|
||||
DISTRIBUIDOR_DIRECCION_CREATE,
|
||||
DISTRIBUIDOR_DIRECCION_UPDATE,
|
||||
|
||||
CLIENTE_DIRECCION_VIEW,
|
||||
CLIENTE_DIRECCION_SEARCH,
|
||||
CLIENTE_DIRECCION_CREATE,
|
||||
CLIENTE_DIRECCION_UPDATE,
|
||||
|
||||
COMPRAR_LIBRO,
|
||||
}
|
||||
|
||||
@@ -4,26 +4,46 @@ import java.util.List;
|
||||
import javax.persistence.Query;
|
||||
import javax.persistence.TypedQuery;
|
||||
import xyz.danielcortes.framework.BaseRepository;
|
||||
import xyz.danielcortes.models.Cliente;
|
||||
import xyz.danielcortes.models.Direccion;
|
||||
import xyz.danielcortes.models.Distribuidor;
|
||||
import xyz.danielcortes.models.Trabajador;
|
||||
|
||||
public class DireccionRepository extends BaseRepository<Direccion> {
|
||||
|
||||
public List<Direccion> getAll() {
|
||||
TypedQuery<Direccion> query = em.createQuery("SELECT t FROM Direccion t", Direccion.class);
|
||||
TypedQuery<Direccion> query = this.em.createQuery("SELECT t FROM Direccion t", Direccion.class);
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
public List<Direccion> search(String term) {
|
||||
Query query = em.createQuery("SELECT d FROM Direccion d WHERE LOWER(d.calle) LIKE :term AND LOWER(d.numero) LIKE :term");
|
||||
Query query = this.em.createQuery("SELECT d FROM Direccion d WHERE LOWER(d.calle) LIKE :term AND LOWER(d.numero) LIKE :term");
|
||||
query.setParameter("term", "%" + term.toLowerCase() + "%");
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
public List<Direccion> search(String term, Trabajador trabajador) {
|
||||
Query query = em.createQuery("SELECT d FROM Direccion d JOIN d.trabajadores t WHERE t.id = :id AND (LOWER(d.calle) LIKE :term OR LOWER(d.numero) LIKE :term)");
|
||||
Query query = this.em.createQuery(
|
||||
"SELECT d FROM Direccion d JOIN d.trabajadores t WHERE t.id = :id AND (LOWER(d.calle) LIKE :term OR LOWER(d.numero) LIKE :term)");
|
||||
query.setParameter("id", trabajador.getId());
|
||||
query.setParameter("term", "%" + term.toLowerCase() + "%");
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
public List<Direccion> search(String term, Cliente cliente) {
|
||||
Query query = this.em
|
||||
.createQuery("SELECT d FROM Direccion d JOIN d.clientes t WHERE t.id = :id AND (LOWER(d.calle) LIKE :term OR LOWER(d.numero) LIKE :term)");
|
||||
query.setParameter("id", cliente.getId());
|
||||
query.setParameter("term", "%" + term.toLowerCase() + "%");
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
public List<Direccion> search(String term, Distribuidor distribuidor) {
|
||||
Query query = this.em
|
||||
.createQuery(
|
||||
"SELECT d FROM Direccion d JOIN d.distribuidores t WHERE t.id = :id AND (LOWER(d.calle) LIKE :term OR LOWER(d.numero) LIKE :term)");
|
||||
query.setParameter("id", distribuidor.getId());
|
||||
query.setParameter("term", "%" + term.toLowerCase() + "%");
|
||||
return query.getResultList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="xyz.danielcortes.views.trabajador.TrabajadorCreatePanel">
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="xyz.danielcortes.views.cliente.TrabajadorCreatePanel">
|
||||
<grid id="27dc6" binding="contentPane" layout-manager="GridLayoutManager" row-count="12" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="20" left="20" bottom="20" right="20"/>
|
||||
<constraints>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="xyz.danielcortes.views.trabajador.TrabajadorSearchPanel">
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="xyz.danielcortes.views.cliente.TrabajadorSearchPanel">
|
||||
<grid id="27dc6" binding="contentPane" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="20" left="20" bottom="20" right="20"/>
|
||||
<constraints>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="xyz.danielcortes.views.trabajador.TrabajadorUpdatePanel">
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="xyz.danielcortes.views.cliente.TrabajadorUpdatePanel">
|
||||
<grid id="27dc6" binding="contentPane" layout-manager="GridLayoutManager" row-count="12" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="20" left="20" bottom="20" right="20"/>
|
||||
<constraints>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="xyz.danielcortes.views.trabajador.TrabajadorViewPanel">
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="xyz.danielcortes.views.cliente.TrabajadorViewPanel">
|
||||
<grid id="27dc6" binding="contentPane" layout-manager="GridLayoutManager" row-count="13" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="20" left="20" bottom="20" right="20"/>
|
||||
<constraints>
|
||||
|
||||
Reference in New Issue
Block a user