Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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