use of org.ovirt.engine.ui.common.widget.table.cell.CheckboxCell 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()));
}
});
}
}
use of org.ovirt.engine.ui.common.widget.table.cell.CheckboxCell in project ovirt-engine by oVirt.
the class QuotaPopupView method initQuotaClusterTable.
private void initQuotaClusterTable() {
quotaClusterTable = new ListModelObjectCellTable<>();
clusterQuotaTableContainer.add(quotaClusterTable);
isClusterInQuotaColumn = new Column<QuotaCluster, Boolean>(new CheckboxCell(true, true)) {
@Override
public Boolean getValue(QuotaCluster object) {
if (selectedClusterGuid.contains(object.getClusterId()) || (object.getMemSizeMB() != null && object.getVirtualCpu() != null)) {
if (!selectedClusterGuid.contains(object.getClusterId())) {
selectedClusterGuid.add(object.getClusterId());
}
return true;
}
return false;
}
};
isClusterInQuotaColumn.setFieldUpdater((index, object, value) -> {
if (value) {
selectedClusterGuid.add(object.getClusterId());
object.setVirtualCpu(QuotaCluster.UNLIMITED_VCPU);
object.setMemSizeMB(QuotaCluster.UNLIMITED_MEM);
} else {
selectedClusterGuid.remove(object.getClusterId());
object.setVirtualCpu(null);
object.setMemSizeMB(null);
}
if (model.getGlobalClusterQuota().getEntity()) {
quotaClusterTable.asEditor().edit(model.getQuotaClusters());
} else {
quotaClusterTable.asEditor().edit(model.getAllDataCenterClusters());
}
});
quotaClusterTable.addColumn(new AbstractTextColumn<QuotaCluster>() {
@Override
public String getValue(QuotaCluster object) {
if (object.getClusterName() == null || object.getClusterName().length() == 0) {
return constants.ultQuotaForAllClustersQuotaPopup();
}
return object.getClusterName();
}
}, constants.clusterNameQuota(), // $NON-NLS-1$
"200px");
// $NON-NLS-1$
quotaClusterTable.addColumn(new QuotaUtilizationStatusColumn<QuotaCluster>(), constants.empty(), "1px");
quotaClusterTable.addColumn(new AbstractTextColumn<QuotaCluster>() {
@Override
public String getValue(QuotaCluster object) {
if (object.getMemSizeMB() == null) {
// $NON-NLS-1$
return "";
} else if (object.getMemSizeMB().equals(QuotaCluster.UNLIMITED_MEM)) {
return messages.unlimitedMemConsumption(object.getMemSizeMBUsage());
} else {
return messages.limitedMemConsumption(object.getMemSizeMBUsage(), object.getMemSizeMB());
}
}
}, constants.quotaOfMemQuota());
quotaClusterTable.addColumn(new AbstractTextColumn<QuotaCluster>() {
@Override
public String getValue(QuotaCluster object) {
if (object.getVirtualCpu() == null) {
// $NON-NLS-1$
return "";
} else if (object.getVirtualCpu().equals(QuotaCluster.UNLIMITED_VCPU)) {
return messages.unlimitedVcpuConsumption(object.getVirtualCpuUsage());
} else {
return messages.limitedVcpuConsumption(object.getVirtualCpuUsage(), object.getVirtualCpu());
}
}
}, constants.quotaOfVcpuQuota());
NullableButtonCell editCellButton = new NullableButtonCell();
Column<QuotaCluster, String> editColumn = new Column<QuotaCluster, String>(editCellButton) {
@Override
public String getValue(QuotaCluster object) {
if (model.getGlobalClusterQuota().getEntity() || (model.getSpecificClusterQuota().getEntity() && selectedClusterGuid.contains(object.getClusterId()))) {
return constants.editCellQuota();
}
return null;
}
};
// $NON-NLS-1$
quotaClusterTable.addColumn(editColumn, constants.empty(), "50px");
editColumn.setFieldUpdater((index, object, value) -> model.editQuotaCluster(object));
}
use of org.ovirt.engine.ui.common.widget.table.cell.CheckboxCell in project ovirt-engine by oVirt.
the class QuotaPopupView method initQuotaStorageTable.
private void initQuotaStorageTable() {
quotaStorageTable = new ListModelObjectCellTable<>();
storageQuotaTableContainer.add(quotaStorageTable);
isStorageInQuotaColumn = new Column<QuotaStorage, Boolean>(new CheckboxCell(true, true)) {
@Override
public Boolean getValue(QuotaStorage object) {
if (selectedStorageGuid.contains(object.getStorageId()) || object.getStorageSizeGB() != null) {
if (!selectedStorageGuid.contains(object.getStorageId())) {
selectedStorageGuid.add(object.getStorageId());
}
return true;
}
return false;
}
};
isStorageInQuotaColumn.setFieldUpdater((index, object, value) -> {
if (value) {
selectedStorageGuid.add(object.getStorageId());
object.setStorageSizeGB(QuotaStorage.UNLIMITED);
} else {
selectedStorageGuid.remove(object.getStorageId());
object.setStorageSizeGB(null);
}
if (model.getGlobalStorageQuota().getEntity()) {
quotaStorageTable.asEditor().edit(model.getQuotaStorages());
} else {
quotaStorageTable.asEditor().edit(model.getAllDataCenterStorages());
}
});
quotaStorageTable.addColumn(new AbstractTextColumn<QuotaStorage>() {
@Override
public String getValue(QuotaStorage object) {
if (object.getStorageName() == null || object.getStorageName().length() == 0) {
return constants.utlQuotaAllStoragesQuotaPopup();
}
return object.getStorageName();
}
}, constants.storageNameQuota(), // $NON-NLS-1$
"200px");
// $NON-NLS-1$
quotaStorageTable.addColumn(new QuotaUtilizationStatusColumn<QuotaStorage>(), constants.empty(), "1px");
quotaStorageTable.addColumn(new AbstractTextColumn<QuotaStorage>() {
@Override
public String getValue(QuotaStorage object) {
if (object.getStorageSizeGB() == null) {
// $NON-NLS-1$
return "";
} else if (object.getStorageSizeGB().equals(QuotaStorage.UNLIMITED)) {
return messages.unlimitedStorageConsumption(object.getStorageSizeGBUsage() == 0 ? // $NON-NLS-1$
"0" : diskSizeRenderer.render(object.getStorageSizeGBUsage()));
} else {
return messages.limitedStorageConsumption(object.getStorageSizeGBUsage() == 0 ? // $NON-NLS-1$
"0" : diskSizeRenderer.render(object.getStorageSizeGBUsage()), object.getStorageSizeGB());
}
}
}, constants.quota());
Column<QuotaStorage, String> editColumn = new Column<QuotaStorage, String>(new NullableButtonCell()) {
@Override
public String getValue(QuotaStorage object) {
if (model.getGlobalStorageQuota().getEntity() || (model.getSpecificStorageQuota().getEntity() && selectedStorageGuid.contains(object.getStorageId()))) {
return constants.editCellQuota();
}
return null;
}
};
editColumn.setFieldUpdater((index, object, value) -> model.editQuotaStorage(object));
// $NON-NLS-1$
quotaStorageTable.addColumn(editColumn, constants.empty(), "50px");
}
Aggregations