Subversion Repositories SmartDukaan

Rev

Rev 3524 | Rev 3872 | 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;
3850 chandransh 4
import in.shop2020.catalog.dashboard.shared.ItemStatus;
1961 ankur.sing 5
 
6
import java.util.List;
7
 
8
import com.google.gwt.core.client.GWT;
3524 chandransh 9
import com.google.gwt.dom.client.Style.Unit;
1961 ankur.sing 10
import com.google.gwt.resources.client.CssResource;
11
import com.google.gwt.uibinder.client.UiBinder;
12
import com.google.gwt.uibinder.client.UiField;
3524 chandransh 13
import com.google.gwt.user.cellview.client.CellTable;
14
import com.google.gwt.user.cellview.client.SimplePager;
15
import com.google.gwt.user.cellview.client.TextColumn;
1961 ankur.sing 16
import com.google.gwt.user.client.Window;
17
import com.google.gwt.user.client.rpc.AsyncCallback;
2489 ankur.sing 18
import com.google.gwt.user.client.ui.Label;
1961 ankur.sing 19
import com.google.gwt.user.client.ui.ResizeComposite;
20
import com.google.gwt.user.client.ui.Widget;
3850 chandransh 21
import com.google.gwt.view.client.AsyncDataProvider;
22
import com.google.gwt.view.client.HasData;
3524 chandransh 23
import com.google.gwt.view.client.ListDataProvider;
3850 chandransh 24
import com.google.gwt.view.client.Range;
3524 chandransh 25
import com.google.gwt.view.client.SelectionChangeEvent;
26
import com.google.gwt.view.client.SingleSelectionModel;
1961 ankur.sing 27
 
2427 ankur.sing 28
/**
29
 * List of items. List contains item Id, product group, brand, model number, model name, color and category
30
 * Dashboard user can select an item in this list and its details are shown in ItemDetails widget.
31
 *
32
 */
