Example usage for com.google.gwt.json.client JSONArray set

List of usage examples for com.google.gwt.json.client JSONArray set

Introduction

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

Prototype

public JSONValue set(int index, JSONValue value) 

Source Link

Document

Sets the specified index to the given value.

Usage

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

License:Apache License

private static JSONArray intArrayToJSONArray(int[] values) {
    JSONArray vals = new JSONArray();
    for (int i = 0, len = values.length; i < len; i++) {
        vals.set(i, new JSONNumber(values[i]));
    }//  w  w w  . ja v  a  2s . c o  m
    return vals;
}

From source file:anzsoft.xmpp4gwt.client.xmpp.presence.PresencePlugin.java

License:Open Source License

public void saveStatus() {
    List<Presence> presences = this.getAllPresenceItems();
    final String prefix = Session.instance().getUser().getStorageID();
    Storage storage = Storage.createStorage(STORAGEKEY, prefix);
    JSONArray jPresences = new JSONArray();
    for (int index = 0; index < presences.size(); index++) {
        jPresences.set(index, new JSONString(presences.get(index).toString()));
    }//from   w  w  w .  ja va2 s .com
    storage.set("data", jPresences.toString());

    //save current self presence status
    storage.set(STORAGE_CURRENTSHOW, currentShow != null ? currentShow.toString() : "");
    storage.set(STORAGE_PRIORITY, String.valueOf(priority));
    storage.set(STORAGE_INIT_PRESENCE, String.valueOf(initialPresenceSended));
}

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

License:Open Source License

public JSONObject toJsonObject() {
    JSONObject object = new JSONObject();
    try {/*from w w  w . jav  a2s .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:anzsoft.xmpp4gwt.client.xmpp.roster.RosterPlugin.java

License:Open Source License

public void saveStatus() {
    try {//  w  w w.j  a  v a 2  s.  c  o  m
        JSONArray jRoster = new JSONArray();
        Iterator<RosterItem> iterator = this.rosterItemsByBareJid.values().iterator();
        int index = 0;
        final String prefix = Session.instance().getUser().getStorageID();
        Storage storage = Storage.createStorage(STORAGEKEY, prefix);
        while (iterator.hasNext()) {
            RosterItem ri = iterator.next();
            jRoster.set(index, new JSONString(ri.getJid()));
            storage.set(ri.getJid(), ri.toJsonObject().toString());
        }
        storage.set("index", jRoster.toString());
    } catch (Exception e) {
        System.out.println(e.toString());
    }
}

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));
        }//  w ww.  j  av  a 2  s . co  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:ccc.client.gwt.core.GWTJson.java

License:Open Source License

/** {@inheritDoc} */
@Override//from   ww  w.j a  v  a2s . c om
public void setStrings(final String key, final Collection<String> values) {
    if (null == values) {
        _delegate.put(key, JSONNull.getInstance());
    } else {
        final JSONArray strings = new JSONArray();
        int i = 0;
        for (final String value : values) {
            strings.set(i, new JSONString(value));
            i++;
        }
        _delegate.put(key, strings);
    }
}

From source file:ccc.client.gwt.core.GWTJson.java

License:Open Source License

/** {@inheritDoc} */
@Override/*from w  w  w  .  ja v a2 s  .  c om*/
public void setJsons(final String key, final Collection<? extends Json> values) {
    final JSONArray value = new JSONArray();
    int i = 0;
    for (final Json j : values) {
        final GWTJson o = (GWTJson) j;
        value.set(i, o.getDelegate());
        i++;
    }
    _delegate.put(key, value);
}

From source file:ch.takoyaki.email.html.client.service.FileServiceImpl.java

License:Open Source License

private void updateFileList(List<String> fListCache2) {
    JSONArray a = new JSONArray();
    for (int i = 0; i < fListCache2.size(); i++) {
        a.set(i, new JSONString(fListCache2.get(i)));
    }/*  www  . j  a v a2 s  .  com*/
    s().setItem(FILE_LIST, a.toString());
    fListCache = fileList();
}

From source file:cl.uai.client.marks.Mark.java

License:Open Source License

protected String getFeedbackToAjax() {
    JSONObject outputFeedback = new JSONObject();
    for (int iterator = 0; iterator < feedback.size(); iterator++) {
        JSONArray array = new JSONArray();
        array.set(0, new JSONString(feedback.get(iterator).getNameOER().replaceAll("\\<.*?>", "")));
        array.set(1, new JSONString(feedback.get(iterator).getName().replaceAll("\\<.*?>", "")));
        array.set(2, new JSONString(feedback.get(iterator).getLink()));

        outputFeedback.put(Integer.toString(iterator), array);
    }//from w ww.  java  2 s  .  co m
    return outputFeedback.toString();
}

From source file:cl.uai.client.page.EditMarkDialog.java

License:Open Source License

public String getFeedback() {
    JSONObject outputFeedback = new JSONObject();
    for (int iterator = 0; iterator < feedbackArray.size(); iterator++) {
        JSONArray array = new JSONArray();
        array.set(0, new JSONString(feedbackArray.get(iterator).getNameOER()));
        array.set(1, new JSONString(feedbackArray.get(iterator).getName()));
        if (feedbackArray.get(iterator).getNameOER().equals("CS50")) {
            array.set(2, new JSONString(feedbackArray.get(iterator).getNameOER()));
        } else {//from   w  w  w .  jav a2 s  .co m
            array.set(2, new JSONString(feedbackArray.get(iterator).getLink()));
        }

        outputFeedback.put(Integer.toString(iterator), array);
    }
    return outputFeedback.toString();
}