javaquery/demo-twitter/src/main/java/org/apidesign/bck2brwsr/demo/twitter/TwitterClient.java
branchmodel
changeset 947 26f7eeb81aec
parent 931 9a7df12648b9
child 948 35f4f8af296c
     1.1 --- a/javaquery/demo-twitter/src/main/java/org/apidesign/bck2brwsr/demo/twitter/TwitterClient.java	Thu Apr 04 13:12:17 2013 +0200
     1.2 +++ b/javaquery/demo-twitter/src/main/java/org/apidesign/bck2brwsr/demo/twitter/TwitterClient.java	Sun Apr 07 22:32:41 2013 +0200
     1.3 @@ -33,7 +33,7 @@
     1.4      @Property(name="activeTweetersName", type=String.class),
     1.5      @Property(name="modifiedList", type=TwitterClient.Twttrs.class),
     1.6      @Property(name="userNameToAdd", type=String.class),
     1.7 -    @Property(name="currentTweets", type=String.class, array = true)
     1.8 +    @Property(name="currentTweets", type=TwitterClient.Twt.class, array = true)
     1.9  })
    1.10  public class TwitterClient {
    1.11      @Model(className = "Tweeters", properties = {
    1.12 @@ -42,6 +42,41 @@
    1.13      })
    1.14      static class Twttrs {
    1.15      }
    1.16 +    @Model(className = "Tweet", properties = {
    1.17 +        @Property(name = "from_user", type = String.class),
    1.18 +        @Property(name = "from_user_id", type = int.class),
    1.19 +        @Property(name = "profile_image_url", type = String.class),
    1.20 +        @Property(name = "text", type = String.class),
    1.21 +        
    1.22 +    })
    1.23 +    static final class Twt {
    1.24 +    }
    1.25 +    @Model(className = "TwitterQuery", properties = {
    1.26 +        @Property(array = true, name = "results", type = Twt.class)
    1.27 +    })
    1.28 +    public static final class TwttrQr {
    1.29 +    }
    1.30 +    
    1.31 +    @OnReceive(url="{url}")
    1.32 +    static void queryTweets(TwitterModel page, TwitterQuery q) {
    1.33 +        page.getCurrentTweets().clear();
    1.34 +        page.getCurrentTweets().addAll(q.getResults());
    1.35 +    }
    1.36 +    
    1.37 +    @OnFunction
    1.38 +    static void refreshTweets(TwitterModel model) {
    1.39 +        Tweeters people = model.getActiveTweeters();
    1.40 +        StringBuilder sb = new StringBuilder();
    1.41 +        sb.append("http://search.twitter.com/search.json?callback=?&rpp=25&q=");
    1.42 +        String sep = "";
    1.43 +        for (String p : people.getUserNames()) {
    1.44 +            sb.append(sep);
    1.45 +            sb.append("from:");
    1.46 +            sb.append(p);
    1.47 +            sep = " OR ";
    1.48 +        }
    1.49 +        model.queryTweets(sb.toString());
    1.50 +    }
    1.51      
    1.52      private static Tweeters tweeters(String listName, String... userNames) {
    1.53          Tweeters t = new Tweeters();
    1.54 @@ -60,7 +95,7 @@
    1.55          svdLst.add(tweeters("Tech pundits", "Scobleizer", "LeoLaporte", "techcrunch", "BoingBoing", "timoreilly", "codinghorror"));
    1.56  
    1.57          model.setActiveTweetersName("NetBeans");
    1.58 -        
    1.59 +
    1.60          model.applyBindings();
    1.61      }
    1.62