Subversion Repositories SmartDukaan

Rev

Rev 4125 | Rev 4175 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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