Rev 3362 | 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 in.shop2020.catalog.dashboard.shared.Utils;import in.shop2020.catalog.dashboard.shared.VendorItemMapping;import in.shop2020.catalog.dashboard.shared.VendorPricings;import java.util.Date;import java.util.HashMap;import java.util.Map;import java.util.Map.Entry;import com.google.gwt.core.client.GWT;import com.google.gwt.event.dom.client.ClickEvent;import com.google.gwt.event.dom.client.ClickHandler;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.user.client.Window;import com.google.gwt.user.client.rpc.AsyncCallback;import com.google.gwt.user.client.ui.Button;import com.google.gwt.user.client.ui.CheckBox;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.TextBox;import com.google.gwt.user.client.ui.Widget;import com.google.gwt.user.datepicker.client.DateBox;/*** Panel contains fields for item details. Some of these fields are editable.* It also contains vendor item pricings, vendor item keys, and item availability in tabular format.* Item availability is made invisible for time being*/public class ItemDetails extends ResizeComposite {private final int TABLE_INDEX_MAPPING_VENDOR_DESC = 0,TABLE_INDEX_MAPPING_ITEM_KEY = 1,TABLE_INDEX_MAPPING_BUTTON = 2,TABLE_INDEX_MAPPING_VENDORID = 3,TABLE_INDEX_MAPPING_ITEM_KEY_OLD = 4;private final int TABLE_INDEX_PRICING_VENDOR_DESC = 0,TABLE_INDEX_PRICING_MOP = 1,TABLE_INDEX_PRICING_DP = 2,TABLE_INDEX_PRICING_TP = 3,TABLE_INDEX_PRICING_BUTTON = 4,TABLE_INDEX_PRICING_VENDORID = 5;private final int TABLE_INDEX_WAREHOUSE_ID = 0,TABLE_INDEX_WAREHOUSE_DESC = 1,TABLE_INDEX_WAREHOUSE_INV = 2;private final String PRICE_WIDTH = "100px", VENDOR_DESC_WIDTH = "130px",VENDOR_ID_WIDTH = "100px", ITEM_KEY_WIDTH = "200px",BUTTON_WIDTH = "50px";interface ItemDetailsUiBinder extends UiBinder<Widget, ItemDetails> {}private static ItemDetailsUiBinder uiBinder = GWT.create(ItemDetailsUiBinder.class);private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);interface ItemDetailStyle extends CssResource{String greenLabel();String fieldChanged();}private Item item, newItem;private CatalogDashboard catalogDashboardPanel;@UiField ItemDetailStyle style;@UiField Label itemId;@UiField TextBox productGroup, brand, modelNumber, modelName, color;@UiField Label contentCategory, catalogItemId;@UiField TextBox statusDesc, comments;@UiField TextBox sellingPrice, mrp, weight;@UiField Label addedOn, retireDate, updatedOn;@UiField Label itemStatus;@UiField TextBox bestDealsText, bestDealsValue;@UiField FlexTable headerAvailability, availabilityTable;@UiField FlexTable headerVendorItemKey, tableVendorItemKey;@UiField FlexTable headerVendorPrices, tableVendorPrices;@UiField TextBox bestSellingRank;@UiField TextBox expectedDelay;@UiField TextBox preferredWarehouse;@UiField CheckBox defaultForEntity, risky;@UiField DateBox startDate;public ItemDetails(Item item){this();setItemDetails(item);}public ItemDetails() {initWidget(uiBinder.createAndBindUi(this));initAvailabilityHeader();initVendorKeysHeader();initVendorPricingHeader();headerAvailability.setVisible(false);availabilityTable.setVisible(false);}/*** Sets the UI fields with item object attributes* Also populates tables for vendor prices, keys and item availability* @param item*/public void setItemDetails(Item item){this.item = item;itemId.setText(item.getId()+"");productGroup.setText(item.getProductGroup());brand.setText(item.getBrand());modelNumber.setText(item.getModelNumber());modelName.setText(item.getModelName());color.setText(item.getColor());statusDesc.setText(item.getItemStatusDesc());contentCategory.setText(item.getContentCategory()+"");comments.setText(item.getComments());catalogItemId.setText(item.getCatalogItemId() + "");mrp.setText(item.getMrp() != null ? item.getMrp()+"" : "");sellingPrice.setText(item.getSellingPrice() != null ? item.getSellingPrice()+"" : "");weight.setText(item.getWeight() != null ? item.getWeight()+"" : "");expectedDelay.setValue(item.getExpectedDelay()+"");preferredWarehouse.setValue(item.getPreferredWarehouse()+"");startDate.setValue(new Date(item.getStartDate()));addedOn.setText(Utils.getDisplayableDate(item.getAddedOn()));retireDate.setText(Utils.getDisplayableDate(item.getRetireDate()));updatedOn.setText(Utils.getDisplayableDate(item.getUpdatedOn()));bestDealsText.setText(item.getBestDealsText());bestDealsValue.setText(item.getBestDealsValue() != null ? item.getBestDealsValue()+"" : "");bestSellingRank.setText(item.getBestSellingRank() != null ? item.getBestSellingRank()+"" : "");defaultForEntity.setValue(item.isDefaultForEntity());risky.setValue(item.isRisky());itemStatus.setText(item.getItemStatus());updateAvailabilityTable(item.getAvailability());updateVendorKeysTable(item.getVendorKeysMap());updateVendorPricingTable(item.getVendorPricesMap());}/*** initialise item availability table header.*/private void initAvailabilityHeader(){headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_ID, "128px");headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_DESC, "300px");headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_INV, "128px");headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_ID, "Warehouse Id");headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_DESC, "Warehouse Desc");headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_INV, "Availability");}/*** initialises vendor item key table header. Creates an Add button and* adds click event listener to it to create and pop up a dialog for adding* a new vendor item key.*/private void initVendorKeysHeader(){headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDORID, VENDOR_ID_WIDTH);headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDOR_DESC, VENDOR_DESC_WIDTH);headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY, ITEM_KEY_WIDTH);headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY_OLD, ITEM_KEY_WIDTH);headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_BUTTON, BUTTON_WIDTH);headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_VENDORID, "Vendor Id");headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_VENDOR_DESC, "Vendor");headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_ITEM_KEY, "Item Key");headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, "Prev Item Key");headerVendorItemKey.getCellFormatter().setVisible(0, TABLE_INDEX_MAPPING_VENDORID, false);headerVendorItemKey.getCellFormatter().setVisible(0, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, false);Button addButton = new Button("Add");headerVendorItemKey.setWidget(0, TABLE_INDEX_MAPPING_BUTTON, addButton);addButton.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {VendorMappingDialog vendorMappingDialog = new VendorMappingDialog(productGroup.getText().trim(), brand.getText().trim(),modelNumber.getText().trim(), color.getText().trim());vendorMappingDialog.updateButton.setText("Add");vendorMappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {@Overridepublic boolean onUpdate(String key, long vendorId) {int row = tableVendorItemKey.getRowCount();tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDORID, VENDOR_ID_WIDTH);tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDOR_DESC, VENDOR_DESC_WIDTH);tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY, ITEM_KEY_WIDTH);tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY_OLD, ITEM_KEY_WIDTH);tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_VENDORID, vendorId + "");tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_VENDOR_DESC, Utils.getVendorDesc(vendorId));tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_ITEM_KEY, key);tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, key);tableVendorItemKey.getCellFormatter().setVisible(row, TABLE_INDEX_MAPPING_VENDORID, false);tableVendorItemKey.getCellFormatter().setVisible(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, false);return true;}});vendorMappingDialog.show();}});}/*** initialises vendor prices table header. Creates an Add button and* adds click event listener to it to create and pop up a dialog for adding* a prices for a new vendor*/private void initVendorPricingHeader(){headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDORID, VENDOR_ID_WIDTH);headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDOR_DESC, VENDOR_DESC_WIDTH);headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_MOP, PRICE_WIDTH);headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_DP, PRICE_WIDTH);headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_TP, PRICE_WIDTH);headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_BUTTON, BUTTON_WIDTH);headerVendorPrices.setText(0, TABLE_INDEX_PRICING_VENDORID, "Vendor Id");headerVendorPrices.setText(0, TABLE_INDEX_PRICING_VENDOR_DESC, "Vendor");headerVendorPrices.setText(0, TABLE_INDEX_PRICING_MOP, "MOP");headerVendorPrices.setText(0, TABLE_INDEX_PRICING_DP, "Dealer Price");headerVendorPrices.setText(0, TABLE_INDEX_PRICING_TP, "Transfer Price");headerVendorPrices.getCellFormatter().setVisible(0, TABLE_INDEX_PRICING_VENDORID, false);Button addButton = new Button("Add");headerVendorPrices.setWidget(0, TABLE_INDEX_PRICING_BUTTON, addButton);addButton.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {VendorPricesDialog vendorPricesDialog = new VendorPricesDialog();vendorPricesDialog.updateButton.setText("Add");vendorPricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {@Overridepublic boolean onUpdate(double mop, double dp, double tp, long vendorId) {if(!vendorExists(vendorId)) {Window.alert("Vendor already exists");return false;}/*if(!validateVendorPrices(mop, dp, tp)) {return false;}*/int row = tableVendorPrices.getRowCount();tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDORID, VENDOR_ID_WIDTH);tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDOR_DESC, VENDOR_DESC_WIDTH);tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_MOP, PRICE_WIDTH);tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_DP, PRICE_WIDTH);tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_TP, PRICE_WIDTH);tableVendorPrices.setText(row, TABLE_INDEX_PRICING_VENDORID, vendorId + "");tableVendorPrices.setText(row, TABLE_INDEX_PRICING_VENDOR_DESC, Utils.getVendorDesc(vendorId));tableVendorPrices.setText(row, TABLE_INDEX_PRICING_MOP, mop + "");tableVendorPrices.setText(row, TABLE_INDEX_PRICING_DP, dp + "");tableVendorPrices.setText(row, TABLE_INDEX_PRICING_TP, tp + "");tableVendorPrices.getCellFormatter().setVisible(row, TABLE_INDEX_PRICING_VENDORID, false);return true;}});vendorPricesDialog.show();}});}/*** Clear and populate item availability table.* @param availabilityMap*/private void updateAvailabilityTable(Map<Long, Long> availabilityMap){availabilityTable.removeAllRows();if(availabilityMap == null) {return;}availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_ID, "128px");availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_DESC, "300px");availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_INV, "128px");int i=0;for(Entry<Long, Long> availability : availabilityMap.entrySet()){availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_ID, availability.getKey() + "");availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_DESC, Utils.getWarehouseDesc(availability.getKey()));availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_INV, availability.getValue() + "");i++;}}/*** Clear and populate vendor item key table with keys in the passed argument.* With each row in the table, an edit button is created and click event listener* is added to it to edit that vendor item key row.* @param vendorKeysMap*/private void updateVendorKeysTable(Map<String, VendorItemMapping> vendorKeysMap){tableVendorItemKey.removeAllRows();if(vendorKeysMap == null || vendorKeysMap.isEmpty()) {return;}tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDORID, VENDOR_ID_WIDTH);tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDOR_DESC, VENDOR_DESC_WIDTH);tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY, ITEM_KEY_WIDTH);tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY_OLD, ITEM_KEY_WIDTH);tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_BUTTON, BUTTON_WIDTH);int i=0;for(Entry<String, VendorItemMapping> e : vendorKeysMap.entrySet()){VendorItemMapping vendorMapping = e.getValue();tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_VENDORID, vendorMapping.getVendorId() + "");tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_VENDOR_DESC, Utils.getVendorDesc(vendorMapping.getVendorId()));tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_ITEM_KEY, vendorMapping.getItemKey());tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, e.getKey().substring(e.getKey().indexOf(Item.KEY_SEPARATOR)+1));Button editButton = new Button("Edit");tableVendorItemKey.setWidget(i, TABLE_INDEX_MAPPING_BUTTON, editButton);editButton.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {Cell cell = tableVendorItemKey.getCellForEvent(event);int row = cell.getRowIndex();long vendorId = Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID));editVendorKey(vendorId, row);}});tableVendorItemKey.getCellFormatter().setVisible(i, TABLE_INDEX_MAPPING_VENDORID, false);tableVendorItemKey.getCellFormatter().setVisible(i, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, false);i++;}}/*** Clear and populate vendor prices table with prices in the passed argument.* With each row in the table, an edit button is created and click event listener* is added to it to edit that vendor prices row.* @param vendorPricingMap*/private void updateVendorPricingTable(Map<Long, VendorPricings> vendorPricingMap){tableVendorPrices.removeAllRows();if(vendorPricingMap == null || vendorPricingMap.isEmpty()) {return;}tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDORID, VENDOR_ID_WIDTH);tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDOR_DESC, VENDOR_DESC_WIDTH);tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_MOP, PRICE_WIDTH);tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_DP, PRICE_WIDTH);tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_TP, PRICE_WIDTH);tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_BUTTON, BUTTON_WIDTH);int i=0;for(VendorPricings vendorDetail : vendorPricingMap.values()){tableVendorPrices.setText(i, TABLE_INDEX_PRICING_VENDORID, vendorDetail.getVendorId() + "");tableVendorPrices.setText(i, TABLE_INDEX_PRICING_VENDOR_DESC, Utils.getVendorDesc(vendorDetail.getVendorId()));tableVendorPrices.setText(i, TABLE_INDEX_PRICING_MOP, vendorDetail.getMop() + "");tableVendorPrices.setText(i, TABLE_INDEX_PRICING_DP, vendorDetail.getDealerPrice() + "");tableVendorPrices.setText(i, TABLE_INDEX_PRICING_TP, vendorDetail.getTransferPrice() + "");Button editButton = new Button("Edit");tableVendorPrices.setWidget(i, TABLE_INDEX_PRICING_BUTTON, editButton);editButton.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {Cell cell = tableVendorPrices.getCellForEvent(event);int row = cell.getRowIndex();long vendorId = Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID));editVendorPrices(vendorId, row);}});tableVendorPrices.getCellFormatter().setVisible(i, TABLE_INDEX_PRICING_VENDORID, false);i++;}}/*** called on the click event of update item button in ItemActions*/void updateItem() {if(item == null) {Window.alert("Please select an item to update.");return;}try {if(!createNewItem()) {return;}String paramsChanged = isItemChanged();if(paramsChanged.equals("")) {Window.alert("Nothing to update. Please change intended item parameters and try again.");return;} else {paramsChanged = "You have changed following items.\n" + paramsChanged;Window.alert(paramsChanged);}} catch(NumberFormatException ex) {ex.printStackTrace();GWT.log("Number format exception");}if(!Utils.validateItem(newItem)) {return;}/*if(!validatePrices()) {return;}*/catalogService.updateItem(newItem, new AsyncCallback<Boolean>() {@Overridepublic void onSuccess(Boolean result) {if(result) {item = newItem;GWT.log("Item updated. Id = " + item.getId());catalogDashboardPanel.getItemListWidget().updateItem(item);getFreshItemFromDB(item.getId());Window.alert("Item updated successfully.");}else {GWT.log("Error updating item");Window.alert("Error updating item");}}@Overridepublic void onFailure(Throwable caught) {caught.printStackTrace();Window.alert("Error while updating item");}});}private void getFreshItemFromDB(long id) {catalogService.getItem(id, new AsyncCallback<Item>() {@Overridepublic void onSuccess(Item result) {setItemDetails(result);}@Overridepublic void onFailure(Throwable caught) {caught.printStackTrace();Window.alert("Unable to fetch item details.");}});}/*** This method is called while updating item.<br> It will create a new Item object and set* its editable attributes with UI fields values and non-editable attributes with old Item* object attributes. This new Item object is then passed to the service to update item in the database.* <br>If update is successful, the old Item object is replaced with the new Item object.* @return true if new Item object is created successfully* <br>false if some error occurs due to NumberFormatException*/private boolean createNewItem() {newItem = new Item();newItem.setId(item.getId());newItem.setVendorCategory(item.getVendorCategory());newItem.setProductGroup(productGroup.getText().trim());newItem.setBrand(brand.getText().trim());newItem.setModelNumber(modelNumber.getText().trim());newItem.setModelName(modelName.getText().trim());newItem.setColor(color.getText().trim());newItem.setContentCategory(contentCategory.getText());newItem.setComments(comments.getText().trim());newItem.setCatalogItemId(Long.parseLong(catalogItemId.getText()));try {if(!mrp.getText().trim().isEmpty()) {double mrpValue = Double.parseDouble(mrp.getText().trim());if(mrpValue <= 0) {throw new NumberFormatException("Negative value of MRP");}newItem.setMrp(mrpValue);}} catch(NumberFormatException ex) {Window.alert("Invalid MRP format/value. Value shoule be greater than zero");return false;}try {if(!sellingPrice.getText().trim().isEmpty()) {double spValue = Double.parseDouble(sellingPrice.getText().trim());if(spValue <= 0) {throw new NumberFormatException("Negative value of Selling price");}newItem.setSellingPrice(spValue);}} catch(NumberFormatException ex) {Window.alert("Invalid Selling Price format/value. Value shoule be greater than zero");return false;}try {if(!weight.getText().trim().isEmpty()) {double wtValue = Double.parseDouble(weight.getText().trim());if(wtValue <= 0) {throw new NumberFormatException("Negative value of Weight");}newItem.setWeight(wtValue);}} catch(NumberFormatException ex) {Window.alert("Invalid weight format/value. Value shoule be greater than zero");return false;}try {if(!startDate.getTextBox().getText().trim().equals("")) {newItem.setStartDate(startDate.getValue().getTime());}} catch(Exception ex) {Window.alert("Invalid start date format");return false;}newItem.setBestDealsText(bestDealsText.getText().trim());try {if(!bestDealsValue.getText().trim().equals("")) {double bdValue = Double.parseDouble(bestDealsValue.getText().trim());if(bdValue < 0) {throw new NumberFormatException("Negative value of BestDealValue");}newItem.setBestDealsValue(bdValue);}} catch(NumberFormatException ex) {Window.alert("Invalid best deal value format");return false;}try {if(!bestSellingRank.getText().trim().equals("")) {long bsrValue = Long.parseLong(bestSellingRank.getText().trim());if(bsrValue < 0) {throw new NumberFormatException("Negative value of Best Selling Rank");}newItem.setBestSellingRank(bsrValue);}} catch(NumberFormatException ex) {Window.alert("Invalid best selling rank format");return false;}newItem.setDefaultForEntity(defaultForEntity.getValue());newItem.setRisky(risky.getValue());try {String expectedDelayText = expectedDelay.getText().trim();if(!expectedDelayText.equals("")){newItem.setExpectedDelay(Integer.parseInt(expectedDelayText));}} catch(NumberFormatException nfe) {Window.alert("Invalid expected delay");return false;}try {String preferredWarehouseText = preferredWarehouse.getText().trim();if(!preferredWarehouseText.equals("")){newItem.setPreferredWarehouse(Long.parseLong(preferredWarehouseText) + "");}}catch(NumberFormatException nfe){Window.alert("Invalid Preferred Warehouse");return false;}/*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.Add the instance to map and set the map to the item instance created above.*/Map<Long, VendorPricings> vendorPrices = new HashMap<Long, VendorPricings>();VendorPricings v;for(int row = 0; row < tableVendorPrices.getRowCount(); row++) {v = new VendorPricings();v.setMop(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP)));v.setDealerPrice(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP)));v.setTransferPrice(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP)));v.setVendorId(Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID)));vendorPrices.put(v.getVendorId(), v);}newItem.setVendorPricesMap(vendorPrices);newItem.setItemStatusDesc(statusDesc.getText().trim());/*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.Add the instance to map and set the map to the item instance created above.*/Map<String, VendorItemMapping> vendorMappings = new HashMap<String, VendorItemMapping>();VendorItemMapping vMapping;for(int row = 0; row < tableVendorItemKey.getRowCount(); row++) {vMapping = new VendorItemMapping();vMapping.setItemKey(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY));vMapping.setVendorId(Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID)));vendorMappings.put(vMapping.getVendorId() + Item.KEY_SEPARATOR + tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD), vMapping);}newItem.setVendorKeysMap(vendorMappings);newItem.setContentCategoryId(item.getContentCategoryId());newItem.setFeatureId(item.getFeatureId());newItem.setFeatureDescription(item.getFeatureDescription());newItem.setAddedOn(item.getAddedOn());newItem.setRetireDate(item.getRetireDate());newItem.setUpdatedOn(item.getUpdatedOn());newItem.setItemStatus(item.getItemStatus());newItem.setOtherInfo(item.getOtherInfo());newItem.setAvailability(item.getAvailability());return true;}/*** This method is called when Edit button is clicked corresponding to a row in* vendor prices table. It will pop up a form to edit the vendor prices.* @param vendorId* @param row*/private void editVendorPrices(final long vendorId, final int row) {String mop = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP);String dp = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP);String tp = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP);VendorPricesDialog pricesDialog = new VendorPricesDialog(mop, dp, tp);pricesDialog.updateButton.setText("Update");pricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {@Overridepublic boolean onUpdate(double mop, double dp, double tp, long vendorId) {if(!validateVendorPrices(mop, dp, tp)) {return false;}tableVendorPrices.setText(row, TABLE_INDEX_PRICING_MOP, mop + "");tableVendorPrices.setText(row, TABLE_INDEX_PRICING_DP, dp + "");tableVendorPrices.setText(row, TABLE_INDEX_PRICING_TP, tp + "");return true;}});pricesDialog.show();}/*** This method is called when Edit button is clicked corresponding to a row in* vendor item key table. It will pop up a form to edit the item key.* @param vendorId* @param row*/private void editVendorKey(final long vendorId, final int row) {String key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY);VendorMappingDialog mappingDialog = new VendorMappingDialog(productGroup.getText().trim(), brand.getText().trim(),modelNumber.getText().trim(), color.getText().trim(), key);mappingDialog.updateButton.setText("Update");mappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {@Overridepublic boolean onUpdate(String itemKey, long vendorId) {if(itemKey == null || itemKey.equals("")) {Window.alert("Item key cannot be empty.");return false;}tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_ITEM_KEY, itemKey);return true;}});mappingDialog.show();}/*** This method compares all the editable UI fields values with attributes in the item object.* If they differ, the attribute name is appended to a string.* @return String showing attributes which are changed by the user for confirmation.* <br>Empty string if nothing is changed.*/private String isItemChanged() {StringBuilder sb = new StringBuilder("");if(!checkParameterIfEqual(productGroup.getText().trim(), item.getProductGroup())) {sb.append("\n-Product Group");}if(!checkParameterIfEqual(brand.getText().trim(), item.getBrand())) {sb.append("\n-Brand");}if(!checkParameterIfEqual(modelNumber.getText().trim(), item.getModelNumber())) {sb.append("\n-Model Number");}if(!checkParameterIfEqual(modelName.getText().trim(), item.getModelName())) {sb.append("\n-Model Name");}if(!checkParameterIfEqual(color.getText().trim(), item.getColor())) {sb.append("\n-Color");}if(!checkParameterIfEqual(statusDesc.getText().trim(), item.getItemStatusDesc())) {sb.append("\n-Status Description");}if(!checkParameterIfEqual(comments.getText().trim(), item.getComments())) {sb.append("\n-Comments");}if(!checkParameterIfEqual(newItem.getMrp(), item.getMrp())) {sb.append("\n-MRP");}if(!checkParameterIfEqual(newItem.getSellingPrice(), item.getSellingPrice())) {sb.append("\n-Selling Price");}if(!checkParameterIfEqual(newItem.getWeight(), item.getWeight())) {sb.append("\n-Weight");}if(!checkParameterIfEqual(bestDealsText.getText().trim(), item.getBestDealsText())) {sb.append("\n-Best Deal Text");}if(!checkParameterIfEqual(newItem.getBestDealsValue(), item.getBestDealsValue())) {sb.append("\n-Best Deal Value");}if(!checkParameterIfEqual(newItem.getBestSellingRank(), item.getBestSellingRank())) {sb.append("\n-Best Selling Rank");}if(item.isDefaultForEntity() != defaultForEntity.getValue()) {sb.append("\n-Default For Entity Flag");}if(item.isRisky() != risky.getValue()) {sb.append("\n-Risky Flag");}if(!checkParameterIfEqual(newItem.getStartDate(), item.getStartDate())) {sb.append("\n-Start Date");}if(item.getExpectedDelay() != newItem.getExpectedDelay()) {sb.append("\n-Expected Delay");}if(item.getPreferredWarehouse() != newItem.getPreferredWarehouse()) {sb.append("\n-Preferred Warehouse");}VendorPricings vendorPricings;long vendorId;for(int row = 0; row < tableVendorPrices.getRowCount(); row++) {vendorId = Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID));vendorPricings = item.getVendorPricesMap().get(vendorId);if(vendorPricings == null) {sb.append("\n-Vendor Prices (Vendor:" + vendorId + ")");continue;}if(vendorPricings.getMop() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP))) {sb.append("\n-MOP (Vendor:" + vendorId + ")");}if(vendorPricings.getDealerPrice() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP))) {sb.append("\n-Dealer Price (Vendor:" + vendorId + ")");}if(vendorPricings.getTransferPrice() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP))) {sb.append("\n-Transfer Price (Vendor:" + vendorId + ")");}}VendorItemMapping mapping;String old_key, new_key;for(int row = 0; row < tableVendorItemKey.getRowCount(); row++) {vendorId = Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID));old_key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD);new_key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY);mapping = item.getVendorKeysMap().get(vendorId + Item.KEY_SEPARATOR + old_key);if(mapping == null || !old_key.equals(new_key)) {sb.append("\n-Vendor Key (Vendor:" + vendorId + ",Key: = " + old_key + ")");continue;}}return sb.toString();}@SuppressWarnings("unused")private boolean validatePrices() {if(newItem.getSellingPrice() > newItem.getMrp()) {Window.alert("Selling price cannot be more than MRP");return false;}for(VendorPricings v : newItem.getVendorPricesMap().values()) {if(newItem.getMrp() < v.getMop()) {Window.alert("MRP cannot be less than MOP. Vendor: " + v.getVendorId());return false;}if(v.getTransferPrice() > v.getMop()) {Window.alert("Transfer Price cannot be more than MOP. Vendor: " + v.getVendorId());return false;}}return true;}private boolean validateVendorPrices(double mop, double dp, double tp) {if(item.getMrp() != null && item.getMrp() < mop) {Window.alert("MOP cannot be more than MRP.");return false;}if(tp > mop) {Window.alert("Transfer Price cannot be more than MOP.");return false;}return true;}public long getItemId() {return item == null ? 0 : item.getId();}public Item getItem() {return item;}/*** This method is used while adding vendor prices to ensure that there is only one row in the table for a vendor.* @param vendorId* @return true if parameter vendor Id is already added to vendor prices table.* <br>else false*/private boolean vendorExists(long vendorId) {long id;for(int i = 0; i < tableVendorPrices.getRowCount(); i++) {id = Long.parseLong(tableVendorPrices.getText(i, TABLE_INDEX_PRICING_VENDORID));if(vendorId == id) {return false;}}return true;}/*** This method is used to check if any of the string item attributes is changed by the user.* @param o1* @param o2* @return true if two strings are equal* <br>true if one of them is null and another is empty.* <br>false otherwise*/private boolean checkParameterIfEqual(Object o1, Object o2) {if(o1 == o2) {return true;}if(o1 != null && o2 != null && o1.equals(o2)) {return true;}if((o1 == null && o2.equals("")) || (o2 == null && o1.equals(""))) {return true;}return false;}public void setCatalogDashboardPanel(CatalogDashboard catalogDashboardPanel) {this.catalogDashboardPanel = catalogDashboardPanel;}}