| 167 |
ashish |
1 |
package in.shop2020.hotspot.dashbaord.client.inbox;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.hotspot.dashbaord.client.event.LoadOrderDetailsEvent;
|
| 4133 |
chandransh |
4 |
import in.shop2020.hotspot.dashbaord.client.event.LoadOrderListEvent;
|
| 4398 |
rajveer |
5 |
import in.shop2020.hotspot.dashbaord.shared.actions.OrderAlert;
|
| 167 |
ashish |
6 |
import in.shop2020.hotspot.dashbaord.shared.actions.Order;
|
| 4133 |
chandransh |
7 |
import in.shop2020.hotspot.dashbaord.shared.actions.OrderType;
|
| 167 |
ashish |
8 |
|
|
|
9 |
import java.util.Date;
|
|
|
10 |
import java.util.List;
|
|
|
11 |
|
|
|
12 |
import org.enunes.gwt.mvp.client.EventBus;
|
|
|
13 |
|
| 4361 |
rajveer |
14 |
import com.google.gwt.cell.client.CheckboxCell;
|
| 167 |
ashish |
15 |
import com.google.gwt.core.client.GWT;
|
| 4124 |
chandransh |
16 |
import com.google.gwt.dom.client.Style.Unit;
|
| 167 |
ashish |
17 |
import com.google.gwt.resources.client.CssResource;
|
|
|
18 |
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
19 |
import com.google.gwt.uibinder.client.UiField;
|
| 4361 |
rajveer |
20 |
import com.google.gwt.user.cellview.client.Column;
|
| 4124 |
chandransh |
21 |
import com.google.gwt.user.cellview.client.DataGrid;
|
|
|
22 |
import com.google.gwt.user.cellview.client.RowStyles;
|
|
|
23 |
import com.google.gwt.user.cellview.client.SimplePager;
|
|
|
24 |
import com.google.gwt.user.cellview.client.TextColumn;
|
| 167 |
ashish |
25 |
import com.google.gwt.user.client.ui.ResizeComposite;
|
|
|
26 |
import com.google.gwt.user.client.ui.Widget;
|
| 4124 |
chandransh |
27 |
import com.google.gwt.view.client.AsyncDataProvider;
|
|
|
28 |
import com.google.gwt.view.client.HasData;
|
|
|
29 |
import com.google.gwt.view.client.Range;
|
|
|
30 |
import com.google.gwt.view.client.SelectionChangeEvent;
|
|
|
31 |
import com.google.gwt.view.client.SingleSelectionModel;
|
| 167 |
ashish |
32 |
|
| 4125 |
chandransh |
33 |
public class OrderList extends ResizeComposite {
|
| 167 |
ashish |
34 |
|
| 4125 |
chandransh |
35 |
interface OrderListUiBinder extends UiBinder<Widget, OrderList>{}
|
| 167 |
ashish |
36 |
|
| 4125 |
chandransh |
37 |
interface SelectionStyle extends CssResource {
|
| 167 |
ashish |
38 |
String selectedRow();
|
| 4004 |
chandransh |
39 |
String fatalRow();
|
|
|
40 |
String criticalRow();
|
| 167 |
ashish |
41 |
}
|
|
|
42 |
//add gin here
|
| 584 |
chandransh |
43 |
private static final OrderListUiBinder binder = GWT.create(OrderListUiBinder.class);
|
| 167 |
ashish |
44 |
|
| 4124 |
chandransh |
45 |
@UiField DataGrid<Order> table;
|
|
|
46 |
// Create paging controls.
|
|
|
47 |
@UiField SimplePager pager = new SimplePager();
|
| 167 |
ashish |
48 |
@UiField SelectionStyle selectionStyle;
|
|
|
49 |
|
| 4361 |
rajveer |
50 |
|
|
|
51 |
Column<Order, Boolean> checkboxColumn = new Column<Order, Boolean>(new CheckboxCell(true, false)) {
|
|
|
52 |
@Override
|
|
|
53 |
public Boolean getValue(Order order) {
|
|
|
54 |
return table.getSelectionModel().isSelected(order);
|
|
|
55 |
}
|
|
|
56 |
};
|
|
|
57 |
|
|
|
58 |
|
| 4666 |
rajveer |
59 |
private TextColumn<Order> promisedShippingDateColumn = new TextColumn<Order>() {
|
|
|
60 |
@Override
|
| 4124 |
chandransh |
61 |
public String getValue(Order order) {
|
| 4666 |
rajveer |
62 |
return getDisplayableDate(new Date(order.getPromisedDeliveryTime()))+"";
|
| 4124 |
chandransh |
63 |
}
|
|
|
64 |
};
|
|
|
65 |
|
|
|
66 |
private TextColumn<Order> paymentModeColumn = new TextColumn<Order>() {
|
|
|
67 |
@Override
|
|
|
68 |
public String getValue(Order order) {
|
|
|
69 |
return order.isCod() ? "COD" : "Prepaid";
|
|
|
70 |
}
|
|
|
71 |
};
|
|
|
72 |
|
|
|
73 |
private TextColumn<Order> idColumn = new TextColumn<Order>() {
|
|
|
74 |
@Override
|
|
|
75 |
public String getValue(Order order) {
|
|
|
76 |
return "" + order.getOrderId();
|
|
|
77 |
}
|
|
|
78 |
};
|
|
|
79 |
|
|
|
80 |
private TextColumn<Order> productDescriptionColumn = new TextColumn<Order>() {
|
|
|
81 |
@Override
|
|
|
82 |
public String getValue(Order order) {
|
|
|
83 |
StringBuilder productDescription = new StringBuilder(order.getProductGroup());
|
|
|
84 |
if(order.getBrand()!=null)
|
|
|
85 |
productDescription.append(" " + order.getBrand());
|
|
|
86 |
if(order.getModelNumber()!=null)
|
|
|
87 |
productDescription.append(" " + order.getModelNumber());
|
|
|
88 |
if(order.getModelName()!=null)
|
|
|
89 |
productDescription.append(" " + order.getModelName());
|
|
|
90 |
if(order.getColor()!=null)
|
| 4175 |
rajveer |
91 |
productDescription.append(" " + order.getColor());
|
|
|
92 |
if(order.getDealText()!=null)
|
|
|
93 |
productDescription.append(" (" + order.getDealText() + ")");
|
| 4124 |
chandransh |
94 |
return productDescription.toString();
|
|
|
95 |
}
|
|
|
96 |
};
|
|
|
97 |
|
|
|
98 |
private TextColumn<Order> creationDateColumn = new TextColumn<Order>() {
|
|
|
99 |
@Override
|
|
|
100 |
public String getValue(Order order) {
|
|
|
101 |
return getDisplayableDate(new Date(order.getCreatedOn()))+"";
|
|
|
102 |
}
|
|
|
103 |
};
|
|
|
104 |
|
|
|
105 |
private TextColumn<Order> promisedDeliveryDateColumn = new TextColumn<Order>() {
|
|
|
106 |
@Override
|
|
|
107 |
public String getValue(Order order) {
|
|
|
108 |
return getDisplayableDate(new Date(order.getPromisedDeliveryTime()))+"";
|
|
|
109 |
}
|
|
|
110 |
};
|
|
|
111 |
|
|
|
112 |
private TextColumn<Order> expectedDeliveryDateColumn = new TextColumn<Order>() {
|
|
|
113 |
@Override
|
|
|
114 |
public String getValue(Order order) {
|
|
|
115 |
return getDisplayableDate(new Date(order.getExpectedDeliveryTime()))+"";
|
|
|
116 |
}
|
|
|
117 |
};
|
|
|
118 |
|
|
|
119 |
private TextColumn<Order> statusMessageColumn = new TextColumn<Order>() {
|
|
|
120 |
@Override
|
|
|
121 |
public String getValue(Order order) {
|
|
|
122 |
return order.getStatusMessage();
|
|
|
123 |
}
|
|
|
124 |
};
|
|
|
125 |
|
|
|
126 |
AsyncDataProvider<Order> asyncDataProvider = new AsyncDataProvider<Order>() {
|
|
|
127 |
|
|
|
128 |
@Override
|
|
|
129 |
protected void onRangeChanged(HasData<Order> display) {
|
|
|
130 |
Range range = display.getVisibleRange();
|
| 4133 |
chandransh |
131 |
int newStart = range.getStart();
|
|
|
132 |
// This is to prevent the recursive firing of onRangeChanged events.
|
|
|
133 |
// Every time fresh data is pushed into the DataProvider, this
|
|
|
134 |
// method is called. This, in turn, fires an event to refresh the
|
|
|
135 |
// data. If the start of the new range is same as that of the
|
|
|
136 |
// currently loaded data, there is no point in proceeding further.
|
|
|
137 |
GWT.log(this + "Current start: " + start + ", New start:" + newStart);
|
|
|
138 |
if(newStart == start)
|
|
|
139 |
return;
|
| 4124 |
chandransh |
140 |
int limit = range.getLength();
|
| 4133 |
chandransh |
141 |
|
|
|
142 |
eventbus.fireEvent(new LoadOrderListEvent(orderType, newStart, limit));
|
| 4124 |
chandransh |
143 |
}
|
|
|
144 |
|
|
|
145 |
};
|
|
|
146 |
|
| 167 |
ashish |
147 |
private final EventBus eventbus;
|
| 4133 |
chandransh |
148 |
private final OrderType orderType;
|
| 167 |
ashish |
149 |
private final List<Order> orders;
|
| 4133 |
chandransh |
150 |
private int count;
|
|
|
151 |
private final int start;
|
| 167 |
ashish |
152 |
|
| 4133 |
chandransh |
153 |
public OrderList(EventBus eventbus, OrderType orderType, List<Order> orders, int start, int count){
|
| 167 |
ashish |
154 |
this.orders = orders;
|
| 4124 |
chandransh |
155 |
this.eventbus = eventbus;
|
| 4133 |
chandransh |
156 |
this.orderType = orderType;
|
|
|
157 |
this.start = start;
|
|
|
158 |
this.count = count;
|
| 167 |
ashish |
159 |
initWidget(binder.createAndBindUi(this));
|
|
|
160 |
initTable();
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
private void initTable(){
|
| 4124 |
chandransh |
164 |
|
|
|
165 |
//Add custom styles to show in case we want to alert the user
|
|
|
166 |
table.setRowStyles(new RowStyles<Order>(){
|
| 167 |
ashish |
167 |
|
| 4124 |
chandransh |
168 |
@Override
|
|
|
169 |
public String getStyleNames(Order order, int rowIndex) {
|
| 4133 |
chandransh |
170 |
if(order==null)
|
|
|
171 |
return "";
|
| 4398 |
rajveer |
172 |
OrderAlert alert = order.getAlert();
|
| 4124 |
chandransh |
173 |
String style = "";
|
|
|
174 |
switch(alert){
|
|
|
175 |
case DELIVERY_TIME_EXCEEDED:
|
|
|
176 |
case SHIPPING_TIME_EXCEEDED:
|
|
|
177 |
case VERIFICATION_DELAYED_TOO_MUCH:
|
|
|
178 |
case ACCEPTANCE_DELAYED_TOO_MUCH:
|
|
|
179 |
case ORDER_NOT_CONNECTED_FOR_TOO_LONG:
|
|
|
180 |
style = selectionStyle.fatalRow();
|
|
|
181 |
break;
|
|
|
182 |
case ACCEPTANCE_DELAYED:
|
|
|
183 |
case VERIFICATION_DELAYED:
|
|
|
184 |
case ORDER_NOT_CONNECTED:
|
|
|
185 |
style = selectionStyle.criticalRow();
|
|
|
186 |
break;
|
|
|
187 |
case WARNING:
|
|
|
188 |
case NONE:
|
|
|
189 |
}
|
|
|
190 |
return style;
|
|
|
191 |
}
|
|
|
192 |
});
|
|
|
193 |
|
| 4361 |
rajveer |
194 |
|
|
|
195 |
|
|
|
196 |
// Add the columns.
|
|
|
197 |
table.addColumn(checkboxColumn,"");
|
| 4666 |
rajveer |
198 |
table.addColumn(promisedShippingDateColumn, "Promised Shipping");
|
| 4124 |
chandransh |
199 |
table.addColumn(paymentModeColumn, "Type");
|
|
|
200 |
table.addColumn(idColumn, "Order Id");
|
|
|
201 |
table.addColumn(productDescriptionColumn, "Product Description");
|
|
|
202 |
table.addColumn(creationDateColumn, "Creation Date");
|
|
|
203 |
table.addColumn(promisedDeliveryDateColumn, "Promised Delivery");
|
|
|
204 |
table.addColumn(expectedDeliveryDateColumn, "Expected Delivery");
|
|
|
205 |
table.addColumn(statusMessageColumn, "Current Status");
|
| 167 |
ashish |
206 |
|
| 4124 |
chandransh |
207 |
//Set the widths
|
|
|
208 |
table.setWidth("100%");
|
| 4670 |
rajveer |
209 |
table.setColumnWidth(checkboxColumn, 30, Unit.PX);
|
|
|
210 |
table.setColumnWidth(promisedShippingDateColumn, 140.0, Unit.PX);
|
| 4124 |
chandransh |
211 |
table.setColumnWidth(paymentModeColumn, 60.0, Unit.PX);
|
| 4125 |
chandransh |
212 |
table.setColumnWidth(idColumn, 70.0, Unit.PX);
|
| 4670 |
rajveer |
213 |
table.setColumnWidth(productDescriptionColumn, 230.0, Unit.PX);
|
|
|
214 |
table.setColumnWidth(creationDateColumn, 140.0, Unit.PX);
|
|
|
215 |
table.setColumnWidth(promisedDeliveryDateColumn, 140.0, Unit.PX);
|
|
|
216 |
table.setColumnWidth(expectedDeliveryDateColumn, 140.0, Unit.PX);
|
|
|
217 |
table.setColumnWidth(statusMessageColumn, 180.0, Unit.PX);
|
| 4124 |
chandransh |
218 |
|
| 4133 |
chandransh |
219 |
table.setRowCount(count, true);
|
|
|
220 |
table.setVisibleRange(start, orders.size());
|
|
|
221 |
|
| 4124 |
chandransh |
222 |
// Connect the table to the data provider.
|
|
|
223 |
asyncDataProvider.addDataDisplay(table);
|
| 4133 |
chandransh |
224 |
|
| 4124 |
chandransh |
225 |
//Add paging support
|
|
|
226 |
pager.setDisplay(table);
|
|
|
227 |
|
|
|
228 |
// Initialize the data
|
| 4133 |
chandransh |
229 |
asyncDataProvider.updateRowCount(count, true);
|
|
|
230 |
asyncDataProvider.updateRowData(start, orders);
|
| 4124 |
chandransh |
231 |
|
|
|
232 |
// Add a selection model to handle item selection.
|
|
|
233 |
final SingleSelectionModel<Order> selectionModel = new SingleSelectionModel<Order>();
|
|
|
234 |
table.setSelectionModel(selectionModel);
|
|
|
235 |
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
|
|
|
236 |
|
|
|
237 |
@Override
|
|
|
238 |
public void onSelectionChange(SelectionChangeEvent event) {
|
|
|
239 |
Order selectedOrder = selectionModel.getSelectedObject();
|
|
|
240 |
eventbus.fireEvent(new LoadOrderDetailsEvent(selectedOrder));
|
| 4004 |
chandransh |
241 |
}
|
| 4124 |
chandransh |
242 |
});
|
|
|
243 |
|
|
|
244 |
}
|
| 167 |
ashish |
245 |
|
| 306 |
ashish |
246 |
private String getDisplayableDate(Date date){
|
|
|
247 |
String dateString = date.toString();
|
|
|
248 |
dateString = dateString.substring(0, dateString.lastIndexOf(" "));
|
|
|
249 |
dateString = dateString.substring(0, dateString.lastIndexOf(" "));
|
|
|
250 |
return dateString;
|
|
|
251 |
}
|
| 167 |
ashish |
252 |
}
|