Subversion Repositories SmartDukaan

Rev

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