muchos cambios en el objetivo que se puedan crear usuarios

Todo por ellos <3

La gracia es que al ver un trabajador te da la opcion de usuario, dentro
de ella si es que no tiene un usuario creado puede crear uno, y una vez
creado, pasa a ver su nombre de usuario y desde esa vista, puede ir a
editar su usuario cambiando su nombre y contraseña a gusto, me
gustaria poder poner un placeholder en el campo de la contraseña pero no
me deja :c
This commit is contained in:
Daniel Cortés
2019-06-04 20:19:12 -04:00
parent dc52c8daae
commit a5a30b3a3d
21 changed files with 1158 additions and 45 deletions

84
dump.sql Normal file
View File

@@ -0,0 +1,84 @@
-- MySQL dump 10.17 Distrib 10.3.15-MariaDB, for Linux (x86_64)
--
-- Host: localhost Database: biblioteca
-- ------------------------------------------------------
-- Server version 10.3.15-MariaDB
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `usuario`
--
DROP TABLE IF EXISTS `usuario`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `usuario` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`nombre` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`trabajador_id` int(10) unsigned NOT NULL,
`inserted_at` timestamp NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (`id`),
KEY `trabajador_id` (`trabajador_id`),
CONSTRAINT `usuario_ibfk_1` FOREIGN KEY (`trabajador_id`) REFERENCES `trabajador` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `usuario`
--
LOCK TABLES `usuario` WRITE;
/*!40000 ALTER TABLE `usuario` DISABLE KEYS */;
/*!40000 ALTER TABLE `usuario` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `trabajador`
--
DROP TABLE IF EXISTS `trabajador`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `trabajador` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`rut` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`nombre` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`apellido_paterno` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`apellido_materno` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`fecha_contrato` date NOT NULL,
`inserted_at` timestamp NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `trabajador`
--
LOCK TABLES `trabajador` WRITE;
/*!40000 ALTER TABLE `trabajador` DISABLE KEYS */;
INSERT INTO `trabajador` VALUES (1,'197638990','Daniel','Cortes','Pincheira','2019-06-04','2019-06-04 22:12:55');
/*!40000 ALTER TABLE `trabajador` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2019-06-04 20:10:06

View File

@@ -13,6 +13,7 @@ drop table if exists ejemplar;
drop table if exists libro_autor; drop table if exists libro_autor;
drop table if exists libro_categoria; drop table if exists libro_categoria;
drop table if exists libro_idioma; drop table if exists libro_idioma;
drop table if exists correo;
drop table if exists direccion; drop table if exists direccion;
drop table if exists telefono; drop table if exists telefono;
drop table if exists empresa; drop table if exists empresa;
@@ -21,10 +22,13 @@ drop table if exists cliente;
drop table if exists trabajador; drop table if exists trabajador;
drop table if exists distribuidor_direccion; drop table if exists distribuidor_direccion;
drop table if exists distribuidor_telefono; drop table if exists distribuidor_telefono;
drop table if exists distribuidor_correo;
drop table if exists cliente_direccion; drop table if exists cliente_direccion;
drop table if exists cliente_telefono; drop table if exists cliente_telefono;
drop table if exists cliente_correo;
drop table if exists trabajador_direccion; drop table if exists trabajador_direccion;
drop table if exists trabajador_telefono; drop table if exists trabajador_telefono;
drop table if exists trabajador_correo;
drop table if exists factura; drop table if exists factura;
drop table if exists boleta; drop table if exists boleta;
drop table if exists compra; drop table if exists compra;
@@ -356,7 +360,7 @@ create table usuario
( (
id int unsigned primary key auto_increment, id int unsigned primary key auto_increment,
nombre varchar(255) not null, nombre varchar(255) not null,
password varbinary(2000) not null, password varchar(255) not null,
trabajador_id int unsigned not null, trabajador_id int unsigned not null,
foreign key (trabajador_id) references trabajador (id) on delete cascade on update cascade, foreign key (trabajador_id) references trabajador (id) on delete cascade on update cascade,
inserted_at timestamp default current_timestamp inserted_at timestamp default current_timestamp
@@ -437,3 +441,9 @@ values (1, 2),
(7, 2), (7, 2),
(8, 2), (8, 2),
(9, 2); (9, 2);
INSERT INTO trabajador
VALUES (1, '197638990', 'Daniel', 'Cortes', 'Pincheira', '2019-06-04', '2019-06-04 18:12:55');
INSERT INTO usuario
VALUES (1, 'admin', 'IF7nbMo9zxGOH++0op8eE+obeILVzsZCguAqPVydL/0=', 1, '2019-06-05 00:08:50');

View File

@@ -31,6 +31,9 @@ import xyz.danielcortes.controllers.trabajador.TrabajadorCreateController;
import xyz.danielcortes.controllers.trabajador.TrabajadorSearchController; import xyz.danielcortes.controllers.trabajador.TrabajadorSearchController;
import xyz.danielcortes.controllers.trabajador.TrabajadorUpdateController; import xyz.danielcortes.controllers.trabajador.TrabajadorUpdateController;
import xyz.danielcortes.controllers.trabajador.TrabajadorViewController; import xyz.danielcortes.controllers.trabajador.TrabajadorViewController;
import xyz.danielcortes.controllers.usuario.UsuarioCreateController;
import xyz.danielcortes.controllers.usuario.UsuarioUpdateController;
import xyz.danielcortes.controllers.usuario.UsuarioViewController;
import xyz.danielcortes.framework.BaseController; import xyz.danielcortes.framework.BaseController;
import xyz.danielcortes.framework.PanelName; import xyz.danielcortes.framework.PanelName;
import xyz.danielcortes.models.Usuario; import xyz.danielcortes.models.Usuario;
@@ -59,6 +62,9 @@ import xyz.danielcortes.views.trabajador.TrabajadorCreatePanel;
import xyz.danielcortes.views.trabajador.TrabajadorSearchPanel; import xyz.danielcortes.views.trabajador.TrabajadorSearchPanel;
import xyz.danielcortes.views.trabajador.TrabajadorUpdatePanel; import xyz.danielcortes.views.trabajador.TrabajadorUpdatePanel;
import xyz.danielcortes.views.trabajador.TrabajadorViewPanel; import xyz.danielcortes.views.trabajador.TrabajadorViewPanel;
import xyz.danielcortes.views.usuario.UsuarioCreatePanel;
import xyz.danielcortes.views.usuario.UsuarioUpdatePanel;
import xyz.danielcortes.views.usuario.UsuarioViewPanel;
public class LaunchController { public class LaunchController {
@@ -110,6 +116,10 @@ public class LaunchController {
this.controllers.put(PanelName.TRABAJADOR_CREATE, new TrabajadorCreateController(new TrabajadorCreatePanel(), this)); this.controllers.put(PanelName.TRABAJADOR_CREATE, new TrabajadorCreateController(new TrabajadorCreatePanel(), this));
this.controllers.put(PanelName.TRABAJADOR_UPDATE, new TrabajadorUpdateController(new TrabajadorUpdatePanel(), this)); this.controllers.put(PanelName.TRABAJADOR_UPDATE, new TrabajadorUpdateController(new TrabajadorUpdatePanel(), this));
this.controllers.put(PanelName.USUARIO_VIEW, new UsuarioViewController(new UsuarioViewPanel(), this));
this.controllers.put(PanelName.USUARIO_CREATE, new UsuarioCreateController(new UsuarioCreatePanel(), this));
this.controllers.put(PanelName.USUARIO_UPDATE, new UsuarioUpdateController(new UsuarioUpdatePanel(), 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);
this.frame.addCard(controller.getView().getContentPane(), name); this.frame.addCard(controller.getView().getContentPane(), name);

View File

@@ -14,14 +14,14 @@ import xyz.danielcortes.views.trabajador.TrabajadorCreatePanel;
public class TrabajadorCreateController extends BaseController { public class TrabajadorCreateController extends BaseController {
private TrabajadorCreatePanel view; private TrabajadorCreatePanel view;
private TrabajadorRespository trabajadorRespository; private TrabajadorRespository respository;
private TrabajadorValidator trabajadorValidator; private TrabajadorValidator validator;
public TrabajadorCreateController(TrabajadorCreatePanel view, LaunchController parent) { public TrabajadorCreateController(TrabajadorCreatePanel view, LaunchController parent) {
super(parent); super(parent);
this.view = view; this.view = view;
this.trabajadorRespository = new TrabajadorRespository(); this.respository = new TrabajadorRespository();
this.trabajadorValidator = new TrabajadorValidator(this.trabajadorRespository); this.validator = new TrabajadorValidator(this.respository);
this.setupListeners(); this.setupListeners();
} }
@@ -36,35 +36,35 @@ public class TrabajadorCreateController extends BaseController {
private void save() { private void save() {
String rut = this.view.getRutField().getText(); String rut = this.view.getRutField().getText();
ValidationResult rutValidation = this.trabajadorValidator.validateRut(rut); ValidationResult rutValidation = this.validator.validateRut(rut);
if(rutValidation.hasError()){ if(rutValidation.hasError()){
rutValidation.showErrorDialog(); rutValidation.showErrorDialog();
return; return;
} }
String nombre = this.view.getNombreField().getText(); String nombre = this.view.getNombreField().getText();
ValidationResult nombreValidation = this.trabajadorValidator.validateNombre(nombre); ValidationResult nombreValidation = this.validator.validateNombre(nombre);
if(nombreValidation.hasError()){ if(nombreValidation.hasError()){
nombreValidation.showErrorDialog(); nombreValidation.showErrorDialog();
return; return;
} }
String apellidoPaterno = this.view.getApellidoPaternoField().getText(); String apellidoPaterno = this.view.getApellidoPaternoField().getText();
ValidationResult apellidoPaternoValidation = this.trabajadorValidator.validateApellidoPaterno(apellidoPaterno); ValidationResult apellidoPaternoValidation = this.validator.validateApellidoPaterno(apellidoPaterno);
if(apellidoPaternoValidation.hasError()){ if(apellidoPaternoValidation.hasError()){
apellidoPaternoValidation.showErrorDialog(); apellidoPaternoValidation.showErrorDialog();
return; return;
} }
String apellidoMaterno = this.view.getApellidoMaternoField().getText(); String apellidoMaterno = this.view.getApellidoMaternoField().getText();
ValidationResult apellidoMaternoValidation = this.trabajadorValidator.validateApellidoMaterno(apellidoMaterno); ValidationResult apellidoMaternoValidation = this.validator.validateApellidoMaterno(apellidoMaterno);
if(apellidoMaternoValidation.hasError()){ if(apellidoMaternoValidation.hasError()){
apellidoMaternoValidation.showErrorDialog(); apellidoMaternoValidation.showErrorDialog();
return; return;
} }
LocalDate fechaContrato = this.view.getFechaContratoPicker().getDate(); LocalDate fechaContrato = this.view.getFechaContratoPicker().getDate();
ValidationResult fechaContratoValidation = this.trabajadorValidator.validateFechaContrato(fechaContrato); ValidationResult fechaContratoValidation = this.validator.validateFechaContrato(fechaContrato);
if(fechaContratoValidation.hasError()){ if(fechaContratoValidation.hasError()){
fechaContratoValidation.showErrorDialog(); fechaContratoValidation.showErrorDialog();
return; return;
@@ -77,7 +77,7 @@ public class TrabajadorCreateController extends BaseController {
trabajador.setFechaContrato(fechaContrato); trabajador.setFechaContrato(fechaContrato);
trabajador.setRut(rut); trabajador.setRut(rut);
trabajadorRespository.save(trabajador); respository.save(trabajador);
this.getParentController().showCard(PanelName.TRABAJADOR_SEARCH); this.getParentController().showCard(PanelName.TRABAJADOR_SEARCH);
} }

View File

@@ -1,6 +1,9 @@
package xyz.danielcortes.controllers.trabajador; package xyz.danielcortes.controllers.trabajador;
import javax.swing.JOptionPane;
import xyz.danielcortes.controllers.LaunchController; import xyz.danielcortes.controllers.LaunchController;
import xyz.danielcortes.controllers.usuario.UsuarioCreateController;
import xyz.danielcortes.controllers.usuario.UsuarioViewController;
import xyz.danielcortes.framework.BaseController; import xyz.danielcortes.framework.BaseController;
import xyz.danielcortes.framework.BasePanel; import xyz.danielcortes.framework.BasePanel;
import xyz.danielcortes.framework.PanelName; import xyz.danielcortes.framework.PanelName;
@@ -28,13 +31,35 @@ public class TrabajadorViewController extends BaseController {
private void setupListeners() { private void setupListeners() {
this.view.getVolverButton().addActionListener(e -> this.getParentController().showCard(PanelName.TRABAJADOR_SEARCH)); this.view.getVolverButton().addActionListener(e -> this.getParentController().showCard(PanelName.TRABAJADOR_SEARCH));
this.view.getUsuarioButton().addActionListener(e -> this.gotoUsuarioView());
}
private void gotoUsuarioView() {
if(this.trabajador.getUsuario() == null) {
int result = JOptionPane.showConfirmDialog(
null,
"El trabajador no tiene un usuario, ¿Desea crear uno?",
"",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE
);
if(result == JOptionPane.YES_OPTION) {
UsuarioCreateController controller = (UsuarioCreateController) this.getParentController().getCard(PanelName.USUARIO_CREATE);
controller.setTrabajador(this.trabajador);
this.getParentController().showCard(PanelName.USUARIO_CREATE);
}
}else {
UsuarioViewController controller = (UsuarioViewController) this.getParentController().getCard(PanelName.USUARIO_VIEW);
controller.setTrabajador(trabajador);
this.getParentController().showCard(PanelName.USUARIO_VIEW);
}
} }
private void fillTrabajador() { private void fillTrabajador() {
if (trabajador == null) if (trabajador == null)
return; return;
this.view.getRutField().setText(this.trabajador.getNombre()); this.view.getRutField().setText(this.trabajador.getRut());
this.view.getNombreField().setText(this.trabajador.getNombre()); this.view.getNombreField().setText(this.trabajador.getNombre());
this.view.getApellidoPaternoField().setText(this.trabajador.getApellidoPaterno()); this.view.getApellidoPaternoField().setText(this.trabajador.getApellidoPaterno());
this.view.getApellidoMaternoField().setText(this.trabajador.getApellidoMaterno()); this.view.getApellidoMaternoField().setText(this.trabajador.getApellidoMaterno());

View File

@@ -0,0 +1,86 @@
package xyz.danielcortes.controllers.usuario;
import java.nio.charset.StandardCharsets;
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.Hash;
import xyz.danielcortes.framework.PanelName;
import xyz.danielcortes.framework.ValidationResult;
import xyz.danielcortes.models.Trabajador;
import xyz.danielcortes.models.Usuario;
import xyz.danielcortes.repository.UsuarioRepository;
import xyz.danielcortes.validator.UsuarioValidator;
import xyz.danielcortes.views.usuario.UsuarioCreatePanel;
public class UsuarioCreateController extends BaseController {
private Trabajador trabajador;
private UsuarioCreatePanel view;
private UsuarioRepository repository;
private UsuarioValidator validator;
public UsuarioCreateController(UsuarioCreatePanel view, LaunchController parentController){
super(parentController);
this.view = view;
this.repository = new UsuarioRepository();
this.validator = new UsuarioValidator(this.repository);
this.setupListeners();
}
@Override
public LaunchController getParentController() {
return this.parentController;
}
@Override
public void show() {
this.view.getUserField().requestFocus();
}
@Override
public BasePanel getView() {
return this.view;
}
public void setTrabajador(Trabajador trabajador) {this.trabajador = trabajador;}
private void setupListeners() {
this.view.getGuardarButton().addActionListener(e -> save());
this.view.getVolverButton().addActionListener(e -> volver());
}
private void save(){
String user = this.view.getUserField().getText();
char[] pass = this.view.getPassField().getPassword();
ValidationResult userValidation = this.validator.validateUsername(user);
if(userValidation.hasError()){
userValidation.showErrorDialog();
return;
}
ValidationResult passValidation = this.validator.validatePassword(pass);
if(passValidation.hasError()){
passValidation.showErrorDialog();
return;
}
Usuario usuario = new Usuario();
usuario.setNombre(user);
usuario.setPassword(Hash.sha256(new String(pass).getBytes(StandardCharsets.UTF_8)));
usuario.setTrabajador(trabajador);
this.repository.save(usuario);
this.trabajador.setUsuario(usuario);
this.volver();
}
private void volver(){
TrabajadorViewController controller = (TrabajadorViewController) this.getParentController().getCard(PanelName.TRABAJADOR_VIEW);
controller.setTrabajador(trabajador);
this.getParentController().showCard(PanelName.TRABAJADOR_VIEW);
}
}

View File

@@ -0,0 +1,91 @@
package xyz.danielcortes.controllers.usuario;
import java.nio.charset.StandardCharsets;
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.Hash;
import xyz.danielcortes.framework.PanelName;
import xyz.danielcortes.framework.ValidationResult;
import xyz.danielcortes.models.Trabajador;
import xyz.danielcortes.repository.UsuarioRepository;
import xyz.danielcortes.validator.UsuarioValidator;
import xyz.danielcortes.views.usuario.UsuarioUpdatePanel;
public class UsuarioUpdateController extends BaseController {
private Trabajador trabajador;
private UsuarioUpdatePanel view;
private UsuarioRepository repository;
private UsuarioValidator validator;
public UsuarioUpdateController(UsuarioUpdatePanel view, LaunchController parentController){
super(parentController);
this.view = view;
this.repository = new UsuarioRepository();
this.validator = new UsuarioValidator(this.repository);
this.setupListeners();
}
@Override
public LaunchController getParentController() {
return this.parentController;
}
@Override
public void show() {
this.view.getUserField().requestFocus();
this.fillUser();
}
@Override
public BasePanel getView() {
return this.view;
}
public void setTrabajador(Trabajador trabajador) {this.trabajador = trabajador;}
public void fillUser() {
this.view.getUserField().setText(this.trabajador.getUsuario().getNombre());
}
private void setupListeners() {
this.view.getActualizarButton().addActionListener(e -> update());
this.view.getVolverButton().addActionListener(e -> volver());
}
private void update(){
String user = this.view.getUserField().getText();
char[] pass = this.view.getPassField().getPassword();
ValidationResult originalValidation = this.validator.validateOriginal(this.trabajador.getUsuario());
if(originalValidation.hasError()){
originalValidation.showErrorDialog();
return;
}
ValidationResult userValidation = this.validator.validateUsername(user);
if(userValidation.hasError()){
userValidation.showErrorDialog();
return;
}
ValidationResult passValidation = this.validator.validatePassword(pass);
if(passValidation.hasError()){
passValidation.showErrorDialog();
return;
}
trabajador.getUsuario().setNombre(user);
trabajador.getUsuario().setPassword(Hash.sha256(new String(pass).getBytes(StandardCharsets.UTF_8)));
this.repository.update(trabajador.getUsuario());
this.volver();
}
private void volver(){
TrabajadorViewController controller = (TrabajadorViewController) this.getParentController().getCard(PanelName.TRABAJADOR_VIEW);
controller.setTrabajador(trabajador);
this.getParentController().showCard(PanelName.TRABAJADOR_VIEW);
}
}

View File

@@ -0,0 +1,88 @@
package xyz.danielcortes.controllers.usuario;
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.PanelName;
import xyz.danielcortes.models.Trabajador;
import xyz.danielcortes.repository.UsuarioRepository;
import xyz.danielcortes.views.usuario.UsuarioViewPanel;
public class UsuarioViewController extends BaseController {
private Trabajador trabajador;
private UsuarioViewPanel view;
private UsuarioRepository repository;
public UsuarioViewController(UsuarioViewPanel view, LaunchController parentController) {
super(parentController);
this.view = view;
this.repository = new UsuarioRepository();
this.setupListeners();
}
@Override
public LaunchController getParentController() {
return this.parentController;
}
@Override
public void show() {
this.view.getUserField().requestFocus();
this.fillUsuario();
}
@Override
public BasePanel getView() {
return this.view;
}
public void setTrabajador(Trabajador trabajador) {
this.trabajador = trabajador;
}
public void fillUsuario() {
this.view.getUserField().setText(this.trabajador.getUsuario().getNombre());
}
private void setupListeners() {
this.view.getVolverButton().addActionListener(e -> volver());
this.view.getEditarButton().addActionListener(e -> editar());
this.view.getEliminarButton().addActionListener(e -> eliminar());
}
private void editar() {
UsuarioUpdateController controller = (UsuarioUpdateController) this.getParentController().getCard(PanelName.USUARIO_UPDATE);
controller.setTrabajador(trabajador);
this.getParentController().showCard(PanelName.USUARIO_UPDATE);
}
private void eliminar(){
if (this.trabajador.getUsuario() == null)
return;
int option = JOptionPane.showConfirmDialog(
null,
"¿Estas seguro de que deseas eliminar el usuario de este trabajador?",
"Confirmacion",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE
);
if (option == JOptionPane.NO_OPTION)
return;
this.repository.delete(this.trabajador.getUsuario());
this.trabajador.setUsuario(null);
this.volver();
}
private void volver() {
TrabajadorViewController controller = (TrabajadorViewController) this.getParentController().getCard(PanelName.TRABAJADOR_VIEW);
controller.setTrabajador(trabajador);
this.getParentController().showCard(PanelName.TRABAJADOR_VIEW);
}
}

View File

@@ -2,6 +2,7 @@ package xyz.danielcortes.framework;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Base64;
public class Hash { public class Hash {
@@ -15,7 +16,7 @@ public class Hash {
} }
} }
public static byte[] sha256(byte[] toHash) { public static String sha256(byte[] toHash) {
return sha.digest(toHash); return Base64.getEncoder().encodeToString(sha.digest(toHash));
} }
} }

View File

@@ -33,5 +33,9 @@ public enum PanelName {
TRABAJADOR_CREATE, TRABAJADOR_CREATE,
TRABAJADOR_UPDATE, TRABAJADOR_UPDATE,
USUARIO_VIEW,
USUARIO_CREATE,
USUARIO_UPDATE,
COMPRAR_LIBRO, COMPRAR_LIBRO,
} }

View File

@@ -2,7 +2,6 @@ package xyz.danielcortes.login;
import java.awt.Dimension; import java.awt.Dimension;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Optional; import java.util.Optional;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
@@ -35,12 +34,6 @@ public class LoginController {
private void login() { private void login() {
String name = this.view.getUserField().getText(); String name = this.view.getUserField().getText();
if (name.equals("admin")) {
this.frame.dispose();
loggedListener.loginTry(new LoggedEvent(this, new Usuario()));
return;
}
Optional<Usuario> optionalUser = this.repository.getByName(name); Optional<Usuario> optionalUser = this.repository.getByName(name);
if (optionalUser.isEmpty()) { if (optionalUser.isEmpty()) {
JOptionPane.showMessageDialog( JOptionPane.showMessageDialog(
@@ -53,8 +46,8 @@ public class LoginController {
} }
Usuario user = optionalUser.get(); Usuario user = optionalUser.get();
byte[] pass = Hash.sha256(new String(this.view.getPassField().getPassword()).getBytes(StandardCharsets.UTF_8)); String pass = Hash.sha256(new String(this.view.getPassField().getPassword()).getBytes(StandardCharsets.UTF_8));
if (Arrays.equals(pass, user.getPassword())) { if (pass.equals(user.getPassword())) {
this.frame.dispose(); this.frame.dispose();
loggedListener.loginTry(new LoggedEvent(this, user)); loggedListener.loginTry(new LoggedEvent(this, user));
} else { } else {

View File

@@ -1,6 +1,5 @@
package xyz.danielcortes.models; package xyz.danielcortes.models;
import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
@@ -22,8 +21,8 @@ public class Usuario {
@Column(name = "nombre") @Column(name = "nombre")
private String nombre; private String nombre;
@Column(name = "password", columnDefinition = "varbinary(2000)") @Column(name = "password")
private byte[] password; private String password;
@OneToOne @OneToOne
@JoinColumn(name = "trabajador_id", referencedColumnName = "id") @JoinColumn(name = "trabajador_id", referencedColumnName = "id")
@@ -45,11 +44,11 @@ public class Usuario {
this.nombre = nombre; this.nombre = nombre;
} }
public byte[] getPassword() { public String getPassword() {
return password; return password;
} }
public void setPassword(byte[] password) { public void setPassword(String password) {
this.password = password; this.password = password;
} }
@@ -70,13 +69,12 @@ public class Usuario {
Usuario usuario = (Usuario) o; Usuario usuario = (Usuario) o;
return Objects.equals(id, usuario.id) && return Objects.equals(id, usuario.id) &&
Objects.equals(nombre, usuario.nombre) && Objects.equals(nombre, usuario.nombre) &&
Arrays.equals(password, usuario.password); Objects.equals(password, usuario.password) &&
Objects.equals(trabajador, usuario.trabajador);
} }
@Override @Override
public int hashCode() { public int hashCode() {
int result = Objects.hash(id, nombre); return Objects.hash(id, nombre, password, trabajador);
result = 31 * result + Arrays.hashCode(password);
return result;
} }
} }

View File

@@ -1,6 +1,7 @@
package xyz.danielcortes.validator; package xyz.danielcortes.validator;
import xyz.danielcortes.framework.ValidationResult; import xyz.danielcortes.framework.ValidationResult;
import xyz.danielcortes.models.Usuario;
import xyz.danielcortes.repository.UsuarioRepository; import xyz.danielcortes.repository.UsuarioRepository;
public class UsuarioValidator { public class UsuarioValidator {
@@ -31,5 +32,12 @@ public class UsuarioValidator {
return ValidationResult.NON_ERROR; return ValidationResult.NON_ERROR;
} }
public ValidationResult validateOriginal(Usuario usuario) {
if(usuario == null){
return new ValidationResult("El usuario no existe");
}
return ValidationResult.NON_ERROR;
}
} }

View File

@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?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.trabajador.TrabajadorViewPanel">
<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"> <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"/> <margin top="20" left="20" bottom="20" right="20"/>
<constraints> <constraints>
<xy x="20" y="20" width="500" height="394"/> <xy x="20" y="20" width="500" height="468"/>
</constraints> </constraints>
<properties/> <properties/>
<border type="none"/> <border type="none"/>
@@ -67,22 +67,22 @@
</component> </component>
<vspacer id="31a4"> <vspacer id="31a4">
<constraints> <constraints>
<grid row="11" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/> <grid row="12" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
</vspacer> </vspacer>
<hspacer id="28129"> <hspacer id="28129">
<constraints> <constraints>
<grid row="11" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="12" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
</hspacer> </hspacer>
<hspacer id="69f08"> <hspacer id="69f08">
<constraints> <constraints>
<grid row="11" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="12" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
</hspacer> </hspacer>
<component id="7d83d" class="javax.swing.JButton" binding="volverButton" default-binding="true"> <component id="7d83d" class="javax.swing.JButton" binding="volverButton" default-binding="true">
<constraints> <constraints>
<grid row="10" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"> <grid row="11" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/> <preferred-size width="150" height="-1"/>
</grid> </grid>
</constraints> </constraints>
@@ -122,6 +122,56 @@
</constraints> </constraints>
<properties/> <properties/>
</component> </component>
<grid id="21544" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="10" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="1a00f" class="javax.swing.JButton" binding="usuarioButton" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value="Usuario"/>
</properties>
</component>
<component id="8a01b" class="javax.swing.JButton" binding="direccionesButton" default-binding="true">
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value="Direcciones"/>
</properties>
</component>
<component id="5f09d" class="javax.swing.JButton" binding="correosButton" default-binding="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value="Correos"/>
</properties>
</component>
<component id="e9b39" class="javax.swing.JButton" binding="telefonosButton" default-binding="true">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value="Telefonos"/>
</properties>
</component>
</children>
</grid>
</children> </children>
</grid> </grid>
</form> </form>

View File

@@ -22,6 +22,10 @@ public class TrabajadorViewPanel extends BasePanel {
private JPanel contentPane; private JPanel contentPane;
private JTextField rutField; private JTextField rutField;
private DatePicker fechaContratoPicker; private DatePicker fechaContratoPicker;
private JButton usuarioButton;
private JButton direccionesButton;
private JButton correosButton;
private JButton telefonosButton;
public JTextField getNombreField() { public JTextField getNombreField() {
return nombreField; return nombreField;
@@ -52,6 +56,23 @@ public class TrabajadorViewPanel extends BasePanel {
return fechaContratoPicker; return fechaContratoPicker;
} }
public JButton getUsuarioButton() {
return usuarioButton;
}
public JButton getDireccionesButton() {
return direccionesButton;
}
public JButton getCorreosButton() {
return correosButton;
}
public JButton getTelefonosButton() {
return telefonosButton;
}
{ {
// GUI initializer generated by IntelliJ IDEA GUI Designer // GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<< // >>> IMPORTANT!! <<<
@@ -66,7 +87,7 @@ public class TrabajadorViewPanel extends BasePanel {
*/ */
private void $$$setupUI$$$() { private void $$$setupUI$$$() {
contentPane = new JPanel(); contentPane = new JPanel();
contentPane.setLayout(new GridLayoutManager(12, 3, new Insets(20, 20, 20, 20), -1, -1)); contentPane.setLayout(new GridLayoutManager(13, 3, new Insets(20, 20, 20, 20), -1, -1));
final JLabel label1 = new JLabel(); final JLabel label1 = new JLabel();
label1.setText("Nombre:"); label1.setText("Nombre:");
contentPane.add(label1, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, contentPane.add(label1, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED,
@@ -99,19 +120,19 @@ public class TrabajadorViewPanel extends BasePanel {
GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(400, -1), null, 0, false)); GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(400, -1), null, 0, false));
final Spacer spacer1 = new Spacer(); final Spacer spacer1 = new Spacer();
contentPane.add(spacer1, contentPane.add(spacer1,
new GridConstraints(11, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, new GridConstraints(12, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null,
null, null, 0, false)); null, null, 0, false));
final Spacer spacer2 = new Spacer(); final Spacer spacer2 = new Spacer();
contentPane.add(spacer2, contentPane.add(spacer2,
new GridConstraints(11, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, new GridConstraints(12, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1,
null, null, null, 0, false)); null, null, null, 0, false));
final Spacer spacer3 = new Spacer(); final Spacer spacer3 = new Spacer();
contentPane.add(spacer3, contentPane.add(spacer3,
new GridConstraints(11, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, new GridConstraints(12, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1,
null, null, null, 0, false)); null, null, null, 0, false));
volverButton = new JButton(); volverButton = new JButton();
volverButton.setText("Volver"); volverButton.setText("Volver");
contentPane.add(volverButton, new GridConstraints(10, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, contentPane.add(volverButton, new GridConstraints(11, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1),
null, 0, false)); null, 0, false));
final JLabel label4 = new JLabel(); final JLabel label4 = new JLabel();
@@ -131,6 +152,31 @@ public class TrabajadorViewPanel extends BasePanel {
contentPane.add(fechaContratoPicker, contentPane.add(fechaContratoPicker,
new GridConstraints(9, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, new GridConstraints(9, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW,
GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final JPanel panel1 = new JPanel();
panel1.setLayout(new GridLayoutManager(1, 4, new Insets(0, 0, 0, 0), -1, -1));
contentPane.add(panel1, new GridConstraints(10, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
usuarioButton = new JButton();
usuarioButton.setText("Usuario");
panel1.add(usuarioButton, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1),
null, 0, false));
direccionesButton = new JButton();
direccionesButton.setText("Direcciones");
panel1.add(direccionesButton, new GridConstraints(0, 3, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1),
null, 0, false));
correosButton = new JButton();
correosButton.setText("Correos");
panel1.add(correosButton, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1),
null, 0, false));
telefonosButton = new JButton();
telefonosButton.setText("Telefonos");
panel1.add(telefonosButton, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1),
null, 0, false));
} }
/** /**

View File

@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="xyz.danielcortes.views.usuario.UsuarioCreatePanel">
<grid id="27dc6" binding="contentPane" layout-manager="GridLayoutManager" row-count="6" 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>
<xy x="20" y="20" width="484" height="218"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="20dee" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Nombre de usuario:"/>
</properties>
</component>
<component id="b91cf" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Contraseña"/>
</properties>
</component>
<component id="ff38e" class="javax.swing.JTextField" binding="userField">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="400" height="-1"/>
</grid>
</constraints>
<properties>
<editable value="true"/>
<enabled value="true"/>
</properties>
</component>
<component id="7cc19" class="javax.swing.JPasswordField" binding="passField">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="400" height="-1"/>
</grid>
</constraints>
<properties>
<editable value="true"/>
<enabled value="true"/>
</properties>
</component>
<grid id="4afc8" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="cd51" class="javax.swing.JButton" binding="guardarButton">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value="Guardar"/>
</properties>
</component>
<component id="57e32" class="javax.swing.JButton" binding="volverButton" default-binding="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value="Volver"/>
</properties>
</component>
</children>
</grid>
<vspacer id="1eb50">
<constraints>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<hspacer id="11bf6">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="6ea79">
<constraints>
<grid row="5" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
</form>

View File

@@ -0,0 +1,116 @@
package xyz.danielcortes.views.usuario;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import java.awt.Dimension;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import xyz.danielcortes.framework.BasePanel;
public class UsuarioCreatePanel extends BasePanel {
private JPanel contentPane;
private JButton guardarButton;
private JTextField userField;
private JPasswordField passField;
private JButton volverButton;
@Override
public JPanel getContentPane() {
return contentPane;
}
public JButton getGuardarButton() {
return guardarButton;
}
public JTextField getUserField() {
return userField;
}
public JPasswordField getPassField() {
return passField;
}
public JButton getVolverButton() {
return volverButton;
}
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
/**
* Method generated by IntelliJ IDEA GUI Designer >>> IMPORTANT!! <<< DO NOT edit this method OR call it in your code!
*
* @noinspection ALL
*/
private void $$$setupUI$$$() {
contentPane = new JPanel();
contentPane.setLayout(new GridLayoutManager(6, 3, new Insets(20, 20, 20, 20), -1, -1));
final JLabel label1 = new JLabel();
label1.setText("Nombre de usuario:");
contentPane.add(label1, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED,
GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final JLabel label2 = new JLabel();
label2.setText("Contraseña");
contentPane.add(label2, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED,
GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
userField = new JTextField();
userField.setEditable(true);
userField.setEnabled(true);
contentPane.add(userField,
new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW,
GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(400, -1), null, 0, false));
passField = new JPasswordField();
passField.setEditable(true);
passField.setEnabled(true);
contentPane.add(passField,
new GridConstraints(3, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW,
GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(400, -1), null, 0, false));
final JPanel panel1 = new JPanel();
panel1.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
contentPane.add(panel1, new GridConstraints(4, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
guardarButton = new JButton();
guardarButton.setText("Guardar");
panel1.add(guardarButton, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1),
null, 0, false));
volverButton = new JButton();
volverButton.setText("Volver");
panel1.add(volverButton, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1),
null, 0, false));
final Spacer spacer1 = new Spacer();
contentPane.add(spacer1,
new GridConstraints(5, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null,
null, null, 0, false));
final Spacer spacer2 = new Spacer();
contentPane.add(spacer2,
new GridConstraints(5, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null,
null, null, 0, false));
final Spacer spacer3 = new Spacer();
contentPane.add(spacer3,
new GridConstraints(5, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null,
null, null, 0, false));
}
/**
* @noinspection ALL
*/
public JComponent $$$getRootComponent$$$() {
return contentPane;
}
}

