Subversion Repositories SmartDukaan

Rev

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

Rev 2427 Rev 2489
Line 12... Line 12...
12
import com.google.gwt.uibinder.client.UiHandler;
12
import com.google.gwt.uibinder.client.UiHandler;
13
import com.google.gwt.user.client.Window;
13
import com.google.gwt.user.client.Window;
14
import com.google.gwt.user.client.rpc.AsyncCallback;
14
import com.google.gwt.user.client.rpc.AsyncCallback;
15
import com.google.gwt.user.client.ui.FlexTable;
15
import com.google.gwt.user.client.ui.FlexTable;
16
import com.google.gwt.user.client.ui.HTMLTable.Cell;
16
import com.google.gwt.user.client.ui.HTMLTable.Cell;
-
 
17
import com.google.gwt.user.client.ui.Label;
17
import com.google.gwt.user.client.ui.ResizeComposite;
18
import com.google.gwt.user.client.ui.ResizeComposite;
18
import com.google.gwt.user.client.ui.Widget;
19
import com.google.gwt.user.client.ui.Widget;
19
 
20
 
20
/**
21
/**
21
 * List of items. List contains item Id, product group, brand, model number, model name, color and category
22
 * 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
 * Dashboard user can select an item in this list and its details are shown in ItemDetails widget.
23
 *
24
 *
24
 */
25
 */
25
public class ItemList extends ResizeComposite{
26
public class ItemList extends ResizeComposite{
26
 
27
 
-
 
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: ";
27
    private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
36
    private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
28
    
37
    
29
    interface ItemListUiBinder extends UiBinder<Widget, ItemList> { }
38
    interface ItemListUiBinder extends UiBinder<Widget, ItemList> { }
30
    private static final ItemListUiBinder uiBinder = GWT.create(ItemListUiBinder.class);
39
    private static final ItemListUiBinder uiBinder = GWT.create(ItemListUiBinder.class);
31
    
40
    
Line 35... Line 44...
35
    }
44
    }
36
 
45
 
37
    @UiField FlexTable header;
46
    @UiField FlexTable header;
38
    @UiField FlexTable itemDescriptionTable;
47
    @UiField FlexTable itemDescriptionTable;
39
    @UiField SelectionStyle selectionStyle;
48
    @UiField SelectionStyle selectionStyle;
-
 
49
    @UiField Label currentlyShowing;
40
    private int selectedRow = -1;
50
    private int selectedRow = -1;
41
    
51
    
42
    private ItemDetails itemDetails;
52
    private ItemDetails itemDetails;
43
    
53
    
