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