[Bug #926] Add constraint to enable the report progress option in a quality form

It can enable the report progress option if the quality form has some item with
a percentage with value 100.

FEA : ItEr72S04BugFixing
This commit is contained in:
Susana Montes Pedreira 2011-03-11 09:42:02 +01:00
parent 523ae93af5
commit 1552ba8784
5 changed files with 85 additions and 3 deletions

View file

@ -405,9 +405,8 @@ public class QualityForm extends BaseEntity {
public boolean checkConstraintAdvanceTypeIsNotNullIfReportAdvance() {
if (advanceType == null) {
return !isReportAdvance();
} else {
return isReportAdvance();
}
return true;
}
}

View file

@ -121,4 +121,14 @@ public interface IQualityFormModel {
*/
void upQualityFormItem(QualityFormItem qualityFormItem);
/**
* Check if exist any {@link QualityFormItem } of the current quality form with the 100 percentage
*/
boolean hasItemWithTotalPercentage();
/**
* Check if the current {@link QualityFormItem } has a 100 percentage
* @param qualityFormItem
*/
Boolean isTotalPercentage(QualityFormItem item);
}

View file

@ -42,6 +42,7 @@ import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Checkbox;
import org.zkoss.zul.Column;
import org.zkoss.zul.Combobox;
import org.zkoss.zul.Constraint;
@ -336,6 +337,29 @@ public class QualityFormCRUDController extends GenericForwardComposer {
* @param QualityFormItem
*/
public void confirmDeleteQualityFormItem(QualityFormItem item) {
if (qualityFormModel.isTotalPercentage(item)) {
try {
if (Messagebox
.show(
_("Deleting thi item, it will disable the report progress option. Are you sure?"),
_("Confirm"),
Messagebox.OK | Messagebox.CANCEL,
Messagebox.QUESTION) == Messagebox.OK) {
Checkbox reportProgress = (Checkbox) editWindow
.getFellowIfAny("checkBoxReportProgress");
disabledCheckbocReportProgress(reportProgress);
} else {
return;
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
deleteQualityFormItem(item);
}
private void deleteQualityFormItem(QualityFormItem item) {
qualityFormModel.confirmDeleteQualityFormItem(item);
Util.reloadBindings(gridQualityFormItems);
}
@ -491,4 +515,28 @@ public class QualityFormCRUDController extends GenericForwardComposer {
predicate = getSelectedName();
}
public void validateReportProgress(Component comp) {
Checkbox checkbox = (Checkbox) comp;
if (checkbox != null) {
if ((checkbox.isChecked()) && (!hasItemWithTotalPercentage())) {
disabledCheckbocReportProgress(checkbox);
messagesForUser
.showMessage(
Level.ERROR,
_("The quality form must have an item with 100% value to report progress"));
}
}
}
private boolean hasItemWithTotalPercentage() {
return this.qualityFormModel.hasItemWithTotalPercentage();
}
private void disabledCheckbocReportProgress(Checkbox reportProgress) {
if (reportProgress != null) {
getQualityForm().setReportAdvance(false);
reportProgress.setChecked(false);
reportProgress.invalidate();
}
}
}

View file

@ -21,6 +21,7 @@
package org.navalplanner.web.qualityforms;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@ -52,6 +53,8 @@ public class QualityFormModel implements IQualityFormModel {
private List<QualityForm> listQualityForms = new ArrayList<QualityForm>();
private final BigDecimal totalPercentage = new BigDecimal(100).setScale(2);
public QualityFormModel() {
}
@ -197,4 +200,25 @@ public class QualityFormModel implements IQualityFormModel {
this.getQualityForm().moveQualityFormItem(qualityFormItem, newPosition);
}
@Override
public boolean hasItemWithTotalPercentage() {
// Check if the current quality form has any item with 100 percentage to
// can report progress
if (getQualityForm() != null) {
for (QualityFormItem item : this.getQualityForm()
.getQualityFormItems()) {
if (isTotalPercentage(item)) {
return true;
}
}
}
return false;
}
@Override
public Boolean isTotalPercentage(QualityFormItem item) {
return (item.getPercentage() != null) ? (item.getPercentage()
.equals(totalPercentage)) : false;
}
}

View file

@ -61,7 +61,8 @@
</row>
<row>
<label value="${i18n:_('Report progress')}" />
<checkbox checked="@{controller.qualityForm.reportAdvance}" />
<checkbox id="checkBoxReportProgress" checked="@{controller.qualityForm.reportAdvance}"
onCheck="controller.validateReportProgress(self);" />
</row>
</rows>
</grid>