After much searching, I ended up getting the answer unintentionally.
I did the following, created a class PessoaPanelController
and instantiated PessoaPanel
in it, called @PostConstruct
and initialized all buttons of PessoaPanel
and now when I need PessoaPanel
eu do @Autowired
no my component and I use it, but the real answer was @Scope("prototype")
which means that every time I instantiate the PersonPanelController the system creates a new separate instance and nobody competes with anyone, it follows my Controller
;
@Component
@Scope("prototype")
public class PessoaPanelController extends AbstractController {
@Autowired
public PessoaPanel frame;
@Autowired
private PessoaController pessoaController;
@Autowired
private PessoaService pessoaService;
public PessoaPanelController() { }
@PostConstruct
public void init() {
/********************************************************************************/
/** Pessoa ToolBar **************************************************************/
/********************************************************************************/
registerAction(this.frame.getBtnPessoaNovo(), new AbstractAction() {
protected void action() { frame.showPopupMenuPessoa(); }
});
registerAction(this.frame.getPopupMenu().getMnuPessoaNovoFisica(), new AbstractAction() {
protected void action() { pessoaController.show(); }
});
registerAction(this.frame.getBtnPessoaEditar(), new AbstractAction() {
protected void action() { pessoaEditar(); }
});
registerAction(this.frame.getBtnPessoaExcluir(), new AbstractAction() {
protected void action() { pessoaExcluir(); }
});
registerAction(this.frame.getBtnPessoaPesquisar(), new AbstractAction() {
protected void action() { refreshTablePessoa(); }
});
this.frame.getTablePessoa().addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent event) {
if(event.getClickCount() == 2) {
pessoaEditar();
}
}
});
this.frame.getTablePessoa().addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e) {
frame.getBtnPessoaEditar().setEnabled(true);
frame.getBtnPessoaExcluir().setEnabled(true);
}
});
}
public void refreshTablePessoa() {
this.frame.refreshTablePessoa(this.pessoaService.getAllPessoas());
}
public void pessoaEditar() {
Pessoa p = frame.getTablePessoa().getPessoaSelected();
if(p != null) {
this.pessoaController.show(p);
}
}
public void pessoaExcluir() {
Pessoa p = frame.getTablePessoa().getPessoaSelected();
if(p != null) {
int opcao = JOptionPane.showConfirmDialog(null,
"Confirma a exclusão deste(s) registro(s)?",
"Atenção",
JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE);
if(opcao == 0) {
this.pessoaService.delete(p.getPessoaId());
}
}
}
public PessoaPanel getPanel() {
return frame;
}
}