use of org.ovirt.engine.ui.uicommonweb.models.EntityModel in project ovirt-engine by oVirt.
the class RegisterEntityInfoPanel method initAppsTable.
protected void initAppsTable() {
appsTable = new EntityModelCellTable<>(false, true);
AbstractTextColumn<String> appNameColumn = new AbstractTextColumn<String>() {
@Override
public String getValue(String appName) {
return appName;
}
};
appsTable.addColumn(appNameColumn, constants.nameSnapshot());
appsTable.setRowData(new ArrayList<EntityModel>());
// $NON-NLS-1$
appsTable.setWidth("100%");
appsTable.setSelectionModel(new NoSelectionModel());
appsTable.setEmptyTableWidget(new NoItemsLabel());
}
use of org.ovirt.engine.ui.uicommonweb.models.EntityModel in project ovirt-engine by oVirt.
the class EntityModelCellTable method addSelectionChangeHandler.
public void addSelectionChangeHandler() {
// Handle selection
getSelectionModel().addSelectionChangeHandler(new Handler() {
@Override
public void onSelectionChange(SelectionChangeEvent event) {
if (getListModel() == null || getListModel().getItems() == null) {
return;
}
// Clear "IsSelected"
for (EntityModel entity : (List<EntityModel>) getListModel().getItems()) {
entity.setIsSelected(false);
}
// Set "IsSelected"
SelectionModel<? super EntityModel> selectionModel = EntityModelCellTable.this.getSelectionModel();
if (selectionModel instanceof SingleSelectionModel) {
EntityModel selectedObject = ((SingleSelectionModel<EntityModel>) selectionModel).getSelectedObject();
clearCurrentSelectedItems();
if (selectedObject != null) {
selectedObject.setIsSelected(true);
getListModel().setSelectedItem(selectedObject);
}
} else if (selectionModel instanceof MultiSelectionModel) {
List<EntityModel> selectedItems = new ArrayList<>();
for (EntityModel entity : ((MultiSelectionModel<EntityModel>) selectionModel).getSelectedSet()) {
entity.setIsSelected(true);
selectedItems.add(entity);
}
clearCurrentSelectedItems();
getListModel().setSelectedItems(selectedItems);
}
}
private void clearCurrentSelectedItems() {
getListModel().setSelectedItems(null);
getListModel().setSelectedItem(null);
}
});
}
use of org.ovirt.engine.ui.uicommonweb.models.EntityModel 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.uicommonweb.models.EntityModel in project ovirt-engine by oVirt.
the class VmDiskAttachPopupWidget method getReadOnlyCheckBoxColumn.
private AbstractCheckboxColumn<EntityModel> getReadOnlyCheckBoxColumn() {
AbstractCheckboxColumn<EntityModel> readOnlyCheckboxColumn = new AbstractCheckboxColumn<EntityModel>((idx, object, value) -> {
DiskModel diskModel = (DiskModel) object.getEntity();
diskModel.setReadOnly(value);
}) {
@Override
protected boolean canEdit(EntityModel object) {
DiskModel diskModel = (DiskModel) object.getEntity();
Disk disk = diskModel.getDisk();
boolean isScsiPassthrough = disk.isScsiPassthrough();
boolean ideLimitation = diskModel.getDiskInterface().getSelectedItem() == DiskInterface.IDE;
return !isScsiPassthrough && !ideLimitation;
}
@Override
public Boolean getValue(EntityModel object) {
DiskModel diskModel = (DiskModel) object.getEntity();
return diskModel.isReadOnly();
}
};
return readOnlyCheckboxColumn;
}
use of org.ovirt.engine.ui.uicommonweb.models.EntityModel in project ovirt-engine by oVirt.
the class VmDiskAttachPopupWidget method edit.
@Override
public void edit(final AttachDiskModel disk) {
driver.edit(disk);
if (!isNewLunDiskEnabled) {
disk.getDiskStorageType().setEntity(DiskStorageType.IMAGE);
}
revealDiskPanel(disk);
diskTypePanel.addRadioButton(constants.imageDisk(), disk.getIsNew() || disk.getDisk().getDiskStorageType() == DiskStorageType.IMAGE, disk.getIsNew(), event -> {
if (disk.getIsNew()) {
disk.getDiskStorageType().setEntity(DiskStorageType.IMAGE);
revealDiskPanel(disk);
}
});
diskTypePanel.addRadioButton(constants.directLunDisk(), !disk.getIsNew() && disk.getDisk().getDiskStorageType() == DiskStorageType.LUN, disk.getIsNew(), event -> {
if (disk.getIsNew()) {
disk.getDiskStorageType().setEntity(DiskStorageType.LUN);
revealDiskPanel(disk);
}
});
diskTypePanel.addRadioButton(constants.cinderDisk(), !disk.getIsNew() && disk.getDisk().getDiskStorageType() == DiskStorageType.CINDER, disk.getIsNew(), event -> {
if (disk.getIsNew()) {
disk.getDiskStorageType().setEntity(DiskStorageType.CINDER);
revealDiskPanel(disk);
}
});
// Add event handlers
disk.getPropertyChangedEvent().addListener((ev, sender, args) -> {
String propName = args.propertyName;
if (propName.equals("IsValid")) {
// $NON-NLS-1$
if (disk.getIsValid()) {
attachDiskPanel.markAsValid();
} else {
attachDiskPanel.markAsInvalid(disk.getInvalidityReasons());
}
} else if ("Message".equals(propName)) {
// $NON-NLS-1$
if (StringHelper.isNotNullOrEmpty(disk.getMessage())) {
messageLabel.setHTML(wrapInUnorderedList(disk.getMessage()));
} else {
// $NON-NLS-1$
messageLabel.setHTML("");
}
}
});
disk.getWarningLabel().getPropertyChangedEvent().addListener((ev, sender, args) -> {
EntityModel ownerModel = (EntityModel) sender;
String propName = args.propertyName;
if ("IsAvailable".equals(propName)) {
// $NON-NLS-1$
warningLabel.setVisible(ownerModel.getIsAvailable());
}
});
disk.getWarningLabel().getEntityChangedEvent().addListener((ev, sender, args) -> warningLabel.setHTML(wrapInUnorderedList(disk.getWarningLabel().getEntity())));
revealDiskPanel(disk);
}
Aggregations