chess/src/main/java/org/apidesign/html/demo/chess/GamesModel.java
branchchess
changeset 52 6bb4070d2c20
parent 51 3f1866fdb2a1
     1.1 --- a/chess/src/main/java/org/apidesign/html/demo/chess/GamesModel.java	Tue Sep 24 22:37:17 2013 +0200
     1.2 +++ b/chess/src/main/java/org/apidesign/html/demo/chess/GamesModel.java	Tue Sep 24 23:52:32 2013 +0200
     1.3 @@ -23,10 +23,8 @@
     1.4   */
     1.5  package org.apidesign.html.demo.chess;
     1.6  
     1.7 -import java.util.List;
     1.8  import net.java.html.json.ComputedProperty;
     1.9  import net.java.html.json.Model;
    1.10 -import net.java.html.json.ModelOperation;
    1.11  import net.java.html.json.Property;
    1.12  
    1.13  /**
    1.14 @@ -34,53 +32,15 @@
    1.15   * @author Jaroslav Tulach <jtulach@netbeans.org>
    1.16   */
    1.17  @Model(className = "Games", properties = {
    1.18 -    @Property(name = "own", array = true, type = Game.class),
    1.19 -    @Property(name = "other", array = true, type = Game.class),
    1.20 +    @Property(name = "whitePlayer", type = String.class),
    1.21 +    @Property(name = "blackPlayer", type = String.class),
    1.22      @Property(name = "selectedColor", type = String.class),
    1.23  })
    1.24  class GamesModel {
    1.25 -    @Model(className = "Game", properties = {
    1.26 -        @Property(name = "gameId", type=String.class),
    1.27 -        @Property(name = "summary", type=String.class),
    1.28 -        @Property(name = "open", type=boolean.class),
    1.29 -        @Property(name = "whitePlayer", type=String.class),
    1.30 -        @Property(name = "blackPlayer", type=String.class)
    1.31 -    })
    1.32 -    static class GameImpl {
    1.33 -        @ComputedProperty static String description(String gameId, String summary) {
    1.34 -            return summary != null ? summary : gameId;
    1.35 -        }
    1.36 -        
    1.37 -        @ComputedProperty static boolean pendingPlayer(String whitePlayer, String blackPlayer) {
    1.38 -            return whitePlayer == null || blackPlayer == null;
    1.39 -        }
    1.40 -    }
    1.41 -    
    1.42 -    
    1.43 -    @ComputedProperty static boolean anyOwnGame(List<Game> own) {
    1.44 -        return !own.isEmpty();
    1.45 -    }
    1.46 -
    1.47 -    @ComputedProperty static boolean anyOtherGame(List<Game> other) {
    1.48 -        return !other.isEmpty();
    1.49 -    }
    1.50 -    
    1.51 -    @ModelOperation static void listGames(Games g, List<Game> games, String username) {
    1.52 -        g.getOwn().clear();
    1.53 -        g.getOther().clear();
    1.54 -        int cnt = 0;
    1.55 -        final int maxGames = 30;
    1.56 -        for (Game game : games) {
    1.57 -            if (
    1.58 -                username.equals(game.getWhitePlayer()) || 
    1.59 -                username.equals(game.getBlackPlayer())
    1.60 -            ) {
    1.61 -                g.getOwn().add(game);
    1.62 -            } else {
    1.63 -                if (cnt++ < maxGames) {
    1.64 -                    g.getOther().add(game);
    1.65 -                }
    1.66 -            }
    1.67 -        }
    1.68 +    @ComputedProperty static boolean correctNames(
    1.69 +        String whitePlayer, String blackPlayer
    1.70 +    ) {
    1.71 +        return whitePlayer != null && blackPlayer != null && !whitePlayer.isEmpty() &&
    1.72 +            !blackPlayer.isEmpty();
    1.73      }
    1.74  }