use of org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn in project ovirt-engine by oVirt.
the class GlusterVolumeGeoReplicationSessionConfigPopupView method initConfigTable.
private void initConfigTable() {
geoReplicationConfigTable = new EntityModelCellTable<>(false, true);
geoReplicationConfigTable.setSelectionModel(new NoSelectionModel());
geoReplicationConfigTable.addColumn(new AbstractEntityModelTextColumn<Pair<Boolean, GlusterGeoRepSessionConfiguration>>() {
@Override
protected String getText(Pair<Boolean, GlusterGeoRepSessionConfiguration> entity) {
return entity.getSecond().getKey();
}
}, constants.optionKeyVolumeParameter(), // $NON-NLS-1$
"150px");
geoReplicationConfigTable.addColumn(new AbstractScrollableTextColumn<EntityModel<Pair<Boolean, GlusterGeoRepSessionConfiguration>>>() {
@Override
public String getValue(EntityModel<Pair<Boolean, GlusterGeoRepSessionConfiguration>> object) {
return object.getEntity().getSecond().getDescription() == null ? constants.notAvailableLabel() : object.getEntity().getSecond().getDescription();
}
}, constants.descriptionVolumeParameter(), // $NON-NLS-1$
"300px");
geoReplicationConfigTable.addColumn(new GlusterConfigAwareColumn(), constants.optionValueVolumeParameter(), // $NON-NLS-1$
"200px");
geoReplicationConfigTable.addColumn(new AbstractCheckboxColumn<EntityModel<Pair<Boolean, GlusterGeoRepSessionConfiguration>>>(true, (index, object, value) -> object.getEntity().setFirst(value)) {
@Override
protected boolean canEdit(EntityModel<Pair<Boolean, GlusterGeoRepSessionConfiguration>> object) {
return true;
}
@Override
public Boolean getValue(EntityModel<Pair<Boolean, GlusterGeoRepSessionConfiguration>> object) {
return object.getEntity().getFirst();
}
}, constants.resetGeoRepSessionConfig());
}
use of org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn in project ovirt-engine by oVirt.
the class AbstractNetworkPopupView method initEntityModelCellTable.
void initEntityModelCellTable() {
AbstractCheckboxHeader assignAllHeader = new AbstractCheckboxHeader() {
@Override
protected void selectionChanged(Boolean value) {
for (NetworkClusterModel networkClusterModel : getClustersTableItems()) {
if (networkClusterModel.getIsChangable()) {
networkClusterModel.setAttached(value);
networkClusterModel.setRequired(value && networkClusterModel.isRequired());
}
}
refreshClustersTable();
}
@Override
public Boolean getValue() {
for (NetworkClusterModel networkClusterModel : getClustersTableItems()) {
if (networkClusterModel.getIsChangable() && !networkClusterModel.isAttached()) {
return false;
}
}
return true;
}
@Override
public boolean isEnabled() {
for (NetworkClusterModel networkClusterModel : getClustersTableItems()) {
if (networkClusterModel.getIsChangable()) {
return true;
}
}
return false;
}
@Override
public String getLabel() {
return constants.attachAll();
}
};
AbstractCheckboxHeader requiredAllHeader = new AbstractCheckboxHeader() {
@Override
protected void selectionChanged(Boolean value) {
for (NetworkClusterModel networkClusterModel : getClustersTableItems()) {
networkClusterModel.setRequired(value && networkClusterModel.isAttached());
}
refreshClustersTable();
}
@Override
public Boolean getValue() {
for (NetworkClusterModel networkClusterModel : getClustersTableItems()) {
if (!networkClusterModel.isRequired()) {
return false;
}
}
return true;
}
@Override
public boolean isEnabled() {
return isRequiredChangeable();
}
@Override
public String getLabel() {
return constants.requiredAll();
}
};
clustersTable.addColumn(new AbstractTextColumn<NetworkClusterModel>() {
@Override
public String getValue(NetworkClusterModel model) {
return model.getName();
}
}, constants.nameClusterHeader());
clustersTable.addColumn(new AbstractCheckboxColumn<NetworkClusterModel>((index, model, value) -> {
model.setAttached(value);
model.setRequired(value && model.isRequired());
refreshClustersTable();
}) {
@Override
public Boolean getValue(NetworkClusterModel model) {
return model.isAttached();
}
@Override
protected boolean canEdit(NetworkClusterModel model) {
return model.getIsChangable();
}
@Override
public void render(Context context, NetworkClusterModel object, SafeHtmlBuilder sb) {
super.render(context, object, sb);
sb.append(templates.textForCheckBox(constants.attach()));
}
}, assignAllHeader, // $NON-NLS-1$
"150px");
clustersTable.addColumn(new AbstractCheckboxColumn<NetworkClusterModel>((index, model, value) -> {
model.setRequired(value && model.isAttached());
refreshClustersTable();
}) {
@Override
public Boolean getValue(NetworkClusterModel model) {
return model.isRequired();
}
@Override
protected boolean canEdit(NetworkClusterModel model) {
return isRequiredChangeable() && model.isAttached();
}
@Override
public void render(Context context, NetworkClusterModel object, SafeHtmlBuilder sb) {
super.render(context, object, sb);
sb.append(templates.textForCheckBox(constants.required()));
}
}, requiredAllHeader, // $NON-NLS-1$
"150px");
}
use of org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn in project ovirt-engine by oVirt.
the class ImportNetworksPopupView method initEntityModelCellTables.
void initEntityModelCellTables() {
providerNetworks.addColumn(new AbstractTextColumn<ExternalNetwork>() {
@Override
public String getValue(ExternalNetwork model) {
return model.getDisplayName();
}
}, constants.nameNetworkHeader());
importedNetworks.addColumn(new AbstractEditTextColumn<ExternalNetwork>((index, model, value) -> model.setDisplayName(value)) {
@Override
public String getValue(ExternalNetwork model) {
return model.getDisplayName();
}
}, constants.nameNetworkHeader());
Column<ExternalNetwork, String> idColumn = new AbstractTextColumn<ExternalNetwork>() {
@Override
public String getValue(ExternalNetwork model) {
return model.getNetwork().getProvidedBy().getExternalId();
}
};
providerNetworks.addColumn(idColumn, constants.idNetworkHeader());
importedNetworks.addColumn(idColumn, constants.idNetworkHeader());
dcColumn = new AbstractListModelListBoxColumn<ExternalNetwork, StoragePool>(new NameRenderer<StoragePool>()) {
@Override
public ListModel<StoragePool> getValue(ExternalNetwork network) {
return network.getDataCenters();
}
};
importedNetworks.addColumn(dcColumn, constants.dcNetworkHeader());
AbstractCheckboxHeader publicAllHeader = new AbstractCheckboxHeader() {
@Override
protected void selectionChanged(Boolean value) {
for (ExternalNetwork model : getAllImportedNetworks()) {
model.setPublicUse(value);
}
refreshImportedNetworks();
}
@Override
public Boolean getValue() {
for (ExternalNetwork model : getAllImportedNetworks()) {
if (!model.isPublicUse()) {
return false;
}
}
return true;
}
@Override
public boolean isEnabled() {
return true;
}
@Override
public void render(Context context, SafeHtmlBuilder sb) {
super.render(context, sb);
sb.append(ImportNetworksPopupView.templates.tableHeaderInlineImage(SafeHtmlUtils.fromTrustedString(new InfoIcon(SafeHtmlUtils.EMPTY_SAFE_HTML).toString())));
}
@Override
public SafeHtml getTooltip() {
return ImportNetworksPopupView.templates.textForCheckBoxHeader(constants.publicNetworkTooltip());
}
@Override
public String getLabel() {
return constants.publicNetwork();
}
};
importedNetworks.addColumn(new AbstractCheckboxColumn<ExternalNetwork>((index, model, value) -> {
model.setPublicUse(value);
refreshImportedNetworks();
}) {
@Override
public Boolean getValue(ExternalNetwork model) {
return model.isPublicUse();
}
@Override
protected boolean canEdit(ExternalNetwork model) {
return true;
}
@Override
public void render(Context context, ExternalNetwork object, SafeHtmlBuilder sb) {
super.render(context, object, sb);
// $NON-NLS-1$
sb.append(templates.textForCheckBox(""));
}
}, publicAllHeader, // $NON-NLS-1$
"80px");
}
use of org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn in project ovirt-engine by oVirt.
the class ImportVmFromExportDomainPopupView method initMainTable.
protected void initMainTable() {
this.table = new ListModelObjectCellTable<>();
table.enableColumnResizing();
AbstractImageResourceColumn<Object> isProblematicImportVmColumn = new AbstractImageResourceColumn<Object>() {
@Override
public ImageResource getValue(Object object) {
ImportVmData importVmData = (ImportVmData) object;
if (importVmData.getError() != null || importVmData.isNameExistsInTheSystem()) {
return resources.errorImage();
}
if (importVmData.getWarning() != null) {
return resources.alertImage();
}
return null;
}
@Override
public SafeHtml getTooltip(Object object) {
ImportVmData importVmData = (ImportVmData) object;
String problem = null;
if (importVmData.getError() != null) {
problem = importVmData.getError();
} else {
problem = importVmData.isNameExistsInTheSystem() ? ConstantsManager.getInstance().getConstants().nameMustBeUniqueInvalidReason() : importVmData.getWarning();
}
return problem != null ? SafeHtmlUtils.fromSafeConstant(problem) : null;
}
};
// $NON-NLS-1$
table.addColumn(isProblematicImportVmColumn, constants.empty(), "30px");
AbstractTextColumn<Object> nameColumn = new AbstractTextColumn<Object>() {
@Override
public String getValue(Object object) {
String originalName = ((ImportVmData) object).getName();
String givenName = ((ImportVmData) object).getVm().getName();
return originalName.equals(givenName) ? givenName : // $NON-NLS-1$ //$NON-NLS-2$
givenName + " (" + originalName + ")";
}
};
// $NON-NLS-1$
table.addColumn(nameColumn, constants.nameVm(), "150px");
AbstractCheckboxColumn<Object> collapseSnapshotsColumn = new AbstractCheckboxColumn<Object>((index, model, value) -> {
((ImportVmData) model).getCollapseSnapshots().setEntity(value);
customSelectionCellFormatType.setEnabled(value);
diskTable.asEditor().edit(importModel.getImportDiskListModel());
}) {
@Override
public Boolean getValue(Object model) {
return ((ImportVmData) model).getCollapseSnapshots().getEntity();
}
@Override
protected boolean canEdit(Object model) {
return ((ImportVmData) model).getCollapseSnapshots().getIsChangable();
}
@Override
protected String getDisabledMessage(Object model) {
return ((ImportVmData) model).getCollapseSnapshots().getChangeProhibitionReason();
}
@Override
public SafeHtml getTooltip(Object object) {
SafeHtml superTooltip = super.getTooltip(object);
if (superTooltip == null) {
return SafeHtmlUtils.fromSafeConstant(constants.importAllocationModifiedCollapse());
}
return superTooltip;
}
};
// $NON-NLS-1$
table.addColumn(collapseSnapshotsColumn, constants.collapseSnapshots(), "130px");
AbstractCheckboxColumn<Object> cloneVMColumn = new AbstractCheckboxColumn<Object>((index, model, value) -> {
((ImportVmData) model).getClone().setEntity(value);
table.asEditor().edit(importModel);
}) {
@Override
public Boolean getValue(Object model) {
return ((ImportVmData) model).getClone().getEntity();
}
@Override
protected boolean canEdit(Object model) {
return ((ImportVmData) model).getClone().getIsChangable();
}
@Override
protected String getDisabledMessage(Object model) {
return ((ImportVmData) model).getClone().getChangeProhibitionReason();
}
};
// $NON-NLS-1$
table.addColumn(cloneVMColumn, constants.cloneVM(), "50px");
AbstractTextColumn<Object> originColumn = new AbstractEnumColumn<Object, OriginType>() {
@Override
protected OriginType getRawValue(Object object) {
return ((ImportVmData) object).getVm().getOrigin();
}
};
// $NON-NLS-1$
table.addColumn(originColumn, constants.originVm(), "100px");
table.addColumn(new AbstractSafeHtmlColumn<Object>() {
@Override
public SafeHtml getValue(Object object) {
return VmTypeColumn.getRenderedValue(((ImportVmData) object).getVm());
}
}, constants.empty(), // $NON-NLS-1$
"30px");
AbstractTextColumn<Object> memoryColumn = new AbstractTextColumn<Object>() {
@Override
public String getValue(Object object) {
return messages.megabytes(String.valueOf(((ImportVmData) object).getVm().getVmMemSizeMb()));
}
};
// $NON-NLS-1$
table.addColumn(memoryColumn, constants.memoryVm(), "90px");
AbstractTextColumn<Object> cpuColumn = new AbstractTextColumn<Object>() {
@Override
public String getValue(Object object) {
return String.valueOf(((ImportVmData) object).getVm().getNumOfCpus());
}
};
// $NON-NLS-1$
table.addColumn(cpuColumn, constants.cpusVm(), "50px");
AbstractTextColumn<Object> archColumn = new AbstractTextColumn<Object>() {
@Override
public String getValue(Object object) {
return String.valueOf(((ImportVmData) object).getVm().getClusterArch());
}
};
// $NON-NLS-1$
table.addColumn(archColumn, constants.architectureVm(), "100px");
AbstractTextColumn<Object> diskColumn = new AbstractTextColumn<Object>() {
@Override
public String getValue(Object object) {
return String.valueOf(((ImportVmData) object).getVm().getDiskMap().size());
}
};
// $NON-NLS-1$
table.addColumn(diskColumn, constants.disksVm(), "55px");
isObjectInSystemColumn = new AbstractImageResourceColumn<Object>() {
@Override
public ImageResource getValue(Object object) {
return ((ImportVmData) object).isExistsInSystem() ? resources.logNormalImage() : null;
}
};
// $NON-NLS-1$
table.addColumn(isObjectInSystemColumn, constants.vmInSetup(), "100px");
table.getSelectionModel().addSelectionChangeHandler(event -> {
ImportVmData selectedObject = ((SingleSelectionModel<ImportVmData>) event.getSource()).getSelectedObject();
customSelectionCellFormatType.setEnabled(selectedObject.getCollapseSnapshots().getEntity());
});
ScrollPanel sp = new ScrollPanel();
sp.add(table);
splitLayoutPanel.add(sp);
table.getElement().getStyle().setPosition(Position.RELATIVE);
}
use of org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn in project ovirt-engine by oVirt.
the class VmSnapshotCustomPreviewPopupWidget method createPreviewTable.
private void createPreviewTable() {
previewTable.addColumn(new AbstractFullDateTimeColumn<SnapshotModel>() {
@Override
protected Date getRawValue(SnapshotModel snapshotModel) {
return snapshotModel.getEntity().getCreationDate();
}
}, constants.dateSnapshot(), // $NON-NLS-1$
"140px");
previewTable.addColumn(new AbstractTextColumn<SnapshotModel>() {
@Override
public String getValue(SnapshotModel snapshotModel) {
return snapshotModel.getEntity().getDescription();
}
}, constants.descriptionSnapshot(), // $NON-NLS-1$
"100px");
previewTable.setSelectionModel(new NoSelectionModel());
Column<SnapshotModel, Boolean> vmConfColumn = new Column<SnapshotModel, Boolean>(new RadioboxCell()) {
@Override
public Boolean getValue(SnapshotModel model) {
Snapshot snapshotVmConf = model.getEntity();
Snapshot toPreviewVmConf = previewSnapshotModel.getSnapshotModel().getEntity();
if (snapshotVmConf == null && toPreviewVmConf == null) {
return true;
}
return snapshotVmConf != null && snapshotVmConf.equals(toPreviewVmConf);
}
@Override
public void render(Context context, SnapshotModel snapshotModel, SafeHtmlBuilder sb) {
if (!snapshotModel.getEntity().isVmConfigurationBroken()) {
super.render(context, snapshotModel, sb);
} else {
sb.appendEscaped(constants.notAvailableLabel());
}
}
};
vmConfColumn.setFieldUpdater((index, snapshotModel, value) -> {
previewSnapshotModel.setSnapshotModel(snapshotModel);
previewSnapshotModel.clearMemorySelection();
updateWarnings();
refreshTable(previewTable);
if (snapshotModel.getVm() == null) {
snapshotModel.updateVmConfiguration(returnValue -> updateInfoPanel());
} else {
updateInfoPanel();
}
});
previewTable.addColumn(vmConfColumn, new ImageResourceHeader(resources.vmConfIcon(), SafeHtmlUtils.fromTrustedString(constants.vmConfiguration())), // $NON-NLS-1$
"30px");
AbstractCheckboxColumn<SnapshotModel> memoryColumn = new AbstractCheckboxColumn<SnapshotModel>((index, snapshotModel, value) -> {
previewSnapshotModel.getSnapshotModel().getMemory().setEntity(value);
refreshTable(previewTable);
updateWarnings();
}) {
@Override
public Boolean getValue(SnapshotModel snapshotModel) {
return snapshotModel.getMemory().getEntity();
}
@Override
protected boolean canEdit(SnapshotModel snapshotModel) {
boolean containsMemory = snapshotModel.getEntity().containsMemory();
SnapshotModel selectedSnapshotModel = previewSnapshotModel.getSnapshotModel();
return containsMemory && snapshotModel == selectedSnapshotModel;
}
@Override
public void render(Context context, SnapshotModel snapshotModel, SafeHtmlBuilder sb) {
if (snapshotModel.getEntity().containsMemory()) {
super.render(context, snapshotModel, sb);
} else {
sb.appendEscaped(constants.notAvailableLabel());
}
}
};
previewTable.addColumn(memoryColumn, templates.iconWithText(imageResourceToSafeHtml(resources.memorySmallIcon()), constants.memorySnapshot()), // $NON-NLS-1$
"100px");
AbstractCheckboxColumn<SnapshotModel> vmLeaseColumn = new AbstractCheckboxColumn<SnapshotModel>((index, snapshotModel, value) -> {
snapshotModel.getLeaseExists().setEntity(value);
refreshTable(previewTable);
updateWarnings();
}) {
@Override
public Boolean getValue(SnapshotModel model) {
if (model.getLeaseExists() != null) {
return model.getLeaseExists().getEntity();
}
return false;
}
@Override
protected boolean canEdit(SnapshotModel snapshotModel) {
// prevent from selecting more then one leases in case many snapshots have leases
if (snapshotModel.getLeaseExists() != null) {
SnapshotModel result = previewSnapshotModel.getSnapshots().getItems().stream().filter(model -> model.getEntity().getId() != snapshotModel.getEntity().getId()).filter(model -> model.getLeaseExists().getEntity() != null).filter(model -> model.getLeaseExists().getEntity()).findFirst().orElse(null);
return result == null;
}
return false;
}
@Override
public void render(Context context, SnapshotModel snapshotModel, SafeHtmlBuilder sb) {
if (snapshotModel.getLeaseExists().getEntity() != null) {
super.render(context, snapshotModel, sb);
} else {
sb.appendEscaped(constants.notAvailableLabel());
}
}
};
// $NON-NLS-1$
previewTable.addColumn(vmLeaseColumn, constants.leaseSnapshot(), "80px");
List<DiskImage> disks = previewSnapshotModel.getAllDisks();
Collections.sort(disks, new DiskByDiskAliasComparator());
for (final DiskImage disk : disks) {
previewTable.addColumn(new AbstractCheckboxColumn<SnapshotModel>((index, snapshotModel, value) -> {
ListModel diskListModel = previewSnapshotModel.getDiskSnapshotsMap().get(disk.getId());
DiskImage image = snapshotModel.getImageByDiskId(disk.getId());
diskListModel.setSelectedItem(Boolean.TRUE.equals(value) ? image : null);
refreshTable(previewTable);
updateWarnings();
updateInfoPanel();
}) {
@Override
public Boolean getValue(SnapshotModel snapshotModel) {
ListModel diskListModel = previewSnapshotModel.getDiskSnapshotsMap().get(disk.getId());
DiskImage image = snapshotModel.getImageByDiskId(disk.getId());
return image != null ? image.equals(diskListModel.getSelectedItem()) : false;
}
@Override
protected boolean canEdit(SnapshotModel model) {
return true;
}
@Override
public void render(Context context, SnapshotModel snapshotModel, SafeHtmlBuilder sb) {
DiskImage image = snapshotModel.getImageByDiskId(disk.getId());
if (image == null) {
sb.appendEscaped(constants.notAvailableLabel());
} else if (image.getImageStatus() == ImageStatus.ILLEGAL) {
sb.append(templates.text(constants.notAvailableLabel()));
} else {
super.render(context, snapshotModel, sb);
}
}
@Override
public SafeHtml getTooltip(SnapshotModel model) {
if (disk != null && disk.getId() != null) {
DiskImage image = model.getImageByDiskId(disk.getId());
if (image != null && image.getImageStatus() == ImageStatus.ILLEGAL) {
return SafeHtmlUtils.fromSafeConstant(constants.illegalStatus());
}
}
return null;
}
}, new SafeHtmlHeader(templates.iconWithText(imageResourceToSafeHtml(resources.diskIcon()), disk.getDiskAlias()), SafeHtmlUtils.fromString(disk.getId().toString())), // $NON-NLS-1$
"120px");
// Edit preview table
previewTable.asEditor().edit(previewSnapshotModel.getSnapshots());
}
previewTable.addCellPreviewHandler(new CellPreviewEvent.Handler<EntityModel>() {
long lastClick = -1000;
@Override
public void onCellPreview(CellPreviewEvent<EntityModel> event) {
NativeEvent nativeEvent = event.getNativeEvent();
long clickAt = System.currentTimeMillis();
if (BrowserEvents.CLICK.equals(nativeEvent.getType())) {
if (clickAt - lastClick < 300) {
// double click: 2 clicks detected within 300 ms
SnapshotModel selectedSnapshotModel = (SnapshotModel) event.getValue();
if (!selectedSnapshotModel.getEntity().isVmConfigurationBroken()) {
previewSnapshotModel.clearSelection(selectedSnapshotModel.getEntity().getId());
previewSnapshotModel.selectSnapshot(selectedSnapshotModel.getEntity().getId());
updateWarnings();
refreshTable(previewTable);
}
}
lastClick = System.currentTimeMillis();
}
}
});
}
Aggregations