Quantcast
Channel: Tópicos
Viewing all articles
Browse latest Browse all 14700

GWT Criar DialogBox

$
0
0
Viva!

Estou a desenvolver uma aplicação usando a framework da google, GWT.

É bastante poderosa, porém, deparei-me com um pequeno problema que à partida, não o seria...

A questão é a seguinte:
Quando um utilizador tenta apagar um registo, quero despelotar um dialogbox com dois botões "sim" e "não" para confirmar se o user confirmar a operação.
Como é obvio, quero criar apenas uma classe que possa chamar quando quero e, que essa classe, quando é chamada ou um método dela, retorne true ou false.

O que eu pretendia era fazer algo como o código abaixo:

Código :
public class Questao extends Window{
boolean resposta;
public Questao(){}
public boolean perguntar(String pergunta){
setAutoCenter(true);
setCanDropComponents(false);
setShowResizer(false);
setShowMinimizeButton(false);
setAutoSize(true);
setIsModal(true);
setShowModalMask(true);
centerInPage();
setCanDragReposition(false);
setAnimateTime(900);

Image img = new Image("/mm.projeto/imagens/question.png");
setTitle("Pergunta");
img.setSize("128px", "128px");

HLayout l = new HLayout();
l.addMember(img);

FlexTable flexTable = new FlexTable();
l.addMember(flexTable);
addItem(l);
flexTable.setSize("398px", "128px");

Label lblTexto = new Label();
lblTexto.setText(pergunta);
flexTable.setWidget(0, 0, lblTexto);
lblTexto.setSize("100%", "39px");

Button btnSim = new Button("Sim");
btnSim.addClickHandler(new ClickHandler() {
public void onclick(ClickEvent event) {
animateHide(AnimationEffect.FADE);
resposta = true;
}
});
flexTable.setWidget(1, 1, btnSim);
btnSim.setWidth("150px");

Button btnNao = new Button("Não");
btnNao.addClickHandler(new ClickHandler() {
public void onclick(ClickEvent event) {
animateHide(AnimationEffect.FADE);
resposta = false;
}
});
flexTable.setWidget(1, 0, btnNao);
btnNao.setWidth("150px");

flexTable.getCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_TOP);
flexTable.getFlexCellFormatter().setColSpan(0, 0, 2);
flexTable.getCellFormatter().setHorizontalAlignment(1, 1, HasHorizontalAlignment.ALIGN_RIGHT);
flexTable.getCellFormatter().setVerticalAlignment(1, 1, HasVerticalAlignment.ALIGN_BOTTOM);
flexTable.getCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_BOTTOM);
flexTable.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_LEFT);

btnNao.setFocus(true);

//animateShow(AnimationEffect.FADE);
show();
return resposta;
}
}

Porém, quando chamo a função perguntar, não consigo fazer com a aplicação espere pela resposta do utilizador...

Alguma ideia/sugestão de como fazer?

Desde já, o meu muito obrigado :)

Viewing all articles
Browse latest Browse all 14700