gpt4 book ai didi

java - 如何使监听器在 CellColumn getValue gwt 中工作?

转载 作者:行者123 更新时间:2023-12-01 12:40:00 26 4
gpt4 key购买 nike

我的要求是将列制作为文本和超链接的组合。因此我无法使用ClickableTextCell。我为此做了以下工作:-

private final Column < Trap, Widget > elementColumn = new Column < Trap, Widget > (new WidgetCell()) {
@Override
public Widget getValue(Trap trap) {
Label label = null;
Anchor anchor = null;

if (trap.getNode() != null) {
label = new InlineLabel(EmsEntryPoint.getMessagesInstance().device() + ": ");

String name = trap.getNode().getName();
if (name == null || name.isEmpty()) {
name = DataConverter.convertLongToHexId(trap.getNode().getId());
}

final Map < String, String > params = new HashMap < String, String > ();
params.put(NetworkActivity.PARAM_NODE_ID, String.valueOf(trap.getNode().getId()));
anchor = new Anchor(name);
anchor.addClickHandler(new ClickHandler() {

@Override
public void onClick(ClickEvent event) {
NodeDetail nodeDetail = new NodeDetail(mInjector, UrlHelper.getPlaceToken(null, params));
bindNodeDetailButtons(nodeDetail);
nodeDetail.showNodeDetailPopup();
}
});
}
FlowPanel panel = new FlowPanel();
panel.add(label);
panel.add(anchor);
return panel;
}
}

我的代码中的一切都是正确的,但我不知道为什么 Anchor 的监听器不起作用。请帮忙。

最佳答案

您必须重写渲染方法并向单元格添加处理程序。

我使用了以下类:

abstract class CustomCell extends AbstractCell<String>{

private MyObject object;
private Set<String> set ;

@Override
public Set<String> getConsumedEvents() {
set = new HashSet<String>();
set.add("click");
return set;
}

public void setObject(MyObject object) {
this.object = object;

}

@Override
public void render(com.google.gwt.cell.client.Cell.Context context,
String value, SafeHtmlBuilder sb) {
sb.appendHtmlConstant("<div><label>"+object.getLabel()+"</label><a id='idofthislelement'>"+object.getAnchor()+"</a></div>");
}

@Override
public void onBrowserEvent(Context context, Element parent,
String value, NativeEvent event,
ValueUpdater<String> valueUpdater) {
super.onBrowserEvent(context, parent, value, event, valueUpdater);

if ("click".equals(event.getType())) {
EventTarget eventTarget = (EventTarget) event.getEventTarget();
Element targetElement = Element.as(eventTarget);
if (parent.getFirstChildElement().isOrHasChild(targetElement)&&targetElement.getId().equals("idofthislelement")) {
doAction(value, valueUpdater,object);
}
}
}

protected abstract void doAction(String value, ValueUpdater<String> valueUpdater,MyObject object);

}

这里是实现:

private void createTextAnchorCol() {
final CustomCell<MyObject> cell = new CustomCell<MyObject>() {

@Override
protected void doAction(String value,
ValueUpdater<String> valueUpdater, MyObject object) {
Window.alert("Clicked");
//do whatever required
}
};
Column<MyObject, String> abc = new Column<MyObject, String>(cell) {

@Override
public String getValue(MyObject object) {
cell.setObject(object);
return null;
}
};

关于java - 如何使监听器在 CellColumn getValue gwt 中工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25199154/

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