Subversion Repositories SmartDukaan

Rev

Rev 2359 | Rev 2489 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2359 Rev 2427
Line 1... Line 1...
1
package in.shop2020.catalog.dashboard.client;
1
package in.shop2020.catalog.dashboard.client;
2
 
2
 
3
import in.shop2020.catalog.dashboard.shared.Item;
3
import in.shop2020.catalog.dashboard.shared.Item;
4
 
4
 
5
import java.util.ArrayList;
-
 
6
import java.util.HashMap;
-
 
7
import java.util.List;
5
import java.util.List;
8
import java.util.Map;
-
 
9
 
6
 
10
import com.google.gwt.core.client.GWT;
7
import com.google.gwt.core.client.GWT;
11
import com.google.gwt.event.dom.client.ClickEvent;
8
import com.google.gwt.event.dom.client.ClickEvent;
12
import com.google.gwt.resources.client.CssResource;
9
import com.google.gwt.resources.client.CssResource;
13
import com.google.gwt.uibinder.client.UiBinder;
10
import com.google.gwt.uibinder.client.UiBinder;
Line 18... Line 15...
18
import com.google.gwt.user.client.ui.FlexTable;
15
import com.google.gwt.user.client.ui.FlexTable;
19
import com.google.gwt.user.client.ui.HTMLTable.Cell;
16
import com.google.gwt.user.client.ui.HTMLTable.Cell;
20
import com.google.gwt.user.client.ui.ResizeComposite;
17
import com.google.gwt.user.client.ui.ResizeComposite;
21
import com.google.gwt.user.client.ui.Widget;
18
import com.google.gwt.user.client.ui.Widget;
22
 
19
 
-
 
20
/**
-
 
21
 * List of items. List contains item Id, product group, brand, model number, model name, color and category
-
 
22
 * Dashboard user can select an item in this list and its details are shown in ItemDetails widget.
-
 
23
 *
-
 
24
 */
