Subversion Repositories SmartDukaan

Rev

Rev 2313 | Rev 3994 | 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;
4
import in.shop2020.hotspot.dashbaord.shared.actions.Order;
5
 
6
import java.util.Date;
7
import java.util.List;
8
 
9
import org.enunes.gwt.mvp.client.EventBus;
10
 
11
import com.google.gwt.core.client.GWT;
12
import com.google.gwt.event.dom.client.ClickEvent;
13
import com.google.gwt.event.dom.client.ClickHandler;
14
import com.google.gwt.resources.client.CssResource;
15
import com.google.gwt.uibinder.client.UiBinder;
16
import com.google.gwt.uibinder.client.UiField;
17
import com.google.gwt.user.client.ui.Anchor;
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;
21
 
22
public class OrderList extends ResizeComposite{
23
 
24
	private int selectedRow = -1;
306 ashish 25
 
2313 chandransh 26
	//private boolean selectedRowIsAlerted = false;
167 ashish 27
 
28
	public interface Listener{
29
		void onSelectItem();
30
	}
31
 
584 chandransh 32
	interface OrderListUiBinder extends UiBinder<Widget, OrderList>{ }
167 ashish 33
 
34
	interface SelectionStyle extends CssResource{
35
		String selectedRow();
306 ashish 36
		String alertsRow();
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.
3065 chandransh 60
		header.getColumnFormatter().setWidth(0, "80px");
61
		header.getColumnFormatter().setWidth(1, "80px");
62
		header.getColumnFormatter().setWidth(2, "100px");
63
	    header.getColumnFormatter().setWidth(3, "100px");
64
	    header.getColumnFormatter().setWidth(4, "250px");
1224 chandransh 65
	    header.getColumnFormatter().setWidth(5, "150px");
3065 chandransh 66
	    header.getColumnFormatter().setWidth(6, "150px");
67
	    header.getColumnFormatter().setWidth(7, "200px");
167 ashish 68
 
1224 chandransh 69
	    header.setText(0, 0, "Batch No");
70
	    header.setText(0, 1, "Serial No");
3065 chandransh 71
	    header.setText(0, 2, "Type");
72
	    header.setText(0, 3, "Order Id");
73
	    header.setText(0, 4, "Product Description");
74
	    header.setText(0, 5, "Date Created");
75
	    header.setText(0, 6, "Expected Delivery");
76
	    header.setText(0, 7, "Current Status");
167 ashish 77
 
78
	    // Initialize the table.
3065 chandransh 79
		table.getColumnFormatter().setWidth(0, "80px");
80
		table.getColumnFormatter().setWidth(1, "80px");
81
		table.getColumnFormatter().setWidth(2, "100px");
82
	    table.getColumnFormatter().setWidth(3, "100px");
83
	    table.getColumnFormatter().setWidth(4, "250px");
1224 chandransh 84
	    table.getColumnFormatter().setWidth(5, "150px");
3065 chandransh 85
	    table.getColumnFormatter().setWidth(6, "150px");
86
	    table.getColumnFormatter().setWidth(7, "200px");    
167 ashish 87
	}
88
 
89
	private void selectRow(int row) {
90
	    // When a row (other than the first one, which is used as a header) is
91
	    // selected, display its associated MailItem.
92
		if(selectedRow != -1){
93
			styleRow(selectedRow, false);
94
		}
95
 
96
	    styleRow(row, true);
534 chandransh 97
	    selectedRow = row;
167 ashish 98
	  }
99
 
100
 
101
	private void styleRow(int row, boolean selected) {
102
	    if (row != -1) {
103
	      String style = selectionStyle.selectedRow();
104
 
105
	      if (selected) {
106
	        table.getRowFormatter().addStyleName(row, style);
107
	      } else {
108
	        table.getRowFormatter().removeStyleName(row, style);
109
	      }
110
	    }
111
	  }
112
 
306 ashish 113
	private void alertRow(int row, boolean remove){
114
		if (row != -1) {
115
		      String style = selectionStyle.alertsRow();
116
		      if(!remove)
117
		    	  table.getRowFormatter().addStyleName(row, style);
118
		      else{
119
		    	  table.getRowFormatter().removeStyleName(row, style);
120
		      }
121
		}		      
122
	}
123
 
124
	private String getDisplayableDate(Date date){
125
		String dateString = date.toString();
126
		dateString = dateString.substring(0, dateString.lastIndexOf(" "));
127
		dateString = dateString.substring(0, dateString.lastIndexOf(" "));
128
		return dateString;		
129
	}
130
 
167 ashish 131
	private void updateTable(){
132
		int i = 0;
534 chandransh 133
		for(final Order order : orders){
985 chandransh 134
			StringBuilder productDescription = new StringBuilder(order.getProductGroup());
135
			if(order.getBrand()!=null)
136
				productDescription.append(" " + order.getBrand());
137
			if(order.getModelNumber()!=null)
138
				productDescription.append(" " + order.getModelNumber());
139
			if(order.getModelName()!=null)
140
				productDescription.append(" " + order.getModelName());
141
			if(order.getColor()!=null)
142
				productDescription.append(" " + order.getColor());
143
 
534 chandransh 144
			Anchor orderIdAnchor = new Anchor(order.getOrderId() + "");
1224 chandransh 145
			table.setText(i, 0, "" + order.getBatchNo());
146
			table.setText(i, 1, "" + order.getSerialNo());
3065 chandransh 147
			table.setText(i, 2, order.isCod() ? "COD" : "Prepaid");
148
			table.setWidget(i, 3, orderIdAnchor);
149
			table.setText(i, 4, productDescription.toString());
150
			table.setText(i, 5, getDisplayableDate(new Date(order.getCreatedOn()))+"");
151
			table.setText(i, 6, getDisplayableDate(new Date(order.getExpectedDeliveryTime()))+"");
152
			table.setText(i, 7, order.getStatusMessage());
167 ashish 153
			i++;
154
			final int j =i-1;
306 ashish 155
 
534 chandransh 156
			if (order.isAlert()){
306 ashish 157
				alertRow(i-1, false);
158
			}
159
 
534 chandransh 160
			orderIdAnchor.addClickHandler(new ClickHandler() {
167 ashish 161
 
162
				@Override
163
				public void onClick(ClickEvent event) {
164
					selectRow(j);
534 chandransh 165
					eventbus.fireEvent(new LoadOrderDetailsEvent(order));
167 ashish 166
				}
167
			});
168
		}
169
	}
170
}