Search in sources :

Example 1 with JSONValue

use of com.google.gwt.json.client.JSONValue in project gwtphonegap by dankurka.

the class ContactBrowserImpl method fromJSON.

public static Contact fromJSON(ContactsBrowserImpl controller, JSONObject jsonContact) {
    ContactBrowserImpl contact = new ContactBrowserImpl(controller);
    // simple fields
    contact.setId(getFieldAsString(jsonContact.get(FIELD_ID)));
    contact.setDisplayName(getFieldAsString(jsonContact.get(CONTACT_DISPLAY_NAME)));
    contact.setNickName(getFieldAsString(jsonContact.get(CONTACT_NICK_NAME)));
    contact.setNote(getFieldAsString(jsonContact.get(CONTACT_NOTE)));
    // birthday
    JSONValue dateValue = jsonContact.get(CONTACT_BIRTHDAY);
    if (dateValue != null && dateValue.isNumber() != null) {
        contact.setBirthDay(new Date((long) dateValue.isNumber().doubleValue()));
    }
    // contact fields
    JSONArray phoneNumberArray = jsonContact.get(CONTACT_PHONE_NUMBERS).isArray();
    LightArray<ContactField> phoneNumbers = getContactFieldsForArray(phoneNumberArray);
    contact.setPhoneNumbers(phoneNumbers);
    JSONArray emailsArray = jsonContact.get(CONTACT_EMAILS).isArray();
    LightArray<ContactField> emails = getContactFieldsForArray(emailsArray);
    contact.setEmails(emails);
    JSONArray imsArray = jsonContact.get(CONTACT_IMS).isArray();
    LightArray<ContactField> ims = getContactFieldsForArray(imsArray);
    contact.setIms(ims);
    JSONArray photosArray = jsonContact.get(CONTACT_PHOTOS).isArray();
    LightArray<ContactField> photos = getContactFieldsForArray(photosArray);
    contact.setPhotos(photos);
    JSONArray categoriesArray = jsonContact.get(CONTACT_CATEGORIES).isArray();
    LightArray<ContactField> categories = getContactFieldsForArray(categoriesArray);
    contact.setCategories(categories);
    JSONArray urlsArray = jsonContact.get(CONTACT_URLS).isArray();
    LightArray<ContactField> urls = getContactFieldsForArray(urlsArray);
    contact.setUrls(urls);
    ContactName name = getName(jsonContact.get(CONTACT_NAME).isObject());
    contact.setName(name);
    LightArray<ContactAddress> addresses = getAddressArray(jsonContact.get(CONTACT_ADDRESSES).isArray());
    contact.setContactAddresses(addresses);
    LightArray<ContactOrganisation> organisations = getContactOrganisationArray(jsonContact.get(CONTACT_ORGANISATION).isArray());
    contact.setOrganisations(organisations);
    return contact;
}
Also used : JSONValue(com.google.gwt.json.client.JSONValue) ContactAddress(com.googlecode.gwtphonegap.client.contacts.ContactAddress) JSONArray(com.google.gwt.json.client.JSONArray) ContactField(com.googlecode.gwtphonegap.client.contacts.ContactField) ContactName(com.googlecode.gwtphonegap.client.contacts.ContactName) Date(java.util.Date) ContactOrganisation(com.googlecode.gwtphonegap.client.contacts.ContactOrganisation)

Example 2 with JSONValue

use of com.google.gwt.json.client.JSONValue in project gwtphonegap by dankurka.

the class ContactsBrowserImpl method loadContactsFromStorage.

protected LightMap<Contact> loadContactsFromStorage() {
    LightMap<Contact> map = CollectionFactory.constructMap();
    String item = storage.getItem("gwtphonegap-contact-emulation");
    if (item == null) {
        return map;
    }
    JSONValue parsed = JSONParser.parseStrict(item);
    JSONObject root = parsed.isObject();
    if (root == null) {
        return map;
    } else {
        Set<String> set = root.keySet();
        for (String key : set) {
            JSONObject jsonContact = root.get(key).isObject();
            Contact contact = parseContact(jsonContact);
            map.put(contact.getId(), contact);
        }
    }
    return map;
}
Also used : JSONValue(com.google.gwt.json.client.JSONValue) JSONObject(com.google.gwt.json.client.JSONObject) Contact(com.googlecode.gwtphonegap.client.contacts.Contact)

Example 3 with JSONValue

use of com.google.gwt.json.client.JSONValue in project che by eclipse.

the class EditorPropertiesManager method getJsonEditorProperties.

/** Returns saved settings for editor in json format if they exist or default settings otherwise. */
public JSONObject getJsonEditorProperties() {
    JSONObject jsonProperties = new JSONObject();
    Map<String, JSONValue> editorProperties = getEditorProperties();
    for (String property : editorProperties.keySet()) {
        jsonProperties.put(property, editorProperties.get(property));
    }
    return jsonProperties;
}
Also used : JSONValue(com.google.gwt.json.client.JSONValue) JSONObject(com.google.gwt.json.client.JSONObject)

Example 4 with JSONValue

use of com.google.gwt.json.client.JSONValue in project che by eclipse.

the class EditorPropertiesSectionPresenter method addProperties.

private void addProperties() {
    Map<String, JSONValue> editorProperties = editorPropertiesManager.getEditorProperties();
    for (String property : properties) {
        JSONValue value = editorProperties.get(property);
        view.addProperty(property, value);
    }
}
Also used : JSONValue(com.google.gwt.json.client.JSONValue)

Example 5 with JSONValue

use of com.google.gwt.json.client.JSONValue in project che by eclipse.

the class EditorPropertiesSectionPresenter method storeChanges.

@Override
public void storeChanges() {
    Map<String, JSONValue> editorProperties = editorPropertiesManager.getEditorProperties();
    for (String property : editorProperties.keySet()) {
        JSONValue actualValue = view.getPropertyValueById(property);
        actualValue = actualValue != null ? actualValue : editorProperties.get(property);
        editorProperties.put(property, actualValue);
    }
    editorPropertiesManager.storeEditorProperties(editorProperties);
    eventBus.fireEvent(new EditorSettingsChangedEvent());
}
Also used : JSONValue(com.google.gwt.json.client.JSONValue) EditorSettingsChangedEvent(org.eclipse.che.ide.api.event.EditorSettingsChangedEvent)

Aggregations

JSONValue (com.google.gwt.json.client.JSONValue)23 JSONObject (com.google.gwt.json.client.JSONObject)13 JSONArray (com.google.gwt.json.client.JSONArray)10 JSONString (com.google.gwt.json.client.JSONString)8 HashMap (java.util.HashMap)5 Date (java.util.Date)4 JSONNumber (com.google.gwt.json.client.JSONNumber)3 EntryPoint (com.google.gwt.core.client.EntryPoint)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 RequestBuilder (com.google.gwt.http.client.RequestBuilder)2 RequestCallback (com.google.gwt.http.client.RequestCallback)2 RequestException (com.google.gwt.http.client.RequestException)2 InlineLabel (com.google.gwt.user.client.ui.InlineLabel)2 StringCallback (com.gwtmobile.phonegap.client.plugins.Bluetooth.StringCallback)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 JsArrayString (com.google.gwt.core.client.JsArrayString)1 Style (com.google.gwt.dom.client.Style)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1