use of org.ovirt.engine.ui.common.widget.table.cell.EventHandlingCell in project ovirt-engine by oVirt.
the class EntityModelCellTable method addCheckBoxColumn.
private void addCheckBoxColumn(boolean hideCheckbox, boolean showSelectAllCheckbox) {
if (!hideCheckbox) {
// Add selection column
Column<EntityModel, Boolean> checkColumn = null;
if (getSelectionModel() instanceof SingleSelectionModel) {
checkColumn = new Column<EntityModel, Boolean>(new RadioboxCell(true, false)) {
@Override
public Boolean getValue(EntityModel object) {
return getSelectionModel().isSelected(object);
}
};
addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant(constants.htmlNonBreakingSpace()));
} else if (getSelectionModel() instanceof MultiSelectionModel) {
checkColumn = new Column<EntityModel, Boolean>(new CheckboxCell(true, false)) {
@Override
public Boolean getValue(EntityModel object) {
return getSelectionModel().isSelected(object);
}
};
if (showSelectAllCheckbox) {
AbstractSelectAllCheckBoxHeader<EntityModel> selectAllHeader = new AbstractSelectAllCheckBoxHeader<EntityModel>() {
@Override
protected void selectionChanged(Boolean value) {
if (getListModel() == null || getListModel().getItems() == null) {
return;
}
handleSelection(value, getListModel(), getSelectionModel());
}
@Override
public Boolean getValue() {
if (getListModel() == null || getListModel().getItems() == null) {
return false;
}
return getCheckValue(getListModel().getItems(), getSelectionModel());
}
};
addColumn(checkColumn, selectAllHeader);
} else {
addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant(constants.htmlNonBreakingSpace()));
}
}
if (checkColumn != null) {
setColumnWidth(checkColumn, CHECK_COLUMN_WIDTH, Unit.PX);
selectionColumnPresent = true;
}
addCellPreviewHandler(event -> {
int columnIndex = event.getColumn();
Cell<?> cell = getColumn(columnIndex).getCell();
if (cell instanceof EventHandlingCell && ((EventHandlingCell) cell).handlesEvent(event)) {
return;
}
if (BrowserEvents.CLICK.equals(event.getNativeEvent().getType()) && !(getSelectionModel() instanceof NoSelectionModel)) {
// Let the selection column deal with this
if (event.getColumn() == 0) {
return;
}
getSelectionModel().setSelected(event.getValue(), !getSelectionModel().isSelected(event.getValue()));
}
});
}
}
Aggregations