| 584 |
chandransh |
1 |
package in.shop2020.hotspot.dashbaord.client.inbox;
|
|
|
2 |
|
| 585 |
chandransh |
3 |
import in.shop2020.hotspot.dashbaord.client.event.LoadItemDetailsEvent;
|
| 584 |
chandransh |
4 |
import in.shop2020.hotspot.dashbaord.shared.actions.Item;
|
|
|
5 |
|
|
|
6 |
import java.util.List;
|
|
|
7 |
|
|
|
8 |
import org.enunes.gwt.mvp.client.EventBus;
|
|
|
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.ui.FlexTable;
|
|
|
17 |
import com.google.gwt.user.client.ui.HTMLTable.Cell;
|
|
|
18 |
import com.google.gwt.user.client.ui.ResizeComposite;
|
|
|
19 |
import com.google.gwt.user.client.ui.Widget;
|
|
|
20 |
|
|
|
21 |
public class ItemList extends ResizeComposite{
|
|
|
22 |
|
|
|
23 |
interface ItemListUiBinder extends UiBinder<Widget, ItemList> {
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
private static final ItemListUiBinder uiBinder = GWT.create(ItemListUiBinder.class);
|
|
|
27 |
|
|
|
28 |
interface SelectionStyle extends CssResource{
|
|
|
29 |
String selectedRow();
|
|
|
30 |
String alertsRow();
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
@UiField FlexTable header;
|
|
|
34 |
@UiField FlexTable itemDescriptionTable;
|
|
|
35 |
@UiField SelectionStyle selectionStyle;
|
|
|
36 |
|
|
|
37 |
private int selectedRow = -1;
|
|
|
38 |
|
|
|
39 |
private final EventBus eventbus;
|
|
|
40 |
|
|
|
41 |
private final List<Item> items;
|
|
|
42 |
|
|
|
43 |
public ItemList(EventBus eventbus, List<Item> items) {
|
|
|
44 |
this.items = items;
|
|
|
45 |
this.eventbus = eventbus;
|
|
|
46 |
initWidget(uiBinder.createAndBindUi(this));
|
|
|
47 |
initHeader();
|
|
|
48 |
updateItemDescriptionTable(this.items);
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
private void initHeader(){
|
|
|
52 |
// Initialize the header.
|
|
|
53 |
header.getColumnFormatter().setWidth(0, "128px");
|
|
|
54 |
header.getColumnFormatter().setWidth(1, "128px");
|
|
|
55 |
header.getColumnFormatter().setWidth(2, "200px");
|
|
|
56 |
header.getColumnFormatter().setWidth(3, "200px");
|
|
|
57 |
header.getColumnFormatter().setWidth(4, "200px");
|
|
|
58 |
header.getColumnFormatter().setWidth(5, "128px");
|
| 960 |
chandransh |
59 |
header.getColumnFormatter().setWidth(6, "128px");
|
| 584 |
chandransh |
60 |
|
|
|
61 |
header.setText(0, 0, "Item Id");
|
| 960 |
chandransh |
62 |
header.setText(0, 1, "Product Group");
|
|
|
63 |
header.setText(0, 2, "Brand");
|
|
|
64 |
header.setText(0, 3, "Model Number");
|
|
|
65 |
header.setText(0, 4, "Model Name");
|
|
|
66 |
header.setText(0, 5, "MRP");
|
|
|
67 |
header.setText(0, 6, "Category");
|
| 584 |
chandransh |
68 |
}
|
|
|
69 |
|
|
|
70 |
private void updateItemDescriptionTable(List<Item> items){
|
|
|
71 |
itemDescriptionTable.getColumnFormatter().setWidth(0, "128px");
|
|
|
72 |
itemDescriptionTable.getColumnFormatter().setWidth(1, "128px");
|
|
|
73 |
itemDescriptionTable.getColumnFormatter().setWidth(2, "200px");
|
|
|
74 |
itemDescriptionTable.getColumnFormatter().setWidth(3, "200px");
|
| 960 |
chandransh |
75 |
itemDescriptionTable.getColumnFormatter().setWidth(4, "200px");
|
|
|
76 |
itemDescriptionTable.getColumnFormatter().setWidth(5, "128px");
|
|
|
77 |
itemDescriptionTable.getColumnFormatter().setWidth(6, "128px");
|
| 584 |
chandransh |
78 |
|
|
|
79 |
int i=0;
|
|
|
80 |
for(final Item item : items){
|
|
|
81 |
int col = 0;
|
|
|
82 |
itemDescriptionTable.setText(i, col++, item.getId() + "");
|
| 960 |
chandransh |
83 |
itemDescriptionTable.setText(i, col++, item.getProductGroup());
|
|
|
84 |
itemDescriptionTable.setText(i, col++, item.getBrand());
|
| 584 |
chandransh |
85 |
itemDescriptionTable.setText(i, col++, item.getModelNumber());
|
|
|
86 |
itemDescriptionTable.setText(i, col++, item.getModelName());
|
|
|
87 |
itemDescriptionTable.setText(i, col++, item.getMrp()+"");
|
| 625 |
chandransh |
88 |
itemDescriptionTable.setText(i, col++, item.getCategory()+"");
|
| 584 |
chandransh |
89 |
i++;
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
@UiHandler("itemDescriptionTable")
|
|
|
94 |
void onClick(ClickEvent event) {
|
|
|
95 |
Cell cell = itemDescriptionTable.getCellForEvent(event);
|
|
|
96 |
int newRowIndex = cell.getRowIndex();
|
|
|
97 |
selectRow(newRowIndex);
|
| 585 |
chandransh |
98 |
String itemId = itemDescriptionTable.getText(newRowIndex, 0);
|
|
|
99 |
eventbus.fireEvent(new LoadItemDetailsEvent(itemId));
|
| 584 |
chandransh |
100 |
}
|
|
|
101 |
|
|
|
102 |
private void selectRow(int row) {
|
|
|
103 |
String style = selectionStyle.selectedRow();
|
|
|
104 |
if(selectedRow != -1){
|
|
|
105 |
itemDescriptionTable.getRowFormatter().removeStyleName(selectedRow, style);
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
itemDescriptionTable.getRowFormatter().addStyleName(row, style);
|
|
|
109 |
selectedRow = row;
|
| 760 |
chandransh |
110 |
}
|
| 584 |
chandransh |
111 |
|
|
|
112 |
}
|