Rev 4399 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.hotspot.dashbaord.client.inbox;import java.util.Date;import java.util.List;import org.enunes.gwt.mvp.client.EventBus;import in.shop2020.hotspot.dashbaord.client.event.LoadReturnOrderDetailsEvent;import in.shop2020.hotspot.dashbaord.shared.actions.Alert;import com.google.gwt.core.client.GWT;import com.google.gwt.event.dom.client.ClickEvent;import com.google.gwt.resources.client.CssResource;import com.google.gwt.uibinder.client.UiBinder;import com.google.gwt.uibinder.client.UiField;import com.google.gwt.uibinder.client.UiHandler;import com.google.gwt.user.client.ui.FlexTable;import com.google.gwt.user.client.ui.ResizeComposite;import com.google.gwt.user.client.ui.Widget;import com.google.gwt.user.client.ui.HTMLTable.Cell;public class AlertList extends ResizeComposite {private static AlertListUiBinder uiBinder = GWT.create(AlertListUiBinder.class);interface AlertListUiBinder extends UiBinder<Widget, AlertList> {}interface SelectionStyle extends CssResource{String selectedRow();String alertsRow();}@UiField FlexTable header;@UiField FlexTable alertsDescriptionTable;@UiField SelectionStyle selectionStyle;private int selectedRow = -1;private final EventBus eventbus;private final List<Alert> alerts;public AlertList(EventBus eventbus, List<Alert> alerts) {this.eventbus = eventbus;this.alerts = alerts;initWidget(uiBinder.createAndBindUi(this));initHeader();updateOrderReturnDescriptionTable(this.alerts);}private void initHeader(){// Initialize the header.header.getColumnFormatter().setWidth(0, "50px");header.getColumnFormatter().setWidth(1, "200px");header.getColumnFormatter().setWidth(2, "200px");header.getColumnFormatter().setWidth(3, "600px");header.setText(0, 0, "Id");header.setText(0, 1, "Type");header.setText(0, 2, "Creation Time");header.setText(0, 3, "Description");}private void updateOrderReturnDescriptionTable(List<Alert> alerts){alertsDescriptionTable.getColumnFormatter().setWidth(0, "50px");alertsDescriptionTable.getColumnFormatter().setWidth(1, "200px");alertsDescriptionTable.getColumnFormatter().setWidth(2, "200px");alertsDescriptionTable.getColumnFormatter().setWidth(3, "600px");int i=0;for(final Alert alert : alerts){int col = 0;alertsDescriptionTable.setText(i, col++, alert.getOrderId() + "");alertsDescriptionTable.setText(i, col++, alert.getAlertType() + "");alertsDescriptionTable.setText(i, col++, getDisplayableDate(new Date(alert.getCreatedAt())));alertsDescriptionTable.setText(i, col++, alert.getDescription());i++;}}@UiHandler("alertsDescriptionTable")void onClick(ClickEvent event) {Cell cell = alertsDescriptionTable.getCellForEvent(event);int newRowIndex = cell.getRowIndex();selectRow(newRowIndex);String alertId = alertsDescriptionTable.getText(newRowIndex, 0);//eventbus.fireEvent(new LoadReturnOrderDetailsEvent(alertId));}private void selectRow(int row) {String style = selectionStyle.selectedRow();if(selectedRow != -1){alertsDescriptionTable.getRowFormatter().removeStyleName(selectedRow, style);}alertsDescriptionTable.getRowFormatter().addStyleName(row, style);selectedRow = row;}private String getDisplayableDate(Date date){String dateString = date.toString();dateString = dateString.substring(0, dateString.lastIndexOf(" "));dateString = dateString.substring(0, dateString.lastIndexOf(" "));return dateString;}}