next.celebs.controller.FavoritesController.java Source code

Java tutorial

Introduction

Here is the source code for next.celebs.controller.FavoritesController.java

Source

/*
 * Copyright 2011 Vancouver Ywebb Consulting Ltd
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package next.celebs.controller;

import next.celebs.Context;
import next.celebs.di.UiGinjector;
import next.celebs.model.Photo;
import next.i.controller.XController;
import next.i.view.MPanelBase;

import com.google.gwt.dom.client.Style;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.IsWidget;

public class FavoritesController extends XController {

    private final static Context ctx = UiGinjector.INSTANCE.getCtx();
    private PhotoDragController dragController;

    public FavoritesController() {
        setTitle("Favorites");
    }

    private void doGetPhotos(FlowPanel imgpanel) {

        for (String id : ctx.getFavorites().keySet()) {
            final Photo p = ctx.getFavorites().get(id);

            Image img = new Image(p.getThumbUrl());
            img.setStyleName("yThumb");

            img.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    dragController = new PhotoDragController(getTitle(), p, true);
                    getNavigationController().pushController(dragController, true);
                }
            });
            imgpanel.add(img);
        }
    }

    public void reload() {
        ((MPanelBase) getView()).remove(0);
        ((MPanelBase) getView()).add(getViewContent().asWidget());
    }

    @Override
    public IsWidget getViewContent() {
        FlowPanel panel = new FlowPanel() {
            @Override
            protected void onLoad() {
                super.onLoad();
                this.clear();
                doGetPhotos(this);
            }

        };
        Style s = panel.getElement().getStyle();
        s.setProperty("backgroundColor", "#fff");
        s.setProperty("padding", "1em");

        return panel;
    }

    @Override
    public Scroll getScrollOrientation() {
        return XController.Scroll.VERTICAL;
    }

}