com.save.client.promodeals.PDDataContainer.java Source code

Java tutorial

Introduction

Here is the source code for com.save.client.promodeals.PDDataContainer.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.save.client.promodeals;

import com.save.model.PromoDeals;
import com.save.service.ClientService;
import com.save.service.PromoDealService;
import com.save.serviceprovider.ClientServiceImpl;
import com.save.serviceprovider.PromoDealServiceImpl;
import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.server.FontAwesome;

/**
 *
 * @author jetdario
 */
public class PDDataContainer extends IndexedContainer {

    ClientService cs = new ClientServiceImpl();
    PromoDealService pds = new PromoDealServiceImpl();
    private int clientId;

    public PDDataContainer(int clientId) {
        this.clientId = clientId;

        addContainerProperty("sn", Integer.class, null);
        addContainerProperty("promo items", String.class, null);
        addContainerProperty("amount", Double.class, null);
        addContainerProperty("quantity", Double.class, null);
        addContainerProperty("product", String.class, null);
        addContainerProperty("view", String.class, null);
        addContainerProperty("edit", String.class, null);
        addContainerProperty("del", String.class, null);

        for (PromoDeals p : pds.getPromoDealsByClientId(getClientId())) {
            Item item = getItem(addItem());
            item.getItemProperty("sn").setValue(p.getPromoId());
            item.getItemProperty("promo items").setValue(p.getPromoItem());
            item.getItemProperty("amount").setValue(p.getPromoAmount());
            item.getItemProperty("quantity").setValue(p.getQuantity());
            item.getItemProperty("product").setValue(p.getProductItem());
            item.getItemProperty("view").setValue(FontAwesome.PRINT.getHtml());
            item.getItemProperty("edit").setValue(FontAwesome.PENCIL.getHtml());
            item.getItemProperty("del").setValue(FontAwesome.TRASH_O.getHtml());
        }
    }

    int getClientId() {
        return clientId;
    }
}