1961 ankur.sing 33
public class ItemList extends ResizeComposite{
34
 
2489 ankur.sing 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
 
3524 chandransh 46
    @UiField CellTable<Item> itemDescriptionTable;
47
    // Create paging controls.
48
    @UiField SimplePager pager = new SimplePager();
49
 
1961 ankur.sing 50
    @UiField SelectionStyle selectionStyle;
2489 ankur.sing 51
    @UiField Label currentlyShowing;
1961 ankur.sing 52
 
2126 ankur.sing 53
    private ItemDetails itemDetails;
54
 
3850 chandransh 55
    private String currentTreeItemSelection = null;
56
 
57
    private TextColumn<Item> idColumn = new TextColumn<Item>() {
58
        @Override
59
        public String getValue(Item item) {
60
            return item.getId() + "";
61
        }
62
    };
63
 
64
    private TextColumn<Item> pgColumn = new TextColumn<Item>() {
65
        @Override
66
        public String getValue(Item item) {
67
            return item.getProductGroup();
68
        }
69
    };
70
 
71
    private TextColumn<Item> brandColumn = new TextColumn<Item>(){
72
        @Override
73
        public String getValue(Item item) {
74
            return item.getBrand();
75
        }
76
    };
77
 
78
    private TextColumn<Item> modelNumberColumn = new TextColumn<Item>(){
79
        @Override
80
        public String getValue(Item item) {
81
            return item.getModelNumber();
82
        }
83
    };
84
 
85
    private TextColumn<Item> modelNameColumn = new TextColumn<Item>(){
86
        @Override
87
        public String getValue(Item item) {
88
            return item.getModelName();
89
        }
90
    };
91
 
92
    private TextColumn<Item> colorColumn = new TextColumn<Item>(){
93
        @Override
94
        public String getValue(Item item) {
95
            return item.getColor();
96
        }
97
    };
98
 
99
    private TextColumn<Item> categoryColumn = new TextColumn<Item>(){
100
        @Override
101
        public String getValue(Item item) {
102
            return item.getContentCategory()+"";
103
        }
104
    };
105
 
3524 chandransh 106
    // Create a data provider.
107
    ListDataProvider<Item> dataProvider = new ListDataProvider<Item>();
108
 
3850 chandransh 109
    AsyncDataProvider<Item> asyncDataProvider = new AsyncDataProvider<Item>() {
110
 
111
        @Override
112
        protected void onRangeChanged(HasData<Item> display) {
113
            Range range = display.getVisibleRange();
114
            int start = range.getStart();
115
            int limit = range.getLength();
116
            if(currentTreeItemSelection == null)
117
                currentTreeItemSelection = CatalogTree.RISKY_ITEMS;
118
            if(currentTreeItemSelection.equals(CatalogTree.ALL_ITEMS))
119
                loadAllItems(start, limit);
120
            else if(currentTreeItemSelection.equals(CatalogTree.ALL_ACTIVE_ITEMS))
121
                loadAllActiveItems(start, limit);
122
            else if(currentTreeItemSelection.equals(CatalogTree.ALL_PAUSED_ITEMS))
123
                loadAllPausedItems(start, limit);
124
            else if(currentTreeItemSelection.equals(CatalogTree.ALL_PHASED_OUT_ITEMS))
125
                loadAllPhasedOutItems(start, limit);
126
            else if(currentTreeItemSelection.equals(CatalogTree.IN_PROCESS_ITEMS))
127
                loadAllInProcessItems(start, limit);
128
            else if(currentTreeItemSelection.equals(CatalogTree.CONTENT_COMPLETE_ITEMS))
129
                loadAllContentCompleteItems(start, limit);
130
            else if(currentTreeItemSelection.equals(CatalogTree.BEST_DEALS))
131
                loadBestDeals(start, limit);
132
            else if(currentTreeItemSelection.equals(CatalogTree.BEST_SELLERS))
133
                loadBestSellers(start, limit);
134
            else if(currentTreeItemSelection.equals(CatalogTree.LATEST_ARRIVALS))
135
                loadLatestArrivals(start, limit);
136
            else if(currentTreeItemSelection.equals(CatalogTree.RISKY_ITEMS))
137
                loadAllRiskyItems(start, limit);
138
        }
139
    };
140
 
1961 ankur.sing 141
    public ItemList() {
142
        initWidget(uiBinder.createAndBindUi(this));
143
        initItemList();
144
    }
3850 chandransh 145
 
1961 ankur.sing 146
    private void initItemList() {
3524 chandransh 147
        // Add the columns.        
148
        itemDescriptionTable.addColumn(idColumn, "Item Id");
149
        itemDescriptionTable.addColumn(pgColumn, "Product Group");
150
        itemDescriptionTable.addColumn(brandColumn, "Brand");
151
        itemDescriptionTable.addColumn(modelNumberColumn, "Model Number");
152
        itemDescriptionTable.addColumn(modelNameColumn, "Model Name");
153
        itemDescriptionTable.addColumn(colorColumn, "Color");
154
        itemDescriptionTable.addColumn(categoryColumn, "Category");
155
 
156
        //Set the widths
157
        itemDescriptionTable.setWidth("100%");
158
        itemDescriptionTable.setColumnWidth(idColumn, 80.0, Unit.PX);
159
        itemDescriptionTable.setColumnWidth(pgColumn, 128.0, Unit.PX);
160
        itemDescriptionTable.setColumnWidth(brandColumn, 150.0, Unit.PX);
161
        itemDescriptionTable.setColumnWidth(modelNumberColumn, 200.0, Unit.PX);
162
        itemDescriptionTable.setColumnWidth(modelNameColumn, 200.0, Unit.PX);
163
        itemDescriptionTable.setColumnWidth(colorColumn, 128.0, Unit.PX);
164
        itemDescriptionTable.setColumnWidth(categoryColumn, 220.0, Unit.PX);
165
 
166
        // Connect the table to the data provider.
3850 chandransh 167
        //dataProvider.addDataDisplay(itemDescriptionTable);
168
        asyncDataProvider.addDataDisplay(itemDescriptionTable);
3524 chandransh 169
 
170
        //Add paging support
171
        pager.setDisplay(itemDescriptionTable);
172
 
173
        // Add a selection model to handle item selection.
174
        final SingleSelectionModel<Item> selectionModel = new SingleSelectionModel<Item>();
175
        itemDescriptionTable.setSelectionModel(selectionModel);
176
        selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
177
 
178
            @Override
179
            public void onSelectionChange(SelectionChangeEvent event) {
180
                Item selectedItem = selectionModel.getSelectedObject();
181
                catalogService.getItem(selectedItem.getId(), new AsyncCallback<Item>() {
182
                    @Override
183
                    public void onSuccess(Item result) {
184
                        itemDetails.setItemDetails(result);
185
                    }
186
                    @Override
187
                    public void onFailure(Throwable caught) {
188
                        caught.printStackTrace();
189
                        Window.alert("Unable to fetch item details.");
190
                    }
191
                });
192
            }
193
        });
