2017-08-14 108 views
0

我有簡單的看法。有UiBinder的和階級本身:GWT popuPanel.hide()不工作

public class NewNotePopupPanel extends Composite implements NewNoteView { 
interface NewNotePopupPanelUiBinder extends UiBinder<PopupPanel, NewNotePopupPanel> { 
} 

private static NewNotePopupPanelUiBinder ourUiBinder = GWT.create(NewNotePopupPanelUiBinder.class); 


@UiField 
PopupPanel popupPanel; 
@UiField 
VerticalPanel newNoteMainPanel; 
@UiField 
HorizontalPanel newNoteHeader; 
@UiField 
Label storedNoteTitle; 
@UiField 
DateLabel noteCreatedDate; 
@UiField 
VerticalPanel contentPanel; 
@UiField 
TextBox currentNoteTitle; 
@UiField 
RichTextArea contentTextArea; 
@UiField 
HorizontalPanel newNoteFooter; 
@UiField 
CheckBox favorite; 
@UiField 
Button save; 
@UiField 
Button close; 

private Presenter presenter; 

static { 
    Resources.INSTANCE.style().ensureInjected(); 
} 

public NewNotePopupPanel() { 
    initWidget(ourUiBinder.createAndBindUi(this)); 
} 

@UiHandler("favorite") 
void onFavoriteCheckBoxClicked(ClickEvent event) { 
    if (presenter != null) { 
     presenter.onFavoriteCheckBoxClicked(); 
    } 
} 

@UiHandler("save") 
void onApplyButtonClicked(ClickEvent event) { 
    if (presenter != null) { 
     presenter.onApplyButtonClicked(); 
    } 
} 

@UiHandler("close") 
void onCancelButtonClicked(ClickEvent event) { 
    popupPanel.hide(); 
} 
} 

UiBinder的:

<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder' 
     xmlns:g='urn:import:com.google.gwt.user.client.ui'> 
<ui:with field="res" type="ru.beleychev.notes.client.ui.Resources"/> 
<g:PopupPanel ui:field="popupPanel" width="600px" modal="true" title="Edit Note" addStyleNames="{res.style.mainPanel}"> 
    <g:VerticalPanel ui:field="newNoteMainPanel"> 
     <g:HorizontalPanel ui:field="newNoteHeader"> 
      <g:Label ui:field="storedNoteTitle" addStyleNames="{res.style.label}"/> 
      <g:DateLabel ui:field="noteCreatedDate" customFormat="EEE, MMM d, yyyy" 
         addStyleNames="{res.style.label}"/> 
     </g:HorizontalPanel> 
     <g:VerticalPanel ui:field="contentPanel"> 
      <g:TextBox ui:field="currentNoteTitle" addStyleNames="{res.style.searchBox}"/> 
      <g:RichTextArea ui:field="contentTextArea" focus="true"/> 
     </g:VerticalPanel> 
     <g:HorizontalPanel ui:field="newNoteFooter"> 
      <g:CheckBox ui:field="favorite"/> 
      <g:Button ui:field="save" text="Save" addStyleNames="{res.style.button}"/> 
      <g:Button ui:field="close" text="Close" addStyleNames="{res.style.button}"/> 
     </g:HorizontalPanel> 
    </g:VerticalPanel> 
</g:PopupPanel> 

該彈出式窗口從另一個視圖中打開。一切都好。 我沒有接口問題。但不幸的是,「關閉」按鈕不會關閉彈出窗口。這很簡單(容易)。問題是什麼? )期待你的建議,夥計們。先謝謝你。

回答

4

why can't i hide DialogBox in UiBinder in GWT?

DialogBox(和PopupPanels一般)談論它們添加到DOM時,不會像其他小部件的工作。您不應該像以前那樣將它們直接附加到它(即,panel.add(yourDialogBox)UiBinder XML文件中)。相反,你應該創建它們,並簡單地調用hide()/show()等方法,以使其顯示/隱藏(即,連接/分離在DOM的末端/從DOM)

+0

我想你說得對,但...你可以使用uibinder創建彈出窗口,只要它是根元素(就像你做的那樣),你不應該做的就是把它作爲一個嵌套元素來創建,因爲這最終會成爲panel.add調用,這對於彈出面板是不正確的。 –