[Bug #986] Prevent removing a label that is being used by an orderelement
FEA: ItEr74S04BugFixing
This commit is contained in:
parent
eb901eac64
commit
2c71128881
2 changed files with 51 additions and 2 deletions
|
|
@ -41,8 +41,10 @@ import org.zkoss.zk.ui.Component;
|
|||
import org.zkoss.zk.ui.WrongValueException;
|
||||
import org.zkoss.zk.ui.event.CheckEvent;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
import org.zkoss.zk.ui.event.InputEvent;
|
||||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||
import org.zkoss.zul.Button;
|
||||
import org.zkoss.zul.Column;
|
||||
import org.zkoss.zul.Constraint;
|
||||
import org.zkoss.zul.Grid;
|
||||
|
|
@ -51,6 +53,7 @@ import org.zkoss.zul.Messagebox;
|
|||
import org.zkoss.zul.Row;
|
||||
import org.zkoss.zul.Textbox;
|
||||
import org.zkoss.zul.Window;
|
||||
import org.zkoss.zul.api.Rows;
|
||||
|
||||
/**
|
||||
* CRUD Controller for {@link LabelType}
|
||||
|
|
@ -90,13 +93,46 @@ public class LabelTypeCRUDController extends GenericForwardComposer {
|
|||
messagesForUser = new MessagesForUser(messagesContainer);
|
||||
messagesEditWindow = new MessagesForUser(editWindow
|
||||
.getFellowIfAny("messagesContainer"));
|
||||
gridLabels = (Grid) editWindow.getFellowIfAny("gridLabels");
|
||||
initializeLabelsGrid();
|
||||
gridLabelTypes = (Grid) listWindow.getFellowIfAny("gridLabelTypes");
|
||||
showListWindow();
|
||||
newLabelTextbox = (Textbox) editWindow
|
||||
.getFellowIfAny("newLabelTextbox");
|
||||
}
|
||||
|
||||
private void initializeLabelsGrid() {
|
||||
gridLabels = (Grid) editWindow.getFellowIfAny("gridLabels");
|
||||
// Renders grid and enables delete button if label is new
|
||||
gridLabels.addEventListener("onInitRender", new EventListener() {
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
gridLabels.renderAll();
|
||||
|
||||
final Rows rows = gridLabels.getRows();
|
||||
for (Iterator i = rows.getChildren().iterator(); i.hasNext();) {
|
||||
final Row row = (Row) i.next();
|
||||
final Label label = (Label) row.getValue();
|
||||
Button btnDelete = (Button) row.getChildren().get(2);
|
||||
if (!canRemoveLabel(label)) {
|
||||
btnDelete.setDisabled(true);
|
||||
btnDelete.setImage("/common/img/ico_borrar_out.png");
|
||||
btnDelete
|
||||
.setHoverImage("/common/img/ico_borrar_out.png");
|
||||
btnDelete.setTooltiptext("");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean canRemoveLabel(Label label) {
|
||||
if (label.isNewObject()) {
|
||||
return true;
|
||||
}
|
||||
return label.getOrderElements().isEmpty();
|
||||
}
|
||||
|
||||
private void showListWindow() {
|
||||
getVisibility().showOnly(listWindow);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import org.navalplanner.business.common.daos.IConfigurationDAO;
|
|||
import org.navalplanner.business.common.entities.EntityNameEnum;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.labels.daos.ILabelDAO;
|
||||
import org.navalplanner.business.labels.daos.ILabelTypeDAO;
|
||||
import org.navalplanner.business.labels.entities.Label;
|
||||
import org.navalplanner.business.labels.entities.LabelType;
|
||||
|
|
@ -57,6 +58,9 @@ public class LabelTypeModel extends IntegrationEntityModel implements
|
|||
@Autowired
|
||||
private ILabelTypeDAO labelTypeDAO;
|
||||
|
||||
@Autowired
|
||||
private ILabelDAO labelDAO;
|
||||
|
||||
@Autowired
|
||||
private IConfigurationDAO configurationDAO;
|
||||
|
||||
|
|
@ -189,7 +193,15 @@ public class LabelTypeModel extends IntegrationEntityModel implements
|
|||
// Safe copy
|
||||
List<Label> labels = new ArrayList<Label>();
|
||||
if (labelType != null) {
|
||||
labels.addAll(labelType.getLabels());
|
||||
labels.addAll(initializeLabels(labelType.getLabels()));
|
||||
}
|
||||
return labels;
|
||||
}
|
||||
|
||||
private Set<Label> initializeLabels(Set<Label> labels) {
|
||||
for (Label each: labels) {
|
||||
labelDAO.reattach(each);
|
||||
each.getOrderElements().size();
|
||||
}
|
||||
return labels;
|
||||
}
|
||||
|
|
@ -253,4 +265,5 @@ public class LabelTypeModel extends IntegrationEntityModel implements
|
|||
throw new ValidationException(invalidValues);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue