ItEr54S09AdaptacionServiciosRESTItEr53S10: Added the checkbox 'generate code' to the entity UnitType.

Also added the attribute 'generateCode' to the entity to make this value persistent.
This commit is contained in:
Jacobo Aragunde Pérez 2010-04-16 11:03:09 +02:00 committed by Javier Moran Rua
parent b38368594d
commit 889485bd1d
5 changed files with 47 additions and 6 deletions

View file

@ -62,6 +62,8 @@ public class UnitType extends IntegrationEntity{
private String measure;
private Boolean generateCode = false;
// Default constructor, needed by Hibernate
protected UnitType() {
@ -80,6 +82,14 @@ public class UnitType extends IntegrationEntity{
this.measure = measure;
}
public Boolean getGenerateCode() {
return generateCode;
}
public void setGenerateCode(Boolean generateCode) {
this.generateCode = generateCode;
}
@AssertTrue(message = "the measure unit type has to be unique. It is already used")
public boolean checkConstraintUniqueName() {
boolean result;

View file

@ -37,6 +37,7 @@
<property name="code" access="property" not-null="true" unique="true"/>
<property name="measure" access="field"/>
<property name="generateCode" not-null="true" />
</class>

View file

@ -16,6 +16,7 @@ import org.navalplanner.web.common.Util;
import org.zkoss.util.logging.Log;
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.util.GenericForwardComposer;
@ -246,4 +247,14 @@ public class UnitTypeController extends GenericForwardComposer {
Util.reloadBindings(listWindow);
getVisibility().showOnly(listWindow);
}
public void onCheckGenerateCode(Event e) {
CheckEvent ce = (CheckEvent) e;
if(ce.isChecked()) {
//we have to auto-generate the code for new objects
if(getUnitType().isNewObject()) {
getUnitType().setCodeAutogenerated();
}
}
}
}

View file

@ -6,6 +6,7 @@ import java.util.List;
import org.apache.commons.lang.Validate;
import org.apache.commons.logging.LogFactory;
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.IUnitTypeDAO;
@ -38,6 +39,9 @@ public class UnitTypeModel implements IUnitTypeModel {
@Autowired
private IUnitTypeDAO unitTypeDAO;
@Autowired
private IConfigurationDAO configurationDAO;
@Override
@Transactional(readOnly=true)
public List<UnitType> getUnitTypes() {
@ -45,8 +49,17 @@ public class UnitTypeModel implements IUnitTypeModel {
}
@Override
@Transactional(readOnly=true)
public void initCreate() {
this.unitTypeState = UnitType.create();
Boolean generateCode = configurationDAO.getConfiguration().
getGenerateCodeForUnitTypes();
if(generateCode) {
this.unitTypeState = UnitType.create();
}
else {
this.unitTypeState = UnitType.create("", "");
}
this.unitTypeState.setGenerateCode(generateCode);
}
@Override

View file

@ -33,11 +33,17 @@
<rows>
<row>
<label value="${i18n:_('Code')}"/>
<textbox
id="codeTextBox"
value="@{controller.unitType.code}"
constraint="@{controller.uniqueCode}"
width="300px"/>
<hbox>
<textbox
id="codeTextBox" width="300px"
value="@{controller.unitType.code}"
constraint="@{controller.uniqueCode}"
disabled="@{controller.unitType.generateCode}" />
<checkbox
id="generateCode" label="${i18n:_('Generate code')}"
onCheck="controller.onCheckGenerateCode(event)"
checked="@{controller.unitType.generateCode}" />
</hbox>
</row>
<row>
<label value="${i18n:_('Unit measure name')}" />