songstock.web.extensions.purchasehistory.PurchaseHistoryView.java Source code

Java tutorial

Introduction

Here is the source code for songstock.web.extensions.purchasehistory.PurchaseHistoryView.java

Source

/**
* Copyright  2013 Universidad Icesi
* 
* This file is part of SongStock.
* 
* SongStock is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* SongStock is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with SongStock.  If not, see <http://www.gnu.org/licenses/>.
**/
package songstock.web.extensions.purchasehistory;

import java.util.List;

import sales.dtos.IItem;

import com.vaadin.annotations.AutoGenerated;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Label;
import com.vaadin.ui.Table;

/**
 * 
 * @author Andrs Paz
 *
 */
public class PurchaseHistoryView extends CustomComponent {

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    @AutoGenerated
    private AbsoluteLayout mainLayout;

    @AutoGenerated
    private Table tablePurchaseHistory;

    @AutoGenerated
    private Label labelTitle;

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public static final String PURCHASE_HISTORY_VIEW = "purchaseHistoryView";

    /**
     * The constructor should first build the main layout, set the
     * composition root and then do any custom initialization.
     *
     * The constructor will not be automatically regenerated by the
     * visual editor.
     */
    public PurchaseHistoryView() {
        buildMainLayout();
        setCompositionRoot(mainLayout);

        // User code
        tablePurchaseHistory.addContainerProperty("Name", String.class, null);
        tablePurchaseHistory.addContainerProperty("Artist", String.class, null);
        tablePurchaseHistory.addContainerProperty("Type", String.class, null);
        tablePurchaseHistory.addContainerProperty("Price", Double.class, null);

        // Allow selecting items from the table.
        tablePurchaseHistory.setSelectable(true);

        // Send changes in selection immediately to server.
        tablePurchaseHistory.setImmediate(true);
    }

    public void loadItems(List<IItem> items) {
        tablePurchaseHistory.removeAllItems();
        if (items != null) {
            for (IItem item : items) {
                tablePurchaseHistory.addItem(
                        new Object[] { item.getName(), item.getArtist(), item.getType(), item.getPrice() }, item);
            }
        }
    }

    @AutoGenerated
    private AbsoluteLayout buildMainLayout() {
        // common part: create layout
        mainLayout = new AbsoluteLayout();
        mainLayout.setImmediate(false);
        mainLayout.setWidth("100%");
        mainLayout.setHeight("100%");

        // top-level component properties
        setWidth("100.0%");
        setHeight("100.0%");

        // labelTitle
        labelTitle = new Label();
        labelTitle.setImmediate(false);
        labelTitle.setWidth("-1px");
        labelTitle.setHeight("-1px");
        labelTitle.setValue("<b>Purchase History</b>");
        labelTitle.setContentMode(com.vaadin.shared.ui.label.ContentMode.HTML);
        mainLayout.addComponent(labelTitle, "top:20.0px;left:20.0px;");

        // tablePurchaseHistory
        tablePurchaseHistory = new Table();
        tablePurchaseHistory.setImmediate(false);
        tablePurchaseHistory.setWidth("100.0%");
        tablePurchaseHistory.setHeight("100.0%");
        mainLayout.addComponent(tablePurchaseHistory, "top:60.0px;right:20.0px;bottom:20.0px;left:20.0px;");

        return mainLayout;
    }

}