JPanel disappearing while giving a get in it

0

I'm building a layer-based application using the Spring Framework, I'm newbie and well doing the wrong thing.

My problem is as follows, as you can see in the image below I have PrincipalFrame and PessoaFrame > PessoaPanel , I need to use PessoaPanel in several places of the system because it is a user mode to fetch anybody from the system, for now I need to use it in PrincipalFrame and PessoaFrame but actions% ) are in Listeners and I do not think it is good practice to declare everything again in PessoaListaController because it will be two places to maintain function for the same purpose. The problem is that when I do:

PrincipalController

And then I'll call the Panel again somewhere else in the system, it ends up being invisible, I tried the following below:

frame.repaint();
frame.getPessoaPanel().visible(true);

Illustration:

WhatismyPersonPanel:

    
asked by anonymous 11.09.2015 / 01:49

1 answer

2

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;
}   

}

    
11.09.2015 / 06:08