diff --git a/src/main/java/info/bukova/isspst/BooleanUtils.java b/src/main/java/info/bukova/isspst/BooleanUtils.java index 484e562a..a15d9cfa 100644 --- a/src/main/java/info/bukova/isspst/BooleanUtils.java +++ b/src/main/java/info/bukova/isspst/BooleanUtils.java @@ -1,13 +1,48 @@ package info.bukova.isspst; +import org.jfree.util.Log; public class BooleanUtils { - public static boolean isEqualByBoolean(Boolean b1, Boolean b2) + private static final String TAG = BooleanUtils.class.getSimpleName(); + + public static boolean isEqualByBooleanValue(Boolean b1, Boolean b2) { boolean bool1 = ((b1 == null) ? false : b1.booleanValue()); boolean bool2 = ((b2 == null) ? false : b2.booleanValue()); boolean equals = (bool1 == bool2); return equals; } + + public static boolean isEqualByBoolean(Boolean b1, Boolean b2) + { + if ((b1 == null) && (b2 == null)) + { + return true; + } + else if ((b1 != null) && (b2 != null)) + { + return (b1.booleanValue() == b2.booleanValue()); + } + + return false; + } + + public static boolean isEqualFilterByBoolean(Boolean value, Boolean filterValue) + { + if (filterValue == null) + { + // Show all records + return true; + } + + if (value == null) + { + // Fuck!!! Tri-state data (null, false, true)... We need new solution for selecting ALL data + Log.warn(TAG + "\nVelky Boolean v databazi... Pozor na filtrovani."); + return true; + } + + return (value.booleanValue() == filterValue.booleanValue()); + } } diff --git a/src/main/java/info/bukova/isspst/data/JoinedItem.java b/src/main/java/info/bukova/isspst/data/JoinedItem.java index 31632aa7..7b3db944 100644 --- a/src/main/java/info/bukova/isspst/data/JoinedItem.java +++ b/src/main/java/info/bukova/isspst/data/JoinedItem.java @@ -1,5 +1,7 @@ package info.bukova.isspst.data; +import info.bukova.isspst.Constants; + import java.math.BigDecimal; import java.util.Date; @@ -220,6 +222,23 @@ public class JoinedItem implements DataModel, FilterableRequirement this.ownedBy = owner; } + protected Boolean itemMaterial; + + public boolean isItemMaterialReal() + { + return ((this.requirement != null) && (this.requirement.getKind() == Constants.REQ_TYPE_MATERIAL)); + } + + public Boolean getItemMaterial() + { + return this.itemMaterial; + } + + public void setItemMaterial(Boolean value) + { + this.itemMaterial = value; + } + @Override public boolean equals(Object obj) { diff --git a/src/main/java/info/bukova/isspst/filters/BooleanFilterListbox.java b/src/main/java/info/bukova/isspst/filters/BooleanFilterListbox.java new file mode 100644 index 00000000..cf123365 --- /dev/null +++ b/src/main/java/info/bukova/isspst/filters/BooleanFilterListbox.java @@ -0,0 +1,57 @@ +package info.bukova.isspst.filters; + +import info.bukova.isspst.StringUtils; + +import java.util.ArrayList; +import java.util.List; + +import org.zkoss.zul.Listbox; +import org.zkoss.zul.Listitem; + +@SuppressWarnings("serial") +public class BooleanFilterListbox extends Listbox +{ + class TristateBooleanListItem extends TristateBoolean + { + public TristateBooleanListItem(String text, int value) + { + this.setText(text); + this.setValue(value); + } + + private String text; + + public String getText() + { + return text; + } + + public void setText(String text) + { + this.text = text; + } + } + + public BooleanFilterListbox() + { + super(); + + List list = new ArrayList(); + list.add(new TristateBooleanListItem(StringUtils.localize("LabelAll"), TristateBoolean.NULL)); + list.add(new TristateBooleanListItem(StringUtils.localize("LabelNo"), TristateBoolean.FALSE)); + list.add(new TristateBooleanListItem(StringUtils.localize("LabelYes"), TristateBoolean.TRUE)); + + for (int i = 0; i < list.size(); i++) + { + TristateBooleanListItem triStateItem = (TristateBooleanListItem) list.get(i); + this.appendItem(triStateItem.getText(), ""); + + Listitem item = this.getItemAtIndex(i); + item.setValue((TristateBoolean) triStateItem); + } + + this.setSelectedIndex(0); + // this.setHflex("1"); + this.setMold("select"); + } +} diff --git a/src/main/java/info/bukova/isspst/filters/JoinedItemFilter.java b/src/main/java/info/bukova/isspst/filters/JoinedItemFilter.java index f3a2ca75..41e8682d 100644 --- a/src/main/java/info/bukova/isspst/filters/JoinedItemFilter.java +++ b/src/main/java/info/bukova/isspst/filters/JoinedItemFilter.java @@ -1,5 +1,6 @@ package info.bukova.isspst.filters; +import info.bukova.isspst.BooleanUtils; import info.bukova.isspst.StringUtils; import info.bukova.isspst.data.JoinedItem; import info.bukova.isspst.data.MUnitEmb; @@ -42,6 +43,7 @@ public class JoinedItemFilter implements Filter @Override public boolean matchesSafely(JoinedItem item) { + boolean foundItemMaterial = BooleanUtils.isEqualFilterByBoolean(item.isItemMaterialReal(), condition.getItemMaterial()); boolean foundCode = StringUtils.isEqualForFilter(item.getCode(), condition.getCode()); boolean foundName = StringUtils.isEqualForFilter(item.getName(), condition.getName()); boolean foundTextItem = StringUtils.isEqualForFilter(item.getTextItem(), condition.getTextItem()); @@ -56,7 +58,18 @@ public class JoinedItemFilter implements Filter boolean foundCenter = Workgroup.isEqualByWorkgroupForFilter(item.getCentre(), condition.getCentre()); boolean foundOwner = User.isEqualByUserForFilter(item.getOwnedBy(), condition.getOwnedBy()); boolean foundDescription = StringUtils.isEqualForFilter(item.getDescription(), condition.getDescription()); - return (foundCode && foundName && foundTextItem && foundDescription && foundQuantity && foundUnitPrice && foundMUnit && foundTotal && foundWorkgroup && foundCenter && foundOwner && foundDescription); + return (foundItemMaterial + && foundCode + && foundName + && foundTextItem + && foundDescription + && foundQuantity + && foundUnitPrice + && foundMUnit + && foundTotal + && foundWorkgroup + && foundCenter + && foundOwner && foundDescription); } @Factory diff --git a/src/main/java/info/bukova/isspst/filters/RequirementFilter.java b/src/main/java/info/bukova/isspst/filters/RequirementFilter.java index 5710afcc..1a13940f 100644 --- a/src/main/java/info/bukova/isspst/filters/RequirementFilter.java +++ b/src/main/java/info/bukova/isspst/filters/RequirementFilter.java @@ -47,7 +47,7 @@ public class RequirementFilter implements Filter boolean foundDescription = StringUtils.isEqualForFilter(item.getDescription(), condition.getDescription()); boolean foundDeliveryDate = DateTimeUtils.isEqualByDateForFilter(item.getDeliveryDate(), condition.getDeliveryDate()); boolean foundUser = User.isEqualByUserForFilter(item.getOwnedBy(), condition.getOwnedBy()); - boolean foundProject = BooleanUtils.isEqualByBoolean(item.getProject(), condition.getProject()); + boolean foundProject = BooleanUtils.isEqualByBooleanValue(item.getProject(), condition.getProject()); return (foundNumser && foundReqDate && foundCenter && foundDescription && foundDeliveryDate && foundUser && foundProject); } diff --git a/src/main/java/info/bukova/isspst/filters/TristateBoolean.java b/src/main/java/info/bukova/isspst/filters/TristateBoolean.java new file mode 100644 index 00000000..ea29ccab --- /dev/null +++ b/src/main/java/info/bukova/isspst/filters/TristateBoolean.java @@ -0,0 +1,87 @@ +package info.bukova.isspst.filters; + +import org.jfree.util.Log; + +public class TristateBoolean +{ + private static final String TAG = TristateBoolean.class.getSimpleName(); + + public static final int NULL = -1; + public static final int FALSE = 0; + public static final int TRUE = 1; + + public static final int getValidValue(final int value) + { + if ((value != TristateBoolean.NULL) && (value != TristateBoolean.FALSE) && (value != TristateBoolean.TRUE)) + { + Log.warn(TAG + "\nBad tristate boolean value."); + return TristateBoolean.NULL; + } + + return value; + } + + public TristateBoolean() + { + this.setValue(TristateBoolean.NULL); + } + + public TristateBoolean(boolean value) + { + this.setValue(value ? TristateBoolean.TRUE : TristateBoolean.FALSE); + } + + public TristateBoolean(int value) + { + this.setValue(value); + } + + protected int value; + + public int getValue() + { + return value; + } + + public void setValue(int value) + { + this.value = TristateBoolean.getValidValue(value); + } + + public Boolean getBoolean() + { + switch (this.value) + { + case TristateBoolean.FALSE: + return new Boolean(false); + + case TristateBoolean.TRUE: + return new Boolean(true); + + default: + return null; + } + } + + @Override + public boolean equals(Object obj) + { + if (obj != null) + { + if (obj instanceof TristateBoolean) + { + TristateBoolean item = (TristateBoolean) obj; + int thisValue = this.getValue(); + int itemValue = item.getValue(); + return (thisValue == itemValue); + } + } + + return false; + } + + public boolean equals(int value) + { + return (this.getValue() == value); + } +} diff --git a/src/main/java/info/bukova/isspst/ui/main/approved/ApprovedList.java b/src/main/java/info/bukova/isspst/ui/main/approved/ApprovedList.java index ecdfc471..aad7ce34 100644 --- a/src/main/java/info/bukova/isspst/ui/main/approved/ApprovedList.java +++ b/src/main/java/info/bukova/isspst/ui/main/approved/ApprovedList.java @@ -5,11 +5,11 @@ import info.bukova.isspst.data.Order; import info.bukova.isspst.data.User; import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.filters.JoinedItemFilter; +import info.bukova.isspst.filters.TristateBoolean; import info.bukova.isspst.services.orders.ApprovedService; import info.bukova.isspst.services.orders.OrderService; import info.bukova.isspst.services.users.UserService; import info.bukova.isspst.services.workgroups.WorkgroupService; -import info.bukova.isspst.ui.BigDecimalConverter; import info.bukova.isspst.ui.ListViewModel; import java.util.ArrayList; @@ -38,24 +38,17 @@ public class ApprovedList extends ListViewModel @WireVariable protected OrderService orderService; - private BigDecimalConverter bigDecimalConverter; - protected List selectedItems; - - @Init + + @Init(superclass = true) public void initApprovedList() { service = approvedService; dataClass = JoinedItem.class; // formZul = "form.zul"; dataFilter = new JoinedItemFilter(getFilterTemplate()); - bigDecimalConverter = new BigDecimalConverter(); selectedItems = new ArrayList(); - } - - public BigDecimalConverter getBigDecimalConverter() - { - return bigDecimalConverter; + this.itemMaterial = new TristateBoolean(); } public List getItems() @@ -123,4 +116,17 @@ public class ApprovedList extends ListViewModel return new ArrayList(); } } + + protected TristateBoolean itemMaterial; + + public TristateBoolean getItemMaterial() + { + return this.itemMaterial; + } + + public void setItemMaterial(TristateBoolean tristate) + { + this.itemMaterial = tristate; + this.getFilterTemplate().setItemMaterial(tristate.getBoolean()); + } } diff --git a/src/main/webapp/WEB-INF/lang-addons/BooleanFilterListbox.xml b/src/main/webapp/WEB-INF/lang-addons/BooleanFilterListbox.xml new file mode 100644 index 00000000..101e8a06 --- /dev/null +++ b/src/main/webapp/WEB-INF/lang-addons/BooleanFilterListbox.xml @@ -0,0 +1,11 @@ + + + + BooleanFilterListbox + xul/html + + booleanfilterlistbox + listbox + info.bukova.isspst.filters.BooleanFilterListbox + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index cd200e25..31e76fe0 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -289,6 +289,9 @@ DbValidationError=Chyba validace true=Ano false=Ne +LabelAll=Vše +LabelYes=Ano +LabelNo=Ne Information=Informace @@ -301,6 +304,7 @@ MaterialRequirements=Požadavky na materiál ServiceRequirement=Požadavek na službu ServiceRequirements=Požadavky na služby ApprovedRequirementItems=Schválené položky požadavků +Material = Materiál CurrentRequirements=Aktuální požadavky CreatedOrders=Vytvořené objednávky diff --git a/src/main/webapp/WEB-INF/zk.xml b/src/main/webapp/WEB-INF/zk.xml index eba7568c..3e534327 100644 --- a/src/main/webapp/WEB-INF/zk.xml +++ b/src/main/webapp/WEB-INF/zk.xml @@ -18,6 +18,7 @@ /WEB-INF/lang-addons/mapa-lang-addon.xml /WEB-INF/lang-addons/ckez-bind-lang-addon.xml /WEB-INF/lang-addons/CzechSortListheader.xml + /WEB-INF/lang-addons/BooleanFilterListbox.xml /css/zk-modify.css diff --git a/src/main/webapp/main/orders/approved/grid.zul b/src/main/webapp/main/orders/approved/grid.zul index 33d27a2d..7de9593e 100644 --- a/src/main/webapp/main/orders/approved/grid.zul +++ b/src/main/webapp/main/orders/approved/grid.zul @@ -32,9 +32,13 @@ + hflex="4" + sort="auto(itemMaterialReal)" + label="${labels.Material}" /> + -
-
- -
-
- -
-
-
+ +
+ +
+
+ +
+
+ +
+
+
@@ -287,14 +296,15 @@