我创建了一个从 DialogBox 扩展的类,以便使用嵌套在 ScrollPanel 中的 FlexTable 对其进行自定义。问题是,即使我有一个带有虚拟代码的滚动处理程序(Window.alert ....),屏幕上也不会出现任何事件,就好像没有引发事件一样。
到目前为止,这是我的代码:
public class LogViewerPopup extends DialogBox {
private DashboardServiceInterfaceAsync myService;
private FlexTable innerTable;
private String tool;
private String version;
private String exec_id;
private String scenario;
private int xPos;
private int yPos;
public LogViewerPopup(DashboardServiceInterfaceAsync myService, String tool, String version, String exec_id, String scenario, int xPos, int yPos) {
super(true, false);
this.myService = myService;
this.tool = tool;
this.version = version;
this.exec_id = exec_id;
this.scenario = scenario;
this.xPos = xPos;
this.yPos = yPos;
this.setStyleName("dialog");
this.setStyleDependentName("dialogContent", true);
this.setAnimationEnabled(true);
this.setGlassEnabled(true);
this.setText(tool + " - " + scenario + " - " + version);
//this.setWidget(new Label(tool + " - " + scenario + " - " + version));
this.setPopupPosition(xPos, yPos);
myService.getLogs(version, tool, exec_id, scenario, new AsyncCallback<ArrayList<HashMap<String,String>>>() {
@Override
public void onSuccess(ArrayList<HashMap<String, String>> result) {
System.out.println("Debug !");
innerTable = new FlexTable();
innerTable.setCellSpacing(0);
ScrollPanel sp = new ScrollPanel();
sp.addScrollHandler(new ScrollHandler() {
@Override
public void onScroll(ScrollEvent event) {
Window.alert("Scrolling !");
}
});
//Headers
addColumn("ID");
addColumn("Date");
addColumn("Scenario");
addColumn("Module");
addColumn("Logtype");
addColumn("Content");
addColumn("Exec ID");
addColumn("Executor");
addColumn("Current Dataset");
addColumn("Total Datasets");
//Results
for(int i = 0 ; i < result.size() ; i++){
innerTable.setWidget(i + 1, 0, new Label(result.get(i).get("id")));
innerTable.setWidget(i + 1, 1, new Label(result.get(i).get("date")));
innerTable.setWidget(i + 1, 2, new Label(result.get(i).get("scenario")));
innerTable.setWidget(i + 1, 3, new Label(result.get(i).get("module")));
innerTable.setWidget(i + 1, 4, new Label(result.get(i).get("logtype")));
innerTable.setWidget(i + 1, 5, new Label(result.get(i).get("content")));
innerTable.setWidget(i + 1, 6, new Label(result.get(i).get("exec_id")));
innerTable.setWidget(i + 1, 7, new Label(result.get(i).get("executor")));
innerTable.setWidget(i + 1, 8, new Label(result.get(i).get("current_dataset")));
innerTable.setWidget(i + 1, 9, new Label(result.get(i).get("total_datasets")));
}
for(int i = 0 ; i < innerTable.getRowCount() ; i++)
for(int j = 0; j < innerTable.getCellCount(i) ; j ++)
innerTable.getCellFormatter().addStyleName(i,j,"FlexTable-Cell");
applyLineStyle();
sp.add(innerTable);
setWidget(sp);
show();
}
@Override
public void onFailure(Throwable caught) {
Window.alert("Error generating the LogViewerPopup : " + caught.getMessage());
}
});
}
private void applyLineStyle(){
HTMLTable.RowFormatter rf = innerTable.getRowFormatter();
for (int row = 1; row < innerTable.getRowCount(); ++row) {
if ((row % 2) != 0) {
rf.addStyleName(row, "FlexTable-OddRow");
}
else {
rf.addStyleName(row, "FlexTable-EvenRow");
}
}
rf.addStyleName(0, "FlexTable-HeaderRow");
}
private void addColumn(String text){
Label label = new Label(text);
label.setWidth("100%");
try{
innerTable.setWidget(0, innerTable.getCellCount(0), label);
}catch(IndexOutOfBoundsException e){
innerTable.setWidget(0, 0, label);
}
}
}
不要关注结构糟糕的代码,因为我正拼命想让这件事最终工作;)
注意:我设法通过将 ScrollPanel 包装在 FocusPanel 中来捕捉滚动,但它并没有真正帮助我,因为我想知道滚动条的精确位置。我正在使用 GWT 3.7