use of com.webobjects.foundation.NSMutableDictionary in project wonder-slim by undur.
the class NSDictionarySerializer method unmarshall.
public Object unmarshall(SerializerState state, Class clazz, Object o) throws UnmarshallException {
JSONObject jso = (JSONObject) o;
String java_class;
try {
java_class = jso.getString("javaClass");
} catch (JSONException e) {
throw new UnmarshallException("Could not read javaClass", e);
}
if (java_class == null) {
throw new UnmarshallException("no type hint");
}
boolean immutableClone = false;
NSMutableDictionary abdictionary;
if (java_class.equals("com.webobjects.foundation.NSDictionary")) {
abdictionary = new NSMutableDictionary();
immutableClone = true;
} else if (java_class.equals("com.webobjects.foundation.NSMutableDictionary")) {
abdictionary = new NSMutableDictionary();
} else {
throw new UnmarshallException("not an NSDictionary");
}
JSONObject jsondictionary;
try {
jsondictionary = jso.getJSONObject("nsdictionary");
} catch (JSONException e) {
throw new UnmarshallException("Could not read dictionary: " + e.getMessage(), e);
}
if (jsondictionary == null) {
throw new UnmarshallException("nsdictionary missing");
}
Iterator i = jsondictionary.keys();
String key = null;
try {
while (i.hasNext()) {
key = (String) i.next();
Object value = ser.unmarshall(state, null, jsondictionary.get(key));
if (value != null) {
abdictionary.setObjectForKey(value, key);
} else {
abdictionary.setObjectForKey(NSKeyValueCoding.NullValue, key);
}
}
NSDictionary finalDictionary = abdictionary;
if (immutableClone) {
finalDictionary = abdictionary.immutableClone();
}
state.setSerialized(o, finalDictionary);
return finalDictionary;
} catch (UnmarshallException e) {
throw new UnmarshallException("key " + key + " " + e.getMessage(), e);
} catch (JSONException e) {
throw new UnmarshallException("key " + key + " " + e.getMessage(), e);
}
}
use of com.webobjects.foundation.NSMutableDictionary in project wonder-slim by undur.
the class AjaxSlider method appendToResponse.
/**
* Overridden to add the initialization javascript for the auto completer.
*/
@Override
public void appendToResponse(WOResponse res, WOContext ctx) {
super.appendToResponse(res, ctx);
_trackerId = safeElementID() + "_tracker";
_handleId = safeElementID() + "_handle";
NSMutableDictionary options = new NSMutableDictionary();
new AjaxOption("axis", "orientation", null, AjaxOption.STRING).addToDictionary(this, options);
new AjaxOption("sliderValue", "value", null, AjaxOption.NUMBER).addToDictionary(this, options);
new AjaxOption("values", "possibleValues", null, AjaxOption.ARRAY).addToDictionary(this, options);
new AjaxOption("alignX", AjaxOption.NUMBER).addToDictionary(this, options);
new AjaxOption("alignY", AjaxOption.NUMBER).addToDictionary(this, options);
new AjaxOption("disabled", AjaxOption.BOOLEAN).addToDictionary(this, options);
new AjaxOption("handleImage", AjaxOption.STRING).addToDictionary(this, options);
new AjaxOption("handleDisabled", AjaxOption.STRING).addToDictionary(this, options);
new AjaxOption("increment", AjaxOption.NUMBER).addToDictionary(this, options);
new AjaxOption("restricted", AjaxOption.BOOLEAN).addToDictionary(this, options);
new AjaxOption("step", AjaxOption.NUMBER).addToDictionary(this, options);
if (hasBinding("onChangeServer")) {
String parent = (String) valueForBinding("onChange");
options.setObjectForKey("function(v) {new Ajax.Request('" + AjaxUtils.ajaxComponentActionUrl(context()) + "', {parameters: '" + context().elementID() + "=' + v + '&ajaxSlideTrigger=onChange'})" + (parent != null ? "; var parentFunction = " + parent + "; parentFunction(v);" : "") + "}", "onChange");
} else {
new AjaxOption("onChange", AjaxOption.SCRIPT).addToDictionary(this, options);
}
if (hasBinding("onSlideServer")) {
String parent = (String) valueForBinding("onSlide");
options.setObjectForKey("function(v) {new Ajax.Request('" + AjaxUtils.ajaxComponentActionUrl(context()) + "', {parameters: '" + context().elementID() + "=' + v + '&ajaxSlideTrigger=onSlide'})" + (parent != null ? "; var parentFunction = " + parent + "; parentFunction(v);" : "") + "}", "onSlide");
} else {
new AjaxOption("onSlide", AjaxOption.SCRIPT).addToDictionary(this, options);
}
Number min = (Number) valueForBinding("minimum", Integer.valueOf(0));
Number max = (Number) valueForBinding("maximum", Integer.valueOf(100));
options.setObjectForKey("$R(" + min + "," + max + ")", "range");
if (min != null && max != null && ERXComponentUtilities.booleanValueForBinding(this, "snap")) {
StringBuilder valuesBuffer = new StringBuilder();
valuesBuffer.append('[');
for (int i = min.intValue(); i <= max.intValue(); i++) {
valuesBuffer.append(i);
if (i < max.intValue()) {
valuesBuffer.append(',');
}
}
valuesBuffer.append(']');
options.setObjectForKey(valuesBuffer.toString(), "values");
}
res.appendContentString("<div class=\"tracker\" id=\"" + _trackerId + "\"><div class=\"handle\" id=\"" + _handleId + "\"></div></div>");
AjaxUtils.appendScriptHeader(res);
if (hasBinding("id")) {
res.appendContentString((String) valueForBinding("id") + " = ");
}
res.appendContentString("new Control.Slider('" + _handleId + "', '" + _trackerId + "', ");
AjaxOptions.appendToResponse(options, res, ctx);
res.appendContentString(");");
AjaxUtils.appendScriptFooter(res);
}
use of com.webobjects.foundation.NSMutableDictionary in project wonder-slim by undur.
the class AjaxModalDialog method createModalBoxOptions.
/**
* @return binding values converted into Ajax options for ModalBox
*/
protected NSMutableDictionary<String, String> createModalBoxOptions() {
NSMutableArray<AjaxOption> ajaxOptionsArray = new NSMutableArray<>();
ajaxOptionsArray.addObject(new AjaxOption("title", AjaxOption.STRING));
ajaxOptionsArray.addObject(new AjaxOption("width", AjaxOption.NUMBER));
ajaxOptionsArray.addObject(new AjaxOption("centerVertically", AjaxOption.BOOLEAN));
ajaxOptionsArray.addObject(new AjaxOption("overlayClose", AjaxOption.BOOLEAN));
ajaxOptionsArray.addObject(new AjaxOption("height", AjaxOption.NUMBER));
ajaxOptionsArray.addObject(new AjaxOption("method", AjaxOption.STRING));
ajaxOptionsArray.addObject(new AjaxOption("params", AjaxOption.DICTIONARY));
ajaxOptionsArray.addObject(new AjaxOption("loadingString", AjaxOption.STRING));
ajaxOptionsArray.addObject(new AjaxOption("closeString", AjaxOption.STRING));
ajaxOptionsArray.addObject(new AjaxOption("closeValue", AjaxOption.STRING));
ajaxOptionsArray.addObject(new AjaxOption("locked", AjaxOption.BOOLEAN));
ajaxOptionsArray.addObject(new AjaxOption("overlayOpacity", AjaxOption.NUMBER));
ajaxOptionsArray.addObject(new AjaxOption("overlayDuration", AjaxOption.NUMBER));
ajaxOptionsArray.addObject(new AjaxOption("slideDownDuration", ERXProperties.stringForKey("er.ajax.modaldialog.slideDownDuration"), AjaxOption.NUMBER));
ajaxOptionsArray.addObject(new AjaxOption("slideUpDuration", ERXProperties.stringForKey("er.ajax.modaldialog.slideUpDuration"), AjaxOption.NUMBER));
ajaxOptionsArray.addObject(new AjaxOption("resizeDuration", ERXProperties.stringForKey("er.ajax.modaldialog.resizeDuration"), AjaxOption.NUMBER));
ajaxOptionsArray.addObject(new AjaxOption("movable", ERXProperties.booleanForKey("er.ajax.modaldialog.movable"), AjaxOption.BOOLEAN));
ajaxOptionsArray.addObject(new AjaxOption("inactiveFade", AjaxOption.BOOLEAN));
ajaxOptionsArray.addObject(new AjaxOption("transitions", AjaxOption.BOOLEAN));
ajaxOptionsArray.addObject(new AjaxOption("autoFocusing", AjaxOption.BOOLEAN));
ajaxOptionsArray.addObject(new AjaxOption("clickOnReturnId", AjaxOption.STRING));
ajaxOptionsArray.addObject(new AjaxOption("clickOnEscId", AjaxOption.STRING));
// IMPORTANT NOTICE. Each callback gets removed from options of the ModalBox after execution
ajaxOptionsArray.addObject(new AjaxOption("beforeLoad", AjaxOption.SCRIPT));
ajaxOptionsArray.addObject(new AjaxOption("afterLoad", AjaxOption.SCRIPT));
ajaxOptionsArray.addObject(new AjaxOption("beforeHide", AjaxOption.SCRIPT));
ajaxOptionsArray.addObject(new AjaxOption("afterResize", AjaxOption.SCRIPT));
ajaxOptionsArray.addObject(new AjaxOption("onShow", AjaxOption.SCRIPT));
ajaxOptionsArray.addObject(new AjaxOption("onUpdate", AjaxOption.SCRIPT));
// JS to notify server when the dialog box is closed. This needs to be added to anything
// bound to afterHide
String closeUpdateContainerID = AjaxUpdateContainer.updateContainerID((String) valueForBinding("closeUpdateContainerID"));
String serverUpdate;
if (closeUpdateContainerID == null) {
serverUpdate = " AUL.request('" + closeDialogURL(context()) + "', null, null, null);";
} else {
String onCloseBeforeUpdate = (String) valueForBinding("onCloseBeforeUpdate", "AMD.shouldRefreshCloseUpdateContainer");
String verifyUpdateContainerRefreshScript = " if (" + onCloseBeforeUpdate + ") { ";
serverUpdate = verifyUpdateContainerRefreshScript + "AUL._update('" + closeUpdateContainerID + "', '" + closeDialogURL(context()) + "', null, null, null); } else { new Ajax.Request('" + closeDialogURL(context()) + "'); }";
}
if (hasBinding("afterHide")) {
String afterHide = (String) valueForBinding("afterHide");
int openingBraceIndex = afterHide.indexOf('{');
if (openingBraceIndex > -1) {
serverUpdate = "function() {" + serverUpdate + " " + afterHide.substring(openingBraceIndex + 1);
} else
throw new RuntimeException("Don't know how to handle afterHide value '" + afterHide + "', did you forget to wrap it in function() { ...}?");
} else {
serverUpdate = "function(v) { " + serverUpdate + '}';
}
ajaxOptionsArray.addObject(new AjaxConstantOption("afterHide", serverUpdate, AjaxOption.SCRIPT));
NSMutableDictionary options = AjaxOption.createAjaxOptionsDictionary(ajaxOptionsArray, this);
return options;
}
use of com.webobjects.foundation.NSMutableDictionary in project wonder-slim by undur.
the class AjaxInPlaceEditTemplate method processAssociations.
protected static NSDictionary processAssociations(NSDictionary associations) {
NSMutableDictionary mutableAssociations = (NSMutableDictionary) associations;
mutableAssociations.setObjectForKey(new WOConstantValueAssociation("edit"), "templateName");
return mutableAssociations;
}
use of com.webobjects.foundation.NSMutableDictionary in project wonder-slim by undur.
the class AjaxInPlaceViewTemplate method processAssociations.
protected static NSDictionary processAssociations(NSDictionary associations) {
NSMutableDictionary mutableAssociations = (NSMutableDictionary) associations;
mutableAssociations.setObjectForKey(new WOConstantValueAssociation("view"), "templateName");
return mutableAssociations;
}
Aggregations