Subversion Repositories SmartDukaan

Rev

Rev 4399 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4399 rajveer 1
package in.shop2020.hotspot.dashbaord.client.inbox;
2
 
4402 rajveer 3
import java.util.Date;
4399 rajveer 4
import java.util.List;
5
 
6
import org.enunes.gwt.mvp.client.EventBus;
7
 
8
import in.shop2020.hotspot.dashbaord.client.event.LoadReturnOrderDetailsEvent;
9
import in.shop2020.hotspot.dashbaord.shared.actions.Alert;
10
 
11
import com.google.gwt.core.client.GWT;
12
import com.google.gwt.event.dom.client.ClickEvent;
13
import com.google.gwt.resources.client.CssResource;
14
import com.google.gwt.uibinder.client.UiBinder;
15
import com.google.gwt.uibinder.client.UiField;
16
import com.google.gwt.uibinder.client.UiHandler;
17
import com.google.gwt.user.client.ui.FlexTable;
18
import com.google.gwt.user.client.ui.ResizeComposite;
19
import com.google.gwt.user.client.ui.Widget;
20
import com.google.gwt.user.client.ui.HTMLTable.Cell;
21
 
22
public class AlertList extends ResizeComposite {
23
 
24
	private static AlertListUiBinder uiBinder = GWT.create(AlertListUiBinder.class);
25
 
26
	interface AlertListUiBinder extends UiBinder<Widget, AlertList> {
27
	}
28
 
29
	interface SelectionStyle extends CssResource{
30
		String selectedRow();
31
		String alertsRow();
32
	}
33
 
34
	@UiField FlexTable header;
35
	@UiField FlexTable alertsDescriptionTable;
36
	@UiField SelectionStyle selectionStyle;
37
 
38
	private int selectedRow = -1;
39
 
40
	private final EventBus eventbus;
41
 
42
	private final List<Alert> alerts;
43
 
44
	public AlertList(EventBus eventbus, List<Alert> alerts) {
45
		this.eventbus = eventbus;
46
		this.alerts = alerts;
47
		initWidget(uiBinder.createAndBindUi(this));
48
		initHeader();
49
		updateOrderReturnDescriptionTable(this.alerts);
50
	}
51
 
52
	private void initHeader(){
53
		// Initialize the header.
54
	    header.getColumnFormatter().setWidth(0, "50px");
55
	    header.getColumnFormatter().setWidth(1, "200px");
56
	    header.getColumnFormatter().setWidth(2, "200px");
57
	    header.getColumnFormatter().setWidth(3, "600px");
4402 rajveer 58
	    header.setText(0, 0, "Id");
4399 rajveer 59
	    header.setText(0, 1, "Type");
60
	    header.setText(0, 2, "Creation Time");
61
	    header.setText(0, 3, "Description");
62
	}
63
 
64
	private void updateOrderReturnDescriptionTable(List<Alert> alerts){
65
		alertsDescriptionTable.getColumnFormatter().setWidth(0, "50px");
66
		alertsDescriptionTable.getColumnFormatter().setWidth(1, "200px");
67
		alertsDescriptionTable.getColumnFormatter().setWidth(2, "200px");
68
		alertsDescriptionTable.getColumnFormatter().setWidth(3, "600px");
69
 
70
		int i=0;
71
		for(final Alert alert : alerts){
72
			int col = 0;
73
			alertsDescriptionTable.setText(i, col++, alert.getOrderId() + "");
74
			alertsDescriptionTable.setText(i, col++, alert.getAlertType() + "");
4402 rajveer 75
			alertsDescriptionTable.setText(i, col++, getDisplayableDate(new Date(alert.getCreatedAt())));
4399 rajveer 76
			alertsDescriptionTable.setText(i, col++, alert.getDescription());
77
			i++;
78
		}
79
	}
80
 
81
	@UiHandler("alertsDescriptionTable")
82
	void onClick(ClickEvent event) {
83
		Cell cell = alertsDescriptionTable.getCellForEvent(event);
84
		int newRowIndex = cell.getRowIndex();
85
		selectRow(newRowIndex);
86
		String alertId = alertsDescriptionTable.getText(newRowIndex, 0);
4402 rajveer 87
		//eventbus.fireEvent(new LoadReturnOrderDetailsEvent(alertId));
4399 rajveer 88
	}
89
 
90
	private void selectRow(int row) {
91
		String style = selectionStyle.selectedRow();
92
		if(selectedRow != -1){
93
			alertsDescriptionTable.getRowFormatter().removeStyleName(selectedRow, style);
94
		}
95
 
96
		alertsDescriptionTable.getRowFormatter().addStyleName(row, style);
97
	    selectedRow = row;
98
	}
99
 
4402 rajveer 100
	private String getDisplayableDate(Date date){
101
		String dateString = date.toString();
102
		dateString = dateString.substring(0, dateString.lastIndexOf(" "));
103
		dateString = dateString.substring(0, dateString.lastIndexOf(" "));
104
		return dateString;		
105
	}
4399 rajveer 106
}