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