2016-06-28 29 views
1

我有一個問題,使用WindowsetIsModal(true)SmartGWT - 無法點擊進入Windows模式的項目

我有這樣的代碼:

@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),並讓這些項目在該窗口上工作。

+0

什麼是EntryPoint類中的'vlPrincipal'?你不要在任何地方聲明它。另外,由於您將SmartGWT和GWT組件混合在一起,因此必須包含您正在使用的特定組件所使用的庫。 – carlossierra

回答

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(重命名爲您的入口點的類名,你不指定):

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中發佈的代碼)。
+0

感謝Carlos,問題是通過將這些項目放在CaptionPanel中不起作用。 對不起我的泰山英語; D –

+0

沒關係。只要記住將來的職位(我認爲這也是一個很好的通用規則:英文代碼......你永遠不知道什麼時候你需要不會說西班牙語的人的幫助)。 – carlossierra