Example usage for com.google.gwt.json.client JSONObject put

List of usage examples for com.google.gwt.json.client JSONObject put

Introduction

In this page you can find the example usage for com.google.gwt.json.client JSONObject put.

Prototype

public JSONValue put(String key, JSONValue jsonValue) 

Source Link

Document

Assign the specified property to the specified value in this JSONObject.

Usage

From source file:amdb.client.slider.RangeSlider.java

License:Apache License

/**
 * A convenient way to create an options JSONObject for the RangeSlider.
 * @param min - default minimum of the slider
 * @param max - default maximum of the slider
 * @param defaultMin - the default value of the lowest anchor
 * @param defaultMax - the default value of the highest anchor
 * @return a JSONObject of RangeSlider options
 *///w w  w  .j a  v a2 s  .  c o m
public static JSONObject getOptions(int min, int max, int defaultMin, int defaultMax) {
    JSONObject options = Slider.getOptions(min, max, new int[] { defaultMin, defaultMax });
    options.put(SliderOption.RANGE.toString(), JSONBoolean.getInstance(true));
    options.put(SliderOption.STEP.toString(), new JSONNumber(1));
    return options;
}

From source file:amdb.client.slider.Slider.java

License:Apache License

/**
 * A convenient way to create an options JSONObject.  Use SliderOption for keys.
 * @param min - default minimum of the slider
 * @param max - default maximum of the slider
 * @param defaultValues - default points of each anchor
 * @return a JSONObject of Slider options
 *//*from   ww  w . j  av  a2  s .  c o m*/
public static JSONObject getOptions(int min, int max, int[] defaultValues) {
    JSONObject options = new JSONObject();
    options.put(SliderOption.MIN.toString(), new JSONNumber(min));
    options.put(SliderOption.MAX.toString(), new JSONNumber(max));
    JSONArray vals = intArrayToJSONArray(defaultValues);
    options.put(SliderOption.VALUES.toString(), vals);
    return options;
}

From source file:anzsoft.xmpp4gwt.client.User.java

License:Open Source License

public boolean suspend() {
    JSONObject jUser = new JSONObject();
    if (domainname == null || username == null)
        return false;

    jUser.put(STORAGE_DOMAIN, new JSONString(domainname));
    //jUser.put("password", new JSONString(password)); //It's uneeded, and not safe
    String strPriority = String.valueOf(priority);
    if (strPriority != null)
        jUser.put(STORAGE_PRIORITY, new JSONString(String.valueOf(priority)));
    jUser.put(STORAGE_RESOURCE, new JSONString(resource));
    jUser.put(STORAGE_USERNAME, new JSONString(username));

    Cookies.setCookie(COOKIENAME, jUser.toString(), null, null, "/", false);
    return true;// w w w.j a v  a 2s.  c  om
}

From source file:anzsoft.xmpp4gwt.client.xmpp.roster.RosterItem.java

License:Open Source License

public JSONObject toJsonObject() {
    JSONObject object = new JSONObject();
    try {//  w  w  w  .j a  va 2s.  co  m
        object.put("jid", new JSONString(this.jid));
        if (this.name != null)
            object.put("name", new JSONString(this.name));
        else
            object.put("name", new JSONString(""));
        if (this.subscription.toString() != null)
            object.put("subscription", new JSONString(this.subscription.toString()));
        else
            object.put("subscription", new JSONString(""));
        if (ask)
            object.put("ask", new JSONString("true"));
        else
            object.put("ask", new JSONString("false"));
        JSONArray jGroup = new JSONArray();
        if (this.groups.length > 0) {
            for (int index = 0; index < this.groups.length; index++) {
                jGroup.set(index, new JSONString(this.groups[index]));
            }
        }
        object.put("groups", jGroup);
        if (this.order != null)
            object.put("order", new JSONString(this.order));
        else
            object.put("order", new JSONString(""));
    } catch (Exception e) {
        System.out.println(e.toString());
        return null;
    }
    return object;
}

From source file:br.com.pegasus.solutions.smartgwt.lib.client.view.impl.advanced.bar.infra.ExportUtil.java

License:Apache License

