Hi,
I have next situation:
I wish to invalidate some menu items how I do it for buttons:
@Subscribe(id = "duplicatesDc", target = Target.DATA_CONTAINER)
public void onDuplicatesDcItemChange(final InstanceContainer.ItemChangeEvent<Duplicate> event) {
if (duplicatesDataGrid.getSingleSelectedItem() == null) {
markAsConfirmedBtn.setEnabled(false);
markAsInDeliveryBtn.setEnabled(false);
markAsDeliveryBtn.setEnabled(false);
} else if (duplicatesDataGrid.getSingleSelectedItem().getStatus().equals(DuplicateStatus.PREPARED)) {
markAsConfirmedBtn.setEnabled(true);
markAsInDeliveryBtn.setEnabled(true);
markAsDeliveryBtn.setEnabled(true);
} else if (duplicatesDataGrid.getSingleSelectedItem().getStatus().equals(DuplicateStatus.CONFIRMED)) {
markAsConfirmedBtn.setEnabled(false);
editBtn.setEnabled(false);
} else if (duplicatesDataGrid.getSingleSelectedItem().getStatus().equals(DuplicateStatus.IN_DELIVERY)) {
markAsConfirmedBtn.setEnabled(false);
markAsInDeliveryBtn.setEnabled(false);
editBtn.setEnabled(false);
} else if (duplicatesDataGrid.getSingleSelectedItem().getStatus().equals(DuplicateStatus.DELIVERED)) {
markAsConfirmedBtn.setEnabled(false);
markAsInDeliveryBtn.setEnabled(false);
markAsDeliveryBtn.setEnabled(false);
editBtn.setEnabled(false);
}
}
@Subscribe("duplicatesDataGrid")
public void onDuplicatesDataGridItemClick(final ItemClickEvent<Duplicate> event) {
if (duplicatesDataGrid.getSingleSelectedItem() == null) {
markAsConfirmedBtn.setEnabled(false);
markAsInDeliveryBtn.setEnabled(false);
markAsDeliveryBtn.setEnabled(false);
} else if (duplicatesDataGrid.getSingleSelectedItem().getStatus().equals(DuplicateStatus.PREPARED)) {
markAsConfirmedBtn.setEnabled(true);
markAsInDeliveryBtn.setEnabled(true);
markAsDeliveryBtn.setEnabled(true);
} else if (duplicatesDataGrid.getSingleSelectedItem().getStatus().equals(DuplicateStatus.CONFIRMED)) {
markAsConfirmedBtn.setEnabled(false);
editBtn.setEnabled(false);
} else if (duplicatesDataGrid.getSingleSelectedItem().getStatus().equals(DuplicateStatus.IN_DELIVERY)) {
markAsConfirmedBtn.setEnabled(false);
markAsInDeliveryBtn.setEnabled(false);
editBtn.setEnabled(false);
} else if (duplicatesDataGrid.getSingleSelectedItem().getStatus().equals(DuplicateStatus.DELIVERED)) {
markAsConfirmedBtn.setEnabled(false);
markAsInDeliveryBtn.setEnabled(false);
markAsDeliveryBtn.setEnabled(false);
editBtn.setEnabled(false);
}
}
or how I invalidate right click menu?
I changed the multi select data grid to single select, I seen not exist handler for this situation.
Another problem was I can’t save with dataContext, but I resolved with dataManager:
private void markCurrentDuplicateAsConfirmedDelivery() {
Duplicate duplicateToMarkAsConfirmedDelivery = duplicatesDataGrid.getSingleSelectedItem();
if (duplicateToMarkAsConfirmedDelivery != null) {
duplicateToMarkAsConfirmedDelivery.setStatus(DuplicateStatus.DELIVERED);
//dataContext.save();
dataManager.save(duplicateToMarkAsConfirmedDelivery);
notifications.create(messageBundle.getMessage("duplicate.delivery")).show();
duplicatesDl.load();
}
}
Thanks for jmix-bookstore example, great work do it jmix team.