SmartGWT - 无法点击项目进入Windows模式

时间:2016-06-28 14:29:49

标签: gwt smartgwt

我使用WindowsetIsModal(true)时遇到一个问题。

我有这段代码:

@Override
public void onModuleLoad() {

    Button tester = new Button("Tester");

    tester.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final com.smartgwt.client.widgets.Window win = new com.smartgwt.client.widgets.Window();
            win.setTitle("Ventana Tester");
            win.setWidth(900);
            win.setHeight(600);
            win.setIsModal(true);
            win.setShowModalMask(true);
            win.centerInPage();
            win.setMinimized(false);

            win.addCloseClickHandler(new CloseClickHandler() {
                @Override
                public void onCloseClick(CloseClientEvent event) {
                    win.destroy();
                }
            });


            PlanBoard pb = new PlanBoard();
            win.addItem(pb);

            win.show();

        }
    });

    vlPrincipal.addMember(tester);

    RootPanel.get("main").add(vlPrincipal);
}

这是PlanBoard类:

public class PlanBoard extends VLayout{


private CaptionPanel contentDetallePlan =  new CaptionPanel("DETALLES DEL PLAN");
private CaptionPanel contentAtributosPlan =  new CaptionPanel("ATRIBUTOS DE PLAN");
private CaptionPanel contentSeccionesPlan =  new CaptionPanel("SECCIONES");

public PlanBoard(){

    contentDetallePlan.setStyleName("estiloCaptionPanel");
    contentAtributosPlan.setStyleName("estiloCaptionPanel");

    addMember(contentDetallePlan);
    addMember(contentAtributosPlan);
    addMember(contentSeccionesPlan);


    preparaDetallePlan();
    preparaAtributosPlan();
}


private void preparaDetallePlan(){

    VLayout contenedorSeccion = new VLayout();

    FlexTable table1 = new FlexTable();
    FlexTable table2 = new FlexTable();
    FlexTable table3 = new FlexTable();

    Label np = new Label("Nombre de Plan:");
    Label npText = new Label("Plan B");

    Label tc = new Label("Tipo de Carta:");
    DynamicForm tcForm = new DynamicForm();
    ComboBoxItem tcBox =  new ComboBoxItem();
    tcBox.setWidth(250);
    tcBox.setShowTitle(false);
    tcForm.setItems(tcBox);

    Label pr = new Label("Periodo:");
    DynamicForm prForm = new DynamicForm();
    ComboBoxItem prBox =  new ComboBoxItem();
    prBox.setWidth(150);
    prBox.setShowTitle(false);
    prForm.setItems(prBox);


    Label dp = new Label("Descripcion:");
    DynamicForm dpForm = new DynamicForm();
    TextAreaItem dpText =  new TextAreaItem();
    dpText.setShowTitle(false);
    dpText.setWidth(600);
    dpForm.setItems(dpText);



    table1.setWidget(0, 0, np);
    table1.setWidget(0, 1, npText);

    table2.setWidget(0, 0, tc);
    table2.setWidget(0, 1, tcForm);
    table2.setWidget(0, 2, pr);
    table2.setWidget(0, 3, prForm);

    table3.setWidget(0, 1, dp);
    table3.setWidget(1, 1, dpForm);

    contenedorSeccion.addMember(table1);
    contenedorSeccion.addMember(table2);
    contenedorSeccion.addMember(table3);

    contentDetallePlan.add(contenedorSeccion);


}

private void preparaAtributosPlan(){

    VLayout contenedorSeccion = new VLayout(); 

    FlexTable table1 = new FlexTable();

    Label fe = new Label("Firma Electornica:");
    CheckboxItem feCheck = new CheckboxItem();
    DateItem feFechaIni = new DateItem();
    DateItem feFechaFin = new DateItem();

    feFechaIni.setUseTextField(true);

    feCheck.setShowTitle(false);

    DynamicForm feForm = new DynamicForm();
    feForm.setItems(feCheck,feFechaIni,feFechaFin);

    table1.setWidget(0, 0, fe);
    table1.setWidget(0, 1, feForm);

    contenedorSeccion.addMember(table1);

    contentAtributosPlan.add(contenedorSeccion);


}

问题是,当我尝试点击CheckBoxItemDateItem时,我无法对其进行编辑,但是当我不使用setIsModal(true)时,它可以正常工作细

我不知道如何将Window设置为modal(true),并让这些项目在该窗口上运行。

1 个答案:

答案 0 :(得分:1)

这是你的代码清理(一点点)和改进,以便你想要实现的目标(这是具有可选/可操作控件的模态窗口):

<强> PlanBoard.java

import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.CheckboxItem;
import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
import com.smartgwt.client.widgets.form.fields.DateItem;
import com.smartgwt.client.widgets.form.fields.StaticTextItem;
import com.smartgwt.client.widgets.form.fields.TextAreaItem;
import com.smartgwt.client.widgets.layout.VLayout;

public class PlanBoard extends VLayout {