View File

@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="xyz.danielcortes.views.usuario.UsuarioUpdatePanel">
<grid id="27dc6" binding="contentPane" layout-manager="GridLayoutManager" row-count="6" 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>
<xy x="20" y="20" width="484" height="218"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="20dee" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Nombre de usuario:"/>
</properties>
</component>
<component id="b91cf" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Contraseña"/>
</properties>
</component>
<component id="ff38e" class="javax.swing.JTextField" binding="userField">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="400" height="-1"/>
</grid>
</constraints>
<properties>
<editable value="true"/>
<enabled value="true"/>
</properties>
</component>
<component id="7cc19" class="javax.swing.JPasswordField" binding="passField">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="400" height="-1"/>
</grid>
</constraints>
<properties>
<editable value="true"/>
<enabled value="true"/>
</properties>
</component>
<grid id="4afc8" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="cd51" class="javax.swing.JButton" binding="actualizarButton">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value="Actualizar"/>
</properties>
</component>
<component id="57e32" class="javax.swing.JButton" binding="volverButton" default-binding="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value="Volver"/>
</properties>
</component>
</children>
</grid>
<vspacer id="1eb50">
<constraints>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<hspacer id="11bf6">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="6ea79">
<constraints>
<grid row="5" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
</form>

View File

@@ -0,0 +1,116 @@
package xyz.danielcortes.views.usuario;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import java.awt.Dimension;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import xyz.danielcortes.framework.BasePanel;
public class UsuarioUpdatePanel extends BasePanel {
private JPanel contentPane;
private JButton actualizarButton;
private JTextField userField;
private JPasswordField passField;
private JButton volverButton;
@Override
public JPanel getContentPane() {
return contentPane;
}
public JButton getActualizarButton() {
return actualizarButton;
}
public JTextField getUserField() {
return userField;
}
public JPasswordField getPassField() {
return passField;
}
public JButton getVolverButton() {
return volverButton;
}
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
/**
* Method generated by IntelliJ IDEA GUI Designer >>> IMPORTANT!! <<< DO NOT edit this method OR call it in your code!
*
* @noinspection ALL
*/
private void $$$setupUI$$$() {
contentPane = new JPanel();
contentPane.setLayout(new GridLayoutManager(6, 3, new Insets(20, 20, 20, 20), -1, -1));
final JLabel label1 = new JLabel();
label1.setText("Nombre de usuario:");
contentPane.add(label1, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED,
GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final JLabel label2 = new JLabel();
label2.setText("Contraseña");
contentPane.add(label2, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED,
GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
userField = new JTextField();
userField.setEditable(true);
userField.setEnabled(true);
contentPane.add(userField,
new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW,
GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(400, -1), null, 0, false));
passField = new JPasswordField();
passField.setEditable(true);
passField.setEnabled(true);
contentPane.add(passField,
new GridConstraints(3, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW,
GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(400, -1), null, 0, false));
final JPanel panel1 = new JPanel();
panel1.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
contentPane.add(panel1, new GridConstraints(4, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
actualizarButton = new JButton();
actualizarButton.setText("Actualizar");
panel1.add(actualizarButton, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1),
null, 0, false));
volverButton = new JButton();
volverButton.setText("Volver");
panel1.add(volverButton, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1),
null, 0, false));
final Spacer spacer1 = new Spacer();
contentPane.add(spacer1,
new GridConstraints(5, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null,
null, null, 0, false));
final Spacer spacer2 = new Spacer();
contentPane.add(spacer2,
new GridConstraints(5, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null,
null, null, 0, false));
final Spacer spacer3 = new Spacer();
contentPane.add(spacer3,
new GridConstraints(5, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null,
null, null, 0, false));
}
/**
* @noinspection ALL
*/
public JComponent $$$getRootComponent$$$() {
return contentPane;
}
}

