ItEr55S13CUAdministracionMateriaisItEr37S11: Check a Material is assigned to an Order, so it can be removed.

This commit is contained in:
Jacobo Aragunde Pérez 2010-04-20 20:46:47 +02:00 committed by Javier Moran Rua
parent 4118a55d8a
commit 6064501a9e
3 changed files with 24 additions and 3 deletions

View file

@ -57,4 +57,6 @@ public interface IMaterialsModel {
List<UnitType> getUnitTypes();
void loadUnitTypes();
boolean canRemoveMaterial(Material material);
}

View file

@ -119,7 +119,7 @@ public class MaterialsController extends
final Row row = (Row) i.next();
final Material material = (Material) row.getValue();
Button btnDelete = (Button) row.getChildren().get(6);
if (!material.isNewObject()) {
if (!materialsModel.canRemoveMaterial(material)) {
btnDelete.setDisabled(true);
btnDelete.setImage("/common/img/ico_borrar_out.png");
btnDelete.setHoverImage("/common/img/ico_borrar_out.png");
@ -502,8 +502,14 @@ public class MaterialsController extends
}
public void remove(Material material) {
materialsModel.removeMaterial(material);
Util.reloadBindings(gridMaterials);
if(materialsModel.canRemoveMaterial(material)) {
materialsModel.removeMaterial(material);
Util.reloadBindings(gridMaterials);
}
else {
messagesForUser.showMessage(Level.ERROR,
_("Cannot delete that material because it is assigned to an order."));
}
}
public void clearSelectionCategoriesTree() {

View file

@ -35,6 +35,7 @@ import org.hibernate.validator.InvalidValue;
import org.navalplanner.business.common.daos.IConfigurationDAO;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.business.materials.daos.IMaterialAssignmentDAO;
import org.navalplanner.business.materials.daos.IMaterialCategoryDAO;
import org.navalplanner.business.materials.daos.IMaterialDAO;
import org.navalplanner.business.materials.daos.IUnitTypeDAO;
@ -66,6 +67,9 @@ public class MaterialsModel implements IMaterialsModel {
@Autowired
IConfigurationDAO configurationDAO;
@Autowired
IMaterialAssignmentDAO materialAssignmentDAO;
MutableTreeModel<MaterialCategory> materialCategories = MutableTreeModel
.create(MaterialCategory.class);
@ -276,4 +280,13 @@ public class MaterialsModel implements IMaterialsModel {
public List<UnitType> getUnitTypes() {
return this.unitTypes;
}
@Override
@Transactional(readOnly = true)
public boolean canRemoveMaterial(Material material) {
if(material.isNewObject()) {
return true;
}
return materialAssignmentDAO.getByMaterial(material).size() == 0;
}
}