Rev 2427 | Rev 3524 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.catalog.dashboard.client;import in.shop2020.catalog.dashboard.shared.Item;import java.util.List;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.Window;import com.google.gwt.user.client.rpc.AsyncCallback;import com.google.gwt.user.client.ui.FlexTable;import com.google.gwt.user.client.ui.HTMLTable.Cell;import com.google.gwt.user.client.ui.Label;import com.google.gwt.user.client.ui.ResizeComposite;import com.google.gwt.user.client.ui.Widget;/*** List of items. List contains item Id, product group, brand, model number, model name, color and category* Dashboard user can select an item in this list and its details are shown in ItemDetails widget.**/public class ItemList extends ResizeComposite{private static final int INDEX_ID = 0,INDEX_PRODUCT_GROUP = 1,INDEX_BRAND = 2,INDEX_MODEL_NUMBER = 3,INDEX_MODEL_NAME = 4,INDEX_COLOR = 5,INDEX_CATEGORY = 6;private static String LEGEND = "Currently Showing: ";private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);interface ItemListUiBinder extends UiBinder<Widget, ItemList> { }private static final ItemListUiBinder uiBinder = GWT.create(ItemListUiBinder.class);interface SelectionStyle extends CssResource{String selectedRow();String alertsRow();}@UiField FlexTable header;@UiField FlexTable itemDescriptionTable;@UiField SelectionStyle selectionStyle;@UiField Label currentlyShowing;private int selectedRow = -1;private ItemDetails itemDetails;public ItemList() {initWidget(uiBinder.createAndBindUi(this));initHeader();initItemList();}private void initItemList() {loadAllRiskyItems();/*For testingloadDummyItems();updateItemDescriptionTable(items);*/}/*** Initialise header of item list table.*/private void initHeader(){header.getColumnFormatter().setWidth(INDEX_ID, "80px");header.getColumnFormatter().setWidth(INDEX_PRODUCT_GROUP, "128px");header.getColumnFormatter().setWidth(INDEX_BRAND, "150px");header.getColumnFormatter().setWidth(INDEX_MODEL_NUMBER, "200px");header.getColumnFormatter().setWidth(INDEX_MODEL_NAME, "200px");header.getColumnFormatter().setWidth(INDEX_COLOR, "128px");header.getColumnFormatter().setWidth(INDEX_CATEGORY, "220px");header.setText(0, INDEX_ID, "Item Id");header.setText(0, INDEX_PRODUCT_GROUP, "Product Group");header.setText(0, INDEX_BRAND, "Brand");header.setText(0, INDEX_MODEL_NUMBER, "Model Number");header.setText(0, INDEX_MODEL_NAME, "Model Name");header.setText(0, INDEX_COLOR, "Color");header.setText(0, INDEX_CATEGORY, "Category");}private void updateItemDescriptionTable(List<Item> items){itemDescriptionTable.removeAllRows();itemDescriptionTable.getColumnFormatter().setWidth(INDEX_ID, "80px");itemDescriptionTable.getColumnFormatter().setWidth(INDEX_PRODUCT_GROUP, "128px");itemDescriptionTable.getColumnFormatter().setWidth(INDEX_BRAND, "150px");itemDescriptionTable.getColumnFormatter().setWidth(INDEX_MODEL_NUMBER, "200px");itemDescriptionTable.getColumnFormatter().setWidth(INDEX_MODEL_NAME, "200px");itemDescriptionTable.getColumnFormatter().setWidth(INDEX_COLOR, "128px");itemDescriptionTable.getColumnFormatter().setWidth(INDEX_CATEGORY, "220px");int i=0;for(final Item item : items){itemDescriptionTable.setText(i, INDEX_ID, item.getId() + "");itemDescriptionTable.setText(i, INDEX_PRODUCT_GROUP, item.getProductGroup());itemDescriptionTable.setText(i, INDEX_BRAND, item.getBrand());itemDescriptionTable.setText(i, INDEX_MODEL_NUMBER, item.getModelNumber());itemDescriptionTable.setText(i, INDEX_MODEL_NAME, item.getModelName());itemDescriptionTable.setText(i, INDEX_COLOR, item.getColor());itemDescriptionTable.setText(i, INDEX_CATEGORY, item.getContentCategory()+"");i++;}}/*** On click of an item in the list, a fresh call is made to the service to fetch item details, vendor prices* and vendor item keys. The item object is then passed to ItemDetails to set the values in UI fields* @param event*/@UiHandler("itemDescriptionTable")void onClick(ClickEvent event) {Cell cell = itemDescriptionTable.getCellForEvent(event);int newRowIndex = cell.getRowIndex();selectRow(newRowIndex);String itemId = itemDescriptionTable.getText(newRowIndex, INDEX_ID);catalogService.getItem(Long.parseLong(itemId), new AsyncCallback<Item>() {@Overridepublic void onSuccess(Item result) {itemDetails.setItemDetails(result);}@Overridepublic void onFailure(Throwable caught) {caught.printStackTrace();Window.alert("Unable to fetch item details.");}});}private void selectRow(int row) {String style = selectionStyle.selectedRow();if(selectedRow != -1){itemDescriptionTable.getRowFormatter().removeStyleName(selectedRow, style);}itemDescriptionTable.getRowFormatter().addStyleName(row, style);selectedRow = row;}/* For testingprivate HashMap map;private List<Item> items;private void loadDummyItems() {Item i = new Item(1, "Handset", "Spice", "mi310", "phone", "White", "Business Phone",1, "comments", 1, 1,"", 3000.50, 3000.00, 3000, 3000, 12, 12345, 12345, 12345, 12345, "ACTIVE", 1, "This item is active",null, "best", 2990, 1, true, true, null, null, null);List<Item> items = new ArrayList<Item>();items.add(i);this.items = items;//itemsMap.put(i.getId(), i);}*/public void loadAllItems() {catalogService.getAllItems(new AsyncCallback<List<Item>>() {public void onFailure(Throwable caught) {caught.printStackTrace();Window.alert("Could not get all items...");}public void onSuccess(List<Item> result) {updateItemDescriptionTable(result);currentlyShowing.setText(LEGEND + "All Items");}});}public void loadAllActiveItems() {catalogService.getAllActiveItems(new AsyncCallback<List<Item>>() {public void onFailure(Throwable caught) {caught.printStackTrace();Window.alert("Could not get all active items...");}public void onSuccess(List<Item> result) {updateItemDescriptionTable(result);currentlyShowing.setText(LEGEND + "Active Items");}});}public void loadAllPhasedOutItems() {catalogService.getAllPhasedOutItems(new AsyncCallback<List<Item>>() {public void onFailure(Throwable caught) {caught.printStackTrace();Window.alert("Could not load phased out items...");}public void onSuccess(List<Item> result) {updateItemDescriptionTable(result);currentlyShowing.setText(LEGEND + "Phased Out Items");}});}public void loadAllPausedItems() {catalogService.getAllPausedItems(new AsyncCallback<List<Item>>() {public void onFailure(Throwable caught) {caught.printStackTrace();Window.alert("Could not load paused items...");}public void onSuccess(List<Item> result) {updateItemDescriptionTable(result);currentlyShowing.setText(LEGEND + "Paused Items");}});}public void loadAllInProcessItems() {catalogService.getAllInProcessItems(new AsyncCallback<List<Item>>() {public void onFailure(Throwable caught) {caught.printStackTrace();Window.alert("Could not load IN_PROCESS items...");}public void onSuccess(List<Item> result) {updateItemDescriptionTable(result);currentlyShowing.setText(LEGEND + "In Process Items");}});}public void loadAllContentCompleteItems() {catalogService.getAllContentCompleteItems(new AsyncCallback<List<Item>>() {public void onFailure(Throwable caught) {caught.printStackTrace();Window.alert("Could not load CONTENT_COMPLETE items...");}public void onSuccess(List<Item> result) {updateItemDescriptionTable(result);currentlyShowing.setText(LEGEND + "Content Complete Items");}});}public void loadAllRiskyItems() {catalogService.getRiskyItems(new AsyncCallback<List<Item>>() {public void onFailure(Throwable caught) {caught.printStackTrace();Window.alert("Could not load RISKY items...");}public void onSuccess(List<Item> result) {updateItemDescriptionTable(result);currentlyShowing.setText(LEGEND + "Risky Items");}});}public void loadBestDeals() {catalogService.getBestDeals(new AsyncCallback<List<Item>>() {public void onFailure(Throwable caught) {caught.printStackTrace();Window.alert("Could not load best deals.");}public void onSuccess(List<Item> result) {updateItemDescriptionTable(result);currentlyShowing.setText(LEGEND + "Best Deals");}});}public void loadLatestArrivals() {catalogService.getLatestArrivals(new AsyncCallback<List<Item>>() {public void onFailure(Throwable caught) {caught.printStackTrace();Window.alert("Could not load latest arrivals.");}public void onSuccess(List<Item> result) {updateItemDescriptionTable(result);currentlyShowing.setText(LEGEND + "Latest Arrivals");}});}public void loadBestSellers() {catalogService.getBestSellers(new AsyncCallback<List<Item>>() {public void onFailure(Throwable caught) {caught.printStackTrace();Window.alert("Could not load best sellers.");}public void onSuccess(List<Item> result) {updateItemDescriptionTable(result);currentlyShowing.setText(LEGEND + "Best Sellers");}});}public void setItemDetails(ItemDetails itemDetails) {this.itemDetails = itemDetails;}/*** This method is called when item is updated in ItemDetails.java to update* attributes in the list also.* @param item*/public void updateItem(Item item) {itemDescriptionTable.setText(selectedRow, INDEX_PRODUCT_GROUP, item.getProductGroup());itemDescriptionTable.setText(selectedRow, INDEX_BRAND, item.getBrand());itemDescriptionTable.setText(selectedRow, INDEX_MODEL_NUMBER, item.getModelNumber());itemDescriptionTable.setText(selectedRow, INDEX_MODEL_NAME, item.getModelName());itemDescriptionTable.setText(selectedRow, INDEX_COLOR, item.getColor());}}