194
 
195
        loadAllRiskyItems();
1961 ankur.sing 196
    }
197
 
3850 chandransh 198
    public void loadAllItems() {
199
        currentTreeItemSelection = CatalogTree.ALL_ITEMS;
200
        itemDescriptionTable.setVisibleRangeAndClearData(new Range(0, pager.getPageSize()), true);
1961 ankur.sing 201
    }
202
 
3850 chandransh 203
    public void loadAllActiveItems() {
204
        currentTreeItemSelection = CatalogTree.ALL_ACTIVE_ITEMS;
205
        itemDescriptionTable.setVisibleRangeAndClearData(new Range(0, pager.getPageSize()), true);
1961 ankur.sing 206
    }
207
 
3850 chandransh 208
    public void loadAllPhasedOutItems() {
209
        currentTreeItemSelection = CatalogTree.ALL_PHASED_OUT_ITEMS;
210
        itemDescriptionTable.setVisibleRangeAndClearData(new Range(0, pager.getPageSize()), true);
211
    }
1961 ankur.sing 212
 
3850 chandransh 213
    public void loadAllPausedItems() {
214
        currentTreeItemSelection = CatalogTree.ALL_PAUSED_ITEMS;
215
        itemDescriptionTable.setVisibleRangeAndClearData(new Range(0, pager.getPageSize()), true);
216
    }
2427 ankur.sing 217
 
3850 chandransh 218
    public void loadAllInProcessItems() {
219
        currentTreeItemSelection = CatalogTree.IN_PROCESS_ITEMS;
220
        itemDescriptionTable.setVisibleRangeAndClearData(new Range(0, pager.getPageSize()), true);
221
    }
222
 
223
    public void loadAllContentCompleteItems(){
224
        currentTreeItemSelection = CatalogTree.CONTENT_COMPLETE_ITEMS;
225
        itemDescriptionTable.setVisibleRangeAndClearData(new Range(0, pager.getPageSize()), true);
226
    }
227
 
228
    public void loadAllRiskyItems() {
229
        currentTreeItemSelection = CatalogTree.RISKY_ITEMS;
230
        itemDescriptionTable.setVisibleRangeAndClearData(new Range(0, pager.getPageSize()), true);
231
    }
232
 
233
    public void loadBestDeals() {
234
        currentTreeItemSelection = CatalogTree.BEST_DEALS;
235
        itemDescriptionTable.setVisibleRangeAndClearData(new Range(0, pager.getPageSize()), true);
236
    }
237
 
238
    public void loadLatestArrivals() {
239
        currentTreeItemSelection = CatalogTree.LATEST_ARRIVALS;
240
        itemDescriptionTable.setVisibleRangeAndClearData(new Range(0, pager.getPageSize()), true);
241
    }
242
 
243
    public void loadBestSellers() {
244
        currentTreeItemSelection = CatalogTree.BEST_SELLERS;
245
        itemDescriptionTable.setVisibleRangeAndClearData(new Range(0, pager.getPageSize()), true);
246
    }
