| 1961 |
ankur.sing |
1 |
package in.shop2020.catalog.dashboard.client;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.catalog.dashboard.shared.Item;
|
|
|
4 |
|
|
|
5 |
import java.util.ArrayList;
|
|
|
6 |
import java.util.HashMap;
|
|
|
7 |
import java.util.List;
|
|
|
8 |
import java.util.Map;
|
|
|
9 |
|
|
|
10 |
import com.google.gwt.core.client.GWT;
|
|
|
11 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
12 |
import com.google.gwt.resources.client.CssResource;
|
|
|
13 |
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
14 |
import com.google.gwt.uibinder.client.UiField;
|
|
|
15 |
import com.google.gwt.uibinder.client.UiHandler;
|
|
|
16 |
import com.google.gwt.user.client.Window;
|
|
|
17 |
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
18 |
import com.google.gwt.user.client.ui.FlexTable;
|
|
|
19 |
import com.google.gwt.user.client.ui.HTMLTable.Cell;
|
|
|
20 |
import com.google.gwt.user.client.ui.ResizeComposite;
|
|
|
21 |
import com.google.gwt.user.client.ui.Widget;
|
|
|
22 |
|
|
|
23 |
public class ItemList extends ResizeComposite{
|
|
|
24 |
|
|
|
25 |
public static final int VISIBLE_ITEMS_COUNT = 10;
|
|
|
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 |
|
|
|
42 |
|
|
|
43 |
private List<Item> items;
|
|
|
44 |
|
| 2126 |
ankur.sing |
45 |
private ItemDetails itemDetails;
|
|
|
46 |
|
| 1961 |
ankur.sing |
47 |
public ItemList() {
|
|
|
48 |
initWidget(uiBinder.createAndBindUi(this));
|
|
|
49 |
initHeader();
|
|
|
50 |
initItemList();
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
private void initItemList() {
|
| 2126 |
ankur.sing |
54 |
loadBestSellers();
|
|
|
55 |
|
| 1992 |
ankur.sing |
56 |
//loadDummyItems();
|
|
|
57 |
//updateItemDescriptionTable(items);
|
| 1961 |
ankur.sing |
58 |
}
|
|
|
59 |
|
|
|
60 |
private void initHeader(){
|
|
|
61 |
// Initialize the header.
|
| 2027 |
ankur.sing |
62 |
header.getColumnFormatter().setWidth(0, "80px");
|
| 1961 |
ankur.sing |
63 |
header.getColumnFormatter().setWidth(1, "128px");
|
| 2027 |
ankur.sing |
64 |
header.getColumnFormatter().setWidth(2, "150px");
|
| 1961 |
ankur.sing |
65 |
header.getColumnFormatter().setWidth(3, "200px");
|
|
|
66 |
header.getColumnFormatter().setWidth(4, "200px");
|
|
|
67 |
header.getColumnFormatter().setWidth(5, "128px");
|
| 2027 |
ankur.sing |
68 |
header.getColumnFormatter().setWidth(6, "220px");
|
| 1961 |
ankur.sing |
69 |
|
|
|
70 |
header.setText(0, 0, "Item Id");
|
|
|
71 |
header.setText(0, 1, "Product Group");
|
|
|
72 |
header.setText(0, 2, "Brand");
|
|
|
73 |
header.setText(0, 3, "Model Number");
|
|
|
74 |
header.setText(0, 4, "Model Name");
|
| 2027 |
ankur.sing |
75 |
header.setText(0, 5, "Color");
|
| 1961 |
ankur.sing |
76 |
header.setText(0, 6, "Category");
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
private void updateItemDescriptionTable(List<Item> items){
|
| 2027 |
ankur.sing |
80 |
itemDescriptionTable.removeAllRows();
|
|
|
81 |
itemDescriptionTable.getColumnFormatter().setWidth(0, "80px");
|
| 1961 |
ankur.sing |
82 |
itemDescriptionTable.getColumnFormatter().setWidth(1, "128px");
|
| 2027 |
ankur.sing |
83 |
itemDescriptionTable.getColumnFormatter().setWidth(2, "150px");
|
| 1961 |
ankur.sing |
84 |
itemDescriptionTable.getColumnFormatter().setWidth(3, "200px");
|
|
|
85 |
itemDescriptionTable.getColumnFormatter().setWidth(4, "200px");
|
|
|
86 |
itemDescriptionTable.getColumnFormatter().setWidth(5, "128px");
|
| 2027 |
ankur.sing |
87 |
itemDescriptionTable.getColumnFormatter().setWidth(6, "220px");
|
| 1961 |
ankur.sing |
88 |
|
|
|
89 |
int i=0;
|
|
|
90 |
for(final Item item : items){
|
| 2027 |
ankur.sing |
91 |
//itemsMap.put(item.getId(), item);
|
| 1961 |
ankur.sing |
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 |
|
|
|
104 |
@UiHandler("itemDescriptionTable")
|
|
|
105 |
void onClick(ClickEvent event) {
|
| 2066 |
ankur.sing |
106 |
|
| 1961 |
ankur.sing |
107 |
Cell cell = itemDescriptionTable.getCellForEvent(event);
|
|
|
108 |
int newRowIndex = cell.getRowIndex();
|
| 1992 |
ankur.sing |
109 |
selectRow(newRowIndex);
|
| 1961 |
ankur.sing |
110 |
String itemId = itemDescriptionTable.getText(newRowIndex, 0);
|
| 2126 |
ankur.sing |
111 |
|
|
|
112 |
catalogService.getItem(Long.parseLong(itemId), new AsyncCallback<Item>() {
|
|
|
113 |
@Override
|
|
|
114 |
public void onSuccess(Item result) {
|
|
|
115 |
itemDetails.setItemDetails(result);
|
|
|
116 |
}
|
|
|
117 |
@Override
|
|
|
118 |
public void onFailure(Throwable caught) {
|
|
|
119 |
Window.alert("Unable to fetch item details.");
|
|
|
120 |
}
|
|
|
121 |
});
|
| 1961 |
ankur.sing |
122 |
}
|
|
|
123 |
|
|
|
124 |
private void selectRow(int row) {
|
|
|
125 |
String style = selectionStyle.selectedRow();
|
|
|
126 |
if(selectedRow != -1){
|
|
|
127 |
itemDescriptionTable.getRowFormatter().removeStyleName(selectedRow, style);
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
itemDescriptionTable.getRowFormatter().addStyleName(row, style);
|
|
|
131 |
selectedRow = row;
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
private void loadDummyItems() {
|
| 1992 |
ankur.sing |
135 |
|
| 2126 |
ankur.sing |
136 |
Item i = new Item(1, "Handset", "Spice", "mi310", "phone", "White", "Business Phone",1, "comments", 1, 1,
|
|
|
137 |
"", 3000.50, 3000.00, 3000, 3000, 12, 12345, 12345, 12345, 12345, "status", 1, null, "best", 2990, 1, true, null, null, null);
|
| 1961 |
ankur.sing |
138 |
List<Item> items = new ArrayList<Item>();
|
|
|
139 |
items.add(i);
|
|
|
140 |
this.items = items;
|
| 2027 |
ankur.sing |
141 |
//itemsMap.put(i.getId(), i);
|
| 1992 |
ankur.sing |
142 |
|
| 1961 |
ankur.sing |
143 |
}
|
|
|
144 |
|
| 1992 |
ankur.sing |
145 |
public void loadAllItems() {
|
| 1961 |
ankur.sing |
146 |
catalogService.getAllItems(new AsyncCallback<List<Item>>() {
|
|
|
147 |
public void onFailure(Throwable caught) {
|
| 2126 |
ankur.sing |
148 |
caught.printStackTrace();
|
| 1992 |
ankur.sing |
149 |
Window.alert("Could not get all items...");
|
| 1961 |
ankur.sing |
150 |
}
|
|
|
151 |
public void onSuccess(List<Item> result) {
|
| 1992 |
ankur.sing |
152 |
updateItemDescriptionTable(result);
|
|
|
153 |
//setItems(result);
|
| 1961 |
ankur.sing |
154 |
}
|
|
|
155 |
});
|
|
|
156 |
}
|
|
|
157 |
|
| 2119 |
ankur.sing |
158 |
public void loadAllActiveItems() {
|
|
|
159 |
catalogService.getAllActiveItems(new AsyncCallback<List<Item>>() {
|
|
|
160 |
public void onFailure(Throwable caught) {
|
| 2126 |
ankur.sing |
161 |
caught.printStackTrace();
|
| 2119 |
ankur.sing |
162 |
Window.alert("Could not get all active items...");
|
|
|
163 |
}
|
|
|
164 |
public void onSuccess(List<Item> result) {
|
|
|
165 |
updateItemDescriptionTable(result);
|
|
|
166 |
//setItems(result);
|
|
|
167 |
}
|
|
|
168 |
});
|
|
|
169 |
}
|
|
|
170 |
|
| 1992 |
ankur.sing |
171 |
public void loadBestDeals() {
|
|
|
172 |
catalogService.getBestDeals(new AsyncCallback<List<Item>>() {
|
|
|
173 |
public void onFailure(Throwable caught) {
|
| 2126 |
ankur.sing |
174 |
caught.printStackTrace();
|
| 1992 |
ankur.sing |
175 |
Window.alert("Could not load best deals.");
|
|
|
176 |
}
|
|
|
177 |
public void onSuccess(List<Item> result) {
|
|
|
178 |
updateItemDescriptionTable(result);
|
|
|
179 |
//setItems(result);
|
|
|
180 |
}
|
|
|
181 |
});
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
public void loadLatestArrivals() {
|
|
|
185 |
catalogService.getLatestArrivals(new AsyncCallback<List<Item>>() {
|
|
|
186 |
public void onFailure(Throwable caught) {
|
| 2126 |
ankur.sing |
187 |
caught.printStackTrace();
|
| 1992 |
ankur.sing |
188 |
Window.alert("Could not load latest arrivals.");
|
|
|
189 |
}
|
|
|
190 |
public void onSuccess(List<Item> result) {
|
|
|
191 |
updateItemDescriptionTable(result);
|
|
|
192 |
//setItems(result);
|
|
|
193 |
}
|
|
|
194 |
});
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
public void loadBestSellers() {
|
|
|
198 |
catalogService.getBestSellers(new AsyncCallback<List<Item>>() {
|
|
|
199 |
public void onFailure(Throwable caught) {
|
| 2126 |
ankur.sing |
200 |
caught.printStackTrace();
|
| 1992 |
ankur.sing |
201 |
Window.alert("Could not load best sellers.");
|
|
|
202 |
}
|
|
|
203 |
public void onSuccess(List<Item> result) {
|
|
|
204 |
updateItemDescriptionTable(result);
|
|
|
205 |
//setItems(result);
|
|
|
206 |
}
|
|
|
207 |
});
|
|
|
208 |
}
|
| 2126 |
ankur.sing |
209 |
|
|
|
210 |
public void setItemDetails(ItemDetails itemDetails) {
|
|
|
211 |
this.itemDetails = itemDetails;
|
|
|
212 |
}
|
| 1992 |
ankur.sing |
213 |
|
| 1961 |
ankur.sing |
214 |
}
|