| 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 |
public interface Listener {
|
|
|
28 |
void onItemSelected(Item item);
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
Map<Long, Item> itemsMap = new HashMap<Long, Item>();
|
|
|
32 |
|
|
|
33 |
private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
|
|
|
34 |
|
|
|
35 |
interface ItemListUiBinder extends UiBinder<Widget, ItemList> { }
|
|
|
36 |
private static final ItemListUiBinder uiBinder = GWT.create(ItemListUiBinder.class);
|
|
|
37 |
|
|
|
38 |
interface SelectionStyle extends CssResource{
|
|
|
39 |
String selectedRow();
|
|
|
40 |
String alertsRow();
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
@UiField FlexTable header;
|
|
|
44 |
@UiField FlexTable itemDescriptionTable;
|
|
|
45 |
@UiField SelectionStyle selectionStyle;
|
|
|
46 |
private Listener listener;
|
|
|
47 |
private int selectedRow = -1;
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
private List<Item> items;
|
|
|
51 |
|
|
|
52 |
public ItemList() {
|
|
|
53 |
initWidget(uiBinder.createAndBindUi(this));
|
|
|
54 |
initHeader();
|
|
|
55 |
initItemList();
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
private void initItemList() {
|
| 1992 |
ankur.sing |
59 |
loadBestDeals();
|
|
|
60 |
//loadDummyItems();
|
|
|
61 |
//updateItemDescriptionTable(items);
|
| 1961 |
ankur.sing |
62 |
}
|
|
|
63 |
|
|
|
64 |
private void initHeader(){
|
|
|
65 |
// Initialize the header.
|
|
|
66 |
header.getColumnFormatter().setWidth(0, "128px");
|
|
|
67 |
header.getColumnFormatter().setWidth(1, "128px");
|
|
|
68 |
header.getColumnFormatter().setWidth(2, "200px");
|
|
|
69 |
header.getColumnFormatter().setWidth(3, "200px");
|
|
|
70 |
header.getColumnFormatter().setWidth(4, "200px");
|
|
|
71 |
header.getColumnFormatter().setWidth(5, "128px");
|
|
|
72 |
header.getColumnFormatter().setWidth(6, "128px");
|
|
|
73 |
|
|
|
74 |
header.setText(0, 0, "Item Id");
|
|
|
75 |
header.setText(0, 1, "Product Group");
|
|
|
76 |
header.setText(0, 2, "Brand");
|
|
|
77 |
header.setText(0, 3, "Model Number");
|
|
|
78 |
header.setText(0, 4, "Model Name");
|
|
|
79 |
header.setText(0, 5, "MRP");
|
|
|
80 |
header.setText(0, 6, "Category");
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
private void updateItemDescriptionTable(List<Item> items){
|
|
|
84 |
itemDescriptionTable.getColumnFormatter().setWidth(0, "128px");
|
|
|
85 |
itemDescriptionTable.getColumnFormatter().setWidth(1, "128px");
|
|
|
86 |
itemDescriptionTable.getColumnFormatter().setWidth(2, "200px");
|
|
|
87 |
itemDescriptionTable.getColumnFormatter().setWidth(3, "200px");
|
|
|
88 |
itemDescriptionTable.getColumnFormatter().setWidth(4, "200px");
|
|
|
89 |
itemDescriptionTable.getColumnFormatter().setWidth(5, "128px");
|
|
|
90 |
itemDescriptionTable.getColumnFormatter().setWidth(6, "128px");
|
|
|
91 |
|
|
|
92 |
int i=0;
|
|
|
93 |
for(final Item item : items){
|
| 1992 |
ankur.sing |
94 |
itemsMap.put(item.getId(), item);
|
| 1961 |
ankur.sing |
95 |
int col = 0;
|
|
|
96 |
itemDescriptionTable.setText(i, col++, item.getId() + "");
|
|
|
97 |
itemDescriptionTable.setText(i, col++, item.getProductGroup());
|
|
|
98 |
itemDescriptionTable.setText(i, col++, item.getBrand());
|
|
|
99 |
itemDescriptionTable.setText(i, col++, item.getModelNumber());
|
|
|
100 |
itemDescriptionTable.setText(i, col++, item.getModelName());
|
|
|
101 |
itemDescriptionTable.setText(i, col++, item.getMrp()+"");
|
|
|
102 |
itemDescriptionTable.setText(i, col++, item.getCategory()+"");
|
|
|
103 |
i++;
|
|
|
104 |
}
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
public void setListener(Listener listener) {
|
|
|
108 |
this.listener = listener;
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
@UiHandler("itemDescriptionTable")
|
|
|
112 |
void onClick(ClickEvent event) {
|
|
|
113 |
Cell cell = itemDescriptionTable.getCellForEvent(event);
|
|
|
114 |
int newRowIndex = cell.getRowIndex();
|
| 1992 |
ankur.sing |
115 |
selectRow(newRowIndex);
|
| 1961 |
ankur.sing |
116 |
String itemId = itemDescriptionTable.getText(newRowIndex, 0);
|
|
|
117 |
Window.alert("Item id = " + itemId);
|
|
|
118 |
|
|
|
119 |
listener.onItemSelected(itemsMap.get(Long.parseLong(itemId)));
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
private void selectRow(int row) {
|
|
|
123 |
String style = selectionStyle.selectedRow();
|
|
|
124 |
if(selectedRow != -1){
|
|
|
125 |
itemDescriptionTable.getRowFormatter().removeStyleName(selectedRow, style);
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
itemDescriptionTable.getRowFormatter().addStyleName(row, style);
|
|
|
129 |
selectedRow = row;
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
private void loadDummyItems() {
|
| 1992 |
ankur.sing |
133 |
|
|
|
134 |
Item i = new Item(1, "Handset", "Spice", "mi310", "phone", "White", 2, "comments", 1, 1,
|
|
|
135 |
"", 3000.50, 3000.00, 3000, 3000, 12, 12345, 12345, 12345, 12345, "status", null, "best", 2990, null, null);
|
| 1961 |
ankur.sing |
136 |
List<Item> items = new ArrayList<Item>();
|
|
|
137 |
items.add(i);
|
|
|
138 |
this.items = items;
|
|
|
139 |
itemsMap.put(i.getId(), i);
|
| 1992 |
ankur.sing |
140 |
|
| 1961 |
ankur.sing |
141 |
}
|
|
|
142 |
|
| 1992 |
ankur.sing |
143 |
public void loadAllItems() {
|
| 1961 |
ankur.sing |
144 |
catalogService.getAllItems(new AsyncCallback<List<Item>>() {
|
|
|
145 |
public void onFailure(Throwable caught) {
|
| 1992 |
ankur.sing |
146 |
Window.alert("Could not get all items...");
|
| 1961 |
ankur.sing |
147 |
}
|
|
|
148 |
public void onSuccess(List<Item> result) {
|
| 1992 |
ankur.sing |
149 |
itemsMap.clear();
|
|
|
150 |
updateItemDescriptionTable(result);
|
|
|
151 |
//setItems(result);
|
| 1961 |
ankur.sing |
152 |
}
|
|
|
153 |
});
|
|
|
154 |
}
|
|
|
155 |
|
| 1992 |
ankur.sing |
156 |
public void loadBestDeals() {
|
|
|
157 |
catalogService.getBestDeals(new AsyncCallback<List<Item>>() {
|
|
|
158 |
public void onFailure(Throwable caught) {
|
|
|
159 |
Window.alert("Could not load best deals.");
|
|
|
160 |
}
|
|
|
161 |
public void onSuccess(List<Item> result) {
|
|
|
162 |
itemsMap.clear();
|
|
|
163 |
updateItemDescriptionTable(result);
|
|
|
164 |
//setItems(result);
|
|
|
165 |
}
|
|
|
166 |
});
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
public void loadLatestArrivals() {
|
|
|
170 |
catalogService.getLatestArrivals(new AsyncCallback<List<Item>>() {
|
|
|
171 |
public void onFailure(Throwable caught) {
|
|
|
172 |
Window.alert("Could not load latest arrivals.");
|
|
|
173 |
}
|
|
|
174 |
public void onSuccess(List<Item> result) {
|
|
|
175 |
itemsMap.clear();
|
|
|
176 |
updateItemDescriptionTable(result);
|
|
|
177 |
//setItems(result);
|
|
|
178 |
}
|
|
|
179 |
});
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
public void loadBestSellers() {
|
|
|
183 |
catalogService.getBestSellers(new AsyncCallback<List<Item>>() {
|
|
|
184 |
public void onFailure(Throwable caught) {
|
|
|
185 |
Window.alert("Could not load best sellers.");
|
|
|
186 |
}
|
|
|
187 |
public void onSuccess(List<Item> result) {
|
|
|
188 |
itemsMap.clear();
|
|
|
189 |
updateItemDescriptionTable(result);
|
|
|
190 |
//setItems(result);
|
|
|
191 |
}
|
|
|
192 |
});
|
|
|
193 |
}
|
|
|
194 |
|
| 1961 |
ankur.sing |
195 |
void setItems(List<Item> items) {
|
|
|
196 |
this.items = items;
|
|
|
197 |
}
|
| 1992 |
ankur.sing |
198 |
|
| 1961 |
ankur.sing |
199 |
}
|