Subversion Repositories SmartDukaan

Rev

Rev 4671 | Rev 7422 | 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;
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) {
4671 rajveer 62
            return getDisplayableDate(new Date(order.getPromisedShippingTime()))+"";
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() + ")");
5387 rajveer 94
			if(order.getQuantity() > 1)
95
				productDescription.append(" (" + order.getQuantity() + ")");
4124 chandransh 96
            return productDescription.toString();
97
        }
98
    };
99
 
100
    private TextColumn<Order> creationDateColumn = new TextColumn<Order>() {
101
        @Override
102
        public String getValue(Order order) {
103
            return getDisplayableDate(new Date(order.getCreatedOn()))+"";
104
        }
105
    };
106
 
107
    private TextColumn<Order> promisedDeliveryDateColumn = new TextColumn<Order>() {
108
        @Override
109
        public String getValue(Order order) {
110
            return getDisplayableDate(new Date(order.getPromisedDeliveryTime()))+"";
111
        }
112
    };
113
 
114
    private TextColumn<Order> expectedDeliveryDateColumn = new TextColumn<Order>() {
115
        @Override
116
        public String getValue(Order order) {
117
            return getDisplayableDate(new Date(order.getExpectedDeliveryTime()))+"";
118
        }
119
    };
120
 
121
    private TextColumn<Order> statusMessageColumn = new TextColumn<Order>() {
122
        @Override
123
        public String getValue(Order order) {
124
            return order.getStatusMessage();
125
        }
126
    };
127
 
128
    AsyncDataProvider<Order> asyncDataProvider = new AsyncDataProvider<Order>() {
129
 
130
		@Override
131
		protected void onRangeChanged(HasData<Order> display) {
132
            Range range = display.getVisibleRange();
4133 chandransh 133
            int newStart = range.getStart();
134
			// This is to prevent the recursive firing of onRangeChanged events.
135
			// Every time fresh data is pushed into the DataProvider, this
136
			// method is called. This, in turn, fires an event to refresh the
137
			// data. If the start of the new range is same as that of the
138
			// currently loaded data, there is no point in proceeding further.
139
            GWT.log(this + "Current start: " + start + ", New start:" + newStart);
140
            if(newStart == start)
141
            	return;
4124 chandransh 142
            int limit = range.getLength();
4133 chandransh 143
 
144
            eventbus.fireEvent(new LoadOrderListEvent(orderType, newStart, limit));
4124 chandransh 145
		}
146
 
147
    };
148
 
167 ashish 149
	private final EventBus eventbus;
4133 chandransh 150
	private final OrderType orderType;
167 ashish 151
	private final List<Order> orders;
4133 chandransh 152
	private int count;
153
	private final int start;
167 ashish 154
 
4133 chandransh 155
	public OrderList(EventBus eventbus, OrderType orderType, List<Order> orders, int start, int count){
167 ashish 156
		this.orders = orders;
4124 chandransh 157
		this.eventbus = eventbus;
4133 chandransh 158
		this.orderType = orderType;
159
		this.start = start;
160
		this.count = count;
167 ashish 161
		initWidget(binder.createAndBindUi(this));
162
		initTable();
163
	}
164
 
165
	private void initTable(){
4124 chandransh 166
 
167
		//Add custom styles to show in case we want to alert the user
168
		table.setRowStyles(new RowStyles<Order>(){
167 ashish 169
 
4124 chandransh 170
			@Override
171
			public String getStyleNames(Order order, int rowIndex) {
4133 chandransh 172
				if(order==null)
173
					return "";
4398 rajveer 174
				OrderAlert alert = order.getAlert();
4124 chandransh 175
				String style = "";
176
			    switch(alert){
177
			    case DELIVERY_TIME_EXCEEDED:
178
			    case SHIPPING_TIME_EXCEEDED:
179
			    case VERIFICATION_DELAYED_TOO_MUCH:
180
			    case ACCEPTANCE_DELAYED_TOO_MUCH:
181
			    case ORDER_NOT_CONNECTED_FOR_TOO_LONG:
182
			        style = selectionStyle.fatalRow();
183
			        break;
184
			    case ACCEPTANCE_DELAYED:
185
			    case VERIFICATION_DELAYED:
186
			    case ORDER_NOT_CONNECTED:
187
			        style = selectionStyle.criticalRow();
188
		            break;
189
			    case WARNING:
190
			    case NONE:
191
			    }
192
				return style;
193
			}
194
		});
195
 
4361 rajveer 196
 
197
 
198
        // Add the columns.
199
	    table.addColumn(checkboxColumn,"");
4666 rajveer 200
        table.addColumn(promisedShippingDateColumn, "Promised Shipping");
4124 chandransh 201
        table.addColumn(paymentModeColumn, "Type");
202
        table.addColumn(idColumn, "Order Id");
203
        table.addColumn(productDescriptionColumn, "Product Description");
204
        table.addColumn(creationDateColumn, "Creation Date");
205
        table.addColumn(promisedDeliveryDateColumn, "Promised Delivery");
206
        table.addColumn(expectedDeliveryDateColumn, "Expected Delivery");
207
        table.addColumn(statusMessageColumn, "Current Status");
167 ashish 208
 
4124 chandransh 209
        //Set the widths
210
        table.setWidth("100%");
4670 rajveer 211
        table.setColumnWidth(checkboxColumn, 30, Unit.PX);
212
        table.setColumnWidth(promisedShippingDateColumn, 140.0, Unit.PX);
4124 chandransh 213
        table.setColumnWidth(paymentModeColumn, 60.0, Unit.PX);
4125 chandransh 214
        table.setColumnWidth(idColumn, 70.0, Unit.PX);
4670 rajveer 215
        table.setColumnWidth(productDescriptionColumn, 230.0, Unit.PX);
216
        table.setColumnWidth(creationDateColumn, 140.0, Unit.PX);
217
        table.setColumnWidth(promisedDeliveryDateColumn, 140.0, Unit.PX);
218
        table.setColumnWidth(expectedDeliveryDateColumn, 140.0, Unit.PX);
219
        table.setColumnWidth(statusMessageColumn, 180.0, Unit.PX);
4124 chandransh 220
 
4133 chandransh 221
        table.setRowCount(count, true);
222
        table.setVisibleRange(start, orders.size());
223
 
4124 chandransh 224
        // Connect the table to the data provider.
225
        asyncDataProvider.addDataDisplay(table);
4133 chandransh 226
 
4124 chandransh 227
        //Add paging support
228
        pager.setDisplay(table);
229
 
230
        // Initialize the data
4133 chandransh 231
		asyncDataProvider.updateRowCount(count, true);
232
		asyncDataProvider.updateRowData(start, orders);
4124 chandransh 233
 
234
        // Add a selection model to handle item selection.
235
        final SingleSelectionModel<Order> selectionModel = new SingleSelectionModel<Order>();
236
        table.setSelectionModel(selectionModel);
237
        selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
238
 
239
            @Override
240
            public void onSelectionChange(SelectionChangeEvent event) {
241
            	Order selectedOrder = selectionModel.getSelectedObject();
242
            	eventbus.fireEvent(new LoadOrderDetailsEvent(selectedOrder));
4004 chandransh 243
            }
4124 chandransh 244
        });
245
 
246
	}
167 ashish 247
 
306 ashish 248
	private String getDisplayableDate(Date date){
249
		String dateString = date.toString();
250
		dateString = dateString.substring(0, dateString.lastIndexOf(" "));
251
		dateString = dateString.substring(0, dateString.lastIndexOf(" "));
252
		return dateString;		
253
	}
167 ashish 254
}