Button b1 = new Button("Update Order");
b1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
if (textfield.getText().equals("")) {
ToastBar.showErrorMessage("You need to enter a Quantity !");
textfield.setUIID("TextFieldError");
return;
}
Part part = CommonContext.INSTANCE.getCurrent();
int q;
try {
q = Integer.parseInt(textfield.getText());
} catch (NumberFormatException ex) {
q = 0;
}
if (q > part.getQty()) {
ToastBar.showErrorMessage("Sorry, there are only " + part.getQty() + " available !");
textfield.setUIID("TextFieldError");
return;
}
textfield.setUIID("TextField");
boolean found = false;
for (Part check : CommonContext.INSTANCE.getOrderModel()) {
if (check.getKey().equalsIgnoreCase(part.getKey())) {
if (q > 0) {
check.setQty(q);
} else {
CommonContext.INSTANCE.getOrderModel().remove(check);
}
found = true;
break;
}
}
if (!found) {
/**
* didn't exists so add a new one
*/
part.setQty(q);
CommonContext.INSTANCE.getOrderModel().add(Part.copy(part));
}
ViewCartForm viewcart = new ViewCartForm().init();
viewcart.setBackForm(backform.getBackForm());
viewcart.show();
}
});