Subversion Repositories SmartDukaan

Rev

Rev 2427 | Rev 3524 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1961 ankur.sing 1
package in.shop2020.catalog.dashboard.client;
2
 
3
import in.shop2020.catalog.dashboard.shared.Item;
4
 
5
import java.util.List;
6
 
7
import com.google.gwt.core.client.GWT;
8
import com.google.gwt.event.dom.client.ClickEvent;
9
import com.google.gwt.resources.client.CssResource;
10
import com.google.gwt.uibinder.client.UiBinder;
11
import com.google.gwt.uibinder.client.UiField;
12
import com.google.gwt.uibinder.client.UiHandler;
13
import com.google.gwt.user.client.Window;
14
import com.google.gwt.user.client.rpc.AsyncCallback;
15
import com.google.gwt.user.client.ui.FlexTable;
16
import com.google.gwt.user.client.ui.HTMLTable.Cell;
2489 ankur.sing 17
import com.google.gwt.user.client.ui.Label;
1961 ankur.sing 18
import com.google.gwt.user.client.ui.ResizeComposite;
19
import com.google.gwt.user.client.ui.Widget;
20
 
2427 ankur.sing 21
/**
22
 * List of items. List contains item Id, product group, brand, model number, model name, color and category
23
 * Dashboard user can select an item in this list and its details are shown in ItemDetails widget.
24
 *
25
 */
