Subversion Repositories SmartDukaan

Rev

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