Bom dia pessoal,
Estou tendo um problema que é o seguinte eu tenho uma tela principal, com as seguintes teclas de atalho:
shell.getDisplay().addFilter(SWT.KeyUp, new Listener() {
@Override
public void handleEvent(Event event) {
switch (event.keyCode) {
case SWT.ESC:
shell.close();
break;
case SWT.F12:
display.syncExec(new Runnable() {
@Override
public void run() {
new Venda(shell);
}
});
break;
default:
break;
}
}
});
Ao pressionar F12 ela abre a tela de venda, construtor da tela de venda:
public Venda(Shell parent) {
super(parent);
this.shell = new Shell(getParent(),SWT.APPLICATION_MODAL);
this.display = getParent().getDisplay();
this.shell.setMaximized(true);
this.shell.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_DARK_GREEN));
this.fontText = new Font(shell.getDisplay(), new FontData("Arial", 28, SWT.NORMAL));
this.fontLabel = new Font(shell.getDisplay(), new FontData("Arial", 13, SWT.NORMAL));
this.shell.setText("Cupom Fiscal - Venda Produto");
this.criaCampos();
this.configuraTeclaAtalho();
this.shell.open();
while (!display.isDisposed()) {
if (!display.isDisposed() && !display.readAndDispatch()) {
display.sleep();
}
}
}
Na tela de venda eu pressiono F3 e abre uma tela de consulta, meu problema é o seguinte:
Quando eu abro a tela de venda pela primeira vez e aciono a tela de consulta funciona normalmente, só que se eu fechar a tela de venda, abrindo novamente e tento abrir a tela de consulta novamente, manda a mensagem: Widget is disposed.
Eu faço a seguinte verificação ante de abrir a tela de consulta e o erro é lançado na linha 02 do código abaixo.
Já procurei na internet como corrigir e não encontrei nada.
if(!abreFechaCaixa){
MessageBox msg = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO);
msg.setMessage("Caixa Fechado, deseja abrir?");
msg.setText(shell.getText());
if(msg.open() == SWT.YES){
abreCaixa();
}
}
if(abreFechaCaixa){
display.syncExec(new Runnable() {
@Override
public void run() {
new Consulta(shell,"Cupom Fiscal - Consulta Produto");
}
});
}
Construtor da classe consulta:
public Consulta(Shell parent) {
super(parent);
this.shell = new Shell(parent, SWT.APPLICATION_MODAL);
this.display = getParent().getDisplay();
this.shell.setText(tituloTela);
this.shell.setLayout(new GridLayout(1, false));
this.fontText = new Font(shell.getDisplay(), new FontData("Arial", 28, SWT.NORMAL));
this.fontLabel = new Font(shell.getDisplay(), new FontData("Arial", 13, SWT.NORMAL));
this.criaCampos();
this.shell.pack();
this.centralizaTela();
this.shell.open();
while (!shell.isDisposed()) {
if (!display.isDisposed() && !display.readAndDispatch()) {
display.sleep();
}
}
}
Alguém teria uma dica de como resolver isso e a melhor forma de fechar janelas em SWT.