我有一个名为Column的表。
我希望当用户mouseOver的nameColumn标题时会触发一个方法
我试过了:
Header<String> nameColumnHeader = new Header<String>(new ClickableTextCell()) {
@Override
public String getValue() {
return "Name";
}
@Override
public final void onBrowserEvent(Context context, Element elem, NativeEvent event) {
if ("mouseover".equals(event.getType())) {
//
meaningMessagesPopup.show();
}
else if("mouseout".equals(event.getType())){
meaningMessagesPopup.hide();
}
}
};
table.addColumn(nameColumn, nameColumnHeader);
但似乎Gwt不承认"mouseover".equals(event.getType())
你知道如何在GWT Header中执行MOUSEOVER事件吗?
答案 0 :(得分:2)
我找到了答案,即创建一个扩展AbstractCell的CustomCell
private class HeaderCell extends AbstractCell<String> {
private String text;
public HeaderCell(String text) {
/*
* Let the parent class know that our cell responds to click events and
* keydown events.
*/
//super("click", "keydown");
super("mouseover");
this.text=text;
}
@Override
public void onBrowserEvent(Context context, Element parent, String value,
NativeEvent event, ValueUpdater<String> valueUpdater) {
// Check that the value is not null.
if (value == null) {
return;
}
// Call the super handler, which handlers the enter key.
super.onBrowserEvent(context, parent, value, event, valueUpdater);
if ("mouseover".equals(event.getType())) {
SafeHtmlBuilder sb=new SafeHtmlBuilder();
sb.appendHtmlConstant("<b>");
sb.appendHtmlConstant("<font color=\"blue\">");
sb.appendEscaped(text);
sb.appendHtmlConstant("</font></b>");
meaningMessagesPopup.setWidget(new HTML(sb.toSafeHtml()));
int left = event.getClientX() -140;
int top = event.getClientY() +30;
meaningMessagesPopup.setPopupPosition(left, top);
// Show the popup
meaningMessagesPopup.show();
}
else if ("mouseout".equals(event.getType())) {
meaningMessagesPopup.hide();
}
}
@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
/*
* Always do a null check on the value. Cell widgets can pass null to
* cells if the underlying data contains a null, or if the data arrives
* out of order.
*/
if (value == null) {
return;
}
sb.appendEscaped(value);
}
}
然后
Header<String> nameColumnHeader = new Header<String>(new HeaderCell("my Text...")) {
@Override
public String getValue() {
return "Name";
}
};
table.addColumn(nameColumn, nameColumnHeader);