    public PlanBoard(){
        preparaDetallePlan();
        preparaAtributosPlan();
        preparaSecciones();
    }


    private void preparaDetallePlan(){
        StaticTextItem np = new StaticTextItem("id2", "Nombre de Plan:");
        StaticTextItem npText = new StaticTextItem("id2", "Plan B");

        ComboBoxItem tcBox =  new ComboBoxItem();
        tcBox.setTitle("Tipo de Carta");
        tcBox.setWidth(250);

        ComboBoxItem prBox =  new ComboBoxItem();
        tcBox.setTitle("Periodo");
        prBox.setWidth(150);

        StaticTextItem dp = new StaticTextItem("id3", "Descripcion:");

        TextAreaItem dpText =  new TextAreaItem();
        dpText.setShowTitle(false);
        dpText.setWidth(600);
        dpText.setStartRow(true);
        dpText.setEndRow(true);
        dpText.setColSpan(2);

        DynamicForm form = new DynamicForm();
        form.setItems(np, npText, tcBox, prBox, dp, dpText);
        form.setIsGroup(true);
        form.setGroupTitle("DETALLES DE PLAN");

        addMember(form);
    }

    private void preparaAtributosPlan(){
        StaticTextItem fe = new StaticTextItem("id4", "Firma Electornica:");
        CheckboxItem feCheck = new CheckboxItem();
        feCheck.setShowTitle(false);

        DateItem feFechaIni = new DateItem();
        DateItem feFechaFin = new DateItem();
        feFechaIni.setUseTextField(true);

        DynamicForm form = new DynamicForm();
        form.setItems(fe, feCheck, feFechaIni, feFechaFin);
        form.setIsGroup(true);
        form.setGroupTitle("ATRIBUTOS DE PLAN");

        addMember(form);
    }

    private void preparaSecciones(){
        DynamicForm form = new DynamicForm();
        form.setIsGroup(true);
        form.setGroupTitle("SECCIONES");
        addMember(form);
    }
}

TestCases.java (重命名为您未指定的EntryPoint类名称):

import com.smartgwt.client.widgets.IButton;  
import com.smartgwt.client.widgets.Window;  
import com.smartgwt.client.widgets.events.ClickEvent;  
import com.smartgwt.client.widgets.events.ClickHandler;  
import com.smartgwt.client.widgets.events.CloseClickEvent;  
import com.smartgwt.client.widgets.events.CloseClickHandler;  
import com.smartgwt.client.widgets.layout.VLayout; 

import com.google.gwt.core.client.EntryPoint;

public class TestCases implements EntryPoint {  

    public void onModuleLoad() {  

         IButton tester = new IButton("Tester");
         tester.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                final Window win = new Window();
                win.setTitle("Ventana Tester");
                win.setWidth(900);
                win.setHeight(600);
                win.setIsModal(true);
                win.setShowModalMask(true);
                win.centerInPage();
                win.setMinimized(false);

                win.addCloseClickHandler(new CloseClickHandler() {
                    @Override
                    public void onCloseClick(CloseClickEvent event) {
                        win.destroy();
                    }
                });

                PlanBoard pb = new PlanBoard();
                win.addItem(pb);
                win.show();
            }
        });

        VLayout vlPrincipal = new VLayout();
        vlPrincipal.addMember(tester);
        vlPrincipal.draw();
    }  
}  

一些注意事项:

  • 除非绝对必要,否则不要混用GWT和SmartGWT小部件,只有当你真正知道自己在做什么时(因为它会产生意想不到的结果,就像你遇到的那样)。在你的情况下,混合是不必要的!
  • 您可以将标题添加到您正在使用的不同控件中,它们将显示为标签。您可以指定标题标签是出现在每个控件的上方还是一侧。
  • 查看this SmartGWT演示,了解如何配置和使用不同类型的DynamicForm控件。你试图做的很多事情,你做的比实际困难更多。
  • 在“风格”方面,不要使用Spanglish编写代码。我会讲西班牙语,所以我理解,但它限制了很多你得到的反馈,因为你的代码更难以理解。使用英语(至少对于您打算在SO中发布的代码)。