Example usage for com.google.gwt.core.client JsArrayString get

List of usage examples for com.google.gwt.core.client JsArrayString get

Introduction

In this page you can find the example usage for com.google.gwt.core.client JsArrayString get.

Prototype

public final native String get(int index) ;

Source Link

Document

Gets the value at a given index.

Usage

From source file:com.google.mobile.trippy.web.client.db.JsoTripItem.java

License:Apache License

public final ArrayList<String> getPhoneNumbers() {
    ArrayList<String> parr = new ArrayList<String>();
    JsArrayString jarr = getPhoneNumbers_();
    for (int i = 0; i < jarr.length(); ++i) {
        parr.add(jarr.get(i));
    }//from  w  ww.j a v  a 2s  .c  o m
    return parr;
}

From source file:com.google.mobile.trippy.web.client.db.LocalDbManager.java

License:Apache License

/**
 * Get trips from main index./*from   w  w  w  .java 2s.co  m*/
 */
public ArrayList<Trip> getTrips() {
    JsArrayString tripKeys = getIndexKeys(KEY_LOCAL_STORE_TRIPS);
    ArrayList<Trip> trips = new ArrayList<Trip>();
    for (int i = 0; i < tripKeys.length(); ++i) {
        trips.add(getTripForKey(tripKeys.get(i)));
    }
    return trips;
}

From source file:com.google.mobile.trippy.web.client.db.LocalDbManager.java

License:Apache License

public void addTrip(final Trip trip) {
    JsoTrip jsoTrip = (JsoTrip) JavaScriptObject.createObject();
    jsoTrip.setTrip(trip);/*from  ww w .  j  a  va 2s . c om*/
    final String tripKey = KEY_LOCAL_STORE_TRIP_PREFIX + trip.getKey();
    LocalDbService.makePersistent(tripKey, new JSONObject(jsoTrip).toString());
    final JsArrayString tripKeys = getIndexKeys(KEY_LOCAL_STORE_TRIPS);
    for (int i = 0; i < tripKeys.length(); ++i) {
        if (tripKeys.get(i).equals(tripKey)) {
            return;
        }
    }
    tripKeys.push(tripKey);
    setIndexKeys(KEY_LOCAL_STORE_TRIPS, tripKeys);
    eventBus.fireEvent(new TripAddedEvent(trip));
}

From source file:com.google.mobile.trippy.web.client.db.LocalDbManager.java

License:Apache License

public void deleteTrip(final Trip trip) {
    final String tripKey = KEY_LOCAL_STORE_TRIP_PREFIX + trip.getKey();
    LocalDbService.deletePersistent(tripKey);
    final JsArrayString tripKeys = getIndexKeys(KEY_LOCAL_STORE_TRIPS);
    final JsArrayString newTripKeys = (JsArrayString) JavaScriptObject.createArray();
    for (int i = 0; i < tripKeys.length(); ++i) {
        if (!tripKeys.get(i).equals(tripKey)) {
            newTripKeys.push(tripKeys.get(i));
        }// ww w.j a v  a  2  s.  com
    }
    setIndexKeys(KEY_LOCAL_STORE_TRIPS, newTripKeys);
    eventBus.fireEvent(new TripDeletedEvent(trip));
}

From source file:com.google.mobile.trippy.web.client.db.LocalDbManager.java

License:Apache License

public void addTripItem(final TripItem tripItem) {
    JsoTripItem jsoTripItem = (JsoTripItem) JavaScriptObject.createObject();
    jsoTripItem.setTripItem(tripItem);//w w  w  . j  a v  a 2 s.  co m
    final String tripItemKey = KEY_LOCAL_STORE_TI_PREFIX + tripItem.getKey();
    LocalDbService.makePersistent(tripItemKey, new JSONObject(jsoTripItem).toString());
    final JsArrayString tripItemKeys = getIndexKeys(KEY_LOCAL_STORE_TIS_PREFIX + tripItem.getTripId());
    for (int i = 0; i < tripItemKeys.length(); ++i) {
        if (tripItemKeys.get(i).equals(tripItemKey)) {
            return;
        }
    }
    tripItemKeys.push(tripItemKey);
    setIndexKeys(KEY_LOCAL_STORE_TIS_PREFIX + tripItem.getTripId(), tripItemKeys);
    eventBus.fireEvent(new TripItemAddedEvent(tripItem));
    final Trip trip = getTrip(tripItem.getTripId());
    final String tripItemStartDate = "Day " + tripItem.getStartDay();
    final String latlng = tripItem.getLatitude() + "," + tripItem.getLongitude();
    utils.addTripItem(tripItemStartDate, tripItem.getTripId(), tripItem.getKey(), tripItem.getName(),
            tripItem.getAddress() + ", " + trip.getLocation(), latlng,
            utils.getTripItemPosition(tripItem.getTripId(), tripItem.getKey(), tripItem.getStartDay()));
}

