From aedc34d55462a75e329bbf342251ff6504cd117e Mon Sep 17 00:00:00 2001 From: Benjamin Culkin Date: Sun, 19 May 2024 17:56:33 -0400 Subject: Initial import from SVN --- .../main/java/net/wotonomy/web/WOPopUpButton.java | 135 +++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOPopUpButton.java (limited to 'projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOPopUpButton.java') diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOPopUpButton.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOPopUpButton.java new file mode 100644 index 0000000..a73636c --- /dev/null +++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOPopUpButton.java @@ -0,0 +1,135 @@ + +package net.wotonomy.web; + +import net.wotonomy.foundation.NSArray; +import net.wotonomy.foundation.NSDictionary; +import net.wotonomy.foundation.NSKeyValueCodingAdditions; + +public class WOPopUpButton extends WOInput { + + public WOPopUpButton() { + super(); + } + + public WOPopUpButton(String aName, NSDictionary assocs, WOElement template) { + super(aName, assocs, template); + } + + protected String inputType() { + return "SELECT"; + } + + protected int inputSize() { + return 1; + } + + protected NSArray list(WOContext c) { + NSArray l = (NSArray)valueForProperty("list", c.component()); + if (l == null) + l = NSArray.EmptyArray; + return l; + } + + protected void setItem(Object v, WOContext c) { + if (associations.objectForKey("item") == null) + return; + setValueForProperty("item", v, c.component()); + } + protected Object item(WOContext c) { + return valueForProperty("item", c.component()); + } + + protected void setSelection(Object v, WOContext c) { + if (associations.objectForKey("selection") == null) + return; + setValueForProperty("selection", v, c.component()); + } + protected Object selection(WOContext c) { + return valueForProperty("selection", c.component()); + } + + public Object value(WOContext c) { + return null; + } + + public void appendToResponse(WOResponse r, WOContext c) { + r.appendContentString(""); + } + + protected void select(Object v, WOContext c) { + if (associations.objectForKey("selection") != null) { + setSelection(v, c); + return; + } + if (associations.objectForKey("item") != null) { + setItem(v,c); + } + } + public void takeValuesFromRequest(WORequest r, WOContext c) { + Object val = r.formValueForKey(inputName(c)); + if (val == null) + return; + NSArray list = list(c); + String valueKey = stringForProperty("value", c.component()); + //If no value binding, just get the index + if (valueKey == null) { + int pos = Integer.parseInt(val.toString()); + val = list.objectAtIndex(pos); + select(val, c); + return; + } + //If value binding is present, lookup the value + java.util.Enumeration numerador = list.objectEnumerator(); + while (numerador.hasMoreElements()) { + Object o = numerador.nextElement(); + if (o instanceof NSKeyValueCodingAdditions) { + Object x = ((NSKeyValueCodingAdditions)o).valueForKeyPath(valueKey); + if (x != null && x.equals(val)) { + select(o, c); + return; + } + } + } + } + +} -- cgit v1.2.3