| 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;
|
| 3524 |
chandransh |
8 |
import com.google.gwt.dom.client.Style.Unit;
|
| 1961 |
ankur.sing |
9 |
import com.google.gwt.resources.client.CssResource;
|
|
|
10 |
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
11 |
import com.google.gwt.uibinder.client.UiField;
|
| 3524 |
chandransh |
12 |
import com.google.gwt.user.cellview.client.CellTable;
|
|
|
13 |
import com.google.gwt.user.cellview.client.SimplePager;
|
|
|
14 |
import com.google.gwt.user.cellview.client.TextColumn;
|
| 1961 |
ankur.sing |
15 |
import com.google.gwt.user.client.Window;
|
|
|
16 |
import com.google.gwt.user.client.rpc.AsyncCallback;
|
| 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;
|
| 3524 |
chandransh |
20 |
import com.google.gwt.view.client.ListDataProvider;
|
|
|
21 |
import com.google.gwt.view.client.SelectionChangeEvent;
|
|
|
22 |
import com.google.gwt.view.client.SingleSelectionModel;
|
| 1961 |
ankur.sing |
23 |
|
| 2427 |
ankur.sing |
24 |
/**
|
|
|
25 |
* List of items. List contains item Id, product group, brand, model number, model name, color and category
|
|
|
26 |
* Dashboard user can select an item in this list and its details are shown in ItemDetails widget.
|
|
|
27 |
*
|
|
|
28 |
*/
|
| 1961 |
ankur.sing |
29 |
public class ItemList extends ResizeComposite{
|
|
|
30 |
|
| 2489 |
ankur.sing |
31 |
private static String LEGEND = "Currently Showing: ";
|
| 1961 |
ankur.sing |
32 |
private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
|
|
|
33 |
|
|
|
34 |
interface ItemListUiBinder extends UiBinder<Widget, ItemList> { }
|
|
|
35 |
private static final ItemListUiBinder uiBinder = GWT.create(ItemListUiBinder.class);
|
|
|
36 |
|
|
|
37 |
interface SelectionStyle extends CssResource{
|
|
|
38 |
String selectedRow();
|
|
|
39 |
String alertsRow();
|
|
|
40 |
}
|
|
|
41 |
|
| 3524 |
chandransh |
42 |
@UiField CellTable<Item> itemDescriptionTable;
|
|
|
43 |
// Create paging controls.
|
|
|
44 |
@UiField SimplePager pager = new SimplePager();
|
|
|
45 |
|
| 1961 |
ankur.sing |
46 |
@UiField SelectionStyle selectionStyle;
|
| 2489 |
ankur.sing |
47 |
@UiField Label currentlyShowing;
|
| 1961 |
ankur.sing |
48 |
private int selectedRow = -1;
|
|
|
49 |
|
| 2126 |
ankur.sing |
50 |
private ItemDetails itemDetails;
|
|
|
51 |
|
| 3524 |
chandransh |
52 |
// Create a data provider.
|
|
|
53 |
ListDataProvider<Item> dataProvider = new ListDataProvider<Item>();
|
|
|
54 |
|
| 1961 |
ankur.sing |
55 |
public ItemList() {
|
|
|
56 |
initWidget(uiBinder.createAndBindUi(this));
|
|
|
57 |
initItemList();
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
private void initItemList() {
|
| 3524 |
chandransh |
61 |
TextColumn<Item> idColumn = new TextColumn<Item>() {
|
|
|
62 |
@Override
|
|
|
63 |
public String getValue(Item item) {
|
|
|
64 |
return item.getId() + "";
|
|
|
65 |
}
|
|
|
66 |
};
|
| 2126 |
ankur.sing |
67 |
|
| 3524 |
chandransh |
68 |
TextColumn<Item> pgColumn = new TextColumn<Item>() {
|
|
|
69 |
@Override
|
|
|
70 |
public String getValue(Item item) {
|
|
|
71 |
return item.getProductGroup();
|
|
|
72 |
}
|
|
|
73 |
};
|
|
|
74 |
|
|
|
75 |
TextColumn<Item> brandColumn = new TextColumn<Item>(){
|
|
|
76 |
@Override
|
|
|
77 |
public String getValue(Item item) {
|
|
|
78 |
return item.getBrand();
|
|
|
79 |
}
|
|
|
80 |
};
|
|
|
81 |
|
|
|
82 |
TextColumn<Item> modelNumberColumn = new TextColumn<Item>(){
|
|
|
83 |
@Override
|
|
|
84 |
public String getValue(Item item) {
|
|
|
85 |
return item.getModelNumber();
|
|
|
86 |
}
|
|
|
87 |
};
|
|
|
88 |
|
|
|
89 |
TextColumn<Item> modelNameColumn = new TextColumn<Item>(){
|
|
|
90 |
@Override
|
|
|
91 |
public String getValue(Item item) {
|
|
|
92 |
return item.getModelName();
|
|
|
93 |
}
|
|
|
94 |
};
|
|
|
95 |
|
|
|
96 |
TextColumn<Item> colorColumn = new TextColumn<Item>(){
|
|
|
97 |
@Override
|
|
|
98 |
public String getValue(Item item) {
|
|
|
99 |
return item.getColor();
|
|
|
100 |
}
|
|
|
101 |
};
|
|
|
102 |
|
|
|
103 |
TextColumn<Item> categoryColumn = new TextColumn<Item>(){
|
|
|
104 |
@Override
|
|
|
105 |
public String getValue(Item item) {
|
|
|
106 |
return item.getContentCategory()+"";
|
|
|
107 |
}
|
|
|
108 |
};
|
| 1961 |
ankur.sing |
109 |
|
| 3524 |
chandransh |
110 |
// Add the columns.
|
|
|
111 |
itemDescriptionTable.addColumn(idColumn, "Item Id");
|
|
|
112 |
itemDescriptionTable.addColumn(pgColumn, "Product Group");
|
|
|
113 |
itemDescriptionTable.addColumn(brandColumn, "Brand");
|
|
|
114 |
itemDescriptionTable.addColumn(modelNumberColumn, "Model Number");
|
|
|
115 |
itemDescriptionTable.addColumn(modelNameColumn, "Model Name");
|
|
|
116 |
itemDescriptionTable.addColumn(colorColumn, "Color");
|
|
|
117 |
itemDescriptionTable.addColumn(categoryColumn, "Category");
|
|
|
118 |
|
|
|
119 |
//Set the widths
|
|
|
120 |
itemDescriptionTable.setWidth("100%");
|
|
|
121 |
itemDescriptionTable.setColumnWidth(idColumn, 80.0, Unit.PX);
|
|
|
122 |
itemDescriptionTable.setColumnWidth(pgColumn, 128.0, Unit.PX);
|
|
|
123 |
itemDescriptionTable.setColumnWidth(brandColumn, 150.0, Unit.PX);
|
|
|
124 |
itemDescriptionTable.setColumnWidth(modelNumberColumn, 200.0, Unit.PX);
|
|
|
125 |
itemDescriptionTable.setColumnWidth(modelNameColumn, 200.0, Unit.PX);
|
|
|
126 |
itemDescriptionTable.setColumnWidth(colorColumn, 128.0, Unit.PX);
|
|
|
127 |
itemDescriptionTable.setColumnWidth(categoryColumn, 220.0, Unit.PX);
|
|
|
128 |
|
|
|
129 |
// Connect the table to the data provider.
|
|
|
130 |
dataProvider.addDataDisplay(itemDescriptionTable);
|
|
|
131 |
|
|
|
132 |
//Add paging support
|
|
|
133 |
pager.setDisplay(itemDescriptionTable);
|
|
|
134 |
|
|
|
135 |
// Add a selection model to handle item selection.
|
|
|
136 |
final SingleSelectionModel<Item> selectionModel = new SingleSelectionModel<Item>();
|
|
|
137 |
itemDescriptionTable.setSelectionModel(selectionModel);
|
|
|
138 |
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
|
|
|
139 |
|
|
|
140 |
@Override
|
|
|
141 |
public void onSelectionChange(SelectionChangeEvent event) {
|
|
|
142 |
Item selectedItem = selectionModel.getSelectedObject();
|
|
|
143 |
catalogService.getItem(selectedItem.getId(), new AsyncCallback<Item>() {
|
|
|
144 |
@Override
|
|
|
145 |
public void onSuccess(Item result) {
|
|
|
146 |
itemDetails.setItemDetails(result);
|
|
|
147 |
}
|
|
|
148 |
@Override
|
|
|
149 |
public void onFailure(Throwable caught) {
|
|
|
150 |
caught.printStackTrace();
|
|
|
151 |
Window.alert("Unable to fetch item details.");
|
|
|
152 |
}
|
|
|
153 |
});
|
|
|
154 |
}
|
|
|
155 |
});
|
|
|
156 |
|
|
|
157 |
|
|
|
158 |
loadAllRiskyItems();
|
| 1961 |
ankur.sing |
159 |
}
|
|
|
160 |
|
|
|
161 |
private void updateItemDescriptionTable(List<Item> items){
|
| 3524 |
chandransh |
162 |
// Add the data to the data provider, which automatically pushes it to the
|
|
|
163 |
// widget.
|
|
|
164 |
List<Item> list = dataProvider.getList();
|
|
|
165 |
list.clear();
|
|
|
166 |
list.addAll(items);
|
| 1961 |
ankur.sing |
167 |
|
| 3524 |
chandransh |
168 |
pager.firstPage();
|
| 1961 |
ankur.sing |
169 |
}
|
|
|
170 |
|
| 2427 |
ankur.sing |
171 |
/**
|
|
|
172 |
* On click of an item in the list, a fresh call is made to the service to fetch item details, vendor prices
|
|
|
173 |
* and vendor item keys. The item object is then passed to ItemDetails to set the values in UI fields
|
|
|
174 |
* @param event
|
|
|
175 |
*/
|
| 3524 |
chandransh |
176 |
// @UiHandler("itemDescriptionTable")
|
|
|
177 |
// void onClick(ClickEvent event) {
|
|
|
178 |
//
|
|
|
179 |
// Cell cell = itemDescriptionTable.getCellForEvent(event);
|
|
|
180 |
// int newRowIndex = cell.getRowIndex();
|
|
|
181 |
// selectRow(newRowIndex);
|
|
|
182 |
// String itemId = itemDescriptionTable.getText(newRowIndex, INDEX_ID);
|
|
|
183 |
//
|
|
|
184 |
// catalogService.getItem(Long.parseLong(itemId), new AsyncCallback<Item>() {
|
|
|
185 |
// @Override
|
|
|
186 |
// public void onSuccess(Item result) {
|
|
|
187 |
// itemDetails.setItemDetails(result);
|
|
|
188 |
// }
|
|
|
189 |
// @Override
|
|
|
190 |
// public void onFailure(Throwable caught) {
|
|
|
191 |
// caught.printStackTrace();
|
|
|
192 |
// Window.alert("Unable to fetch item details.");
|
|
|
193 |
// }
|
|
|
194 |
// });
|
|
|
195 |
// }
|
| 2066 |
ankur.sing |
196 |
|
| 1961 |
ankur.sing |
197 |
private void selectRow(int row) {
|
| 3524 |
chandransh |
198 |
//TODO: Change the style of the selected row
|
|
|
199 |
// String style = selectionStyle.selectedRow();
|
|
|
200 |
// if(selectedRow != -1){
|
|
|
201 |
// itemDescriptionTable.getRowElement(row)owFormatter().removeStyleName(selectedRow, style);
|
|
|
202 |
// }
|
|
|
203 |
//
|
|
|
204 |
// itemDescriptionTable.getRowFormatter().addStyleName(row, style);
|
|
|
205 |
// selectedRow = row;
|
| 1961 |
ankur.sing |
206 |
}
|
|
|
207 |
|
| 2427 |
ankur.sing |
208 |
/* For testing
|
|
|
209 |
private HashMap map;
|
|
|
210 |
private List<Item> items;
|
|
|
211 |
private void loadDummyItems() {
|
| 2126 |
ankur.sing |
212 |
Item i = new Item(1, "Handset", "Spice", "mi310", "phone", "White", "Business Phone",1, "comments", 1, 1,
|
| 2359 |
ankur.sing |
213 |
"", 3000.50, 3000.00, 3000, 3000, 12, 12345, 12345, 12345, 12345, "ACTIVE", 1, "This item is active",
|
|
|
214 |
null, "best", 2990, 1, true, true, null, null, null);
|
| 1961 |
ankur.sing |
215 |
List<Item> items = new ArrayList<Item>();
|
|
|
216 |
items.add(i);
|
|
|
217 |
this.items = items;
|
| 2027 |
ankur.sing |
218 |
//itemsMap.put(i.getId(), i);
|
| 2427 |
ankur.sing |
219 |
}*/
|
| 1961 |
ankur.sing |
220 |
|
| 2427 |
ankur.sing |
221 |
|
| 1992 |
ankur.sing |
222 |
public void loadAllItems() {
|
| 1961 |
ankur.sing |
223 |
catalogService.getAllItems(new AsyncCallback<List<Item>>() {
|
|
|
224 |
public void onFailure(Throwable caught) {
|
| 2126 |
ankur.sing |
225 |
caught.printStackTrace();
|
| 1992 |
ankur.sing |
226 |
Window.alert("Could not get all items...");
|
| 1961 |
ankur.sing |
227 |
}
|
|
|
228 |
public void onSuccess(List<Item> result) {
|
| 1992 |
ankur.sing |
229 |
updateItemDescriptionTable(result);
|
| 2489 |
ankur.sing |
230 |
currentlyShowing.setText(LEGEND + "All Items");
|
| 1961 |
ankur.sing |
231 |
}
|
|
|
232 |
});
|
|
|
233 |
}
|
|
|
234 |
|
| 2119 |
ankur.sing |
235 |
public void loadAllActiveItems() {
|
|
|
236 |
catalogService.getAllActiveItems(new AsyncCallback<List<Item>>() {
|
|
|
237 |
public void onFailure(Throwable caught) {
|
| 2126 |
ankur.sing |
238 |
caught.printStackTrace();
|
| 2119 |
ankur.sing |
239 |
Window.alert("Could not get all active items...");
|
|
|
240 |
}
|
|
|
241 |
public void onSuccess(List<Item> result) {
|
|
|
242 |
updateItemDescriptionTable(result);
|
| 2489 |
ankur.sing |
243 |
currentlyShowing.setText(LEGEND + "Active Items");
|
| 2119 |
ankur.sing |
244 |
}
|
|
|
245 |
});
|
|
|
246 |
}
|
|
|
247 |
|
| 2208 |
ankur.sing |
248 |
public void loadAllPhasedOutItems() {
|
|
|
249 |
catalogService.getAllPhasedOutItems(new AsyncCallback<List<Item>>() {
|
|
|
250 |
public void onFailure(Throwable caught) {
|
|
|
251 |
caught.printStackTrace();
|
|
|
252 |
Window.alert("Could not load phased out items...");
|
|
|
253 |
}
|
|
|
254 |
public void onSuccess(List<Item> result) {
|
|
|
255 |
updateItemDescriptionTable(result);
|
| 2489 |
ankur.sing |
256 |
currentlyShowing.setText(LEGEND + "Phased Out Items");
|
| 2208 |
ankur.sing |
257 |
}
|
|
|
258 |
});
|
|
|
259 |
}
|
|
|
260 |
|
|
|
261 |
public void loadAllPausedItems() {
|
|
|
262 |
catalogService.getAllPausedItems(new AsyncCallback<List<Item>>() {
|
|
|
263 |
public void onFailure(Throwable caught) {
|
|
|
264 |
caught.printStackTrace();
|
|
|
265 |
Window.alert("Could not load paused items...");
|
|
|
266 |
}
|
|
|
267 |
public void onSuccess(List<Item> result) {
|
|
|
268 |
updateItemDescriptionTable(result);
|
| 2489 |
ankur.sing |
269 |
currentlyShowing.setText(LEGEND + "Paused Items");
|
| 2208 |
ankur.sing |
270 |
}
|
|
|
271 |
});
|
|
|
272 |
}
|
|
|
273 |
|
| 2359 |
ankur.sing |
274 |
public void loadAllInProcessItems() {
|
|
|
275 |
catalogService.getAllInProcessItems(new AsyncCallback<List<Item>>() {
|
|
|
276 |
public void onFailure(Throwable caught) {
|
|
|
277 |
caught.printStackTrace();
|
|
|
278 |
Window.alert("Could not load IN_PROCESS items...");
|
|
|
279 |
}
|
|
|
280 |
public void onSuccess(List<Item> result) {
|
|
|
281 |
updateItemDescriptionTable(result);
|
| 2489 |
ankur.sing |
282 |
currentlyShowing.setText(LEGEND + "In Process Items");
|
| 2359 |
ankur.sing |
283 |
}
|
|
|
284 |
});
|
|
|
285 |
}
|
|
|
286 |
|
|
|
287 |
public void loadAllContentCompleteItems() {
|
|
|
288 |
catalogService.getAllContentCompleteItems(new AsyncCallback<List<Item>>() {
|
|
|
289 |
public void onFailure(Throwable caught) {
|
|
|
290 |
caught.printStackTrace();
|
|
|
291 |
Window.alert("Could not load CONTENT_COMPLETE items...");
|
|
|
292 |
}
|
|
|
293 |
public void onSuccess(List<Item> result) {
|
|
|
294 |
updateItemDescriptionTable(result);
|
| 2489 |
ankur.sing |
295 |
currentlyShowing.setText(LEGEND + "Content Complete Items");
|
| 2359 |
ankur.sing |
296 |
}
|
|
|
297 |
});
|
|
|
298 |
}
|
|
|
299 |
|
|
|
300 |
public void loadAllRiskyItems() {
|
|
|
301 |
catalogService.getRiskyItems(new AsyncCallback<List<Item>>() {
|
|
|
302 |
public void onFailure(Throwable caught) {
|
|
|
303 |
caught.printStackTrace();
|
|
|
304 |
Window.alert("Could not load RISKY items...");
|
|
|
305 |
}
|
|
|
306 |
public void onSuccess(List<Item> result) {
|
|
|
307 |
updateItemDescriptionTable(result);
|
| 2489 |
ankur.sing |
308 |
currentlyShowing.setText(LEGEND + "Risky Items");
|
| 2359 |
ankur.sing |
309 |
}
|
|
|
310 |
});
|
|
|
311 |
}
|
|
|
312 |
|
| 1992 |
ankur.sing |
313 |
public void loadBestDeals() {
|
|
|
314 |
catalogService.getBestDeals(new AsyncCallback<List<Item>>() {
|
|
|
315 |
public void onFailure(Throwable caught) {
|
| 2126 |
ankur.sing |
316 |
caught.printStackTrace();
|
| 1992 |
ankur.sing |
317 |
Window.alert("Could not load best deals.");
|
|
|
318 |
}
|
|
|
319 |
public void onSuccess(List<Item> result) {
|
|
|
320 |
updateItemDescriptionTable(result);
|
| 2489 |
ankur.sing |
321 |
currentlyShowing.setText(LEGEND + "Best Deals");
|
| 1992 |
ankur.sing |
322 |
}
|
|
|
323 |
});
|
|
|
324 |
}
|
|
|
325 |
|
|
|
326 |
public void loadLatestArrivals() {
|
|
|
327 |
catalogService.getLatestArrivals(new AsyncCallback<List<Item>>() {
|
|
|
328 |
public void onFailure(Throwable caught) {
|
| 2126 |
ankur.sing |
329 |
caught.printStackTrace();
|
| 1992 |
ankur.sing |
330 |
Window.alert("Could not load latest arrivals.");
|
|
|
331 |
}
|
|
|
332 |
public void onSuccess(List<Item> result) {
|
|
|
333 |
updateItemDescriptionTable(result);
|
| 2489 |
ankur.sing |
334 |
currentlyShowing.setText(LEGEND + "Latest Arrivals");
|
| 1992 |
ankur.sing |
335 |
}
|
|
|
336 |
});
|
|
|
337 |
}
|
|
|
338 |
|
|
|
339 |
public void loadBestSellers() {
|
|
|
340 |
catalogService.getBestSellers(new AsyncCallback<List<Item>>() {
|
|
|
341 |
public void onFailure(Throwable caught) {
|
| 2126 |
ankur.sing |
342 |
caught.printStackTrace();
|
| 1992 |
ankur.sing |
343 |
Window.alert("Could not load best sellers.");
|
|
|
344 |
}
|
|
|
345 |
public void onSuccess(List<Item> result) {
|
|
|
346 |
updateItemDescriptionTable(result);
|
| 2489 |
ankur.sing |
347 |
currentlyShowing.setText(LEGEND + "Best Sellers");
|
| 1992 |
ankur.sing |
348 |
}
|
|
|
349 |
});
|
|
|
350 |
}
|
| 2126 |
ankur.sing |
351 |
|
|
|
352 |
public void setItemDetails(ItemDetails itemDetails) {
|
|
|
353 |
this.itemDetails = itemDetails;
|
|
|
354 |
}
|
| 2489 |
ankur.sing |
355 |
|
|
|
356 |
/**
|
|
|
357 |
* This method is called when item is updated in ItemDetails.java to update
|
|
|
358 |
* attributes in the list also.
|
|
|
359 |
* @param item
|
|
|
360 |
*/
|
|
|
361 |
public void updateItem(Item item) {
|
| 3524 |
chandransh |
362 |
//TODO: Update the item in the list when its details are updated
|
|
|
363 |
// itemDescriptionTable.setText(selectedRow, INDEX_PRODUCT_GROUP, item.getProductGroup());
|
|
|
364 |
// itemDescriptionTable.setText(selectedRow, INDEX_BRAND, item.getBrand());
|
|
|
365 |
// itemDescriptionTable.setText(selectedRow, INDEX_MODEL_NUMBER, item.getModelNumber());
|
|
|
366 |
// itemDescriptionTable.setText(selectedRow, INDEX_MODEL_NAME, item.getModelName());
|
|
|
367 |
// itemDescriptionTable.setText(selectedRow, INDEX_COLOR, item.getColor());
|
| 2489 |
ankur.sing |
368 |
}
|
| 1961 |
ankur.sing |
369 |
}
|