Se crearon clases para la validacion de los controladores
This commit is contained in:
@@ -16,15 +16,12 @@ import xyz.danielcortes.controllers.categoria.CategoriaSearchController;
|
|||||||
import xyz.danielcortes.controllers.categoria.CategoriaUpdateController;
|
import xyz.danielcortes.controllers.categoria.CategoriaUpdateController;
|
||||||
import xyz.danielcortes.controllers.categoria.CategoriaViewController;
|
import xyz.danielcortes.controllers.categoria.CategoriaViewController;
|
||||||
import xyz.danielcortes.controllers.editorial.EditorialCreateController;
|
import xyz.danielcortes.controllers.editorial.EditorialCreateController;
|
||||||
import xyz.danielcortes.controllers.editorial.EditorialDeleteController;
|
|
||||||
import xyz.danielcortes.controllers.editorial.EditorialListController;
|
import xyz.danielcortes.controllers.editorial.EditorialListController;
|
||||||
import xyz.danielcortes.controllers.editorial.EditorialUpdateController;
|
import xyz.danielcortes.controllers.editorial.EditorialUpdateController;
|
||||||
import xyz.danielcortes.controllers.idioma.IdiomaCreateController;
|
import xyz.danielcortes.controllers.idioma.IdiomaCreateController;
|
||||||
import xyz.danielcortes.controllers.idioma.IdiomaDeleteController;
|
|
||||||
import xyz.danielcortes.controllers.idioma.IdiomaListController;
|
import xyz.danielcortes.controllers.idioma.IdiomaListController;
|
||||||
import xyz.danielcortes.controllers.idioma.IdiomaUpdateController;
|
import xyz.danielcortes.controllers.idioma.IdiomaUpdateController;
|
||||||
import xyz.danielcortes.controllers.libro.LibroCreateController;
|
import xyz.danielcortes.controllers.libro.LibroCreateController;
|
||||||
import xyz.danielcortes.controllers.libro.LibroDeleteController;
|
|
||||||
import xyz.danielcortes.controllers.libro.LibroListController;
|
import xyz.danielcortes.controllers.libro.LibroListController;
|
||||||
import xyz.danielcortes.controllers.libro.LibroUpdateController;
|
import xyz.danielcortes.controllers.libro.LibroUpdateController;
|
||||||
import xyz.danielcortes.framework.PanelName;
|
import xyz.danielcortes.framework.PanelName;
|
||||||
@@ -38,15 +35,12 @@ import xyz.danielcortes.views.categoria.CategoriaSearchPanel;
|
|||||||
import xyz.danielcortes.views.categoria.CategoriaUpdatePanel;
|
import xyz.danielcortes.views.categoria.CategoriaUpdatePanel;
|
||||||
import xyz.danielcortes.views.categoria.CategoriaViewPanel;
|
import xyz.danielcortes.views.categoria.CategoriaViewPanel;
|
||||||
import xyz.danielcortes.views.editorial.EditorialCreatePanel;
|
import xyz.danielcortes.views.editorial.EditorialCreatePanel;
|
||||||
import xyz.danielcortes.views.editorial.EditorialDeletePanel;
|
|
||||||
import xyz.danielcortes.views.editorial.EditorialListPanel;
|
import xyz.danielcortes.views.editorial.EditorialListPanel;
|
||||||
import xyz.danielcortes.views.editorial.EditorialUpdatePanel;
|
import xyz.danielcortes.views.editorial.EditorialUpdatePanel;
|
||||||
import xyz.danielcortes.views.idioma.IdiomaCreatePanel;
|
import xyz.danielcortes.views.idioma.IdiomaCreatePanel;
|
||||||
import xyz.danielcortes.views.idioma.IdiomaDeletePanel;
|
|
||||||
import xyz.danielcortes.views.idioma.IdiomaListPanel;
|
import xyz.danielcortes.views.idioma.IdiomaListPanel;
|
||||||
import xyz.danielcortes.views.idioma.IdiomaUpdatePanel;
|
import xyz.danielcortes.views.idioma.IdiomaUpdatePanel;
|
||||||
import xyz.danielcortes.views.libro.LibroCreatePanel;
|
import xyz.danielcortes.views.libro.LibroCreatePanel;
|
||||||
import xyz.danielcortes.views.libro.LibroDeletePanel;
|
|
||||||
import xyz.danielcortes.views.libro.LibroListPanel;
|
import xyz.danielcortes.views.libro.LibroListPanel;
|
||||||
import xyz.danielcortes.views.libro.LibroUpdatePanel;
|
import xyz.danielcortes.views.libro.LibroUpdatePanel;
|
||||||
|
|
||||||
@@ -71,7 +65,6 @@ public class LaunchController {
|
|||||||
this.controllers.put(PanelName.LIBRO_SEARCH, new LibroListController(new LibroListPanel(), this));
|
this.controllers.put(PanelName.LIBRO_SEARCH, new LibroListController(new LibroListPanel(), this));
|
||||||
this.controllers.put(PanelName.LIBRO_CREATE, new LibroCreateController(new LibroCreatePanel(), this));
|
this.controllers.put(PanelName.LIBRO_CREATE, new LibroCreateController(new LibroCreatePanel(), this));
|
||||||
this.controllers.put(PanelName.LIBRO_UPDATE, new LibroUpdateController(new LibroUpdatePanel(), this));
|
this.controllers.put(PanelName.LIBRO_UPDATE, new LibroUpdateController(new LibroUpdatePanel(), this));
|
||||||
this.controllers.put(PanelName.LIBRO_DELETE, new LibroDeleteController(new LibroDeletePanel(), this));
|
|
||||||
|
|
||||||
this.controllers.put(PanelName.AUTOR_VIEW, new AutorViewController(new AutorViewPanel(), this));
|
this.controllers.put(PanelName.AUTOR_VIEW, new AutorViewController(new AutorViewPanel(), this));
|
||||||
this.controllers.put(PanelName.AUTOR_SEARCH, new AutorSearchController(new AutorSearchPanel(), this));
|
this.controllers.put(PanelName.AUTOR_SEARCH, new AutorSearchController(new AutorSearchPanel(), this));
|
||||||
@@ -81,7 +74,6 @@ public class LaunchController {
|
|||||||
this.controllers.put(PanelName.IDIOMA_SEARCH, new IdiomaListController(new IdiomaListPanel(), this));
|
this.controllers.put(PanelName.IDIOMA_SEARCH, new IdiomaListController(new IdiomaListPanel(), this));
|
||||||
this.controllers.put(PanelName.IDIOMA_CREATE, new IdiomaCreateController(new IdiomaCreatePanel(), this));
|
this.controllers.put(PanelName.IDIOMA_CREATE, new IdiomaCreateController(new IdiomaCreatePanel(), this));
|
||||||
this.controllers.put(PanelName.IDIOMA_UPDATE, new IdiomaUpdateController(new IdiomaUpdatePanel(), this));
|
this.controllers.put(PanelName.IDIOMA_UPDATE, new IdiomaUpdateController(new IdiomaUpdatePanel(), this));
|
||||||
this.controllers.put(PanelName.IDIOMA_DELETE, new IdiomaDeleteController(new IdiomaDeletePanel(), this));
|
|
||||||
|
|
||||||
this.controllers.put(PanelName.CATEGORIA_SEARCH, new CategoriaSearchController(new CategoriaSearchPanel(), this));
|
this.controllers.put(PanelName.CATEGORIA_SEARCH, new CategoriaSearchController(new CategoriaSearchPanel(), this));
|
||||||
this.controllers.put(PanelName.CATEGORIA_CREATE, new CategoriaCreateController(new CategoriaCreatePanel(), this));
|
this.controllers.put(PanelName.CATEGORIA_CREATE, new CategoriaCreateController(new CategoriaCreatePanel(), this));
|
||||||
@@ -91,7 +83,6 @@ public class LaunchController {
|
|||||||
this.controllers.put(PanelName.EDITORIAL_SEARCH, new EditorialListController(new EditorialListPanel(), this));
|
this.controllers.put(PanelName.EDITORIAL_SEARCH, new EditorialListController(new EditorialListPanel(), this));
|
||||||
this.controllers.put(PanelName.EDITORIAL_CREATE, new EditorialCreateController(new EditorialCreatePanel(), this));
|
this.controllers.put(PanelName.EDITORIAL_CREATE, new EditorialCreateController(new EditorialCreatePanel(), this));
|
||||||
this.controllers.put(PanelName.EDITORIAL_UPDATE, new EditorialUpdateController(new EditorialUpdatePanel(), this));
|
this.controllers.put(PanelName.EDITORIAL_UPDATE, new EditorialUpdateController(new EditorialUpdatePanel(), this));
|
||||||
this.controllers.put(PanelName.EDITORIAL_DELETE, new EditorialDeleteController(new EditorialDeletePanel(), this));
|
|
||||||
|
|
||||||
for (PanelName name : this.controllers.keySet()) {
|
for (PanelName name : this.controllers.keySet()) {
|
||||||
BaseController controller = this.controllers.get(name);
|
BaseController controller = this.controllers.get(name);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package xyz.danielcortes.controllers.autor;
|
package xyz.danielcortes.controllers.autor;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import xyz.danielcortes.controllers.BaseController;
|
import xyz.danielcortes.controllers.BaseController;
|
||||||
import xyz.danielcortes.controllers.LaunchController;
|
import xyz.danielcortes.controllers.LaunchController;
|
||||||
import xyz.danielcortes.models.Autor;
|
import xyz.danielcortes.models.Autor;
|
||||||
@@ -12,11 +11,13 @@ public class AutorCreateController extends BaseController {
|
|||||||
|
|
||||||
private AutorCreatePanel view;
|
private AutorCreatePanel view;
|
||||||
private AutorRepository autorRepository;
|
private AutorRepository autorRepository;
|
||||||
|
private AutorValidator validator;
|
||||||
|
|
||||||
public AutorCreateController(AutorCreatePanel view, LaunchController parent) {
|
public AutorCreateController(AutorCreatePanel view, LaunchController parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.autorRepository = new AutorRepository();
|
this.autorRepository = new AutorRepository();
|
||||||
|
this.validator = new AutorValidator(this.autorRepository);
|
||||||
this.setupListeners();
|
this.setupListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,11 +33,11 @@ public class AutorCreateController extends BaseController {
|
|||||||
|
|
||||||
private void save() {
|
private void save() {
|
||||||
String nombre = view.getNombreField().getText();
|
String nombre = view.getNombreField().getText();
|
||||||
if (!validateNombre(nombre)) return;
|
if (!this.validator.validateNombre(nombre)) return;
|
||||||
String apellidoPaterno = view.getApellidoPaternoField().getText();
|
String apellidoPaterno = view.getApellidoPaternoField().getText();
|
||||||
if (!validateApellidoPaterno(apellidoPaterno)) return;
|
if (!this.validator.validateApellidoPaterno(apellidoPaterno)) return;
|
||||||
String apellidoMaterno = view.getApellidoMaternoField().getText();
|
String apellidoMaterno = view.getApellidoMaternoField().getText();
|
||||||
if (!validateApellidoMaterno(apellidoMaterno)) return;
|
if (!this.validator.validateApellidoMaterno(apellidoMaterno)) return;
|
||||||
|
|
||||||
Autor autor = new Autor();
|
Autor autor = new Autor();
|
||||||
autor.setNombre(nombre);
|
autor.setNombre(nombre);
|
||||||
@@ -51,63 +52,6 @@ public class AutorCreateController extends BaseController {
|
|||||||
this.view.getNombreField().requestFocus();
|
this.view.getNombreField().requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateNombre(String nombre) {
|
|
||||||
if (nombre == null) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
this.view.getContentPane(),
|
|
||||||
"El nombre es nulo",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
} else if (nombre.isEmpty()) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
this.view.getContentPane(),
|
|
||||||
"El nombre esta vacío",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean validateApellidoPaterno(String apellidoPaterno) {
|
|
||||||
if (apellidoPaterno == null) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
this.view.getContentPane(),
|
|
||||||
"El apellido paterno es nulo",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
} else if (apellidoPaterno.isEmpty()) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
this.view.getContentPane(),
|
|
||||||
"El apellido paterno esta vacío",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean validateApellidoMaterno(String apellidoMaterno) {
|
|
||||||
if (apellidoMaterno == null) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
this.view.getContentPane(),
|
|
||||||
"El apellido materno es nulo",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
} else if (apellidoMaterno.isEmpty()) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
this.view.getContentPane(),
|
|
||||||
"El apellido materno esta vacío",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasePanel getView() {
|
public BasePanel getView() {
|
||||||
return this.view;
|
return this.view;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,11 +15,13 @@ public class AutorSearchController extends BaseController {
|
|||||||
|
|
||||||
private AutorSearchPanel view;
|
private AutorSearchPanel view;
|
||||||
private AutorRepository autorRepository;
|
private AutorRepository autorRepository;
|
||||||
|
private AutorValidator validator;
|
||||||
|
|
||||||
public AutorSearchController(AutorSearchPanel view, LaunchController parent) {
|
public AutorSearchController(AutorSearchPanel view, LaunchController parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.autorRepository = new AutorRepository();
|
this.autorRepository = new AutorRepository();
|
||||||
|
this.validator = new AutorValidator(this.autorRepository);
|
||||||
this.setupListeners();
|
this.setupListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,6 +56,8 @@ public class AutorSearchController extends BaseController {
|
|||||||
Autor autor = this.getSelectedAutor();
|
Autor autor = this.getSelectedAutor();
|
||||||
if (autor == null)
|
if (autor == null)
|
||||||
return;
|
return;
|
||||||
|
if(!this.validator.isDeleteable(autor))
|
||||||
|
return;
|
||||||
|
|
||||||
int option = JOptionPane.showConfirmDialog(
|
int option = JOptionPane.showConfirmDialog(
|
||||||
null,
|
null,
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package xyz.danielcortes.controllers.autor;
|
package xyz.danielcortes.controllers.autor;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import xyz.danielcortes.controllers.BaseController;
|
import xyz.danielcortes.controllers.BaseController;
|
||||||
import xyz.danielcortes.controllers.LaunchController;
|
import xyz.danielcortes.controllers.LaunchController;
|
||||||
import xyz.danielcortes.framework.PanelName;
|
import xyz.danielcortes.framework.PanelName;
|
||||||
@@ -14,11 +13,13 @@ public class AutorUpdateController extends BaseController {
|
|||||||
private Autor autor;
|
private Autor autor;
|
||||||
private AutorUpdatePanel view;
|
private AutorUpdatePanel view;
|
||||||
private AutorRepository autorRepository;
|
private AutorRepository autorRepository;
|
||||||
|
private AutorValidator validator;
|
||||||
|
|
||||||
public AutorUpdateController(AutorUpdatePanel view, LaunchController parent) {
|
public AutorUpdateController(AutorUpdatePanel view, LaunchController parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.autorRepository = new AutorRepository();
|
this.autorRepository = new AutorRepository();
|
||||||
|
this.validator = new AutorValidator(this.autorRepository);
|
||||||
this.setupListeners();
|
this.setupListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,19 +49,19 @@ public class AutorUpdateController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void update() {
|
private void update() {
|
||||||
if (!validateOriginal(this.autor))
|
if (!this.validator.validateOriginal(this.autor))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String nombre = this.view.getNombreField().getText();
|
String nombre = this.view.getNombreField().getText();
|
||||||
if (!validateNombre(nombre))
|
if (!this.validator.validateNombre(nombre))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String apellidoPaterno = this.view.getApellidoPaternoField().getText();
|
String apellidoPaterno = this.view.getApellidoPaternoField().getText();
|
||||||
if (!validateApellidoPaterno(apellidoPaterno))
|
if (!this.validator.validateApellidoPaterno(apellidoPaterno))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String apellidoMaterno = this.view.getApellidoMaternoField().getText();
|
String apellidoMaterno = this.view.getApellidoMaternoField().getText();
|
||||||
if (!validateApellidoMaterno(apellidoMaterno))
|
if (!this.validator.validateApellidoMaterno(apellidoMaterno))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
assert this.autor != null;
|
assert this.autor != null;
|
||||||
@@ -73,73 +74,6 @@ public class AutorUpdateController extends BaseController {
|
|||||||
this.getParentController().showCard(PanelName.AUTOR_SEARCH);
|
this.getParentController().showCard(PanelName.AUTOR_SEARCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateOriginal(Autor original) {
|
|
||||||
if (original == null) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
null,
|
|
||||||
"No hay Autor seleccionado",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean validateNombre(String nombre) {
|
|
||||||
if (nombre == null) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
this.view.getContentPane(),
|
|
||||||
"El nombre es nulo",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
} else if (nombre.isEmpty()) {
|
|
||||||
JOptionPane.showMessageDialog(this.view.getContentPane(),
|
|
||||||
"El nombre esta vacío",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean validateApellidoPaterno(String apellidoPaterno) {
|
|
||||||
if (apellidoPaterno == null) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
this.view.getContentPane(),
|
|
||||||
"El apellido paterno es nulo",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
} else if (apellidoPaterno.isEmpty()) {
|
|
||||||
JOptionPane.showMessageDialog(this.view.getContentPane(),
|
|
||||||
"El apellido paterno esta vacío",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean validateApellidoMaterno(String apellidoMaterno) {
|
|
||||||
if (apellidoMaterno == null) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
this.view.getContentPane(),
|
|
||||||
"El apellido materno es nulo",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
} else if (apellidoMaterno.isEmpty()) {
|
|
||||||
JOptionPane.showMessageDialog(this.view.getContentPane(),
|
|
||||||
"El apellido materno esta vacío",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasePanel getView() {
|
public BasePanel getView() {
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package xyz.danielcortes.controllers.autor;
|
||||||
|
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import xyz.danielcortes.models.Autor;
|
||||||
|
import xyz.danielcortes.repository.AutorRepository;
|
||||||
|
|
||||||
|
public class AutorValidator {
|
||||||
|
|
||||||
|
private AutorRepository autorRepository;
|
||||||
|
|
||||||
|
public AutorValidator(AutorRepository autorRepository) {
|
||||||
|
this.autorRepository = autorRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean validateNombre(String nombre) {
|
||||||
|
if (nombre == null) {
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
null,
|
||||||
|
"El nombre es nulo",
|
||||||
|
"Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return false;
|
||||||
|
} else if (nombre.isEmpty()) {
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
null,
|
||||||
|
"El nombre esta vacío",
|
||||||
|
"Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean validateApellidoPaterno(String apellidoPaterno) {
|
||||||
|
if (apellidoPaterno == null) {
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
null,
|
||||||
|
"El apellido paterno es nulo",
|
||||||
|
"Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return false;
|
||||||
|
} else if (apellidoPaterno.isEmpty()) {
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
null,
|
||||||
|
"El apellido paterno esta vacío",
|
||||||
|
"Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean validateApellidoMaterno(String apellidoMaterno) {
|
||||||
|
if (apellidoMaterno == null) {
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
null,
|
||||||
|
"El apellido materno es nulo",
|
||||||
|
"Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return false;
|
||||||
|
} else if (apellidoMaterno.isEmpty()) {
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
null,
|
||||||
|
"El apellido materno esta vacío",
|
||||||
|
"Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean validateOriginal(Autor original) {
|
||||||
|
if (original == null) {
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
null,
|
||||||
|
"No hay Autor seleccionado",
|
||||||
|
"Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDeleteable(Autor autor){
|
||||||
|
if(autor.getLibros().size() > 0){
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
null,
|
||||||
|
"No se puede eliminar el autor ya que tiene libros asociados",
|
||||||
|
"Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package xyz.danielcortes.controllers.categoria;
|
package xyz.danielcortes.controllers.categoria;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import xyz.danielcortes.controllers.BaseController;
|
import xyz.danielcortes.controllers.BaseController;
|
||||||
import xyz.danielcortes.controllers.LaunchController;
|
import xyz.danielcortes.controllers.LaunchController;
|
||||||
import xyz.danielcortes.models.Categoria;
|
import xyz.danielcortes.models.Categoria;
|
||||||
@@ -11,11 +10,14 @@ import xyz.danielcortes.views.categoria.CategoriaCreatePanel;
|
|||||||
public class CategoriaCreateController extends BaseController {
|
public class CategoriaCreateController extends BaseController {
|
||||||
private CategoriaRepository categoriaRepository;
|
private CategoriaRepository categoriaRepository;
|
||||||
private CategoriaCreatePanel view;
|
private CategoriaCreatePanel view;
|
||||||
|
private CategoriaValidator validator;
|
||||||
|
|
||||||
public CategoriaCreateController(CategoriaCreatePanel view, LaunchController parent) {
|
public CategoriaCreateController(CategoriaCreatePanel view, LaunchController parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
this.view = view;
|
this.view = view;
|
||||||
categoriaRepository = new CategoriaRepository();
|
this.categoriaRepository = new CategoriaRepository();
|
||||||
|
this.validator = new CategoriaValidator(this.categoriaRepository);
|
||||||
|
|
||||||
this.setupListeners();
|
this.setupListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +33,7 @@ public class CategoriaCreateController extends BaseController {
|
|||||||
|
|
||||||
private void save() {
|
private void save() {
|
||||||
String nombre = view.getNombreField().getText();
|
String nombre = view.getNombreField().getText();
|
||||||
if(!validateNombre(nombre)) return;
|
if(!this.validator.validateNombre(nombre)) return;
|
||||||
|
|
||||||
Categoria categoria = new Categoria();
|
Categoria categoria = new Categoria();
|
||||||
categoria.setNombre(nombre);
|
categoria.setNombre(nombre);
|
||||||
@@ -42,25 +44,6 @@ public class CategoriaCreateController extends BaseController {
|
|||||||
this.view.getNombreField().requestFocus();
|
this.view.getNombreField().requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateNombre(String nombre) {
|
|
||||||
if (nombre == null) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
this.view.getContentPane(),
|
|
||||||
"El nombre es nulo",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
} else if (nombre.isEmpty()) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
this.view.getContentPane(),
|
|
||||||
"El nombre esta vacío",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasePanel getView() {
|
public BasePanel getView() {
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,13 +15,16 @@ public class CategoriaSearchController extends BaseController {
|
|||||||
|
|
||||||
private CategoriaRepository categoriaRepository;
|
private CategoriaRepository categoriaRepository;
|
||||||
private CategoriaSearchPanel view;
|
private CategoriaSearchPanel view;
|
||||||
|
private CategoriaValidator validator;
|
||||||
|
|
||||||
public CategoriaSearchController(CategoriaSearchPanel view, LaunchController parent) {
|
public CategoriaSearchController(CategoriaSearchPanel view, LaunchController parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.categoriaRepository = new CategoriaRepository();
|
this.categoriaRepository = new CategoriaRepository();
|
||||||
|
this.validator = new CategoriaValidator(this.categoriaRepository);
|
||||||
this.loadCategoriaTable();
|
this.loadCategoriaTable();
|
||||||
this.setupListeners();
|
this.setupListeners();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -51,6 +54,8 @@ public class CategoriaSearchController extends BaseController {
|
|||||||
Categoria categoria = this.getSelectedCategoria();
|
Categoria categoria = this.getSelectedCategoria();
|
||||||
if (categoria == null)
|
if (categoria == null)
|
||||||
return;
|
return;
|
||||||
|
if(!this.validator.isDeleteable(categoria))
|
||||||
|
return;
|
||||||
|
|
||||||
int option = JOptionPane.showConfirmDialog(
|
int option = JOptionPane.showConfirmDialog(
|
||||||
null,
|
null,
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package xyz.danielcortes.controllers.categoria;
|
||||||
|
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import xyz.danielcortes.models.Categoria;
|
||||||
|
import xyz.danielcortes.repository.CategoriaRepository;
|
||||||
|
|
||||||
|
public class CategoriaValidator {
|
||||||
|
|
||||||
|
private CategoriaRepository categoriaRepository;
|
||||||
|
|
||||||
|
public CategoriaValidator(CategoriaRepository categoriaRepository) {
|
||||||
|
this.categoriaRepository = categoriaRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean validateNombre(String nombre) {
|
||||||
|
if (nombre == null) {
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
null,
|
||||||
|
"El nombre es nulo",
|
||||||
|
"Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return false;
|
||||||
|
} else if (nombre.isEmpty()) {
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
null,
|
||||||
|
"El nombre esta vacío",
|
||||||
|
"Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isDeleteable(Categoria categoria){
|
||||||
|
if(categoria.getLibros().size() > 0){
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
null,
|
||||||
|
"No se puede eliminar la categoria ya que tiene libros asociados",
|
||||||
|
"Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package xyz.danielcortes.controllers.editorial;
|
package xyz.danielcortes.controllers.editorial;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import xyz.danielcortes.controllers.BaseController;
|
import xyz.danielcortes.controllers.BaseController;
|
||||||
import xyz.danielcortes.controllers.LaunchController;
|
import xyz.danielcortes.controllers.LaunchController;
|
||||||
import xyz.danielcortes.models.Editorial;
|
import xyz.danielcortes.models.Editorial;
|
||||||
@@ -12,11 +11,13 @@ public class EditorialCreateController extends BaseController {
|
|||||||
|
|
||||||
private EditorialRepository editorialRepository;
|
private EditorialRepository editorialRepository;
|
||||||
private EditorialCreatePanel view;
|
private EditorialCreatePanel view;
|
||||||
|
private EditorialValidator validator;
|
||||||
|
|
||||||
public EditorialCreateController(EditorialCreatePanel view, LaunchController parent) {
|
public EditorialCreateController(EditorialCreatePanel view, LaunchController parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.editorialRepository = new EditorialRepository();
|
this.editorialRepository = new EditorialRepository();
|
||||||
|
this.validator = new EditorialValidator(this.editorialRepository);
|
||||||
|
|
||||||
this.setupListeners();
|
this.setupListeners();
|
||||||
}
|
}
|
||||||
@@ -33,36 +34,17 @@ public class EditorialCreateController extends BaseController {
|
|||||||
|
|
||||||
private void save() {
|
private void save() {
|
||||||
String nombre = this.view.getNombreField().getText();
|
String nombre = this.view.getNombreField().getText();
|
||||||
if(!validateNombre(nombre)) return;
|
if(!this.validator.validateNombre(nombre)) return;
|
||||||
|
|
||||||
Editorial editorial = new Editorial();
|
Editorial editorial = new Editorial();
|
||||||
editorial.setNombre(nombre);
|
editorial.setNombre(nombre);
|
||||||
|
|
||||||
editorialRepository.save(editorial);
|
this.editorialRepository.save(editorial);
|
||||||
|
|
||||||
this.view.getNombreField().setText("");
|
this.view.getNombreField().setText("");
|
||||||
this.view.getNombreField().requestFocus();
|
this.view.getNombreField().requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateNombre(String nombre) {
|
|
||||||
if (nombre == null) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
this.view.getContentPane(),
|
|
||||||
"El nombre es nulo",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
} else if (nombre.isEmpty()) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
this.view.getContentPane(),
|
|
||||||
"El nombre esta vacío",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasePanel getView() {
|
public BasePanel getView() {
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
package xyz.danielcortes.controllers.editorial;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import javax.swing.JComboBox;
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import xyz.danielcortes.controllers.BaseController;
|
|
||||||
import xyz.danielcortes.controllers.LaunchController;
|
|
||||||
import xyz.danielcortes.models.Editorial;
|
|
||||||
import xyz.danielcortes.repository.EditorialRepository;
|
|
||||||
import xyz.danielcortes.views.BasePanel;
|
|
||||||
import xyz.danielcortes.views.editorial.EditorialDeletePanel;
|
|
||||||
|
|
||||||
public class EditorialDeleteController extends BaseController {
|
|
||||||
private EditorialDeletePanel view;
|
|
||||||
private EditorialRepository editorialRepository;
|
|
||||||
|
|
||||||
public EditorialDeleteController(EditorialDeletePanel view, LaunchController parent) {
|
|
||||||
super(parent);
|
|
||||||
this.view = view;
|
|
||||||
this.editorialRepository = new EditorialRepository();
|
|
||||||
|
|
||||||
this.setupListeners();
|
|
||||||
this.loadEditorialCombo();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void show() {
|
|
||||||
this.reload();
|
|
||||||
this.view.getEditorialCombo().requestFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setupListeners(){
|
|
||||||
this.view.getEliminarButton().addActionListener(e -> this.delete());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void delete(){
|
|
||||||
Editorial selected = (Editorial) this.view.getEditorialCombo().getSelectedItem();
|
|
||||||
if(!validateEditorial(selected)) return;
|
|
||||||
|
|
||||||
this.editorialRepository.delete(selected);
|
|
||||||
this.reload();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean validateEditorial(Editorial editorial){
|
|
||||||
if (editorial== null) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
this.view.getContentPane(),
|
|
||||||
"No hay editorial seleccionada",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reload() {
|
|
||||||
this.loadEditorialCombo();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadEditorialCombo(){
|
|
||||||
List<Editorial> editoriales = this.editorialRepository.getAll();
|
|
||||||
JComboBox<Editorial> comboBox = this.view.getEditorialCombo();
|
|
||||||
comboBox.removeAllItems();
|
|
||||||
for(Editorial editorial: editoriales){
|
|
||||||
comboBox.addItem(editorial);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasePanel getView() {
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,6 @@ package xyz.danielcortes.controllers.editorial;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.swing.JComboBox;
|
import javax.swing.JComboBox;
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import xyz.danielcortes.controllers.BaseController;
|
import xyz.danielcortes.controllers.BaseController;
|
||||||
import xyz.danielcortes.controllers.LaunchController;
|
import xyz.danielcortes.controllers.LaunchController;
|
||||||
import xyz.danielcortes.models.Editorial;
|
import xyz.danielcortes.models.Editorial;
|
||||||
@@ -14,11 +13,13 @@ public class EditorialUpdateController extends BaseController {
|
|||||||
|
|
||||||
private EditorialUpdatePanel view;
|
private EditorialUpdatePanel view;
|
||||||
private EditorialRepository editorialRepository;
|
private EditorialRepository editorialRepository;
|
||||||
|
private EditorialValidator validator;
|
||||||
|
|
||||||
public EditorialUpdateController(EditorialUpdatePanel view, LaunchController parent) {
|
public EditorialUpdateController(EditorialUpdatePanel view, LaunchController parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.editorialRepository = new EditorialRepository();
|
this.editorialRepository = new EditorialRepository();
|
||||||
|
this.validator = new EditorialValidator(this.editorialRepository);
|
||||||
this.setupListeners();
|
this.setupListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,11 +41,11 @@ public class EditorialUpdateController extends BaseController {
|
|||||||
|
|
||||||
private void update() {
|
private void update() {
|
||||||
Editorial original = (Editorial) this.view.getEditorialCombo().getSelectedItem();
|
Editorial original = (Editorial) this.view.getEditorialCombo().getSelectedItem();
|
||||||
if (!validateOriginal(original))
|
if (!this.validator.validateOriginal(original))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String nombre = this.view.getNombreField().getText();
|
String nombre = this.view.getNombreField().getText();
|
||||||
if (!validateNombre(nombre))
|
if (!this.validator.validateNombre(nombre))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
assert original != null;
|
assert original != null;
|
||||||
@@ -56,37 +57,6 @@ public class EditorialUpdateController extends BaseController {
|
|||||||
this.view.getNombreField().requestFocus();
|
this.view.getNombreField().requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateOriginal(Editorial original) {
|
|
||||||
if (original == null) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
null,
|
|
||||||
"No hay Editorial seleccionada",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean validateNombre(String nombre) {
|
|
||||||
if (nombre == null) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
this.view.getContentPane(),
|
|
||||||
"El nombre es nulo",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
} else if (nombre.isEmpty()) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
this.view.getContentPane(),
|
|
||||||
"El nombre esta vacío",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reload() {
|
public void reload() {
|
||||||
this.loadEditorialCombo();
|
this.loadEditorialCombo();
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package xyz.danielcortes.controllers.editorial;
|
||||||
|
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import xyz.danielcortes.models.Editorial;
|
||||||
|
import xyz.danielcortes.repository.EditorialRepository;
|
||||||
|
|
||||||
|
public class EditorialValidator {
|
||||||
|
|
||||||
|
private EditorialRepository editorialRepository;
|
||||||
|
|
||||||
|
public EditorialValidator(EditorialRepository editorialRepository) {
|
||||||
|
this.editorialRepository = editorialRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean validateNombre(String nombre) {
|
||||||
|
if (nombre == null) {
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
null,
|
||||||
|
"El nombre es nulo",
|
||||||
|
"Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return false;
|
||||||
|
} else if (nombre.isEmpty()) {
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
null,
|
||||||
|
"El nombre esta vacío",
|
||||||
|
"Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean validateOriginal(Editorial original) {
|
||||||
|
if (original == null) {
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
null,
|
||||||
|
"No hay Editorial seleccionada",
|
||||||
|
"Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package xyz.danielcortes.controllers.idioma;
|
package xyz.danielcortes.controllers.idioma;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import xyz.danielcortes.controllers.BaseController;
|
import xyz.danielcortes.controllers.BaseController;
|
||||||
import xyz.danielcortes.controllers.LaunchController;
|
import xyz.danielcortes.controllers.LaunchController;
|
||||||
import xyz.danielcortes.models.Idioma;
|
import xyz.danielcortes.models.Idioma;
|
||||||
@@ -12,11 +11,13 @@ public class IdiomaCreateController extends BaseController {
|
|||||||
|
|
||||||
private IdiomaRepository idiomaRepository;
|
private IdiomaRepository idiomaRepository;
|
||||||
private IdiomaCreatePanel view;
|
private IdiomaCreatePanel view;
|
||||||
|
private IdiomaValidator validator;
|
||||||
|
|
||||||
public IdiomaCreateController(IdiomaCreatePanel view, LaunchController parent) {
|
public IdiomaCreateController(IdiomaCreatePanel view, LaunchController parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
this.idiomaRepository = new IdiomaRepository();
|
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
this.idiomaRepository = new IdiomaRepository();
|
||||||
|
this.validator = new IdiomaValidator(this.idiomaRepository);
|
||||||
|
|
||||||
this.setupListeners();
|
this.setupListeners();
|
||||||
}
|
}
|
||||||
@@ -33,7 +34,8 @@ public class IdiomaCreateController extends BaseController {
|
|||||||
|
|
||||||
private void save() {
|
private void save() {
|
||||||
String nombre = view.getNombreField().getText();
|
String nombre = view.getNombreField().getText();
|
||||||
if (!validateNombre(nombre)) return;
|
if (!this.validator.validateNombre(nombre))
|
||||||
|
return;
|
||||||
|
|
||||||
Idioma idioma = new Idioma();
|
Idioma idioma = new Idioma();
|
||||||
idioma.setNombre(nombre);
|
idioma.setNombre(nombre);
|
||||||
@@ -44,25 +46,6 @@ public class IdiomaCreateController extends BaseController {
|
|||||||
this.view.getNombreField().requestFocus();
|
this.view.getNombreField().requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateNombre(String nombre) {
|
|
||||||
if (nombre == null) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
this.view.getContentPane(),
|
|
||||||
"El nombre es nulo",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
} else if (nombre.isEmpty()) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
this.view.getContentPane(),
|
|
||||||
"El nombre esta vacío",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasePanel getView() {
|
public BasePanel getView() {
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,73 +0,0 @@
|
|||||||
package xyz.danielcortes.controllers.idioma;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import javax.swing.JComboBox;
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import xyz.danielcortes.controllers.BaseController;
|
|
||||||
import xyz.danielcortes.controllers.LaunchController;
|
|
||||||
import xyz.danielcortes.models.Idioma;
|
|
||||||
import xyz.danielcortes.repository.IdiomaRepository;
|
|
||||||
import xyz.danielcortes.views.BasePanel;
|
|
||||||
import xyz.danielcortes.views.idioma.IdiomaDeletePanel;
|
|
||||||
|
|
||||||
public class IdiomaDeleteController extends BaseController {
|
|
||||||
|
|
||||||
private IdiomaDeletePanel view;
|
|
||||||
private IdiomaRepository idiomaRepository;
|
|
||||||
|
|
||||||
public IdiomaDeleteController(IdiomaDeletePanel view, LaunchController parent) {
|
|
||||||
super(parent);
|
|
||||||
this.view = view;
|
|
||||||
this.idiomaRepository = new IdiomaRepository();
|
|
||||||
this.loadIdiomaCombo();
|
|
||||||
this.setupListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void show() {
|
|
||||||
this.reload();
|
|
||||||
this.view.getIdiomaCombo().requestFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setupListeners() {
|
|
||||||
this.view.getEliminarButton().addActionListener(e -> this.delete());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void delete() {
|
|
||||||
Idioma selected = (Idioma) this.view.getIdiomaCombo().getSelectedItem();
|
|
||||||
if (!validateIdioma(selected)) return;
|
|
||||||
|
|
||||||
this.idiomaRepository.delete(selected);
|
|
||||||
this.reload();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean validateIdioma(Idioma idioma) {
|
|
||||||
if (idioma == null) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
this.view.getContentPane(),
|
|
||||||
"No hay idioma seleccionado",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reload() {
|
|
||||||
this.loadIdiomaCombo();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadIdiomaCombo() {
|
|
||||||
List<Idioma> idiomas = this.idiomaRepository.getAll();
|
|
||||||
JComboBox<Idioma> combobox = this.view.getIdiomaCombo();
|
|
||||||
combobox.removeAllItems();
|
|
||||||
for (Idioma idioma : idiomas) {
|
|
||||||
combobox.addItem(idioma);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasePanel getView() {
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,6 @@ package xyz.danielcortes.controllers.idioma;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.swing.JComboBox;
|
import javax.swing.JComboBox;
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import xyz.danielcortes.controllers.BaseController;
|
import xyz.danielcortes.controllers.BaseController;
|
||||||
import xyz.danielcortes.controllers.LaunchController;
|
import xyz.danielcortes.controllers.LaunchController;
|
||||||
import xyz.danielcortes.models.Idioma;
|
import xyz.danielcortes.models.Idioma;
|
||||||
@@ -14,11 +13,13 @@ public class IdiomaUpdateController extends BaseController {
|
|||||||
|
|
||||||
private IdiomaUpdatePanel view;
|
private IdiomaUpdatePanel view;
|
||||||
private IdiomaRepository idiomaRepository;
|
private IdiomaRepository idiomaRepository;
|
||||||
|
private IdiomaValidator validator;
|
||||||
|
|
||||||
public IdiomaUpdateController(IdiomaUpdatePanel view, LaunchController parent) {
|
public IdiomaUpdateController(IdiomaUpdatePanel view, LaunchController parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.idiomaRepository = new IdiomaRepository();
|
this.idiomaRepository = new IdiomaRepository();
|
||||||
|
this.validator = new IdiomaValidator(this.idiomaRepository);
|
||||||
this.setupListeners();
|
this.setupListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,10 +41,10 @@ public class IdiomaUpdateController extends BaseController {
|
|||||||
|
|
||||||
private void update() {
|
private void update() {
|
||||||
Idioma original = (Idioma) this.view.getIdiomaCombo().getSelectedItem();
|
Idioma original = (Idioma) this.view.getIdiomaCombo().getSelectedItem();
|
||||||
if (!validateOriginal(original)) return;
|
if (!this.validator.validateOriginal(original)) return;
|
||||||
|
|
||||||
String nombre = this.view.getNombreField().getText();
|
String nombre = this.view.getNombreField().getText();
|
||||||
if (!validateNombre(nombre)) return;
|
if (!this.validator.validateNombre(nombre)) return;
|
||||||
|
|
||||||
assert original != null;
|
assert original != null;
|
||||||
original.setNombre(nombre);
|
original.setNombre(nombre);
|
||||||
@@ -54,38 +55,6 @@ public class IdiomaUpdateController extends BaseController {
|
|||||||
this.view.getNombreField().requestFocus();
|
this.view.getNombreField().requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateOriginal(Idioma original) {
|
|
||||||
if (original == null) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
null,
|
|
||||||
"No hay Idioma seleccionado",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean validateNombre(String nombre) {
|
|
||||||
if (nombre == null) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
this.view.getContentPane(),
|
|
||||||
"El nombre es nulo",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
} else if (nombre.isEmpty()) {
|
|
||||||
JOptionPane.showMessageDialog(
|
|
||||||
this.view.getContentPane(),
|
|
||||||
"El nombre esta vacío",
|
|
||||||
"Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reload() {
|
public void reload() {
|
||||||
this.loadIdiomaCombo();
|
this.loadIdiomaCombo();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package xyz.danielcortes.controllers.idioma;
|
||||||
|
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import xyz.danielcortes.models.Idioma;
|
||||||
|
import xyz.danielcortes.repository.IdiomaRepository;
|
||||||
|
|
||||||
|
public class IdiomaValidator {
|
||||||
|
|
||||||
|
private IdiomaRepository idiomaRepository;
|
||||||
|
|
||||||
|
public IdiomaValidator(IdiomaRepository idiomaRepository) {
|
||||||
|
this.idiomaRepository = idiomaRepository;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean validateOriginal(Idioma original) {
|
||||||
|
if (original == null) {
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
null,
|
||||||
|
"No hay Idioma seleccionado",
|
||||||
|
"Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean validateNombre(String nombre) {
|
||||||
|
if (nombre == null) {
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
null,
|
||||||
|
"El nombre es nulo",
|
||||||
|
"Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return false;
|
||||||
|
} else if (nombre.isEmpty()) {
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
null,
|
||||||
|
"El nombre esta vacío",
|
||||||
|
"Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -85,7 +85,7 @@ public class BaseTableModel<T> extends AbstractTableModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setRows(List<T> items) {
|
public void setRows(List<T> items) {
|
||||||
rows.clear();
|
this.removeRows();
|
||||||
rows.addAll(items);
|
rows.addAll(items);
|
||||||
this.fireTableRowsInserted(0, getRowCount() - 1);
|
this.fireTableRowsInserted(0, getRowCount() - 1);
|
||||||
}
|
}
|
||||||
@@ -104,6 +104,10 @@ public class BaseTableModel<T> extends AbstractTableModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public T getRow(int row){
|
public T getRow(int row){
|
||||||
return rows.get(row);
|
if(row > -1 || row < this.getRowCount()) {
|
||||||
|
return rows.get(row);
|
||||||
|
}else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user