Web implementation of the Gourmet Recipe Manager
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

375 lines
8.1 KiB

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;
import com.mousetech.gourmetj.IngredientDigester;
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.
*
* TestedBy @see IngredientUITest
*
* @author timh
* @since Dec 2, 2021
*/
public class IngredientUI implements IngredientIF {
private Ingredient ingredient;
/**
* Constructor.
* @param ingredient
*/
public IngredientUI(Ingredient ingredient) {
this.ingredient = ingredient;
}
public Ingredient getIngredient() {
return this.ingredient;
}
private boolean ingGroup;
/**
* @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.
*
* @return <code>true</code> for an Ingredient Group
* header row.
*/
public boolean isIngGroup() {
return this.ingGroup;
}
/**
* Row selection checkbox (UI only)
*/
private boolean selected;
/**
* @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
* @see #getAmount
*/
public String getDisplayAmount() {
// TODO
Double amt = ingredient.getAmount();
if ( amt == null ) {
return "";
}
String amt1 = IngredientDigester.displayAmount(
IngredientAmountFormat.IA_SYMBOLS, amt, ingredient.getRangeamount());
return amt1;
}
/**
* Set amount display-friendly
* @see #setAmount
*/
public void setDisplayAmount(String amount) {
if ( amount.isBlank() ) {
ingredient.setAmount(null);
}
IngredientDigester digester = new IngredientDigester();
Double[] amt = digester.digestAmount(amount);
ingredient.setAmount(amt[0]);
ingredient.setRangeamount(amt[1]);
}
/**
* @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
* @return
*/
public boolean getOptionalCB() {
return ingredient.getOptional() != 0;
}
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);
}
/**
* @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);
}
// This goes to the shopCats table via ManyToOne at save time.
private String shopCat;
/**
* @return the shopCat
*/
public String getShopCat() {
return shopCat;
}
/**
* @param shopCat the shopCat to set
*/
public void setShopCat(String shopCat) {
this.shopCat = shopCat;
}
/**
* @return
* @see java.lang.Object#toString()
*/
public String toString() {
return ingredient.toString();
}
}