public static String getDataAsJson(ListGrid listGrid) {
    JSONObject jsonObj = new JSONObject();

    ListGridRecord[] records = listGrid.getRecords();
    for (int i = 0; i < records.length; i++) {
        ListGridRecord listGridRecord = records[i];
        ListGridField[] listGridFields = listGrid.getFields();
        JSONObject json = new JSONObject();

        for (int j = 0; j < listGridFields.length; j++) {
            ListGridField listGridField = listGridFields[j];
            String name = listGridField.getName();
            if (name.contains(FIELD_NAME_CLASS_SEPARATOR)) {
                name = name.split(FIELD_NAME_CLASS_SEPARATOR)[0];
            }//from   ww  w . jav  a  2s.  c o m

            String value = listGridRecord.getAttribute(listGridField.getName());
            if (value != null) {
                try {
                    BigInteger number = new BigInteger(value);
                    json.put(name, new JSONNumber(number.intValue()));
                } catch (Exception e) {
                    try {
                        BigDecimal decimal = new BigDecimal(value);
                        decimal.setScale(2, RoundingMode.HALF_UP);
                        json.put(name, new JSONNumber(decimal.doubleValue()));
                    } catch (Exception e2) {
                        json.put(name, new JSONString(value));
                    }
                }
            } else {
                json.put(name, new JSONString(""));
            }
        }

        jsonObj.put("jsonRecord" + (i + 1), json);
    }

    return jsonObj.toString();
}

From source file:ca.nanometrics.gflot.client.util.JSONHelper.java

License:Open Source License

public static JSONObjectWrapper wrapArrayIntoObject(String objectName, String[] values) {
    JSONObject jsonObj = new JSONObject();
    jsonObj.put(objectName, wrapArray(values).getWrappedObj());
    return wrapObject(jsonObj);
}

From source file:ca.nanometrics.gflot.client.util.JSONHelper.java

License:Open Source License

public static JSONObjectWrapper wrapArrayIntoObject(String objectName, Double[] values) {
    JSONObject jsonObj = new JSONObject();
    jsonObj.put(objectName, wrapArray(values).getWrappedObj());
    return wrapObject(jsonObj);
}

From source file:ca.nanometrics.gflot.client.util.JSONHelper.java

License:Open Source License

public static JSONObjectWrapper wrapArrayIntoObject(String objectName, JSONWrapper[] values) {
    JSONObject jsonObj = new JSONObject();
    jsonObj.put(objectName, wrapArray(values).getWrappedObj());
    return wrapObject(jsonObj);
}

From source file:ca.upei.ic.timetable.client.CourseViewController.java

License:Apache License

public void search() {
    JSONObject department = new JSONObject();
    for (String d : departmentCriteria_.keySet()) {
        if (departmentCriteria_.get(d)) {
            department.put(d, JSONBoolean.getInstance(true));
        }/*  www .  j a v  a  2 s  .  c o  m*/
    }
    JSONObject level = new JSONObject();
    for (String l : levelCriteria_.keySet()) {
        if (levelCriteria_.get(l)) {
            level.put(l, JSONBoolean.getInstance(true));
        }
    }
    JSONObject semester = new JSONObject();
    for (String s : semesterCriteria_.keySet()) {
        if (semesterCriteria_.get(s))
            semester.put(s, JSONBoolean.getInstance(true));
    }

    JSONObject value = new JSONObject();
    value.put("department", department);
    value.put("level", level);
    value.put("semester", semester);
    value.put("day", new JSONString(courseDay_));
    value.put("startTime", new JSONString(courseStartTime_));

    Service.defaultInstance().askCourses(value.toString(), new RequestCallback() {

        public void onError(Request request, Throwable exception) {
            app_.error(ApplicationController.OOPS, exception);
        }

        public void onResponseReceived(Request request, Response response) {

            try {
                JSONArray parsedArray = (JSONArray) JSONParser.parse(response.getText());
                // remove the selected courses
                // filtered array
                JSONArray filteredArray = new JSONArray();
                int filtered_index = 0;
                for (int i = 0; i < parsedArray.size(); i++) {
                    JSONObject o = (JSONObject) parsedArray.get(i);
                    int id = (int) ((JSONNumber) o.get("id")).doubleValue();
                    if (!isSelected(id)) {
                        filteredArray.set(filtered_index++, o);
                    }
                }
                // clear out the view so we can add courses
                view_.clear();
                // add the selected values first
                for (int index : selectionIndexes_) {
                    view_.addCourse(index, selectionValues_.get(index), true);
                }
                // add the remaining courses
                view_.loadJSON(filteredArray);
            } catch (Throwable e) {
                app_.error("Error: " + response.getText(), e);
            }
        }

    });
}

From source file:ca.upei.ic.timetable.client.Service.java

License:Apache License

public void askCourseDetail(int courseId, RequestCallback callback) {
    JSONObject object = new JSONObject();
    object.put("id", new JSONNumber(courseId));
    currentCourseDetailRequest_ = remote_.post("get_course_detail", "application/json", object.toString(),
            callback);/*from   w  ww  .  java2  s .  co  m*/
}