gpt4 book ai didi

java - 在 GWT DisclosurePanel 标题中的小部件之一上设置自定义 onClick

转载 作者:行者123 更新时间:2023-12-02 07:52:07 26 4
gpt4 key购买 nike

我有以下用户界面情况:

<g:DisclosurePanel width="100%" ui:field="disclosurePanel">
<g:customHeader>
<g:HorizontalPanel width="100%" ui:field="tableRow">
<g:cell width="16px" horizontalAlignment="ALIGN_CENTER">
<g:Image url="images/plus-icon.gif" ui:field="icon"></g:Image>
</g:cell>
<g:cell width="20%">
<g:Label ui:field="productName"></g:Label>
</g:cell>
<g:cell>
<g:Anchor ui:field="info"><ui:msg>More info...</ui:msg></g:Anchor>
</g:cell>
</g:HorizontalPanel>
</g:customHeader>
<g:VerticalPanel width="100%" ui:field="details">
<!-- details panel here -->
</g:VerticalPanel>
</g:DisclosurePanel>

我想将事件处理程序方法绑定(bind)到 anchor 信息。然而,我在标题中的每个小部件都会打开和关闭披露面板,即使我通过以下方式在 info 上挂接某些内容:

@UiHandler("info")
public void onInfoClicked(ClickEvent event)
{
// do something custom, but do not open/close the disclosurepanel
}

我希望这可以在不制作自定义复合 Material 或其他东西的情况下实现。你能帮我吗?

最佳答案

DisclosurePanel 的 header 是私有(private)内部类 ClickableHeader:

private final class ClickableHeader extends SimplePanel {

private ClickableHeader() {
// Anchor is used to allow keyboard access.
super(DOM.createAnchor());
Element elem = getElement();
DOM.setElementProperty(elem, "href", "javascript:void(0);");
// Avoids layout problems from having blocks in inlines.
DOM.setStyleAttribute(elem, "display", "block");
sinkEvents(Event.ONCLICK);
setStyleName(STYLENAME_HEADER);
}

@Override
public void onBrowserEvent(Event event) {
// no need to call super.
switch (DOM.eventGetType(event)) {
case Event.ONCLICK:
// Prevent link default action.
DOM.eventPreventDefault(event);
setOpen(!isOpen);
}
}
}

假设你的代码:

@UiField
DisclosurePanel p;

//call this somewhere once on widget creation to
//prevent header's default click handler
private void myInit()
{
p.getHeader().unsinkEvents(Event.ONCLICK);
}

@UiHandler("info")
public void onInfoClicked(ClickEvent event)
{
//trigger "standard" click handler if you want
if(someCondition) {
//convert GwtEvent descendant to NativeEvent descendant;
p.getHeader().onBrowserEvent(event.getNativeEvent().<Event> cast());
}

// do something custom, but do not open/close the disclosurepanel
}

关于java - 在 GWT DisclosurePanel 标题中的小部件之一上设置自定义 onClick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10118694/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com