View File

@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="xyz.danielcortes.views.usuario.UsuarioViewPanel">
<grid id="27dc6" binding="contentPane" layout-manager="GridLayoutManager" row-count="4" 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>
<xy x="20" y="20" width="484" height="158"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="20dee" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Nombre de usuario:"/>
</properties>
</component>
<component id="ff38e" class="javax.swing.JTextField" binding="userField">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="400" height="-1"/>
</grid>
</constraints>
<properties>
<editable value="false"/>
</properties>
</component>
<grid id="4afc8" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="57e32" class="javax.swing.JButton" binding="volverButton" default-binding="true">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value="Volver"/>
</properties>
</component>
<component id="a051d" class="javax.swing.JButton" binding="editarButton" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value="Editar"/>
</properties>
</component>
<component id="f165b" class="javax.swing.JButton" binding="eliminarButton" default-binding="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value="Eliminar"/>
</properties>
</component>
</children>
</grid>
<vspacer id="1eb50">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<hspacer id="11bf6">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="6ea79">
<constraints>
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
</form>

View File

@@ -0,0 +1,109 @@
package xyz.danielcortes.views.usuario;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import java.awt.Dimension;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import xyz.danielcortes.framework.BasePanel;
public class UsuarioViewPanel extends BasePanel {
private JPanel contentPane;
private JTextField userField;
private JButton volverButton;
private JButton editarButton;
private JButton eliminarButton;
@Override
public JPanel getContentPane() {
return contentPane;
}
public JTextField getUserField() {
return userField;
}
public JButton getVolverButton() {
return volverButton;
}
public JButton getEditarButton() {
return editarButton;
}
public JButton getEliminarButton() {
return eliminarButton;
}
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
/**
* Method generated by IntelliJ IDEA GUI Designer >>> IMPORTANT!! <<< DO NOT edit this method OR call it in your code!
*
* @noinspection ALL
*/
private void $$$setupUI$$$() {
contentPane = new JPanel();
contentPane.setLayout(new GridLayoutManager(4, 3, new Insets(20, 20, 20, 20), -1, -1));
final JLabel label1 = new JLabel();
label1.setText("Nombre de usuario:");
contentPane.add(label1, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED,
GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
userField = new JTextField();
userField.setEditable(false);
contentPane.add(userField,
new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW,
GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(400, -1), null, 0, false));
final JPanel panel1 = new JPanel();
panel1.setLayout(new GridLayoutManager(1, 3, new Insets(0, 0, 0, 0), -1, -1));
contentPane.add(panel1, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
volverButton = new JButton();
volverButton.setText("Volver");
panel1.add(volverButton, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1),
null, 0, false));
editarButton = new JButton();
editarButton.setText("Editar");
panel1.add(editarButton, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1),
null, 0, false));
eliminarButton = new JButton();
eliminarButton.setText("Eliminar");
panel1.add(eliminarButton, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1),
null, 0, false));
final Spacer spacer1 = new Spacer();
contentPane.add(spacer1,
new GridConstraints(3, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null,
null, null, 0, false));
final Spacer spacer2 = new Spacer();
contentPane.add(spacer2,
new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null,
null, null, 0, false));
final Spacer spacer3 = new Spacer();
contentPane.add(spacer3,
new GridConstraints(3, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null,
null, null, 0, false));
}
/**
* @noinspection ALL
*/
public JComponent $$$getRootComponent$$$() {
return contentPane;
}
}