summaryrefslogtreecommitdiff
path: root/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOPopUpButton.java
diff options
context:
space:
mode:
Diffstat (limited to 'projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOPopUpButton.java')
-rw-r--r--projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOPopUpButton.java251
1 files changed, 127 insertions, 124 deletions
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
index a73636c..a40c828 100644
--- 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
@@ -7,129 +7,132 @@ 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("<SELECT NAME=\"");
- r.appendContentString(inputName(c));
- r.appendContentString("\" SIZE=");
- r.appendContentString(Integer.toString(inputSize()));
- r.appendContentString(">");
- java.util.Enumeration numerador = list(c).objectEnumerator();
- String displayKey = stringForProperty("displayString", c.component());
- String valueKey = stringForProperty("value", c.component());
- Object sel = selection(c);
- if (sel == null)
- sel = item(c);
- int pos = 0;
- while (numerador.hasMoreElements()) {
- Object item = numerador.nextElement();
- setItem(item, c);
- r.appendContentString("<OPTION ");
- //Append the "SELECTED" attribute if it's the selected item
- if (sel != null && item.equals(sel))
- r.appendContentString("SELECTED ");
- r.appendContentString("VALUE=\"");
- //Append the value
- if (valueKey != null && item instanceof NSKeyValueCodingAdditions) {
- Object val = ((NSKeyValueCodingAdditions)item).valueForKeyPath(valueKey);
- if (val == null)
- val = "null";
- r.appendContentString(val.toString());
- } else
- r.appendContentString(Integer.toString(pos));
- r.appendContentString("\">");
- //Append display string
- if (displayKey != null && item instanceof NSKeyValueCodingAdditions) {
- Object ds = ((NSKeyValueCodingAdditions)item).valueForKeyPath(displayKey);
- if (ds == null)
- ds = "";
- r.appendContentString(ds.toString());
- } else
- r.appendContentString(item.toString());
- r.appendContentString("\n");
- pos++;
- }
- r.appendContentString("</SELECT>");
- }
-
- 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;
- }
- }
- }
- }
+ 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("<SELECT NAME=\"");
+ r.appendContentString(inputName(c));
+ r.appendContentString("\" SIZE=");
+ r.appendContentString(Integer.toString(inputSize()));
+ r.appendContentString(">");
+ java.util.Enumeration numerador = list(c).objectEnumerator();
+ String displayKey = stringForProperty("displayString", c.component());
+ String valueKey = stringForProperty("value", c.component());
+ Object sel = selection(c);
+ if (sel == null)
+ sel = item(c);
+ int pos = 0;
+ while (numerador.hasMoreElements()) {
+ Object item = numerador.nextElement();
+ setItem(item, c);
+ r.appendContentString("<OPTION ");
+ // Append the "SELECTED" attribute if it's the selected item
+ if (sel != null && item.equals(sel))
+ r.appendContentString("SELECTED ");
+ r.appendContentString("VALUE=\"");
+ // Append the value
+ if (valueKey != null && item instanceof NSKeyValueCodingAdditions) {
+ Object val = ((NSKeyValueCodingAdditions) item).valueForKeyPath(valueKey);
+ if (val == null)
+ val = "null";
+ r.appendContentString(val.toString());
+ } else
+ r.appendContentString(Integer.toString(pos));
+ r.appendContentString("\">");
+ // Append display string
+ if (displayKey != null && item instanceof NSKeyValueCodingAdditions) {
+ Object ds = ((NSKeyValueCodingAdditions) item).valueForKeyPath(displayKey);
+ if (ds == null)
+ ds = "";
+ r.appendContentString(ds.toString());
+ } else
+ r.appendContentString(item.toString());
+ r.appendContentString("\n");
+ pos++;
+ }
+ r.appendContentString("</SELECT>");
+ }
+
+ 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;
+ }
+ }
+ }
+ }
}