通过customcomponent关闭窗口?

时间:2013-12-03 17:02:56

标签: java frameworks vaadin vaadin7

我在vaadin7上有一个CustomComponent,这个自定义组件被添加到外部类的窗口中。现在,我正在寻找一个解决方案,如何通过我的CustomComponent关闭此窗口。 当我点击btnSair(btnClose)时,我希望窗口关闭。

我正在尝试这个

/** window template */
public class WindowTemplate extends Window{     
    public WindowTemplate(String title, CustomComponent cc){        
    super(title);       
    setSizeUndefined();
    setModal(true);
    setClosable(false);
    setDraggable(false);
    setResizable(false);        
    setIcon(new ThemeResource("../icons/ibg_icon.png"));
    setContent(cc);
    center();
}
}


/** my customcomponent */
public class CadCur extends CustomComponent {   
    @AutoGenerated
private VerticalLayout mainLayout;  
@AutoGenerated
private PasswordField repeteSenha;
@AutoGenerated
private PasswordField senha;
@AutoGenerated
private TextField email;
@AutoGenerated
private TextField nome;

//buttons
private Button btnSalvar;
private Button btnSair;

    public CadCur() {
        buildMainLayout();      
    setCompositionRoot(mainLayout);
}

@AutoGenerated
    private VerticalLayout buildMainLayout() {
    mainLayout = new VerticalLayout();
    mainLayout.setImmediate(false);     
    mainLayout.setWidth("1024px");
    mainLayout.setMargin(true);
    mainLayout.setSpacing(true);

    //image
    Image foto = new Image();
    foto.setWidth("128px");
    foto.setHeight("128px");        
    mainLayout.addComponent(foto);
    mainLayout.addComponent(new Button("Avatar"));

    // nome
    nome = new TextField();
    nome.setCaption("Nome");
    nome.setImmediate(false);
    nome.setWidth("100.0%");
    nome.setHeight("-1px");
    nome.setRequired(true);
    nome.setMaxLength(50);      
    mainLayout.addComponent(nome);

    // email
    email = new TextField();
    email.setCaption("Email");
    email.setImmediate(false);
    email.setWidth("100.0%");
    email.setHeight("-1px");
    email.setRequired(true);
    email.setMaxLength(300);
    mainLayout.addComponent(email);


    // senha
    senha = new PasswordField();
    senha.setCaption("Senha");
    senha.setImmediate(false);
    senha.setWidth("-1px");
    senha.setHeight("-1px");
    senha.setRequired(true);
    senha.setMaxLength(8);
    mainLayout.addComponent(senha);

    // repeteSenha
    repeteSenha = new PasswordField();
    repeteSenha.setCaption("Confirme a senha");
    repeteSenha.setImmediate(false);
    repeteSenha.setWidth("-1px");
    repeteSenha.setHeight("-1px");
    repeteSenha.setRequired(true);
    repeteSenha.setMaxLength(8);        
    mainLayout.addComponent(repeteSenha);

    //buttons
    HorizontalLayout hLayoutButtons = new HorizontalLayout();
    hLayoutButtons.setSpacing(true);
    btnSalvar = new Button("Salvar");       
    btnSalvar.setIcon(new ThemeResource("../icons/accept.png"));
    btnSalvar.setDescription("Salvar informações");
    btnSalvar.addClickListener(new Button.ClickListener() {         
        @Override
        public void buttonClick(ClickEvent event) {
            // TODO Auto-generated method stub

        }
    });     
    hLayoutButtons.addComponent(btnSalvar);


    btnSair = new Button("Sair(Close)");        
    btnSair.setIcon(new ThemeResource("../icons/cancel.png"));
    btnSair.setDescription("Sair desta aplicação");
    btnSair.addClickListener(new Button.ClickListener() {           
        @Override
        public void buttonClick(ClickEvent event) {
            /** here I want to click btnSair(btnClose) Window close */
        }
    });

    hLayoutButtons.addComponent(btnSair);       
    mainLayout.addComponent(hLayoutButtons);

    return mainLayout;
}

}


/** my UI */
public class PrincipalUI extends UI implements Button.ClickListener{
@Override
protected void init(VaadinRequest request) {
        getCurrent().addWindow(new WindowTemplate("MyWindowTemplate", new CadCur()));
    }
}

有什么想法吗?

感谢

0 个答案:

没有答案