Handle null in 'optional' Ingredient field
This commit is contained in:
parent
5ef369743a
commit
e5984e5d6f
|
@ -1,6 +1,5 @@
|
||||||
package com.mousetech.gourmetj;
|
package com.mousetech.gourmetj;
|
||||||
|
|
||||||
|
|
||||||
import com.mousetech.gourmetj.persistence.model.Ingredient;
|
import com.mousetech.gourmetj.persistence.model.Ingredient;
|
||||||
import com.mousetech.gourmetj.persistence.model.IngredientIF;
|
import com.mousetech.gourmetj.persistence.model.IngredientIF;
|
||||||
import com.mousetech.gourmetj.persistence.model.Recipe;
|
import com.mousetech.gourmetj.persistence.model.Recipe;
|
||||||
|
@ -9,8 +8,8 @@ import com.mousetech.gourmetj.IngredientDigester.IngredientAmountFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JSF-friendly decorator for @see Ingredient. Formats amount
|
* JSF-friendly decorator for @see Ingredient. Formats amount
|
||||||
* with fractions and supports checkboxes. Primary use
|
* with fractions and supports checkboxes. Primary use is as a
|
||||||
* is as a JSF TableModel wrapped content in @see RecipeDetailBean.
|
* JSF TableModel wrapped content in @see RecipeDetailBean.
|
||||||
*
|
*
|
||||||
* TestedBy @see IngredientUITest
|
* TestedBy @see IngredientUITest
|
||||||
*
|
*
|
||||||
|
@ -22,6 +21,7 @@ public class IngredientUI implements IngredientIF {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
*
|
||||||
* @param ingredient
|
* @param ingredient
|
||||||
*/
|
*/
|
||||||
public IngredientUI(Ingredient ingredient) {
|
public IngredientUI(Ingredient ingredient) {
|
||||||
|
@ -33,6 +33,7 @@ public class IngredientUI implements IngredientIF {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean ingGroup;
|
private boolean ingGroup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ingGroup the ingGroup to set
|
* @param ingGroup the ingGroup to set
|
||||||
*/
|
*/
|
||||||
|
@ -41,13 +42,13 @@ public class IngredientUI implements IngredientIF {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ingredient groups are rendered visually as synthetic
|
* Ingredient groups are rendered visually as synthetic rows.
|
||||||
* rows. Actual group IDs are part of line-item ingredients,
|
* Actual group IDs are part of line-item ingredients, so
|
||||||
* so when building the model, we create a group row when
|
* when building the model, we create a group row when the
|
||||||
* the line item inggroup value changes.
|
* line item inggroup value changes.
|
||||||
*
|
*
|
||||||
* @return <code>true</code> for an Ingredient Group
|
* @return <code>true</code> for an Ingredient Group header
|
||||||
* header row.
|
* row.
|
||||||
*/
|
*/
|
||||||
public boolean isIngGroup() {
|
public boolean isIngGroup() {
|
||||||
return this.ingGroup;
|
return this.ingGroup;
|
||||||
|
@ -59,7 +60,6 @@ public class IngredientUI implements IngredientIF {
|
||||||
|
|
||||||
private boolean selected;
|
private boolean selected;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the selected status
|
* @return the selected status
|
||||||
*/
|
*/
|
||||||
|
@ -74,7 +74,6 @@ public class IngredientUI implements IngredientIF {
|
||||||
this.selected = selected;
|
this.selected = selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return
|
||||||
* @see com.mousetech.gourmetj.persistence.model.Ingredient#getAmount()
|
* @see com.mousetech.gourmetj.persistence.model.Ingredient#getAmount()
|
||||||
|
@ -93,25 +92,28 @@ public class IngredientUI implements IngredientIF {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get amount display-friendly
|
* Get amount display-friendly
|
||||||
|
*
|
||||||
* @see #getAmount
|
* @see #getAmount
|
||||||
*/
|
*/
|
||||||
public String getDisplayAmount() {
|
public String getDisplayAmount() {
|
||||||
// TODO
|
// TODO
|
||||||
Double amt = ingredient.getAmount();
|
Double amt = ingredient.getAmount();
|
||||||
if ( amt == null ) {
|
if (amt == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
String amt1 = IngredientDigester.displayAmount(
|
String amt1 = IngredientDigester.displayAmount(
|
||||||
IngredientAmountFormat.IA_SYMBOLS, amt, ingredient.getRangeamount());
|
IngredientAmountFormat.IA_SYMBOLS, amt,
|
||||||
|
ingredient.getRangeamount());
|
||||||
return amt1;
|
return amt1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set amount display-friendly
|
* Set amount display-friendly
|
||||||
|
*
|
||||||
* @see #setAmount
|
* @see #setAmount
|
||||||
*/
|
*/
|
||||||
public void setDisplayAmount(String amount) {
|
public void setDisplayAmount(String amount) {
|
||||||
if ( amount.isBlank() ) {
|
if (amount.isBlank()) {
|
||||||
ingredient.setAmount(null);
|
ingredient.setAmount(null);
|
||||||
}
|
}
|
||||||
IngredientDigester digester = new IngredientDigester();
|
IngredientDigester digester = new IngredientDigester();
|
||||||
|
@ -119,6 +121,7 @@ public class IngredientUI implements IngredientIF {
|
||||||
ingredient.setAmount(amt[0]);
|
ingredient.setAmount(amt[0]);
|
||||||
ingredient.setRangeamount(amt[1]);
|
ingredient.setRangeamount(amt[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return
|
||||||
* @see com.mousetech.gourmetj.persistence.model.Ingredient#getDeleted()
|
* @see com.mousetech.gourmetj.persistence.model.Ingredient#getDeleted()
|
||||||
|
@ -225,10 +228,15 @@ public class IngredientUI implements IngredientIF {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get optional value in boolean Checkbox friendly form
|
* Get optional value in boolean Checkbox friendly form
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean getOptionalCB() {
|
public boolean getOptionalCB() {
|
||||||
return ingredient.getOptional() != 0;
|
Integer optional = ingredient.getOptional();
|
||||||
|
if (optional == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return optional != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOptionalCB(boolean value) {
|
public void setOptionalCB(boolean value) {
|
||||||
|
@ -328,7 +336,7 @@ public class IngredientUI implements IngredientIF {
|
||||||
* @see com.mousetech.gourmetj.persistence.model.Ingredient#setShopoptional(java.lang.Integer)
|
* @see com.mousetech.gourmetj.persistence.model.Ingredient#setShopoptional(java.lang.Integer)
|
||||||
*/
|
*/
|
||||||
public void setShopoptionalCB(boolean shopoptional) {
|
public void setShopoptionalCB(boolean shopoptional) {
|
||||||
ingredient.setShopoptional(shopoptional? 1:0);
|
ingredient.setShopoptional(shopoptional ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -347,8 +355,8 @@ public class IngredientUI implements IngredientIF {
|
||||||
ingredient.setUnit(unit);
|
ingredient.setUnit(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This goes to the shopCats table via ManyToOne at save
|
||||||
// This goes to the shopCats table via ManyToOne at save time.
|
// time.
|
||||||
private String shopCat;
|
private String shopCat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user