44
    public ItemList() {
54
    public ItemList() {
Line 58... Line 68...
58
    
68
    
59
    /**
69
    /**
60
     * Initialise header of item list table.
70
     * Initialise header of item list table.
61
     */
71
     */
62
    private void initHeader(){
72
    private void initHeader(){
63
        header.getColumnFormatter().setWidth(0, "80px");
73
        header.getColumnFormatter().setWidth(INDEX_ID, "80px");
64
        header.getColumnFormatter().setWidth(1, "128px");
74
        header.getColumnFormatter().setWidth(INDEX_PRODUCT_GROUP, "128px");
65
        header.getColumnFormatter().setWidth(2, "150px");
75
        header.getColumnFormatter().setWidth(INDEX_BRAND, "150px");
66
        header.getColumnFormatter().setWidth(3, "200px");
76
        header.getColumnFormatter().setWidth(INDEX_MODEL_NUMBER, "200px");
67
        header.getColumnFormatter().setWidth(4, "200px");
77
        header.getColumnFormatter().setWidth(INDEX_MODEL_NAME, "200px");
68
        header.getColumnFormatter().setWidth(5, "128px");
78
        header.getColumnFormatter().setWidth(INDEX_COLOR, "128px");
69
        header.getColumnFormatter().setWidth(6, "220px");
79
        header.getColumnFormatter().setWidth(INDEX_CATEGORY, "220px");
70
 
80
 
71
        header.setText(0, 0, "Item Id");
81
        header.setText(0, INDEX_ID, "Item Id");
72
        header.setText(0, 1, "Product Group");
82
        header.setText(0, INDEX_PRODUCT_GROUP, "Product Group");
73
        header.setText(0, 2, "Brand");
83
        header.setText(0, INDEX_BRAND, "Brand");
74
        header.setText(0, 3, "Model Number");
84
        header.setText(0, INDEX_MODEL_NUMBER, "Model Number");
75
        header.setText(0, 4, "Model Name");
85
        header.setText(0, INDEX_MODEL_NAME, "Model Name");
76
        header.setText(0, 5, "Color");
86
        header.setText(0, INDEX_COLOR, "Color");
77
        header.setText(0, 6, "Category");
87
        header.setText(0, INDEX_CATEGORY, "Category");
78
    }
88
    }
79
    
89
    
80
    private void updateItemDescriptionTable(List<Item> items){
90
    private void updateItemDescriptionTable(List<Item> items){
81
        itemDescriptionTable.removeAllRows();
91
        itemDescriptionTable.removeAllRows();
82
        itemDescriptionTable.getColumnFormatter().setWidth(0, "80px");
92
        itemDescriptionTable.getColumnFormatter().setWidth(INDEX_ID, "80px");
83
        itemDescriptionTable.getColumnFormatter().setWidth(1, "128px");
93
        itemDescriptionTable.getColumnFormatter().setWidth(INDEX_PRODUCT_GROUP, "128px");
84
        itemDescriptionTable.getColumnFormatter().setWidth(2, "150px");
94
        itemDescriptionTable.getColumnFormatter().setWidth(INDEX_BRAND, "150px");
85
        itemDescriptionTable.getColumnFormatter().setWidth(3, "200px");
95
        itemDescriptionTable.getColumnFormatter().setWidth(INDEX_MODEL_NUMBER, "200px");
86
        itemDescriptionTable.getColumnFormatter().setWidth(4, "200px");
96
        itemDescriptionTable.getColumnFormatter().setWidth(INDEX_MODEL_NAME, "200px");
87
        itemDescriptionTable.getColumnFormatter().setWidth(5, "128px");
97
        itemDescriptionTable.getColumnFormatter().setWidth(INDEX_COLOR, "128px");
88
        itemDescriptionTable.getColumnFormatter().setWidth(6, "220px");
98
        itemDescriptionTable.getColumnFormatter().setWidth(INDEX_CATEGORY, "220px");
89
        
99
        
90
        int i=0;
100
        int i=0;
91
        for(final Item item : items){
101
        for(final Item item : items){
92
            int col = 0;
-
 
93
            itemDescriptionTable.setText(i, col++, item.getId() + "");
102
            itemDescriptionTable.setText(i, INDEX_ID, item.getId() + "");
94
            itemDescriptionTable.setText(i, col++, item.getProductGroup());
103
            itemDescriptionTable.setText(i, INDEX_PRODUCT_GROUP, item.getProductGroup());
95
            itemDescriptionTable.setText(i, col++, item.getBrand());
104
            itemDescriptionTable.setText(i, INDEX_BRAND, item.getBrand());
96
            itemDescriptionTable.setText(i, col++, item.getModelNumber());
105
            itemDescriptionTable.setText(i, INDEX_MODEL_NUMBER, item.getModelNumber());
97
            itemDescriptionTable.setText(i, col++, item.getModelName());
106
            itemDescriptionTable.setText(i, INDEX_MODEL_NAME, item.getModelName());
98
            itemDescriptionTable.setText(i, col++, item.getColor());
107
            itemDescriptionTable.setText(i, INDEX_COLOR, item.getColor());
99
            itemDescriptionTable.setText(i, col++, item.getContentCategory()+"");
108
            itemDescriptionTable.setText(i, INDEX_CATEGORY, item.getContentCategory()+"");
100
            i++;
109
            i++;
101
        }
110
        }
102
    }
111
    }
103
    
112
    
104
    /**
113
    /**
Line 110... Line 119...
110
    void onClick(ClickEvent event) {
119
    void onClick(ClickEvent event) {
111
 
120
 
112
        Cell cell = itemDescriptionTable.getCellForEvent(event);
121
        Cell cell = itemDescriptionTable.getCellForEvent(event);
113
        int newRowIndex = cell.getRowIndex();
122
        int newRowIndex = cell.getRowIndex();
114
        selectRow(newRowIndex);
123
        selectRow(newRowIndex);
115
        String itemId = itemDescriptionTable.getText(newRowIndex, 0);
124
        String itemId = itemDescriptionTable.getText(newRowIndex, INDEX_ID);
116
        
125
        
117
        catalogService.getItem(Long.parseLong(itemId), new AsyncCallback<Item>() {
126
        catalogService.getItem(Long.parseLong(itemId), new AsyncCallback<Item>() {
118
            @Override
127
            @Override
119
            public void onSuccess(Item result) {
128
            public void onSuccess(Item result) {
120
                itemDetails.setItemDetails(result);
129
                itemDetails.setItemDetails(result);
121
            }
130
            }
122
            @Override
131
            @Override
123
            public void onFailure(Throwable caught) {
132
            public void onFailure(Throwable caught) {
-
 
133
                caught.printStackTrace();
124
                Window.alert("Unable to fetch item details.");
134
                Window.alert("Unable to fetch item details.");
125
            }
135
            }
126
        });
136
        });
127
    }
137
    }
128
 
138
 
Line 156... Line 166...
156
                caught.printStackTrace();
166
                caught.printStackTrace();
157
                Window.alert("Could not get all items...");
167
                Window.alert("Could not get all items...");
158
            }
168
            }
159
            public void onSuccess(List<Item> result) {
169
            public void onSuccess(List<Item> result) {
160
                updateItemDescriptionTable(result);
170
                updateItemDescriptionTable(result);
-
 
171
                currentlyShowing.setText(LEGEND + "All Items"); 
161
            }
172
            }
162
        });
173
        });
163
    }
174
    }
164
    
175
    
165
    public void loadAllActiveItems() {
176
    public void loadAllActiveItems() {
Line 168... Line 179...
168
                caught.printStackTrace();
179
                caught.printStackTrace();
169
                Window.alert("Could not get all active items...");
180
                Window.alert("Could not get all active items...");
170
            }
181
            }
171
            public void onSuccess(List<Item> result) {
182
            public void onSuccess(List<Item> result) {
172
                updateItemDescriptionTable(result);
183
                updateItemDescriptionTable(result);
-
 
184
                currentlyShowing.setText(LEGEND + "Active Items");
173
            }
185
            }
174
        });
186
        });
175
    }
187
    }
176
    
188
    
177
    public void loadAllPhasedOutItems() {
189
    public void loadAllPhasedOutItems() {
Line 180... Line 192...
180
                caught.printStackTrace();
192
                caught.printStackTrace();
181
                Window.alert("Could not load phased out items...");
193
                Window.alert("Could not load phased out items...");
182
            }
194
            }
183
            public void onSuccess(List<Item> result) {
195
            public void onSuccess(List<Item> result) {
184
                updateItemDescriptionTable(result);
196
                updateItemDescriptionTable(result);
-
 
197
                currentlyShowing.setText(LEGEND + "Phased Out Items");
185
            }
198
            }
186
        });
199
        });
187
    }
200
    }
188
    
201
    
189
    public void loadAllPausedItems() {
202
    public void loadAllPausedItems() {
Line 192... Line 205...
192
                caught.printStackTrace();
205
                caught.printStackTrace();
193
                Window.alert("Could not load paused items...");
206
                Window.alert("Could not load paused items...");
194
            }
207
            }
195
            public void onSuccess(List<Item> result) {
208
            public void onSuccess(List<Item> result) {
196
                updateItemDescriptionTable(result);
209
                updateItemDescriptionTable(result);
-
 
210
                currentlyShowing.setText(LEGEND + "Paused Items");
197
            }
211
            }
198
        });
212
        });
199
    }
213
    }
200
    
214
    
201
    public void loadAllInProcessItems() {
215
    public void loadAllInProcessItems() {
Line 204... Line 218...
204
                caught.printStackTrace();
218
                caught.printStackTrace();
205
                Window.alert("Could not load IN_PROCESS items...");
219
                Window.alert("Could not load IN_PROCESS items...");
206
            }
220
            }
207
            public void onSuccess(List<Item> result) {
221
            public void onSuccess(List<Item> result) {
208
                updateItemDescriptionTable(result);
222
                updateItemDescriptionTable(result);
-
 
223
                currentlyShowing.setText(LEGEND + "In Process Items");
209
            }
224
            }
210
        });
225
        });
211
    }
226
    }
212
    
227
    
213
    public void loadAllContentCompleteItems() {
228
    public void loadAllContentCompleteItems() {
Line 216... Line 231...
216
                caught.printStackTrace();
231
                caught.printStackTrace();
217
                Window.alert("Could not load CONTENT_COMPLETE items...");
232
                Window.alert("Could not load CONTENT_COMPLETE items...");
218
            }
233
            }
219
            public void onSuccess(List<Item> result) {
234
            public void onSuccess(List<Item> result) {
220
                updateItemDescriptionTable(result);
235
                updateItemDescriptionTable(result);
-
 
236
                currentlyShowing.setText(LEGEND + "Content Complete Items");
221
            }
237
            }
222
        });
238
        });
223
    }
239
    }
224
    
240
    
225
    public void loadAllRiskyItems() {
241
    public void loadAllRiskyItems() {
Line 228... Line 244...
228
                caught.printStackTrace();
244
                caught.printStackTrace();
229
                Window.alert("Could not load RISKY items...");
245
                Window.alert("Could not load RISKY items...");
230
            }
246
            }
231
            public void onSuccess(List<Item> result) {
247
            public void onSuccess(List<Item> result) {
232
                updateItemDescriptionTable(result);
248
                updateItemDescriptionTable(result);
-
 
249
                currentlyShowing.setText(LEGEND + "Risky Items");
233
            }
250
            }
234
        });
251
        });
235
    }
252
    }
236
    
253
    
237
    public void loadBestDeals() {
254
    public void loadBestDeals() {
Line 240... Line 257...
240
                caught.printStackTrace();
257
                caught.printStackTrace();
241
                Window.alert("Could not load best deals.");
258
                Window.alert("Could not load best deals.");
242
            }
259
            }
243
            public void onSuccess(List<Item> result) {
260
            public void onSuccess(List<Item> result) {
244
                updateItemDescriptionTable(result);
261
                updateItemDescriptionTable(result);
-
 
262
                currentlyShowing.setText(LEGEND + "Best Deals");
245
            }
263
            }
246
        });
264
        });
247
    }
265
    }
248
    
266
    
249
    public void loadLatestArrivals() {
267
    public void loadLatestArrivals() {
Line 252... Line 270...
252
                caught.printStackTrace();
270
                caught.printStackTrace();
253
                Window.alert("Could not load latest arrivals.");
271
                Window.alert("Could not load latest arrivals.");
254
            }
272
            }
255
            public void onSuccess(List<Item> result) {
273
            public void onSuccess(List<Item> result) {
256
                updateItemDescriptionTable(result);
274
                updateItemDescriptionTable(result);
-
 
275
                currentlyShowing.setText(LEGEND + "Latest Arrivals");
257
            }
276
            }
258
        });
277
        });
259
    }
278
    }
260
    
279
    
261
    public void loadBestSellers() {
280
    public void loadBestSellers() {
Line 264... Line 283...
264
                caught.printStackTrace();
283
                caught.printStackTrace();
265
                Window.alert("Could not load best sellers.");
284
                Window.alert("Could not load best sellers.");
266
            }
285
            }
267
            public void onSuccess(List<Item> result) {
286
            public void onSuccess(List<Item> result) {
268
                updateItemDescriptionTable(result);
287
                updateItemDescriptionTable(result);
-
 
288
                currentlyShowing.setText(LEGEND + "Best Sellers");
269
            }
289
            }
270
        });
290
        });
271
    }
291
    }
272
 
292
 
273
    public void setItemDetails(ItemDetails itemDetails) {
293
    public void setItemDetails(ItemDetails itemDetails) {
274
        this.itemDetails = itemDetails;
294
        this.itemDetails = itemDetails;
275
    }
295
    }
-
 
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
    }
276
}
309
}