GWT Custom DataGrid SelectionHandler не выбирает подэлементы
Наконец я запустил пользовательский DataGrid. Это то же самое, что и на витрине GWT. Таким образом, я получил некоторые подпункты и некоторые основные элементы. Но теперь я хочу обнаружить ClickEvents. Через некоторое время я узнал, что мне нужен SelectionHandler. Но после его реализации выбираются только основные элементы. Есть ли способ поймать выбор подпунктов?
Я также установил один как выбранный через selectionHandler.setSelected(subitem, true);
и это сработало отлично, но как мне получить выбор по моим подпунктам из userinput/ClickEvent?
Основной код просто:selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
@Override
public void onSelectionChange(final SelectionChangeEvent event) {
File selected = ((SingleSelectionModel) selectionModel).getSelectedObject();
if(selected != null){
Window.alert(selected.getFileName());
}
}
}
});
/** * Renders the data rows that display each contact in the table. */ private class CustomTableBuilder extends AbstractCellTableBuilder<File> { private final String childCell = " " + FileTreeViewImpl.this.resources.styles().childCell(); private final String rowStyle; private final String selectedRowStyle; private final String cellStyle; private final String selectedCellStyle; public CustomTableBuilder() { super(FileTreeViewImpl.this.fileDataGrid); DefaultSelectionEventManager.createCustomManager(new DefaultSelectionEventManager .WhitelistEventTranslator<File>(0)); // Cache styles for faster access. com.google.gwt.user.cellview.client.AbstractCellTable.Style style = FileTreeViewImpl.this.fileDataGrid.getResources().style(); this.rowStyle = style.evenRow(); this.selectedRowStyle = " " + style.selectedRow(); this.cellStyle = style.cell() + " " + style.evenRowCell(); this.selectedCellStyle = " " + style.selectedRowCell(); } @Override protected void buildRowImpl(final File rowValue, final int absRowIndex) { buildContactRow(rowValue, absRowIndex, false); // Display list of files. if (FileTreeViewImpl.this.displayFolderContent.contains(rowValue.getFileName())) { Set<File> files = FileTreeViewImpl.this.folderMap.get(rowValue.getFileName()); for (File file : files) { buildContactRow(file, absRowIndex, true); } } } /** * Build a row. * * @param rowValue * the file info * @param absRowIndex * the absolute row index * @param isFriend * true if this is a subrow, false if a top level row */ private void buildContactRow(final File rowValue, final int absRowIndex, final boolean isFriend) { // Calculate the row styles. SelectionModel<? super File> selectionModel = FileTreeViewImpl.this.fileDataGrid.getSelectionModel(); boolean isSelected = (selectionModel == null || rowValue == null) ? false : selectionModel.isSelected(rowValue); StringBuilder trClasses = new StringBuilder(this.rowStyle); if (isSelected) { trClasses.append(this.selectedRowStyle); } // Calculate the cell styles. String cellStyles = this.cellStyle; if (isSelected) { cellStyles += this.selectedCellStyle; } if (isFriend) { cellStyles += this.childCell; } TableRowBuilder row = startRow(); row.className(trClasses.toString()); // Column one to expand the submenu. TableCellBuilder td = row.startTD(); td.style().outlineStyle(OutlineStyle.NONE).endStyle(); if (!isFriend) { renderCell(td, createContext(0), FileTreeViewImpl.this.viewFolderContent, rowValue); } td.endTD(); // Filename goes here. td = row.startTD(); td.className(cellStyles); td.style().outlineStyle(OutlineStyle.NONE).endStyle(); if (isFriend) { td.text(rowValue.getFileName()); } else { renderCell(td, createContext(1), FileTreeViewImpl.this.nameColumn, rowValue); } td.endTD(); // Filesize goes here. td = row.startTD(); td.className(cellStyles); td.style().outlineStyle(OutlineStyle.NONE).endStyle(); if (isFriend) { td.text(rowValue.getFileSizeAsString()); } else { renderCell(td, createContext(2), FileTreeViewImpl.this.sizeColumn, rowValue); } td.endTD(); // Last Editor goes here. td = row.startTD(); td.className(cellStyles); td.style().outlineStyle(OutlineStyle.NONE).endStyle(); if (isFriend) { td.text(rowValue.getLastEditedBy()); } else { renderCell(td, createContext(3), FileTreeViewImpl.this.editedColumn, rowValue); } td.endTD(); row.endTR(); } }</code>Привет