247
 
248
    private void updateItemDescriptionTableRowCount(Integer count){
249
        asyncDataProvider.updateRowCount(count, true);
250
    }
251
 
252
    private void updateAsyncItemDescriptionTable(int start, List<Item> items){
253
        // Add the data to the data provider, which automatically pushes it to the
254
        // widget.
255
        asyncDataProvider.updateRowData(start, items);
256
    }
257
 
258
    private void loadAllItems(final int offset, final int limit) {
259
        catalogService.getAllItems(offset, limit, new AsyncCallback<List<Item>>() {
1961 ankur.sing 260
            public void onFailure(Throwable caught) {
2126 ankur.sing 261
                caught.printStackTrace();
1992 ankur.sing 262
                Window.alert("Could not get all items...");
1961 ankur.sing 263
            }
264
            public void onSuccess(List<Item> result) {
3850 chandransh 265
                updateAsyncItemDescriptionTable(offset, result);
266
                currentlyShowing.setText(LEGEND + "All Items");
1961 ankur.sing 267
            }
268
        });
3850 chandransh 269
 
270
        catalogService.getItemCountByStatus(false, ItemStatus.ACTIVE, new AsyncCallback<Integer>() {
271
 
272
            @Override
273
            public void onFailure(Throwable caught) {
274
                caught.printStackTrace();
275
                Window.alert("Could not get the count of items...");
276
            }
277
 
278
            @Override
279
            public void onSuccess(Integer count) {
280
                updateItemDescriptionTableRowCount(count);
281
            }
282
        });
1961 ankur.sing 283
    }
284
 
3850 chandransh 285
    private void loadAllActiveItems(final int offset, final int limit) {
286
        catalogService.getAllActiveItems(offset, limit, new AsyncCallback<List<Item>>() {
2119 ankur.sing 287
            public void onFailure(Throwable caught) {
2126 ankur.sing 288
                caught.printStackTrace();
2119 ankur.sing 289
                Window.alert("Could not get all active items...");
290
            }
291
            public void onSuccess(List<Item> result) {
3850 chandransh 292
                updateAsyncItemDescriptionTable(offset, result);
2489 ankur.sing 293
                currentlyShowing.setText(LEGEND + "Active Items");
2119 ankur.sing 294
            }
295
        });
3850 chandransh 296
 
297
        catalogService.getItemCountByStatus(true, ItemStatus.ACTIVE, new AsyncCallback<Integer>() {
298
 
299
            @Override
300
            public void onFailure(Throwable caught) {
301
                caught.printStackTrace();
302
                Window.alert("Could not get the count of items...");
303
            }
304
 
305
            @Override
306
            public void onSuccess(Integer count) {
307
                updateItemDescriptionTableRowCount(count);
308
            }
309
        });
2119 ankur.sing 310
    }
311
 
3850 chandransh 312
    private void loadAllPhasedOutItems(final int offset, int limit){
313
        catalogService.getAllPhasedOutItems(offset, limit, new AsyncCallback<List<Item>>() {
2208 ankur.sing 314
            public void onFailure(Throwable caught) {
315
                caught.printStackTrace();
316
                Window.alert("Could not load phased out items...");
317
            }
318
            public void onSuccess(List<Item> result) {
3850 chandransh 319
                updateAsyncItemDescriptionTable(offset, result);
2489 ankur.sing 320
                currentlyShowing.setText(LEGEND + "Phased Out Items");
2208 ankur.sing 321
            }
322
        });
3850 chandransh 323
 
324
        catalogService.getItemCountByStatus(true, ItemStatus.PHASED_OUT, new AsyncCallback<Integer>() {
325
 
326
            @Override
327
            public void onFailure(Throwable caught) {
328
                caught.printStackTrace();
329
                Window.alert("Could not get the count of items...");
330
            }
331
 
332
            @Override
333
            public void onSuccess(Integer count) {
334
                updateItemDescriptionTableRowCount(count);
335
            }
336
        });
2208 ankur.sing 337
    }
338
 
