1つのカスタム列を持つCellTableがあり、手動でレンダリングして、一連のHTMLPanel / Anchor/FlowPanelウィジェットを含むFlowPanelを配置します。その中にはDecoratorPanelがあります。
もちろん、DecoratorPanelはテーブルとしてレンダリングされます。
レンダリングは次のように行われます。
public class MyExpandableCell extends AbstractCell<String> {
...
@Override
public void render(com.google.gwt.cell.client.Cell.Context context, String value, SafeHtmlBuilder sb) {
if (value != null) {
FlowPanel fp = createDetailsFlowPanel(value);
sb.appendHtmlConstant(fp.getElement().getString());
}
}
これで、クリックイベントのハンドラーをメインのCellTableに追加しました。ハンドラーで、ツリーをトラバースして、CellTableに属する最初のTRを見つけます。これには、「偶数行」または「奇数行」のCSSクラスが含まれているかどうかを確認します。
ただし、クリックがセルテーブルのTD内にあるDecoratorPanel内で発生すると、クリックはセルテーブル領域に属するため、ハンドラーもトリガーされます。
親TRにCellTableCSSクラスがないことを確認すると、これを検出できます。
質問:このようなクリックイベントの処理を、実際に属するDecoratorPanelに戻すにはどうすればよいですか?現在のように、DecoratorPanelは拡張されません。これは、クリックハンドラーが、CellTableレベルでのすべてのクリックをインターセプトして抑制するためだと思います。
table = setupMyCellTable(PAGE_SIZE, CLIENT_BUNDLE, myCellTableResources);
mydataprovider.addDataDisplay(table);
table.sinkEvents(Event.ONCLICK);
table.addDomHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent e) {
boolean isClick = "click".equals(e.getNativeEvent().getType());
if (isClick) {
Element originalElement = e.getNativeEvent().getEventTarget().cast();
Element element = originalElement;
String ctTrClassEven = CLIENT_BUNDLE.mainCss().cellTableEvenRow();
String ctTrClassEven = CLIENT_BUNDLE.mainCss().cellTableOddRow();
// Looking for closest parent TR which has one
// of the two row class names (for this cellTable):
while (element != null
&& !"tr".equalsIgnoreCase(element.getTagName())
&& !(element.getClassName().contains(ctTrClassEven) ||
element.getClassName().contains(ctTrClassEven))) {
element = element.getParentElement();
}
if (element != null) {
if (element.getClassName().contains(ctTrClassEven)
|| element.getClassName().contains(ctTrClassEven)) {
// Found cell table's TR. Set new TR height.
} else {
// Found TR from DecoratorPanel inside of the celltable's cell.
// Do nothing. But how do I make sure
// that decorator panel processes this click and expands?
return;
// Did not work: NS_ERROR_ILLEGAL_VALUE javascript exception.
// if (originalElement != null) {
// originalElement.dispatchEvent(e.getNativeEvent());
// }
}
} else {
debugStr.setText("(did not find tr)");
}
}
}
}, ClickEvent.getType());