23
public class ItemList extends ResizeComposite{
25
public class ItemList extends ResizeComposite{
24
 
26
 
25
    public static final int VISIBLE_ITEMS_COUNT = 10;
-
 
26
    
-
 
27
    private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
27
    private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
28
    
28
    
29
    interface ItemListUiBinder extends UiBinder<Widget, ItemList> { }
29
    interface ItemListUiBinder extends UiBinder<Widget, ItemList> { }
30
    private static final ItemListUiBinder uiBinder = GWT.create(ItemListUiBinder.class);
30
    private static final ItemListUiBinder uiBinder = GWT.create(ItemListUiBinder.class);
31
    
31
    
Line 37... Line 37...
37
    @UiField FlexTable header;
37
    @UiField FlexTable header;
38
    @UiField FlexTable itemDescriptionTable;
38
    @UiField FlexTable itemDescriptionTable;
39
    @UiField SelectionStyle selectionStyle;
39
    @UiField SelectionStyle selectionStyle;
40
    private int selectedRow = -1;
40
    private int selectedRow = -1;
41
    
41
    
42
    private HashMap map;
-
 
43
    private List<Item> items;
-
 
44
    
-
 
45
    private ItemDetails itemDetails;
42
    private ItemDetails itemDetails;
46
    
43
    
47
    public ItemList() {
44
    public ItemList() {
48
        initWidget(uiBinder.createAndBindUi(this));
45
        initWidget(uiBinder.createAndBindUi(this));
49
        initHeader();
46
        initHeader();
Line 51... Line 48...
51
    }
48
    }
52
    
49
    
53
    private void initItemList() {
50
    private void initItemList() {
54
        loadAllRiskyItems();
51
        loadAllRiskyItems();
55
        
52
        
-
 
53
        /*For testing
56
        //loadDummyItems();
54
        loadDummyItems();
57
        //updateItemDescriptionTable(items);
55
        updateItemDescriptionTable(items);
-
 
56
        */
58
    }
57
    }
59
    
58
    
-
 
59
    /**
-
 
60
     * Initialise header of item list table.
-
 
61
     */
60
    private void initHeader(){
62
    private void initHeader(){
61
        // Initialize the header.
-
 
62
        header.getColumnFormatter().setWidth(0, "80px");
63
        header.getColumnFormatter().setWidth(0, "80px");
63
        header.getColumnFormatter().setWidth(1, "128px");
64
        header.getColumnFormatter().setWidth(1, "128px");
64
        header.getColumnFormatter().setWidth(2, "150px");
65
        header.getColumnFormatter().setWidth(2, "150px");
65
        header.getColumnFormatter().setWidth(3, "200px");
66
        header.getColumnFormatter().setWidth(3, "200px");
66
        header.getColumnFormatter().setWidth(4, "200px");
67
        header.getColumnFormatter().setWidth(4, "200px");
Line 86... Line 87...
86
        itemDescriptionTable.getColumnFormatter().setWidth(5, "128px");
87
        itemDescriptionTable.getColumnFormatter().setWidth(5, "128px");
87
        itemDescriptionTable.getColumnFormatter().setWidth(6, "220px");
88
        itemDescriptionTable.getColumnFormatter().setWidth(6, "220px");
88
        
89
        
89
        int i=0;
90
        int i=0;
90
        for(final Item item : items){
91
        for(final Item item : items){
91
            //itemsMap.put(item.getId(), item);
-
 
92
            int col = 0;
92
            int col = 0;
93
            itemDescriptionTable.setText(i, col++, item.getId() + "");
93
            itemDescriptionTable.setText(i, col++, item.getId() + "");
94
            itemDescriptionTable.setText(i, col++, item.getProductGroup());
94
            itemDescriptionTable.setText(i, col++, item.getProductGroup());
95
            itemDescriptionTable.setText(i, col++, item.getBrand());
95
            itemDescriptionTable.setText(i, col++, item.getBrand());
96
            itemDescriptionTable.setText(i, col++, item.getModelNumber());
96
            itemDescriptionTable.setText(i, col++, item.getModelNumber());
Line 99... Line 99...
99
            itemDescriptionTable.setText(i, col++, item.getContentCategory()+"");
99
            itemDescriptionTable.setText(i, col++, item.getContentCategory()+"");
100
            i++;
100
            i++;
101
        }
101
        }
102
    }
102
    }
103
    
103
    
-
 
104
    /**
-
 
105
     * On click of an item in the list, a fresh call is made to the service to fetch item details, vendor prices
-
 
106
     * and vendor item keys. The item object is then passed to ItemDetails to set the values in UI fields 
-
 
107
     * @param event
-
 
108
     */
104
    @UiHandler("itemDescriptionTable")
109
    @UiHandler("itemDescriptionTable")
105
    void onClick(ClickEvent event) {
110
    void onClick(ClickEvent event) {
106
 
111
 
107
        Cell cell = itemDescriptionTable.getCellForEvent(event);
112
        Cell cell = itemDescriptionTable.getCellForEvent(event);
108
        int newRowIndex = cell.getRowIndex();
113
        int newRowIndex = cell.getRowIndex();
Line 129... Line 134...
129
            
134
            
130
        itemDescriptionTable.getRowFormatter().addStyleName(row, style);
135
        itemDescriptionTable.getRowFormatter().addStyleName(row, style);
131
        selectedRow = row;
136
        selectedRow = row;
132
    }
137
    }
133
    
138
    
-
 
139
    /* For testing
-
 
140
      private HashMap map;
-
 
141
      private List<Item> items;
134
    private void loadDummyItems() {
142
      private void loadDummyItems() {
135
        
-
 
136
        Item i = new Item(1, "Handset", "Spice", "mi310", "phone", "White", "Business Phone",1, "comments", 1, 1, 
143
        Item i = new Item(1, "Handset", "Spice", "mi310", "phone", "White", "Business Phone",1, "comments", 1, 1, 
137
                "", 3000.50, 3000.00, 3000, 3000, 12, 12345, 12345, 12345, 12345, "ACTIVE", 1, "This item is active",
144
                "", 3000.50, 3000.00, 3000, 3000, 12, 12345, 12345, 12345, 12345, "ACTIVE", 1, "This item is active",
138
                null, "best", 2990, 1, true, true, null, null, null);
145
                null, "best", 2990, 1, true, true, null, null, null);
139
        List<Item> items = new ArrayList<Item>();
146
        List<Item> items = new ArrayList<Item>();
140
        items.add(i);
147
        items.add(i);
141
        this.items = items;
148
        this.items = items;
142
        //itemsMap.put(i.getId(), i);
149
        //itemsMap.put(i.getId(), i);
143
        
150
    }*/
144
    }
151
    
145
    
152
    
146
    public void loadAllItems() {
153
    public void loadAllItems() {
147
        catalogService.getAllItems(new AsyncCallback<List<Item>>() {
154
        catalogService.getAllItems(new AsyncCallback<List<Item>>() {
148
            public void onFailure(Throwable caught) {
155
            public void onFailure(Throwable caught) {
149
                caught.printStackTrace();
156
                caught.printStackTrace();
Line 264... Line 271...
264
    }
271
    }
265
 
272
 
266
    public void setItemDetails(ItemDetails itemDetails) {
273
    public void setItemDetails(ItemDetails itemDetails) {
267
        this.itemDetails = itemDetails;
274
        this.itemDetails = itemDetails;
268
    }
275
    }
269
    
-
 
270
}
276
}