3850 chandransh 339
    private void loadAllPausedItems(final int offset, int limit) {
340
        catalogService.getAllPausedItems(offset, limit, new AsyncCallback<List<Item>>() {
2208 ankur.sing 341
            public void onFailure(Throwable caught) {
342
                caught.printStackTrace();
343
                Window.alert("Could not load paused items...");
344
            }
345
            public void onSuccess(List<Item> result) {
3850 chandransh 346
                updateAsyncItemDescriptionTable(offset, result);
2489 ankur.sing 347
                currentlyShowing.setText(LEGEND + "Paused Items");
2208 ankur.sing 348
            }
349
        });
3850 chandransh 350
 
351
        catalogService.getItemCountByStatus(true, ItemStatus.PAUSED, new AsyncCallback<Integer>() {
352
 
353
            @Override
354
            public void onFailure(Throwable caught) {
355
                caught.printStackTrace();
356
                Window.alert("Could not get the count of items...");
357
            }
358
 
359
            @Override
360
            public void onSuccess(Integer count) {
361
                updateItemDescriptionTableRowCount(count);
362
            }
363
        });
2208 ankur.sing 364
    }
365
 
3850 chandransh 366
    private void loadAllInProcessItems(final int offset, int limit) {
367
        catalogService.getAllInProcessItems(offset, limit, new AsyncCallback<List<Item>>() {
2359 ankur.sing 368
            public void onFailure(Throwable caught) {
369
                caught.printStackTrace();
370
                Window.alert("Could not load IN_PROCESS items...");
371
            }
372
            public void onSuccess(List<Item> result) {
3850 chandransh 373
                updateAsyncItemDescriptionTable(offset, result);
2489 ankur.sing 374
                currentlyShowing.setText(LEGEND + "In Process Items");
2359 ankur.sing 375
            }
376
        });
3850 chandransh 377
 
378
        catalogService.getItemCountByStatus(true, ItemStatus.IN_PROCESS, new AsyncCallback<Integer>() {
379
 
380
            @Override
381
            public void onFailure(Throwable caught) {
382
                caught.printStackTrace();
383
                Window.alert("Could not get the count of items...");
384
            }
385
 
386
            @Override
387
            public void onSuccess(Integer count) {
388
                updateItemDescriptionTableRowCount(count);
389
            }
390
        });
2359 ankur.sing 391
    }
392
 
3850 chandransh 393
    private void loadAllContentCompleteItems(final int offset, int limit) {
394
        catalogService.getAllContentCompleteItems(offset, limit, new AsyncCallback<List<Item>>() {
2359 ankur.sing 395
            public void onFailure(Throwable caught) {
396
                caught.printStackTrace();
397
                Window.alert("Could not load CONTENT_COMPLETE items...");
398
            }
399
            public void onSuccess(List<Item> result) {
3850 chandransh 400
                updateAsyncItemDescriptionTable(offset, result);
2489 ankur.sing 401
                currentlyShowing.setText(LEGEND + "Content Complete Items");
2359 ankur.sing 402
            }
403
        });
3850 chandransh 404
 
405
        catalogService.getItemCountByStatus(true, ItemStatus.CONTENT_COMPLETE, new AsyncCallback<Integer>() {
406
 
407
            @Override
2359 ankur.sing 408
            public void onFailure(Throwable caught) {
409
                caught.printStackTrace();
3850 chandransh 410
                Window.alert("Could not get the count of items...");
2359 ankur.sing 411
            }
3850 chandransh 412
 
413
            @Override
414
            public void onSuccess(Integer count) {
415
                updateItemDescriptionTableRowCount(count);
2359 ankur.sing 416
            }
417
        });
418
    }
419
 