From source file:com.google.mobile.trippy.web.client.db.LocalDbManager.java

License:Apache License

public void deleteTripItem(final String tripId, final String tripItemId) {
    final TripItem tripItem = getTripItem(tripItemId);
    final String tripItemKey = KEY_LOCAL_STORE_TI_PREFIX + tripItemId;
    LocalDbService.deletePersistent(tripItemKey);
    final JsArrayString tripItemKeys = getIndexKeys(KEY_LOCAL_STORE_TIS_PREFIX + tripId);
    final JsArrayString newTripItemKeys = (JsArrayString) JavaScriptObject.createArray();
    for (int i = 0; i < tripItemKeys.length(); ++i) {
        if (!tripItemKeys.get(i).equals(tripItemKey)) {
            newTripItemKeys.push(tripItemKeys.get(i));
        }/*from   w  w  w .  jav a  2  s. c  o  m*/
    }
    setIndexKeys(KEY_LOCAL_STORE_TIS_PREFIX + tripId, newTripItemKeys);
    eventBus.fireEvent(new TripItemDeletedEvent(tripItem));
    utils.remTripItem(tripItemId);
}

From source file:com.google.mobile.trippy.web.client.db.LocalDbManager.java

License:Apache License

/**
 * Get trip items from main index./*w  w  w .  j  av a  2s .c  om*/
 */
public ArrayList<TripItem> getTripItems(final String tripId) {
    final JsArrayString tripItemKeys = getIndexKeys(KEY_LOCAL_STORE_TIS_PREFIX + tripId);
    final ArrayList<TripItem> tripItems = new ArrayList<TripItem>();
    for (int i = 0; i < tripItemKeys.length(); ++i) {
        final TripItem tripItem = getTripItemForKey(tripItemKeys.get(i));
        if (tripItem != null && tripItem.getStatus().equals(Status.ACTIVE)) {
            tripItems.add(tripItem);
        }
    }
    return tripItems;
}

From source file:com.google.mobile.trippy.web.client.db.LocalDbManager.java

License:Apache License

public ArrayList<String> getTripItemIds() {
    final JsArrayString keys = getIndexKeys(KEY_LOCAL_STORE_TIS_PREFIX);
    final ArrayList<String> ids = new ArrayList<String>();
    for (int i = 0; i < keys.length(); ++i) {
        final String key = keys.get(i);
        final String id = key.replace(KEY_LOCAL_STORE_TI_PREFIX, "");
        ids.add(id);//from   w w w  . j  a v a  2 s.co m
    }
    return ids;
}

From source file:com.google.mobile.trippy.web.client.db.LocalDbManager.java

License:Apache License

public void addComment(final Comment comment) {
    final JsoComment jsoComment = (JsoComment) JavaScriptObject.createObject();
    jsoComment.setComment(comment);//from  ww w .  java  2s  .  com
    final String commentKey = KEY_LOCAL_STORE_COMMENT_PREFIX + comment.getKey();
    LocalDbService.makePersistent(commentKey, new JSONObject(jsoComment).toString());
    final JsArrayString commentKeys = getIndexKeys(
            KEY_LOCAL_STORE_COMMENTS_PREFIX + comment.getTripId() + "_" + comment.getTripItemId());
    for (int i = 0; i < commentKeys.length(); ++i) {
        if (commentKeys.get(i).equals(commentKey)) {
            return;
        }
    }
    commentKeys.push(commentKey);
    setIndexKeys(KEY_LOCAL_STORE_COMMENTS_PREFIX + comment.getTripId() + "_" + comment.getTripItemId(),
            commentKeys);
    eventBus.fireEvent(new CommentAddedEvent(comment));
}

From source file:com.google.mobile.trippy.web.client.db.LocalDbManager.java

License:Apache License

public void deleteComment(final String tripId, final String tripItemId, final String commentId) {
    final Comment comment = getComment(commentId);
    final String commentKey = KEY_LOCAL_STORE_COMMENT_PREFIX + commentId;
    LocalDbService.deletePersistent(commentKey);
    final JsArrayString commentKeys = getIndexKeys(KEY_LOCAL_STORE_COMMENTS_PREFIX + tripId + "_" + tripItemId);
    final JsArrayString newCommentKeys = (JsArrayString) JavaScriptObject.createArray();
    for (int i = 0; i < commentKeys.length(); ++i) {
        if (!commentKeys.get(i).equals(commentKey)) {
            newCommentKeys.push(commentKeys.get(i));
        }//from w ww  .j a  va2 s .  co m
    }
    setIndexKeys(KEY_LOCAL_STORE_COMMENTS_PREFIX + tripId + "_" + tripItemId, newCommentKeys);
    eventBus.fireEvent(new CommentDeletedEvent(comment));
}