| 760 |
chandransh |
1 |
package in.shop2020.hotspot.dashbaord.client.inbox;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.hotspot.dashbaord.client.event.LoadProviderDetailsEvent;
|
|
|
4 |
|
|
|
5 |
import java.util.Map;
|
|
|
6 |
|
|
|
7 |
import org.enunes.gwt.mvp.client.EventBus;
|
|
|
8 |
|
|
|
9 |
import com.google.gwt.core.client.GWT;
|
|
|
10 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
11 |
import com.google.gwt.resources.client.CssResource;
|
|
|
12 |
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
13 |
import com.google.gwt.uibinder.client.UiField;
|
|
|
14 |
import com.google.gwt.uibinder.client.UiHandler;
|
|
|
15 |
import com.google.gwt.user.client.ui.FlexTable;
|
|
|
16 |
import com.google.gwt.user.client.ui.ResizeComposite;
|
|
|
17 |
import com.google.gwt.user.client.ui.Widget;
|
|
|
18 |
import com.google.gwt.user.client.ui.HTMLTable.Cell;
|
|
|
19 |
|
|
|
20 |
public class ProivderList extends ResizeComposite {
|
|
|
21 |
|
|
|
22 |
interface ProivderListUiBinder extends UiBinder<Widget, ProivderList> {
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
private static ProivderListUiBinder uiBinder = GWT.create(ProivderListUiBinder.class);
|
|
|
26 |
|
|
|
27 |
interface SelectionStyle extends CssResource{
|
|
|
28 |
String selectedRow();
|
|
|
29 |
String alertsRow();
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
@UiField FlexTable header;
|
|
|
33 |
@UiField FlexTable providerTable;
|
|
|
34 |
@UiField SelectionStyle selectionStyle;
|
|
|
35 |
|
|
|
36 |
private int selectedRow = -1;
|
|
|
37 |
|
|
|
38 |
private final EventBus eventbus;
|
|
|
39 |
|
| 4603 |
rajveer |
40 |
private final Map<Long, String> providers;
|
| 760 |
chandransh |
41 |
|
| 4603 |
rajveer |
42 |
public ProivderList(EventBus eventbus, Map<Long, String> providers) {
|
| 760 |
chandransh |
43 |
this.providers = providers;
|
|
|
44 |
this.eventbus = eventbus;
|
|
|
45 |
initWidget(uiBinder.createAndBindUi(this));
|
|
|
46 |
initHeader();
|
|
|
47 |
updateProviderTable(this.providers);
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
private void initHeader(){
|
|
|
51 |
header.getColumnFormatter().setWidth(0, "128px");
|
|
|
52 |
header.getColumnFormatter().setWidth(1, "128px");
|
|
|
53 |
|
|
|
54 |
header.setText(0, 0, "Provider Id");
|
|
|
55 |
header.setText(0, 1, "Proivder Name");
|
|
|
56 |
}
|
|
|
57 |
|
| 4603 |
rajveer |
58 |
private void updateProviderTable(Map<Long, String> providers){
|
| 760 |
chandransh |
59 |
providerTable.getColumnFormatter().setWidth(0, "128px");
|
|
|
60 |
providerTable.getColumnFormatter().setWidth(1, "128px");
|
|
|
61 |
|
|
|
62 |
int i=0;
|
| 4603 |
rajveer |
63 |
for(final Map.Entry<Long, String> entry : providers.entrySet()){
|
| 760 |
chandransh |
64 |
int col = 0;
|
| 2449 |
chandransh |
65 |
providerTable.setText(i, col++, entry.getKey() + "");
|
|
|
66 |
providerTable.setText(i, col++, entry.getValue());
|
| 760 |
chandransh |
67 |
i++;
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
@UiHandler("providerTable")
|
|
|
72 |
void onClick(ClickEvent event) {
|
|
|
73 |
Cell cell = providerTable.getCellForEvent(event);
|
|
|
74 |
int newRowIndex = cell.getRowIndex();
|
|
|
75 |
selectRow(newRowIndex);
|
|
|
76 |
String providerId = providerTable.getText(newRowIndex, 0);
|
| 4606 |
rajveer |
77 |
eventbus.fireEvent(new LoadProviderDetailsEvent(providerId, providers.get(Long.parseLong(providerId))));
|
| 760 |
chandransh |
78 |
}
|
|
|
79 |
|
|
|
80 |
private void selectRow(int row) {
|
|
|
81 |
String style = selectionStyle.selectedRow();
|
|
|
82 |
if(selectedRow != -1){
|
|
|
83 |
providerTable.getRowFormatter().removeStyleName(selectedRow, style);
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
providerTable.getRowFormatter().addStyleName(row, style);
|
|
|
87 |
selectedRow = row;
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
}
|