gourmetj-springboot/src/main/java/com/mousetech/gourmetj/IngredientUI.java

387 lines
8.4 KiB
Java
Raw Normal View History

2021-12-28 20:59:40 +00:00
package com.mousetech.gourmetj;
import com.mousetech.gourmetj.persistence.model.Ingredient;
import com.mousetech.gourmetj.persistence.model.IngredientIF;
import com.mousetech.gourmetj.persistence.model.Recipe;
2022-01-04 15:17:43 +00:00
import com.mousetech.gourmetj.persistence.model.Shopcat;
2021-12-28 20:59:40 +00:00
import com.mousetech.gourmetj.IngredientDigester.IngredientAmountFormat;
/**
* JSF-friendly decorator for @see Ingredient. Formats amount
* with fractions and supports checkboxes. Primary use is as a
* JSF TableModel wrapped content in @see RecipeDetailBean.
2021-12-28 20:59:40 +00:00
*
* TestedBy @see IngredientUITest
*
* @author timh
* @since Dec 2, 2021
*/
public class IngredientUI implements IngredientIF {
private Ingredient ingredient;
/**
* Constructor.
*
2022-01-06 14:49:07 +00:00
* @param ingredient Ingredient that we facade. If null,
* constructs a dummy Ingredient (example, for group item).
2021-12-28 20:59:40 +00:00
*/
public IngredientUI(Ingredient ingredient) {
2022-01-06 14:49:07 +00:00
if ( ingredient == null ) {
ingredient = new Ingredient();
}
2021-12-28 20:59:40 +00:00
this.ingredient = ingredient;
}
public Ingredient getIngredient() {
return this.ingredient;
}
2021-12-28 20:59:40 +00:00
private boolean ingGroup;
2021-12-28 20:59:40 +00:00
/**
* @param ingGroup the ingGroup to set
*/
public void setIngGroup(boolean ingGroup) {
this.ingGroup = ingGroup;
}
/**
* Ingredient groups are rendered visually as synthetic rows.
* Actual group IDs are part of line-item ingredients, so
* when building the model, we create a group row when the
* line item inggroup value changes.
2021-12-28 20:59:40 +00:00
*
* @return <code>true</code> for an Ingredient Group header
* row.
2021-12-28 20:59:40 +00:00
*/
public boolean isIngGroup() {
return this.ingGroup;
}
2021-12-28 20:59:40 +00:00
/**
* Row selection checkbox (UI only)
*/
2021-12-28 20:59:40 +00:00
private boolean selected;
2021-12-28 20:59:40 +00:00
/**
* @return the selected status
*/
public boolean isSelected() {
return selected;
}
/**
* @param selected the selected to set
*/
public void setSelected(boolean selected) {
this.selected = selected;
}
/**
* @return
* @see com.mousetech.gourmetj.persistence.model.Ingredient#getAmount()
*/
public Double getAmount() {
return ingredient.getAmount();
}
/**
* @param amount
* @see com.mousetech.gourmetj.persistence.model.Ingredient#setAmount(java.lang.Double)
*/
public void setAmount(Double amount) {
ingredient.setAmount(amount);
}
/**
* Get amount display-friendly
*
2021-12-28 20:59:40 +00:00
* @see #getAmount
*/
public String getDisplayAmount() {
Double amt = ingredient.getAmount();
if (amt == null) {
2021-12-28 20:59:40 +00:00
return "";
}
String amt1 = IngredientDigester.displayAmount(
IngredientAmountFormat.IA_SYMBOLS, amt,
ingredient.getRangeamount());
2021-12-28 20:59:40 +00:00
return amt1;
}
/**
* Set amount display-friendly
*
2021-12-28 20:59:40 +00:00
* @see #setAmount
*/
public void setDisplayAmount(String amount) {
if (amount.isBlank()) {
2021-12-28 20:59:40 +00:00
ingredient.setAmount(null);
}
2022-01-05 16:02:42 +00:00
Double[] amt = IngredientDigester.digestAmount(amount);
2021-12-28 20:59:40 +00:00
ingredient.setAmount(amt[0]);
ingredient.setRangeamount(amt[1]);
}
2021-12-28 20:59:40 +00:00
/**
* @return
* @see com.mousetech.gourmetj.persistence.model.Ingredient#getDeleted()
*/
public Integer getDeleted() {
return ingredient.getDeleted();
}
/**
* @param deleted
* @see com.mousetech.gourmetj.persistence.model.Ingredient#setDeleted(java.lang.Integer)
*/
public void setDeleted(Integer deleted) {
ingredient.setDeleted(deleted);
}
/**
* @return
* @see com.mousetech.gourmetj.persistence.model.Ingredient#getId()
*/
public Long getId() {
return ingredient.getId();
}
/**
* @param id
* @see com.mousetech.gourmetj.persistence.model.Ingredient#setId(long)
*/
public void setId(Long id) {
ingredient.setId(id);
}
/**
* @return
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return ingredient.hashCode();
}
/**
* @return
* @see com.mousetech.gourmetj.persistence.model.Ingredient#getInggroup()
*/
public String getInggroup() {
return ingredient.getInggroup();
}
/**
* @param inggroup
* @see com.mousetech.gourmetj.persistence.model.Ingredient#setInggroup(java.lang.String)
*/
public void setInggroup(String inggroup) {
ingredient.setInggroup(inggroup);
}
/**
* @return
* @see com.mousetech.gourmetj.persistence.model.Ingredient#getIngkey()
*/
public String getIngkey() {
return ingredient.getIngkey();
}
/**
* @param ingkey
* @see com.mousetech.gourmetj.persistence.model.Ingredient#setIngkey(java.lang.String)
*/
public void setIngkey(String ingkey) {
ingredient.setIngkey(ingkey);
}
/**
* @return
* @see com.mousetech.gourmetj.persistence.model.Ingredient#getItem()
*/
public String getItem() {
return ingredient.getItem();
}
/**
* @param item
* @see com.mousetech.gourmetj.persistence.model.Ingredient#setItem(java.lang.String)
*/
public void setItem(String item) {
ingredient.setItem(item);
}
/**
* @return
* @see com.mousetech.gourmetj.persistence.model.Ingredient#getOptional()
*/
public Integer getOptional() {
return ingredient.getOptional();
}
/**
* @param optional
* @see com.mousetech.gourmetj.persistence.model.Ingredient#setOptional(java.lang.Integer)
*/
public void setOptional(Integer optional) {
ingredient.setOptional(optional);
}
/**
* Get optional value in boolean Checkbox friendly form
*
2021-12-28 20:59:40 +00:00
* @return
*/
public boolean getOptionalCB() {
Integer optional = ingredient.getOptional();
if (optional == null) {
return false;
}
return optional != 0;
2021-12-28 20:59:40 +00:00
}
public void setOptionalCB(boolean value) {
ingredient.setOptional(value ? 1 : 0);
}
/**
* @return
* @see com.mousetech.gourmetj.persistence.model.Ingredient#getPosition()
*/
public Integer getPosition() {
return ingredient.getPosition();
}
/**
* @param position
* @see com.mousetech.gourmetj.persistence.model.Ingredient#setPosition(java.lang.Integer)
*/
public void setPosition(Integer position) {
ingredient.setPosition(position);
}
/**
* @return
* @see com.mousetech.gourmetj.persistence.model.Ingredient#getRangeamount()
*/
public Double getRangeamount() {
return ingredient.getRangeamount();
}
/**
* @param rangeamount
* @see com.mousetech.gourmetj.persistence.model.Ingredient#setRangeamount(java.lang.Double)
*/
public void setRangeamount(Double rangeamount) {
ingredient.setRangeamount(rangeamount);
}
/**
* @return
* @see com.mousetech.gourmetj.persistence.model.Ingredient#getRecipe()
*/
public Recipe getRecipe() {
return ingredient.getRecipe();
}
/**
* @param recipe
* @see com.mousetech.gourmetj.persistence.model.Ingredient#setRecipe(com.mousetech.gourmetj.persistence.model.Recipe)
*/
public void setRecipe(Recipe recipe) {
ingredient.setRecipe(recipe);
}
/**
* @return
* @see com.mousetech.gourmetj.persistence.model.Ingredient#getRefid()
*/
public Long getRefid() {
return ingredient.getRefid();
}
/**
* @param refid
* @see com.mousetech.gourmetj.persistence.model.Ingredient#setRefid(java.lang.Long)
*/
public void setRefid(Long refid) {
ingredient.setRefid(refid);
}
/**
* @return
* @see com.mousetech.gourmetj.persistence.model.Ingredient#getShopoptional()
*/
public Integer getShopoptional() {
return ingredient.getShopoptional();
}
/**
* @param shopoptional
* @see com.mousetech.gourmetj.persistence.model.Ingredient#setShopoptional(java.lang.Integer)
*/
public void setShopoptional(Integer shopoptional) {
ingredient.setShopoptional(shopoptional);
}
/**
* @return
* @see com.mousetech.gourmetj.persistence.model.Ingredient#getShopoptional()
*/
public boolean getShopoptionalCB() {
return ingredient.getShopoptional() != 0;
}
/**
* @param shopoptional
* @see com.mousetech.gourmetj.persistence.model.Ingredient#setShopoptional(java.lang.Integer)
*/
public void setShopoptionalCB(boolean shopoptional) {
ingredient.setShopoptional(shopoptional ? 1 : 0);
2021-12-28 20:59:40 +00:00
}
/**
* @return
* @see com.mousetech.gourmetj.persistence.model.Ingredient#getUnit()
*/
public String getUnit() {
return ingredient.getUnit();
}
/**
* @param unit
* @see com.mousetech.gourmetj.persistence.model.Ingredient#setUnit(java.lang.String)
*/
public void setUnit(String unit) {
ingredient.setUnit(unit);
}
/**
* @return the shopCat
*/
public String getShopCat() {
2022-01-04 15:17:43 +00:00
Shopcat scat = this.ingredient.getShopCat();
if ( scat == null ) {
return null;
}
return scat.getShopcategory();
2021-12-28 20:59:40 +00:00
}
/**
* @param shopCat the shopCat to set
*/
2022-01-04 15:17:43 +00:00
public void setShopCat(Shopcat shopCat) {
this.ingredient.setShopCat(shopCat);
2021-12-28 20:59:40 +00:00
}
/**
* @return
* @see java.lang.Object#toString()
*/
public String toString() {
return ingredient.toString();
}
}