Subversion Repositories SmartDukaan

Rev

Rev 3994 | Rev 4124 | 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;
4004 chandransh 4
import in.shop2020.hotspot.dashbaord.shared.actions.Alert;
167 ashish 5
import in.shop2020.hotspot.dashbaord.shared.actions.Order;
6
 
7
import java.util.Date;
8
import java.util.List;
9
 
10
import org.enunes.gwt.mvp.client.EventBus;
11
 
12
import com.google.gwt.core.client.GWT;
13
import com.google.gwt.event.dom.client.ClickEvent;
14
import com.google.gwt.resources.client.CssResource;
15
import com.google.gwt.uibinder.client.UiBinder;
16
import com.google.gwt.uibinder.client.UiField;
4004 chandransh 17
import com.google.gwt.uibinder.client.UiHandler;
167 ashish 18
import com.google.gwt.user.client.ui.FlexTable;
19
import com.google.gwt.user.client.ui.ResizeComposite;
20
import com.google.gwt.user.client.ui.Widget;
4004 chandransh 21
import com.google.gwt.user.client.ui.HTMLTable.Cell;
167 ashish 22
 
23
public class OrderList extends ResizeComposite{
24
 
25
	private int selectedRow = -1;
306 ashish 26
 
167 ashish 27
	public interface Listener{
28
		void onSelectItem();
29
	}
30
 
584 chandransh 31
	interface OrderListUiBinder extends UiBinder<Widget, OrderList>{ }
167 ashish 32
 
33
	interface SelectionStyle extends CssResource{
34
		String selectedRow();
4004 chandransh 35
		String fatalRow();
36
		String criticalRow();
167 ashish 37
	}
38
	//add gin here
584 chandransh 39
	private static final OrderListUiBinder binder = GWT.create(OrderListUiBinder.class);
167 ashish 40
 
41
	@UiField FlexTable header;
42
	@UiField FlexTable table;
43
	@UiField SelectionStyle selectionStyle;
44
 
45
	private final EventBus eventbus;
46
 
47
	private final List<Order> orders;
48
 
49
	public OrderList(EventBus eventbus, List<Order> orders){
50
		this.orders = orders;
51
		initWidget(binder.createAndBindUi(this));
52
		this.eventbus = eventbus;
53
		initTable();
54
		updateTable();
55
		selectedRow = -1;
56
	}
57
 
58
	private void initTable(){
59
		// Initialize the header.
3994 chandransh 60
		header.getColumnFormatter().setWidth(0, "40px");
4004 chandransh 61
		header.getColumnFormatter().setWidth(1, "50px");
3994 chandransh 62
		header.getColumnFormatter().setWidth(2, "60px");
63
	    header.getColumnFormatter().setWidth(3, "60px");
3065 chandransh 64
	    header.getColumnFormatter().setWidth(4, "250px");
1224 chandransh 65
	    header.getColumnFormatter().setWidth(5, "150px");
3065 chandransh 66
	    header.getColumnFormatter().setWidth(6, "150px");
3994 chandransh 67
	    header.getColumnFormatter().setWidth(7, "150px");
68
	    header.getColumnFormatter().setWidth(8, "200px");
167 ashish 69
 
3994 chandransh 70
	    header.setText(0, 0, "Batch");
71
	    header.setText(0, 1, "S. No");
3065 chandransh 72
	    header.setText(0, 2, "Type");
73
	    header.setText(0, 3, "Order Id");
74
	    header.setText(0, 4, "Product Description");
75
	    header.setText(0, 5, "Date Created");
3994 chandransh 76
	    header.setText(0, 6, "Promised Delivery");
77
	    header.setText(0, 7, "Expected Delivery");
78
	    header.setText(0, 8, "Current Status");
167 ashish 79
 
80
	    // Initialize the table.
3994 chandransh 81
		table.getColumnFormatter().setWidth(0, "40px");
4004 chandransh 82
		table.getColumnFormatter().setWidth(1, "50px");
3994 chandransh 83
		table.getColumnFormatter().setWidth(2, "60px");
84
	    table.getColumnFormatter().setWidth(3, "60px");
3065 chandransh 85
	    table.getColumnFormatter().setWidth(4, "250px");
1224 chandransh 86
	    table.getColumnFormatter().setWidth(5, "150px");
3065 chandransh 87
	    table.getColumnFormatter().setWidth(6, "150px");
3994 chandransh 88
	    table.getColumnFormatter().setWidth(7, "150px");
89
	    table.getColumnFormatter().setWidth(8, "200px");    
167 ashish 90
	}
91
 
4004 chandransh 92
    @UiHandler("table")
93
    void onClick(ClickEvent event) {
94
        Cell cell = table.getCellForEvent(event);
95
        int newRowIndex = cell.getRowIndex();
96
        selectRow(newRowIndex);
97
        eventbus.fireEvent(new LoadOrderDetailsEvent(orders.get(newRowIndex)));
98
    }
99
 
167 ashish 100
	private void selectRow(int row) {
101
	    // When a row (other than the first one, which is used as a header) is
102
	    // selected, display its associated MailItem.
103
		if(selectedRow != -1){
104
			styleRow(selectedRow, false);
105
		}
106
 
107
	    styleRow(row, true);
534 chandransh 108
	    selectedRow = row;
4004 chandransh 109
	}
167 ashish 110
 
4004 chandransh 111
    private void styleRow(int row, boolean selected) {
112
        if (row != -1) {
113
            String style = selectionStyle.selectedRow();
167 ashish 114
 
4004 chandransh 115
            if (selected) {
116
                table.getRowFormatter().addStyleName(row, style);
117
            } else {
118
                table.getRowFormatter().removeStyleName(row, style);
119
            }
120
        }
121
    }
167 ashish 122
 
306 ashish 123
	private String getDisplayableDate(Date date){
124
		String dateString = date.toString();
125
		dateString = dateString.substring(0, dateString.lastIndexOf(" "));
126
		dateString = dateString.substring(0, dateString.lastIndexOf(" "));
127
		return dateString;		
128
	}
129
 
167 ashish 130
	private void updateTable(){
131
		int i = 0;
534 chandransh 132
		for(final Order order : orders){
985 chandransh 133
			StringBuilder productDescription = new StringBuilder(order.getProductGroup());
134
			if(order.getBrand()!=null)
135
				productDescription.append(" " + order.getBrand());
136
			if(order.getModelNumber()!=null)
137
				productDescription.append(" " + order.getModelNumber());
138
			if(order.getModelName()!=null)
139
				productDescription.append(" " + order.getModelName());
140
			if(order.getColor()!=null)
141
				productDescription.append(" " + order.getColor());
142
 
1224 chandransh 143
			table.setText(i, 0, "" + order.getBatchNo());
144
			table.setText(i, 1, "" + order.getSerialNo());
3065 chandransh 145
			table.setText(i, 2, order.isCod() ? "COD" : "Prepaid");
4004 chandransh 146
			table.setText(i, 3, "" + order.getOrderId());
3065 chandransh 147
			table.setText(i, 4, productDescription.toString());
148
			table.setText(i, 5, getDisplayableDate(new Date(order.getCreatedOn()))+"");
3994 chandransh 149
			table.setText(i, 6, getDisplayableDate(new Date(order.getPromisedDeliveryTime()))+"");
150
			table.setText(i, 7, getDisplayableDate(new Date(order.getExpectedDeliveryTime()))+"");
151
			table.setText(i, 8, order.getStatusMessage());
4004 chandransh 152
			applyAlertStyle(i, order.getAlert());
167 ashish 153
			i++;
154
		}
155
	}
4004 chandransh 156
 
157
	private void applyAlertStyle(int row, Alert alert){
158
	    String style;
159
	    switch(alert){
160
	    case DELIVERY_TIME_EXCEEDED:
161
	    case SHIPPING_TIME_EXCEEDED:
162
	    case VERIFICATION_DELAYED_TOO_MUCH:
163
	    case ACCEPTANCE_DELAYED_TOO_MUCH:
164
	    case ORDER_NOT_CONNECTED_FOR_TOO_LONG:
165
	        style = selectionStyle.fatalRow();
166
	        table.getRowFormatter().addStyleName(row, style);
167
	        break;
168
	    case ACCEPTANCE_DELAYED:
169
	    case VERIFICATION_DELAYED:
170
	    case ORDER_NOT_CONNECTED:
171
	        style = selectionStyle.criticalRow();
172
            table.getRowFormatter().addStyleName(row, style);
173
            break;
174
	    case WARNING:
175
	    case NONE:
176
	    }
177
	}
167 ashish 178
}