1961 ankur.sing 26
public class ItemList extends ResizeComposite{
27
 
2489 ankur.sing 28
    private static final int INDEX_ID = 0, 
29
                             INDEX_PRODUCT_GROUP = 1, 
30
                             INDEX_BRAND = 2, 
31
                             INDEX_MODEL_NUMBER = 3, 
32
                             INDEX_MODEL_NAME = 4,
33
                             INDEX_COLOR = 5, 
34
                             INDEX_CATEGORY = 6;
35
    private static String LEGEND = "Currently Showing: ";
1961 ankur.sing 36
    private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
37
 
38
    interface ItemListUiBinder extends UiBinder<Widget, ItemList> { }
39
    private static final ItemListUiBinder uiBinder = GWT.create(ItemListUiBinder.class);
40
 
41
    interface SelectionStyle extends CssResource{
42
        String selectedRow();
43
        String alertsRow();
44
    }
45
 
46
    @UiField FlexTable header;
47
    @UiField FlexTable itemDescriptionTable;
48
    @UiField SelectionStyle selectionStyle;
2489 ankur.sing 49
    @UiField Label currentlyShowing;
1961 ankur.sing 50
    private int selectedRow = -1;
51
 
2126 ankur.sing 52
    private ItemDetails itemDetails;
53
 
1961 ankur.sing 54
    public ItemList() {
55
        initWidget(uiBinder.createAndBindUi(this));
56
        initHeader();
57
        initItemList();
58
    }
59
 
60
    private void initItemList() {
2359 ankur.sing 61
        loadAllRiskyItems();
2126 ankur.sing 62
 
2427 ankur.sing 63
        /*For testing
64
        loadDummyItems();
65
        updateItemDescriptionTable(items);
66
        */
1961 ankur.sing 67
    }
68
 
2427 ankur.sing 69
    /**
70
     * Initialise header of item list table.
71
     */
1961 ankur.sing 72
    private void initHeader(){
2489 ankur.sing 73
        header.getColumnFormatter().setWidth(INDEX_ID, "80px");
74
        header.getColumnFormatter().setWidth(INDEX_PRODUCT_GROUP, "128px");
75
        header.getColumnFormatter().setWidth(INDEX_BRAND, "150px");
76
        header.getColumnFormatter().setWidth(INDEX_MODEL_NUMBER, "200px");
77
        header.getColumnFormatter().setWidth(INDEX_MODEL_NAME, "200px");
78
        header.getColumnFormatter().setWidth(INDEX_COLOR, "128px");
79
        header.getColumnFormatter().setWidth(INDEX_CATEGORY, "220px");
1961 ankur.sing 80
 
2489 ankur.sing 81
        header.setText(0, INDEX_ID, "Item Id");
82
        header.setText(0, INDEX_PRODUCT_GROUP, "Product Group");
83
        header.setText(0, INDEX_BRAND, "Brand");
84
        header.setText(0, INDEX_MODEL_NUMBER, "Model Number");
85
        header.setText(0, INDEX_MODEL_NAME, "Model Name");
86
        header.setText(0, INDEX_COLOR, "Color");
87
        header.setText(0, INDEX_CATEGORY, "Category");
1961 ankur.sing 88
    }
89
 
90
    private void updateItemDescriptionTable(List<Item> items){
2027 ankur.sing 91
        itemDescriptionTable.removeAllRows();
2489 ankur.sing 92
        itemDescriptionTable.getColumnFormatter().setWidth(INDEX_ID, "80px");
93
        itemDescriptionTable.getColumnFormatter().setWidth(INDEX_PRODUCT_GROUP, "128px");
94
        itemDescriptionTable.getColumnFormatter().setWidth(INDEX_BRAND, "150px");
95
        itemDescriptionTable.getColumnFormatter().setWidth(INDEX_MODEL_NUMBER, "200px");
96
        itemDescriptionTable.getColumnFormatter().setWidth(INDEX_MODEL_NAME, "200px");
97
        itemDescriptionTable.getColumnFormatter().setWidth(INDEX_COLOR, "128px");
98
        itemDescriptionTable.getColumnFormatter().setWidth(INDEX_CATEGORY, "220px");
1961 ankur.sing 99
 
100
        int i=0;
101
        for(final Item item : items){
2489 ankur.sing 102
            itemDescriptionTable.setText(i, INDEX_ID, item.getId() + "");
103
            itemDescriptionTable.setText(i, INDEX_PRODUCT_GROUP, item.getProductGroup());
104
            itemDescriptionTable.setText(i, INDEX_BRAND, item.getBrand());
105
            itemDescriptionTable.setText(i, INDEX_MODEL_NUMBER, item.getModelNumber());
106
            itemDescriptionTable.setText(i, INDEX_MODEL_NAME, item.getModelName());
107
            itemDescriptionTable.setText(i, INDEX_COLOR, item.getColor());
108
            itemDescriptionTable.setText(i, INDEX_CATEGORY, item.getContentCategory()+"");
1961 ankur.sing 109
            i++;
110
        }
111
    }
112
 
2427 ankur.sing 113
    /**
114
     * On click of an item in the list, a fresh call is made to the service to fetch item details, vendor prices
115
     * and vendor item keys. The item object is then passed to ItemDetails to set the values in UI fields 
116
     * @param event
117
     */
1961 ankur.sing 118
    @UiHandler("itemDescriptionTable")
119
    void onClick(ClickEvent event) {
2066 ankur.sing 120
 
1961 ankur.sing 121
        Cell cell = itemDescriptionTable.getCellForEvent(event);
122
        int newRowIndex = cell.getRowIndex();
1992 ankur.sing 123
        selectRow(newRowIndex);
2489 ankur.sing 124
        String itemId = itemDescriptionTable.getText(newRowIndex, INDEX_ID);
2126 ankur.sing 125
 
126
        catalogService.getItem(Long.parseLong(itemId), new AsyncCallback<Item>() {
127
            @Override
128
            public void onSuccess(Item result) {
129
                itemDetails.setItemDetails(result);
130
            }
131
            @Override
132
            public void onFailure(Throwable caught) {
2489 ankur.sing 133
                caught.printStackTrace();
2126 ankur.sing 134
                Window.alert("Unable to fetch item details.");
135
            }
136
        });
1961 ankur.sing 137
    }
138
 
139
    private void selectRow(int row) {
140
        String style = selectionStyle.selectedRow();
141
        if(selectedRow != -1){
142
            itemDescriptionTable.getRowFormatter().removeStyleName(selectedRow, style);
143
        }
144
 
145
        itemDescriptionTable.getRowFormatter().addStyleName(row, style);
146
        selectedRow = row;
147
    }
148
 
2427 ankur.sing 149
    /* For testing
150
      private HashMap map;
151
      private List<Item> items;
152
      private void loadDummyItems() {
2126 ankur.sing 153
        Item i = new Item(1, "Handset", "Spice", "mi310", "phone", "White", "Business Phone",1, "comments", 1, 1, 
2359 ankur.sing 154
                "", 3000.50, 3000.00, 3000, 3000, 12, 12345, 12345, 12345, 12345, "ACTIVE", 1, "This item is active",
155
                null, "best", 2990, 1, true, true, null, null, null);
1961 ankur.sing 156
        List<Item> items = new ArrayList<Item>();
157
        items.add(i);
158
        this.items = items;
2027 ankur.sing 159
        //itemsMap.put(i.getId(), i);
2427 ankur.sing 160
    }*/
1961 ankur.sing 161
 
2427 ankur.sing 162
 
1992 ankur.sing 163
    public void loadAllItems() {
1961 ankur.sing 164
        catalogService.getAllItems(new AsyncCallback<List<Item>>() {
165
            public void onFailure(Throwable caught) {
2126 ankur.sing 166
                caught.printStackTrace();
1992 ankur.sing 167
                Window.alert("Could not get all items...");
1961 ankur.sing 168
            }
169
            public void onSuccess(List<Item> result) {
1992 ankur.sing 170
                updateItemDescriptionTable(result);
2489 ankur.sing 171
                currentlyShowing.setText(LEGEND + "All Items"); 
1961 ankur.sing 172
            }
173
        });
174
    }
175
 
2119 ankur.sing 176
    public void loadAllActiveItems() {
177
        catalogService.getAllActiveItems(new AsyncCallback<List<Item>>() {
178
            public void onFailure(Throwable caught) {
2126 ankur.sing 179
                caught.printStackTrace();
2119 ankur.sing 180
                Window.alert("Could not get all active items...");
181
            }
182
            public void onSuccess(List<Item> result) {
183
                updateItemDescriptionTable(result);
2489 ankur.sing 184
                currentlyShowing.setText(LEGEND + "Active Items");
2119 ankur.sing 185
            }
186
        });
187
    }
188
 
2208 ankur.sing 189
    public void loadAllPhasedOutItems() {
190
        catalogService.getAllPhasedOutItems(new AsyncCallback<List<Item>>() {
191
            public void onFailure(Throwable caught) {
192
                caught.printStackTrace();
193
                Window.alert("Could not load phased out items...");
194
            }
195
            public void onSuccess(List<Item> result) {
196
                updateItemDescriptionTable(result);
2489 ankur.sing 197
                currentlyShowing.setText(LEGEND + "Phased Out Items");
2208 ankur.sing 198
            }
199
        });
200
    }
201
 
202
    public void loadAllPausedItems() {
203
        catalogService.getAllPausedItems(new AsyncCallback<List<Item>>() {
204
            public void onFailure(Throwable caught) {
205
                caught.printStackTrace();
206
                Window.alert("Could not load paused items...");
207
            }
208
            public void onSuccess(List<Item> result) {
209
                updateItemDescriptionTable(result);
2489 ankur.sing 210
                currentlyShowing.setText(LEGEND + "Paused Items");
2208 ankur.sing 211
            }
212
        });
213
    }
214
 
2359 ankur.sing 215
    public void loadAllInProcessItems() {
216
        catalogService.getAllInProcessItems(new AsyncCallback<List<Item>>() {
217
            public void onFailure(Throwable caught) {
218
                caught.printStackTrace();
219
                Window.alert("Could not load IN_PROCESS items...");
220
            }
221
            public void onSuccess(List<Item> result) {
222
                updateItemDescriptionTable(result);
2489 ankur.sing 223
                currentlyShowing.setText(LEGEND + "In Process Items");
2359 ankur.sing 224
            }
225
        });
226
    }
227
 
228
    public void loadAllContentCompleteItems() {
229
        catalogService.getAllContentCompleteItems(new AsyncCallback<List<Item>>() {
230
            public void onFailure(Throwable caught) {
231
                caught.printStackTrace();
232
                Window.alert("Could not load CONTENT_COMPLETE items...");
233
            }
234
            public void onSuccess(List<Item> result) {
235
                updateItemDescriptionTable(result);
2489 ankur.sing 236
                currentlyShowing.setText(LEGEND + "Content Complete Items");
2359 ankur.sing 237
            }
238
        });
239
    }
240
 
241
    public void loadAllRiskyItems() {
242
        catalogService.getRiskyItems(new AsyncCallback<List<Item>>() {
243
            public void onFailure(Throwable caught) {
244
                caught.printStackTrace();
245
                Window.alert("Could not load RISKY items...");
246
            }
247
            public void onSuccess(List<Item> result) {
248
                updateItemDescriptionTable(result);
2489 ankur.sing 249
                currentlyShowing.setText(LEGEND + "Risky Items");
2359 ankur.sing 250
            }
251
        });
252
    }
253
 
1992 ankur.sing 254
    public void loadBestDeals() {
255
        catalogService.getBestDeals(new AsyncCallback<List<Item>>() {
256
            public void onFailure(Throwable caught) {
2126 ankur.sing 257
                caught.printStackTrace();
1992 ankur.sing 258
                Window.alert("Could not load best deals.");
259
            }
260
            public void onSuccess(List<Item> result) {
261
                updateItemDescriptionTable(result);
2489 ankur.sing 262
                currentlyShowing.setText(LEGEND + "Best Deals");
1992 ankur.sing 263
            }
264
        });
265
    }
266
 
267
    public void loadLatestArrivals() {
268
        catalogService.getLatestArrivals(new AsyncCallback<List<Item>>() {
269
            public void onFailure(Throwable caught) {
2126 ankur.sing 270
                caught.printStackTrace();
1992 ankur.sing 271
                Window.alert("Could not load latest arrivals.");
272
            }
273
            public void onSuccess(List<Item> result) {
274
                updateItemDescriptionTable(result);
2489 ankur.sing 275
                currentlyShowing.setText(LEGEND + "Latest Arrivals");
1992 ankur.sing 276
            }
277
        });
278
    }
279
 
280
    public void loadBestSellers() {
281
        catalogService.getBestSellers(new AsyncCallback<List<Item>>() {
282
            public void onFailure(Throwable caught) {
2126 ankur.sing 283
                caught.printStackTrace();
1992 ankur.sing 284
                Window.alert("Could not load best sellers.");
285
            }
286
            public void onSuccess(List<Item> result) {
287
                updateItemDescriptionTable(result);
2489 ankur.sing 288
                currentlyShowing.setText(LEGEND + "Best Sellers");
1992 ankur.sing 289
            }
290
        });
291
    }
2126 ankur.sing 292
 
293
    public void setItemDetails(ItemDetails itemDetails) {
294
        this.itemDetails = itemDetails;
295
    }
2489 ankur.sing 296
 
297
    /**
298
     * This method is called when item is updated in ItemDetails.java to update 
299
     * attributes in the list also.
300
     * @param item
301
     */
302
    public void updateItem(Item item) {
303
        itemDescriptionTable.setText(selectedRow, INDEX_PRODUCT_GROUP, item.getProductGroup());
304
        itemDescriptionTable.setText(selectedRow, INDEX_BRAND, item.getBrand());
305
        itemDescriptionTable.setText(selectedRow, INDEX_MODEL_NUMBER, item.getModelNumber());
306
        itemDescriptionTable.setText(selectedRow, INDEX_MODEL_NAME, item.getModelName());
307
        itemDescriptionTable.setText(selectedRow, INDEX_COLOR, item.getColor());
308
    }
1961 ankur.sing 309
}