| 167 |
ashish |
1 |
package in.shop2020.hotspot.dashbaord.client.inbox;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.hotspot.dashbaord.client.event.LoadOrderDetailsEvent;
|
|
|
4 |
import in.shop2020.hotspot.dashbaord.shared.actions.Order;
|
|
|
5 |
|
|
|
6 |
import java.util.Date;
|
|
|
7 |
import java.util.List;
|
|
|
8 |
|
|
|
9 |
import org.enunes.gwt.mvp.client.EventBus;
|
|
|
10 |
|
|
|
11 |
import com.google.gwt.core.client.GWT;
|
|
|
12 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
13 |
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
14 |
import com.google.gwt.resources.client.CssResource;
|
|
|
15 |
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
16 |
import com.google.gwt.uibinder.client.UiField;
|
|
|
17 |
import com.google.gwt.user.client.ui.Anchor;
|
|
|
18 |
import com.google.gwt.user.client.ui.FlexTable;
|
|
|
19 |
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
|
|
|
20 |
import com.google.gwt.user.client.ui.ResizeComposite;
|
|
|
21 |
import com.google.gwt.user.client.ui.Widget;
|
|
|
22 |
|
|
|
23 |
public class OrderList extends ResizeComposite{
|
|
|
24 |
|
|
|
25 |
private int selectedRow = -1;
|
|
|
26 |
|
|
|
27 |
public interface Listener{
|
|
|
28 |
void onSelectItem();
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
interface Binder extends UiBinder<Widget, OrderList>{ }
|
|
|
32 |
|
|
|
33 |
interface SelectionStyle extends CssResource{
|
|
|
34 |
String selectedRow();
|
|
|
35 |
}
|
|
|
36 |
//add gin here
|
|
|
37 |
private static final Binder binder = GWT.create(Binder.class);
|
|
|
38 |
|
|
|
39 |
@UiField FlexTable header;
|
|
|
40 |
@UiField FlexTable table;
|
|
|
41 |
@UiField SelectionStyle selectionStyle;
|
|
|
42 |
|
|
|
43 |
private final EventBus eventbus;
|
|
|
44 |
|
|
|
45 |
private final List<Order> orders;
|
|
|
46 |
|
|
|
47 |
public OrderList(EventBus eventbus, List<Order> orders){
|
|
|
48 |
this.orders = orders;
|
|
|
49 |
initWidget(binder.createAndBindUi(this));
|
|
|
50 |
this.eventbus = eventbus;
|
|
|
51 |
initTable();
|
|
|
52 |
updateTable();
|
|
|
53 |
selectedRow = -1;
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
private void initTable(){
|
|
|
57 |
// Initialize the header.
|
|
|
58 |
header.getColumnFormatter().setWidth(0, "128px");
|
|
|
59 |
header.getColumnFormatter().setWidth(1, "128px");
|
|
|
60 |
header.getColumnFormatter().setWidth(2, "128px");
|
|
|
61 |
header.getColumnFormatter().setWidth(3, "128px");
|
|
|
62 |
header.getColumnFormatter().setWidth(4, "128px");
|
|
|
63 |
//header.getColumnFormatter().setWidth(5, "128px");
|
|
|
64 |
|
|
|
65 |
header.setText(0, 0, "Order Id");
|
|
|
66 |
header.setText(0, 1, "Customer Id");
|
|
|
67 |
header.setText(0, 2, "Date Created");
|
|
|
68 |
header.setText(0, 3, "Expected Delivery");
|
|
|
69 |
header.setText(0, 4, "Current Status");
|
|
|
70 |
header.setText(0, 5, "Status Message");
|
|
|
71 |
|
|
|
72 |
// Initialize the table.
|
|
|
73 |
table.getColumnFormatter().setWidth(0, "128px");
|
|
|
74 |
table.getColumnFormatter().setWidth(1, "128px");
|
|
|
75 |
table.getColumnFormatter().setWidth(2, "128px");
|
|
|
76 |
table.getColumnFormatter().setWidth(3, "128px");
|
|
|
77 |
table.getColumnFormatter().setWidth(4, "128px");
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
private void selectRow(int row) {
|
|
|
81 |
// When a row (other than the first one, which is used as a header) is
|
|
|
82 |
// selected, display its associated MailItem.
|
|
|
83 |
if(selectedRow != -1){
|
|
|
84 |
styleRow(selectedRow, false);
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
styleRow(row, true);
|
|
|
88 |
selectedRow = row;
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
|
|
|
92 |
private void styleRow(int row, boolean selected) {
|
|
|
93 |
if (row != -1) {
|
|
|
94 |
String style = selectionStyle.selectedRow();
|
|
|
95 |
|
|
|
96 |
if (selected) {
|
|
|
97 |
table.getRowFormatter().addStyleName(row, style);
|
|
|
98 |
} else {
|
|
|
99 |
table.getRowFormatter().removeStyleName(row, style);
|
|
|
100 |
}
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
private void updateTable(){
|
|
|
105 |
int i = 0;
|
|
|
106 |
for(final Order o : orders){
|
|
|
107 |
Anchor a = new Anchor(o.getTransactionId() + "");
|
|
|
108 |
table.setWidget(i, 0, a);
|
|
|
109 |
table.setText(i, 1, o.getCustomerId()+ "");
|
|
|
110 |
table.setText(i, 2, new Date(o.getCreatedOn())+"");
|
|
|
111 |
table.setText(i, 3, new Date(o.getExpectedDeliveryTime())+"");
|
|
|
112 |
table.setText(i, 4, o.getStatus());
|
|
|
113 |
table.setText(i, 5, o.getStatusMessage());
|
|
|
114 |
i++;
|
|
|
115 |
final int j =i-1;
|
|
|
116 |
a.addClickHandler(new ClickHandler() {
|
|
|
117 |
|
|
|
118 |
@Override
|
|
|
119 |
public void onClick(ClickEvent event) {
|
|
|
120 |
// TODO Auto-generated method stub
|
|
|
121 |
|
|
|
122 |
selectRow(j);
|
|
|
123 |
eventbus.fireEvent(new LoadOrderDetailsEvent(o));
|
|
|
124 |
}
|
|
|
125 |
});
|
|
|
126 |
}
|
|
|
127 |
}
|
|
|
128 |
}
|