Ejemplo n.º 1
0
 /** Creates a new category, sending it to the server and adding it to the model. */
 public void createCategory(String name, int parentId, AsyncCallback<Category> callback) {
   final Category cat = new Category();
   cat.name = name;
   cat.parentId = parentId;
   cat.creator = _ctx.getMe();
   Function<Integer, Category> toCat =
       new Function<Integer, Category>() {
         public Category apply(Integer catId) {
           cat.categoryId = catId;
           return cat;
         }
       };
   Function<Category, Void> addCatOp =
       new Function<Category, Void>() {
         public Void apply(Category cat) {
           List<Category> cats = _catmap.get(cat.parentId);
           if (cats == null) {
             _catmap.put(cat.parentId, cats = new ArrayList<Category>());
           }
           cats.add(cat);
           return null;
         }
       };
   _editorsvc.createCategory(cat, Callbacks.map(Callbacks.before(callback, addCatOp), toCat));
 }