// TODO play an error sound
// TODO display an error message
return;
}
final Colony sender = comboFrom.getModel().getEntry(from);
final Colony receiver = comboTo.getModel().getEntry(to);
// Is there enough resource in the sender colony?
Map<Resource, BigDecimal> map = new HashMap<Resource, BigDecimal>();
Resource[] resources = Resource.values();
for (Resource r : resources) {
String strVal = fields.get(r).getText();
if ("".equals(strVal)) {
strVal = "0";
}
BigDecimal value = BigDecimal.valueOf(Long.valueOf(strVal));
map.put(r, value);
}
if (!ResourceHelper.enoughResourcesFor(map, sender)) {
// TODO play an error sound
// TODO display an error message
return;
}
// Is there enough space in the target colony?
if (!ResourceHelper.enoughSpaceFor(map, receiver)) {
// TODO play an error sound
// TODO display an error message
return;
}
// Everything is allright, resources can be transfered
// Remove from sender and add to receiver...
for (Resource r : resources) {
// Send...
sender.updateResource(r, map.get(r).negate());
// Receive...
receiver.updateResource(r, map.get(r));
}
hide();
}