3850 chandransh 420
    private void loadAllRiskyItems(final int start, final int limit) {
421
        catalogService.getRiskyItems(new AsyncCallback<List<Item>>() {
1992 ankur.sing 422
            public void onFailure(Throwable caught) {
2126 ankur.sing 423
                caught.printStackTrace();
3850 chandransh 424
                Window.alert("Could not load RISKY items...");
1992 ankur.sing 425
            }
426
            public void onSuccess(List<Item> result) {
3850 chandransh 427
                updateAsyncItemDescriptionTable(0, result.subList(start, Math.min(start + limit, result.size())));
428
                updateItemDescriptionTableRowCount(result.size());
429
                currentTreeItemSelection = CatalogTree.RISKY_ITEMS;
430
                currentlyShowing.setText(LEGEND + "Risky Items");
1992 ankur.sing 431
            }
432
        });
433
    }
3850 chandransh 434
 
435
    private void loadLatestArrivals(final int start, final int limit) {
1992 ankur.sing 436
        catalogService.getLatestArrivals(new AsyncCallback<List<Item>>() {
437
            public void onFailure(Throwable caught) {
2126 ankur.sing 438
                caught.printStackTrace();
1992 ankur.sing 439
                Window.alert("Could not load latest arrivals.");
440
            }
441
            public void onSuccess(List<Item> result) {
3850 chandransh 442
                updateAsyncItemDescriptionTable(0, result.subList(start, Math.min(start + limit, result.size())));
443
                updateItemDescriptionTableRowCount(result.size());
2489 ankur.sing 444
                currentlyShowing.setText(LEGEND + "Latest Arrivals");
1992 ankur.sing 445
            }
446
        });
3850 chandransh 447
 
1992 ankur.sing 448
    }
3850 chandransh 449
 
450
    private void loadBestSellers(final int start, final int limit) {
1992 ankur.sing 451
        catalogService.getBestSellers(new AsyncCallback<List<Item>>() {
452
            public void onFailure(Throwable caught) {
2126 ankur.sing 453
                caught.printStackTrace();
1992 ankur.sing 454
                Window.alert("Could not load best sellers.");
455
            }
456
            public void onSuccess(List<Item> result) {
3850 chandransh 457
                updateAsyncItemDescriptionTable(0, result.subList(start, Math.min(start + limit, result.size())));
458
                updateItemDescriptionTableRowCount(result.size());
2489 ankur.sing 459
                currentlyShowing.setText(LEGEND + "Best Sellers");
1992 ankur.sing 460
            }
461
        });
462
    }
2126 ankur.sing 463
 
3850 chandransh 464
    private void loadBestDeals(final int start, final int limit) {
465
        catalogService.getBestDeals(new AsyncCallback<List<Item>>() {
466
            public void onFailure(Throwable caught) {
467
                caught.printStackTrace();
468
                Window.alert("Could not load best deals.");
469
            }
470
            public void onSuccess(List<Item> result) {
471
                updateAsyncItemDescriptionTable(0, result.subList(start, Math.min(start + limit, result.size())));
472
                updateItemDescriptionTableRowCount(result.size());
473
                currentlyShowing.setText(LEGEND + "Best Deals");
474
            }
475
        });
476
    }
477
 
2126 ankur.sing 478
    public void setItemDetails(ItemDetails itemDetails) {
479
        this.itemDetails = itemDetails;
480
    }
2489 ankur.sing 481
 
482
    /**
483
     * This method is called when item is updated in ItemDetails.java to update 
484
     * attributes in the list also.
485
     * @param item
486
     */
487
    public void updateItem(Item item) {
3524 chandransh 488
        //TODO: Update the item in the list when its details are updated
489
//        itemDescriptionTable.setText(selectedRow, INDEX_PRODUCT_GROUP, item.getProductGroup());
490
//        itemDescriptionTable.setText(selectedRow, INDEX_BRAND, item.getBrand());
491
//        itemDescriptionTable.setText(selectedRow, INDEX_MODEL_NUMBER, item.getModelNumber());
492
//        itemDescriptionTable.setText(selectedRow, INDEX_MODEL_NAME, item.getModelName());
493
//        itemDescriptionTable.setText(selectedRow, INDEX_COLOR, item.getColor());
2489 ankur.sing 494
    }
1961 ankur.sing 495
}