| 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;
|
|
|
17 |
import com.google.gwt.user.client.ui.ResizeComposite;
|
|
|
18 |
import com.google.gwt.user.client.ui.Widget;
|
|
|
19 |
|
| 2427 |
ankur.sing |
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 |
*/
|
| 1961 |
ankur.sing |
25 |
public class ItemList extends ResizeComposite{
|
|
|
26 |
|
|
|
27 |
private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
|
|
|
28 |
|
|
|
29 |
interface ItemListUiBinder extends UiBinder<Widget, ItemList> { }
|
|
|
30 |
private static final ItemListUiBinder uiBinder = GWT.create(ItemListUiBinder.class);
|
|
|
31 |
|
|
|
32 |
interface SelectionStyle extends CssResource{
|
|
|
33 |
String selectedRow();
|
|
|
34 |
String alertsRow();
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
@UiField FlexTable header;
|
|
|
38 |
@UiField FlexTable itemDescriptionTable;
|
|
|
39 |
@UiField SelectionStyle selectionStyle;
|
|
|
40 |
private int selectedRow = -1;
|
|
|
41 |
|
| 2126 |
ankur.sing |
42 |
private ItemDetails itemDetails;
|
|
|
43 |
|
| 1961 |
ankur.sing |
44 |
public ItemList() {
|
|
|
45 |
initWidget(uiBinder.createAndBindUi(this));
|
|
|
46 |
initHeader();
|
|
|
47 |
initItemList();
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
private void initItemList() {
|
| 2359 |
ankur.sing |
51 |
loadAllRiskyItems();
|
| 2126 |
ankur.sing |
52 |
|
| 2427 |
ankur.sing |
53 |
/*For testing
|
|
|
54 |
loadDummyItems();
|
|
|
55 |
updateItemDescriptionTable(items);
|
|
|
56 |
*/
|
| 1961 |
ankur.sing |
57 |
}
|
|
|
58 |
|
| 2427 |
ankur.sing |
59 |
/**
|
|
|
60 |
* Initialise header of item list table.
|
|
|
61 |
*/
|
| 1961 |
ankur.sing |
62 |
private void initHeader(){
|
| 2027 |
ankur.sing |
63 |
header.getColumnFormatter().setWidth(0, "80px");
|
| 1961 |
ankur.sing |
64 |
header.getColumnFormatter().setWidth(1, "128px");
|
| 2027 |
ankur.sing |
65 |
header.getColumnFormatter().setWidth(2, "150px");
|
| 1961 |
ankur.sing |
66 |
header.getColumnFormatter().setWidth(3, "200px");
|
|
|
67 |
header.getColumnFormatter().setWidth(4, "200px");
|
|
|
68 |
header.getColumnFormatter().setWidth(5, "128px");
|
| 2027 |
ankur.sing |
69 |
header.getColumnFormatter().setWidth(6, "220px");
|
| 1961 |
ankur.sing |
70 |
|
|
|
71 |
header.setText(0, 0, "Item Id");
|
|
|
72 |
header.setText(0, 1, "Product Group");
|
|
|
73 |
header.setText(0, 2, "Brand");
|
|
|
74 |
header.setText(0, 3, "Model Number");
|
|
|
75 |
header.setText(0, 4, "Model Name");
|
| 2027 |
ankur.sing |
76 |
header.setText(0, 5, "Color");
|
| 1961 |
ankur.sing |
77 |
header.setText(0, 6, "Category");
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
private void updateItemDescriptionTable(List<Item> items){
|
| 2027 |
ankur.sing |
81 |
itemDescriptionTable.removeAllRows();
|
|
|
82 |
itemDescriptionTable.getColumnFormatter().setWidth(0, "80px");
|
| 1961 |
ankur.sing |
83 |
itemDescriptionTable.getColumnFormatter().setWidth(1, "128px");
|
| 2027 |
ankur.sing |
84 |
itemDescriptionTable.getColumnFormatter().setWidth(2, "150px");
|
| 1961 |
ankur.sing |
85 |
itemDescriptionTable.getColumnFormatter().setWidth(3, "200px");
|
|
|
86 |
itemDescriptionTable.getColumnFormatter().setWidth(4, "200px");
|
|
|
87 |
itemDescriptionTable.getColumnFormatter().setWidth(5, "128px");
|
| 2027 |
ankur.sing |
88 |
itemDescriptionTable.getColumnFormatter().setWidth(6, "220px");
|
| 1961 |
ankur.sing |
89 |
|
|
|
90 |
int i=0;
|
|
|
91 |
for(final Item item : items){
|
|
|
92 |
int col = 0;
|
|
|
93 |
itemDescriptionTable.setText(i, col++, item.getId() + "");
|
|
|
94 |
itemDescriptionTable.setText(i, col++, item.getProductGroup());
|
|
|
95 |
itemDescriptionTable.setText(i, col++, item.getBrand());
|
|
|
96 |
itemDescriptionTable.setText(i, col++, item.getModelNumber());
|
|
|
97 |
itemDescriptionTable.setText(i, col++, item.getModelName());
|
| 2027 |
ankur.sing |
98 |
itemDescriptionTable.setText(i, col++, item.getColor());
|
| 2105 |
ankur.sing |
99 |
itemDescriptionTable.setText(i, col++, item.getContentCategory()+"");
|
| 1961 |
ankur.sing |
100 |
i++;
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
|
| 2427 |
ankur.sing |
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 |
*/
|
| 1961 |
ankur.sing |
109 |
@UiHandler("itemDescriptionTable")
|
|
|
110 |
void onClick(ClickEvent event) {
|
| 2066 |
ankur.sing |
111 |
|
| 1961 |
ankur.sing |
112 |
Cell cell = itemDescriptionTable.getCellForEvent(event);
|
|
|
113 |
int newRowIndex = cell.getRowIndex();
|
| 1992 |
ankur.sing |
114 |
selectRow(newRowIndex);
|
| 1961 |
ankur.sing |
115 |
String itemId = itemDescriptionTable.getText(newRowIndex, 0);
|
| 2126 |
ankur.sing |
116 |
|
|
|
117 |
catalogService.getItem(Long.parseLong(itemId), new AsyncCallback<Item>() {
|
|
|
118 |
@Override
|
|
|
119 |
public void onSuccess(Item result) {
|
|
|
120 |
itemDetails.setItemDetails(result);
|
|
|
121 |
}
|
|
|
122 |
@Override
|
|
|
123 |
public void onFailure(Throwable caught) {
|
|
|
124 |
Window.alert("Unable to fetch item details.");
|
|
|
125 |
}
|
|
|
126 |
});
|
| 1961 |
ankur.sing |
127 |
}
|
|
|
128 |
|
|
|
129 |
private void selectRow(int row) {
|
|
|
130 |
String style = selectionStyle.selectedRow();
|
|
|
131 |
if(selectedRow != -1){
|
|
|
132 |
itemDescriptionTable.getRowFormatter().removeStyleName(selectedRow, style);
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
itemDescriptionTable.getRowFormatter().addStyleName(row, style);
|
|
|
136 |
selectedRow = row;
|
|
|
137 |
}
|
|
|
138 |
|
| 2427 |
ankur.sing |
139 |
/* For testing
|
|
|
140 |
private HashMap map;
|
|
|
141 |
private List<Item> items;
|
|
|
142 |
private void loadDummyItems() {
|
| 2126 |
ankur.sing |
143 |
Item i = new Item(1, "Handset", "Spice", "mi310", "phone", "White", "Business Phone",1, "comments", 1, 1,
|
| 2359 |
ankur.sing |
144 |
"", 3000.50, 3000.00, 3000, 3000, 12, 12345, 12345, 12345, 12345, "ACTIVE", 1, "This item is active",
|
|
|
145 |
null, "best", 2990, 1, true, true, null, null, null);
|
| 1961 |
ankur.sing |
146 |
List<Item> items = new ArrayList<Item>();
|
|
|
147 |
items.add(i);
|
|
|
148 |
this.items = items;
|
| 2027 |
ankur.sing |
149 |
//itemsMap.put(i.getId(), i);
|
| 2427 |
ankur.sing |
150 |
}*/
|
| 1961 |
ankur.sing |
151 |
|
| 2427 |
ankur.sing |
152 |
|
| 1992 |
ankur.sing |
153 |
public void loadAllItems() {
|
| 1961 |
ankur.sing |
154 |
catalogService.getAllItems(new AsyncCallback<List<Item>>() {
|
|
|
155 |
public void onFailure(Throwable caught) {
|
| 2126 |
ankur.sing |
156 |
caught.printStackTrace();
|
| 1992 |
ankur.sing |
157 |
Window.alert("Could not get all items...");
|
| 1961 |
ankur.sing |
158 |
}
|
|
|
159 |
public void onSuccess(List<Item> result) {
|
| 1992 |
ankur.sing |
160 |
updateItemDescriptionTable(result);
|
| 1961 |
ankur.sing |
161 |
}
|
|
|
162 |
});
|
|
|
163 |
}
|
|
|
164 |
|
| 2119 |
ankur.sing |
165 |
public void loadAllActiveItems() {
|
|
|
166 |
catalogService.getAllActiveItems(new AsyncCallback<List<Item>>() {
|
|
|
167 |
public void onFailure(Throwable caught) {
|
| 2126 |
ankur.sing |
168 |
caught.printStackTrace();
|
| 2119 |
ankur.sing |
169 |
Window.alert("Could not get all active items...");
|
|
|
170 |
}
|
|
|
171 |
public void onSuccess(List<Item> result) {
|
|
|
172 |
updateItemDescriptionTable(result);
|
|
|
173 |
}
|
|
|
174 |
});
|
|
|
175 |
}
|
|
|
176 |
|
| 2208 |
ankur.sing |
177 |
public void loadAllPhasedOutItems() {
|
|
|
178 |
catalogService.getAllPhasedOutItems(new AsyncCallback<List<Item>>() {
|
|
|
179 |
public void onFailure(Throwable caught) {
|
|
|
180 |
caught.printStackTrace();
|
|
|
181 |
Window.alert("Could not load phased out items...");
|
|
|
182 |
}
|
|
|
183 |
public void onSuccess(List<Item> result) {
|
|
|
184 |
updateItemDescriptionTable(result);
|
|
|
185 |
}
|
|
|
186 |
});
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
public void loadAllPausedItems() {
|
|
|
190 |
catalogService.getAllPausedItems(new AsyncCallback<List<Item>>() {
|
|
|
191 |
public void onFailure(Throwable caught) {
|
|
|
192 |
caught.printStackTrace();
|
|
|
193 |
Window.alert("Could not load paused items...");
|
|
|
194 |
}
|
|
|
195 |
public void onSuccess(List<Item> result) {
|
|
|
196 |
updateItemDescriptionTable(result);
|
|
|
197 |
}
|
|
|
198 |
});
|
|
|
199 |
}
|
|
|
200 |
|
| 2359 |
ankur.sing |
201 |
public void loadAllInProcessItems() {
|
|
|
202 |
catalogService.getAllInProcessItems(new AsyncCallback<List<Item>>() {
|
|
|
203 |
public void onFailure(Throwable caught) {
|
|
|
204 |
caught.printStackTrace();
|
|
|
205 |
Window.alert("Could not load IN_PROCESS items...");
|
|
|
206 |
}
|
|
|
207 |
public void onSuccess(List<Item> result) {
|
|
|
208 |
updateItemDescriptionTable(result);
|
|
|
209 |
}
|
|
|
210 |
});
|
|
|
211 |
}
|
|
|
212 |
|
|
|
213 |
public void loadAllContentCompleteItems() {
|
|
|
214 |
catalogService.getAllContentCompleteItems(new AsyncCallback<List<Item>>() {
|
|
|
215 |
public void onFailure(Throwable caught) {
|
|
|
216 |
caught.printStackTrace();
|
|
|
217 |
Window.alert("Could not load CONTENT_COMPLETE items...");
|
|
|
218 |
}
|
|
|
219 |
public void onSuccess(List<Item> result) {
|
|
|
220 |
updateItemDescriptionTable(result);
|
|
|
221 |
}
|
|
|
222 |
});
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
public void loadAllRiskyItems() {
|
|
|
226 |
catalogService.getRiskyItems(new AsyncCallback<List<Item>>() {
|
|
|
227 |
public void onFailure(Throwable caught) {
|
|
|
228 |
caught.printStackTrace();
|
|
|
229 |
Window.alert("Could not load RISKY items...");
|
|
|
230 |
}
|
|
|
231 |
public void onSuccess(List<Item> result) {
|
|
|
232 |
updateItemDescriptionTable(result);
|
|
|
233 |
}
|
|
|
234 |
});
|
|
|
235 |
}
|
|
|
236 |
|
| 1992 |
ankur.sing |
237 |
public void loadBestDeals() {
|
|
|
238 |
catalogService.getBestDeals(new AsyncCallback<List<Item>>() {
|
|
|
239 |
public void onFailure(Throwable caught) {
|
| 2126 |
ankur.sing |
240 |
caught.printStackTrace();
|
| 1992 |
ankur.sing |
241 |
Window.alert("Could not load best deals.");
|
|
|
242 |
}
|
|
|
243 |
public void onSuccess(List<Item> result) {
|
|
|
244 |
updateItemDescriptionTable(result);
|
|
|
245 |
}
|
|
|
246 |
});
|
|
|
247 |
}
|
|
|
248 |
|
|
|
249 |
public void loadLatestArrivals() {
|
|
|
250 |
catalogService.getLatestArrivals(new AsyncCallback<List<Item>>() {
|
|
|
251 |
public void onFailure(Throwable caught) {
|
| 2126 |
ankur.sing |
252 |
caught.printStackTrace();
|
| 1992 |
ankur.sing |
253 |
Window.alert("Could not load latest arrivals.");
|
|
|
254 |
}
|
|
|
255 |
public void onSuccess(List<Item> result) {
|
|
|
256 |
updateItemDescriptionTable(result);
|
|
|
257 |
}
|
|
|
258 |
});
|
|
|
259 |
}
|
|
|
260 |
|
|
|
261 |
public void loadBestSellers() {
|
|
|
262 |
catalogService.getBestSellers(new AsyncCallback<List<Item>>() {
|
|
|
263 |
public void onFailure(Throwable caught) {
|
| 2126 |
ankur.sing |
264 |
caught.printStackTrace();
|
| 1992 |
ankur.sing |
265 |
Window.alert("Could not load best sellers.");
|
|
|
266 |
}
|
|
|
267 |
public void onSuccess(List<Item> result) {
|
|
|
268 |
updateItemDescriptionTable(result);
|
|
|
269 |
}
|
|
|
270 |
});
|
|
|
271 |
}
|
| 2126 |
ankur.sing |
272 |
|
|
|
273 |
public void setItemDetails(ItemDetails itemDetails) {
|
|
|
274 |
this.itemDetails = itemDetails;
|
|
|
275 |
}
|
| 1961 |
ankur.sing |
276 |
}
|