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.CategoriaViewController;
|
||||
import xyz.danielcortes.controllers.editorial.EditorialCreateController;
|
||||
import xyz.danielcortes.controllers.editorial.EditorialDeleteController;
|
||||
import xyz.danielcortes.controllers.editorial.EditorialListController;
|
||||
import xyz.danielcortes.controllers.editorial.EditorialUpdateController;
|
||||
import xyz.danielcortes.controllers.idioma.IdiomaCreateController;
|
||||
import xyz.danielcortes.controllers.idioma.IdiomaDeleteController;
|
||||
import xyz.danielcortes.controllers.idioma.IdiomaListController;
|
||||
import xyz.danielcortes.controllers.idioma.IdiomaUpdateController;
|
||||
import xyz.danielcortes.controllers.libro.LibroCreateController;
|
||||
import xyz.danielcortes.controllers.libro.LibroDeleteController;
|
||||
import xyz.danielcortes.controllers.libro.LibroListController;
|
||||
import xyz.danielcortes.controllers.libro.LibroUpdateController;
|
||||
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.CategoriaViewPanel;
|
||||
import xyz.danielcortes.views.editorial.EditorialCreatePanel;
|
||||
import xyz.danielcortes.views.editorial.EditorialDeletePanel;
|
||||
import xyz.danielcortes.views.editorial.EditorialListPanel;
|
||||
import xyz.danielcortes.views.editorial.EditorialUpdatePanel;
|
||||
import xyz.danielcortes.views.idioma.IdiomaCreatePanel;
|
||||
import xyz.danielcortes.views.idioma.IdiomaDeletePanel;
|
||||
import xyz.danielcortes.views.idioma.IdiomaListPanel;
|
||||
import xyz.danielcortes.views.idioma.IdiomaUpdatePanel;
|
||||
import xyz.danielcortes.views.libro.LibroCreatePanel;
|
||||
import xyz.danielcortes.views.libro.LibroDeletePanel;
|
||||
import xyz.danielcortes.views.libro.LibroListPanel;
|
||||
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_CREATE, new LibroCreateController(new LibroCreatePanel(), 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_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_CREATE, new IdiomaCreateController(new IdiomaCreatePanel(), 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_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_CREATE, new EditorialCreateController(new EditorialCreatePanel(), 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()) {
|
||||
BaseController controller = this.controllers.get(name);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package xyz.danielcortes.controllers.autor;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import xyz.danielcortes.controllers.BaseController;
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.models.Autor;
|
||||
@@ -12,11 +11,13 @@ public class AutorCreateController extends BaseController {
|
||||
|
||||
private AutorCreatePanel view;
|
||||
private AutorRepository autorRepository;
|
||||
private AutorValidator validator;
|
||||
|
||||
public AutorCreateController(AutorCreatePanel view, LaunchController parent) {
|
||||
super(parent);
|
||||
this.view = view;
|
||||
this.autorRepository = new AutorRepository();
|
||||
this.validator = new AutorValidator(this.autorRepository);
|
||||
this.setupListeners();
|
||||
}
|
||||
|
||||
@@ -32,11 +33,11 @@ public class AutorCreateController extends BaseController {
|
||||
|
||||
private void save() {
|
||||
String nombre = view.getNombreField().getText();
|
||||
if (!validateNombre(nombre)) return;
|
||||
if (!this.validator.validateNombre(nombre)) return;
|
||||
String apellidoPaterno = view.getApellidoPaternoField().getText();
|
||||
if (!validateApellidoPaterno(apellidoPaterno)) return;
|
||||
if (!this.validator.validateApellidoPaterno(apellidoPaterno)) return;
|
||||
String apellidoMaterno = view.getApellidoMaternoField().getText();
|
||||
if (!validateApellidoMaterno(apellidoMaterno)) return;
|
||||
if (!this.validator.validateApellidoMaterno(apellidoMaterno)) return;
|
||||
|
||||
Autor autor = new Autor();
|
||||
autor.setNombre(nombre);
|
||||
@@ -51,63 +52,6 @@ public class AutorCreateController extends BaseController {
|
||||
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() {
|
||||
return this.view;
|
||||
}
|
||||
|
||||
@@ -15,11 +15,13 @@ public class AutorSearchController extends BaseController {
|
||||
|
||||
private AutorSearchPanel view;
|
||||
private AutorRepository autorRepository;
|
||||
private AutorValidator validator;
|
||||
|
||||
public AutorSearchController(AutorSearchPanel view, LaunchController parent) {
|
||||
super(parent);
|
||||
this.view = view;
|
||||
this.autorRepository = new AutorRepository();
|
||||
this.validator = new AutorValidator(this.autorRepository);
|
||||
this.setupListeners();
|
||||
}
|
||||
|
||||
@@ -54,6 +56,8 @@ public class AutorSearchController extends BaseController {
|
||||
Autor autor = this.getSelectedAutor();
|
||||
if (autor == null)
|
||||
return;
|
||||
if(!this.validator.isDeleteable(autor))
|
||||
return;
|
||||
|
||||
int option = JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package xyz.danielcortes.controllers.autor;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import xyz.danielcortes.controllers.BaseController;
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.framework.PanelName;
|
||||
@@ -14,11 +13,13 @@ public class AutorUpdateController extends BaseController {
|
||||
private Autor autor;
|
||||
private AutorUpdatePanel view;
|
||||
private AutorRepository autorRepository;
|
||||
private AutorValidator validator;
|
||||
|
||||
public AutorUpdateController(AutorUpdatePanel view, LaunchController parent) {
|
||||
super(parent);
|
||||
this.view = view;
|
||||
this.autorRepository = new AutorRepository();
|
||||
this.validator = new AutorValidator(this.autorRepository);
|
||||
this.setupListeners();
|
||||
}
|
||||
|
||||
@@ -48,19 +49,19 @@ public class AutorUpdateController extends BaseController {
|
||||
}
|
||||
|
||||
private void update() {
|
||||
if (!validateOriginal(this.autor))
|
||||
if (!this.validator.validateOriginal(this.autor))
|
||||
return;
|
||||
|
||||
String nombre = this.view.getNombreField().getText();
|
||||
if (!validateNombre(nombre))
|
||||
if (!this.validator.validateNombre(nombre))
|
||||
return;
|
||||
|
||||
String apellidoPaterno = this.view.getApellidoPaternoField().getText();
|
||||
if (!validateApellidoPaterno(apellidoPaterno))
|
||||
if (!this.validator.validateApellidoPaterno(apellidoPaterno))
|
||||
return;
|
||||
|
||||
String apellidoMaterno = this.view.getApellidoMaternoField().getText();
|
||||
if (!validateApellidoMaterno(apellidoMaterno))
|
||||
if (!this.validator.validateApellidoMaterno(apellidoMaterno))
|
||||
return;
|
||||
|
||||
assert this.autor != null;
|
||||
@@ -73,73 +74,6 @@ public class AutorUpdateController extends BaseController {
|
||||
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() {
|
||||
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;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import xyz.danielcortes.controllers.BaseController;
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.models.Categoria;
|
||||
@@ -11,11 +10,14 @@ import xyz.danielcortes.views.categoria.CategoriaCreatePanel;
|
||||
public class CategoriaCreateController extends BaseController {
|
||||
private CategoriaRepository categoriaRepository;
|
||||
private CategoriaCreatePanel view;
|
||||
private CategoriaValidator validator;
|
||||
|
||||
public CategoriaCreateController(CategoriaCreatePanel view, LaunchController parent) {
|
||||
super(parent);
|
||||
this.view = view;
|
||||
categoriaRepository = new CategoriaRepository();
|
||||
this.categoriaRepository = new CategoriaRepository();
|
||||
this.validator = new CategoriaValidator(this.categoriaRepository);
|
||||
|
||||
this.setupListeners();
|
||||
}
|
||||
|
||||
@@ -31,7 +33,7 @@ public class CategoriaCreateController extends BaseController {
|
||||
|
||||
private void save() {
|
||||
String nombre = view.getNombreField().getText();
|
||||
if(!validateNombre(nombre)) return;
|
||||
if(!this.validator.validateNombre(nombre)) return;
|
||||
|
||||
Categoria categoria = new Categoria();
|
||||
categoria.setNombre(nombre);
|
||||
@@ -42,25 +44,6 @@ public class CategoriaCreateController extends BaseController {
|
||||
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() {
|
||||
return view;
|
||||
}
|
||||
|
||||
@@ -15,13 +15,16 @@ public class CategoriaSearchController extends BaseController {
|
||||
|
||||
private CategoriaRepository categoriaRepository;
|
||||
private CategoriaSearchPanel view;
|
||||
private CategoriaValidator validator;
|
||||
|
||||
public CategoriaSearchController(CategoriaSearchPanel view, LaunchController parent) {
|
||||
super(parent);
|
||||
this.view = view;
|
||||
this.categoriaRepository = new CategoriaRepository();
|
||||
this.validator = new CategoriaValidator(this.categoriaRepository);
|
||||
this.loadCategoriaTable();
|
||||
this.setupListeners();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,6 +54,8 @@ public class CategoriaSearchController extends BaseController {
|
||||
Categoria categoria = this.getSelectedCategoria();
|
||||
if (categoria == null)
|
||||
return;
|
||||
if(!this.validator.isDeleteable(categoria))
|
||||
return;
|
||||
|
||||
int option = JOptionPane.showConfirmDialog(
|
||||
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;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import xyz.danielcortes.controllers.BaseController;
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.models.Editorial;
|
||||
@@ -12,11 +11,13 @@ public class EditorialCreateController extends BaseController {
|
||||
|
||||
private EditorialRepository editorialRepository;
|
||||
private EditorialCreatePanel view;
|
||||
private EditorialValidator validator;
|
||||
|
||||
public EditorialCreateController(EditorialCreatePanel view, LaunchController parent) {
|
||||
super(parent);
|
||||
this.view = view;
|
||||
this.editorialRepository = new EditorialRepository();
|
||||
this.validator = new EditorialValidator(this.editorialRepository);
|
||||
|
||||
this.setupListeners();
|
||||
}
|
||||
@@ -33,36 +34,17 @@ public class EditorialCreateController extends BaseController {
|
||||
|
||||
private void save() {
|
||||
String nombre = this.view.getNombreField().getText();
|
||||
if(!validateNombre(nombre)) return;
|
||||
if(!this.validator.validateNombre(nombre)) return;
|
||||
|
||||
Editorial editorial = new Editorial();
|
||||
editorial.setNombre(nombre);
|
||||
|
||||
editorialRepository.save(editorial);
|
||||
this.editorialRepository.save(editorial);
|
||||
|
||||
this.view.getNombreField().setText("");
|
||||
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() {
|
||||
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 javax.swing.JComboBox;
|
||||
import javax.swing.JOptionPane;
|
||||
import xyz.danielcortes.controllers.BaseController;
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.models.Editorial;
|
||||
@@ -14,11 +13,13 @@ public class EditorialUpdateController extends BaseController {
|
||||
|
||||
private EditorialUpdatePanel view;
|
||||
private EditorialRepository editorialRepository;
|
||||
private EditorialValidator validator;
|
||||
|
||||
public EditorialUpdateController(EditorialUpdatePanel view, LaunchController parent) {
|
||||
super(parent);
|
||||
this.view = view;
|
||||
this.editorialRepository = new EditorialRepository();
|
||||
this.validator = new EditorialValidator(this.editorialRepository);
|
||||
this.setupListeners();
|
||||
}
|
||||
|
||||
@@ -40,11 +41,11 @@ public class EditorialUpdateController extends BaseController {
|
||||
|
||||
private void update() {
|
||||
Editorial original = (Editorial) this.view.getEditorialCombo().getSelectedItem();
|
||||
if (!validateOriginal(original))
|
||||
if (!this.validator.validateOriginal(original))
|
||||
return;
|
||||
|
||||
String nombre = this.view.getNombreField().getText();
|
||||
if (!validateNombre(nombre))
|
||||
if (!this.validator.validateNombre(nombre))
|
||||
return;
|
||||
|
||||
assert original != null;
|
||||
@@ -56,37 +57,6 @@ public class EditorialUpdateController extends BaseController {
|
||||
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() {
|
||||
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;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import xyz.danielcortes.controllers.BaseController;
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.models.Idioma;
|
||||
@@ -12,11 +11,13 @@ public class IdiomaCreateController extends BaseController {
|
||||
|
||||
private IdiomaRepository idiomaRepository;
|
||||
private IdiomaCreatePanel view;
|
||||
private IdiomaValidator validator;
|
||||
|
||||
public IdiomaCreateController(IdiomaCreatePanel view, LaunchController parent) {
|
||||
super(parent);
|
||||
this.idiomaRepository = new IdiomaRepository();
|
||||
this.view = view;
|
||||
this.idiomaRepository = new IdiomaRepository();
|
||||
this.validator = new IdiomaValidator(this.idiomaRepository);
|
||||
|
||||
this.setupListeners();
|
||||
}
|
||||
@@ -33,7 +34,8 @@ public class IdiomaCreateController extends BaseController {
|
||||
|
||||
private void save() {
|
||||
String nombre = view.getNombreField().getText();
|
||||
if (!validateNombre(nombre)) return;
|
||||
if (!this.validator.validateNombre(nombre))
|
||||
return;
|
||||
|
||||
Idioma idioma = new Idioma();
|
||||
idioma.setNombre(nombre);
|
||||
@@ -44,25 +46,6 @@ public class IdiomaCreateController extends BaseController {
|
||||
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() {
|
||||
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 javax.swing.JComboBox;
|
||||
import javax.swing.JOptionPane;
|
||||
import xyz.danielcortes.controllers.BaseController;
|
||||
import xyz.danielcortes.controllers.LaunchController;
|
||||
import xyz.danielcortes.models.Idioma;
|
||||
@@ -14,11 +13,13 @@ public class IdiomaUpdateController extends BaseController {
|
||||
|
||||
private IdiomaUpdatePanel view;
|
||||
private IdiomaRepository idiomaRepository;
|
||||
private IdiomaValidator validator;
|
||||
|
||||
public IdiomaUpdateController(IdiomaUpdatePanel view, LaunchController parent) {
|
||||
super(parent);
|
||||
this.view = view;
|
||||
this.idiomaRepository = new IdiomaRepository();
|
||||
this.validator = new IdiomaValidator(this.idiomaRepository);
|
||||
this.setupListeners();
|
||||
}
|
||||
|
||||
@@ -40,10 +41,10 @@ public class IdiomaUpdateController extends BaseController {
|
||||
|
||||
private void update() {
|
||||
Idioma original = (Idioma) this.view.getIdiomaCombo().getSelectedItem();
|
||||
if (!validateOriginal(original)) return;
|
||||
if (!this.validator.validateOriginal(original)) return;
|
||||
|
||||
String nombre = this.view.getNombreField().getText();
|
||||
if (!validateNombre(nombre)) return;
|
||||
if (!this.validator.validateNombre(nombre)) return;
|
||||
|
||||
assert original != null;
|
||||
original.setNombre(nombre);
|
||||
@@ -54,38 +55,6 @@ public class IdiomaUpdateController extends BaseController {
|
||||
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() {
|
||||
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) {
|
||||
rows.clear();
|
||||
this.removeRows();
|
||||
rows.addAll(items);
|
||||
this.fireTableRowsInserted(0, getRowCount() - 1);
|
||||
}
|
||||
@@ -104,6 +104,10 @@ public class BaseTableModel<T> extends AbstractTableModel {
|
||||
}
|
||||
|
||||
public T getRow(int row){
|
||||
if(row > -1 || row < this.getRowCount()) {
|
||||
return rows.get(row);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user