Subversion Repositories SmartDukaan

Rev

Rev 2427 | Rev 2566 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1961 ankur.sing 1
package in.shop2020.catalog.dashboard.client;
2
 
3
import in.shop2020.catalog.dashboard.shared.Item;
2066 ankur.sing 4
import in.shop2020.catalog.dashboard.shared.Utils;
2119 ankur.sing 5
import in.shop2020.catalog.dashboard.shared.VendorItemMapping;
6
import in.shop2020.catalog.dashboard.shared.VendorPricings;
1961 ankur.sing 7
 
8
import java.util.Date;
2066 ankur.sing 9
import java.util.HashMap;
1992 ankur.sing 10
import java.util.Map;
11
import java.util.Map.Entry;
1961 ankur.sing 12
 
13
import com.google.gwt.core.client.GWT;
14
import com.google.gwt.event.dom.client.ClickEvent;
1992 ankur.sing 15
import com.google.gwt.event.dom.client.ClickHandler;
16
import com.google.gwt.resources.client.CssResource;
1961 ankur.sing 17
import com.google.gwt.uibinder.client.UiBinder;
18
import com.google.gwt.uibinder.client.UiField;
19
import com.google.gwt.uibinder.client.UiHandler;
20
import com.google.gwt.user.client.Window;
2126 ankur.sing 21
import com.google.gwt.user.client.rpc.AsyncCallback;
1961 ankur.sing 22
import com.google.gwt.user.client.ui.Button;
2066 ankur.sing 23
import com.google.gwt.user.client.ui.CheckBox;
1992 ankur.sing 24
import com.google.gwt.user.client.ui.FlexTable;
25
import com.google.gwt.user.client.ui.HTMLTable.Cell;
1961 ankur.sing 26
import com.google.gwt.user.client.ui.Label;
27
import com.google.gwt.user.client.ui.ResizeComposite;
28
import com.google.gwt.user.client.ui.TextBox;
29
import com.google.gwt.user.client.ui.Widget;
2068 ankur.sing 30
import com.google.gwt.user.datepicker.client.DateBox;
1961 ankur.sing 31
 
2427 ankur.sing 32
/**
33
 * Panel contains fields for item details. Some of these fields are editable.
34
 * It also contains vendor item pricings, vendor item keys, and item availability in tabular format.
35
 * Item availability is made invisible for time being 
36
 */
1961 ankur.sing 37
public class ItemDetails extends ResizeComposite {
38
 
2359 ankur.sing 39
    private final int TABLE_INDEX_MAPPING_VENDOR_DESC = 0, 
40
                      TABLE_INDEX_MAPPING_ITEM_KEY = 1,
41
                      TABLE_INDEX_MAPPING_BUTTON = 2,
42
                      TABLE_INDEX_MAPPING_VENDORID = 3, 
43
                      TABLE_INDEX_MAPPING_ITEM_KEY_OLD = 4;
44
 
45
    private final int TABLE_INDEX_PRICING_VENDOR_DESC = 0, 
46
                      TABLE_INDEX_PRICING_MOP = 1,
47
                      TABLE_INDEX_PRICING_DP = 2,
48
                      TABLE_INDEX_PRICING_TP = 3,
49
                      TABLE_INDEX_PRICING_BUTTON = 4,
50
                      TABLE_INDEX_PRICING_VENDORID = 5;
51
 
2119 ankur.sing 52
    private final int TABLE_INDEX_WAREHOUSE_ID = 0,
53
                      TABLE_INDEX_WAREHOUSE_DESC = 1,
54
                      TABLE_INDEX_WAREHOUSE_INV = 2;
2359 ankur.sing 55
 
56
    private final String PRICE_WIDTH = "100px", VENDOR_DESC_WIDTH = "130px",
57
                         VENDOR_ID_WIDTH = "100px", ITEM_KEY_WIDTH = "200px",
58
                         BUTTON_WIDTH = "50px";
2066 ankur.sing 59
 
60
    interface ItemDetailsUiBinder extends UiBinder<Widget, ItemDetails> {}
61
    private static ItemDetailsUiBinder uiBinder = GWT.create(ItemDetailsUiBinder.class);
2126 ankur.sing 62
    private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
2066 ankur.sing 63
 
1961 ankur.sing 64
 
2066 ankur.sing 65
    interface ItemDetailStyle extends CssResource{
66
        String greenLabel();
67
        String fieldChanged();
68
    }
1961 ankur.sing 69
 
2105 ankur.sing 70
    private Item item, newItem;
2489 ankur.sing 71
    private CatalogDashboard catalogDashboardPanel;
2066 ankur.sing 72
 
73
    @UiField ItemDetailStyle style;
74
    @UiField Label itemId;
75
    @UiField TextBox productGroup, brand, modelNumber, modelName, color;
2105 ankur.sing 76
    @UiField Label contentCategory, catalogItemId;
2359 ankur.sing 77
    @UiField TextBox statusDesc, comments;
2105 ankur.sing 78
    @UiField TextBox sellingPrice, mrp, weight;
79
    @UiField Label addedOn, retireDate, updatedOn;
2066 ankur.sing 80
    @UiField Label itemStatus;
81
    @UiField TextBox bestDealsText, bestDealsValue; 
82
    @UiField FlexTable headerAvailability, availabilityTable;
2427 ankur.sing 83
    @UiField FlexTable headerVendorItemKey, tableVendorItemKey;
84
    @UiField FlexTable headerVendorPrices, tableVendorPrices;
2066 ankur.sing 85
    @UiField TextBox bestSellingRank;
2252 ankur.sing 86
    @UiField CheckBox defaultForEntity, risky;
2068 ankur.sing 87
    @UiField DateBox startDate;
2066 ankur.sing 88
 
89
    public ItemDetails(Item item){
2105 ankur.sing 90
        this();
2066 ankur.sing 91
        setItemDetails(item);
92
    }
93
 
94
    public ItemDetails() {
95
        initWidget(uiBinder.createAndBindUi(this));
96
        initAvailabilityHeader();
2427 ankur.sing 97
        initVendorKeysHeader();
98
        initVendorPricingHeader();
2119 ankur.sing 99
 
2105 ankur.sing 100
        headerAvailability.setVisible(false);
101
        availabilityTable.setVisible(false);
2066 ankur.sing 102
    }
103
 
2427 ankur.sing 104
    /**
105
     * Sets the UI fields with item object attributes
106
     * Also populates tables for vendor prices, keys and item availability
107
     * @param item
108
     */
2066 ankur.sing 109
    public void setItemDetails(Item item){
110
        this.item = item;
111
        itemId.setText(item.getId()+"");
112
        productGroup.setText(item.getProductGroup());
113
        brand.setText(item.getBrand());
114
        modelNumber.setText(item.getModelNumber());
115
        modelName.setText(item.getModelName());
116
        color.setText(item.getColor());
117
 
2359 ankur.sing 118
        statusDesc.setText(item.getItemStatusDesc());
2105 ankur.sing 119
        contentCategory.setText(item.getContentCategory()+"");
2066 ankur.sing 120
        comments.setText(item.getComments());
121
        catalogItemId.setText(item.getCatalogItemId() + "");
122
 
2489 ankur.sing 123
        mrp.setText(item.getMrp() != null ? item.getMrp()+"" : "");
124
        sellingPrice.setText(item.getSellingPrice() != null ? item.getSellingPrice()+"" : "");
125
        weight.setText(item.getWeight() != null ? item.getWeight()+"" : "");
2068 ankur.sing 126
 
127
        startDate.setValue(new Date(item.getStartDate()));
128
        addedOn.setText(Utils.getDisplayableDate(item.getAddedOn()));
129
        retireDate.setText(Utils.getDisplayableDate(item.getRetireDate()));
130
        updatedOn.setText(Utils.getDisplayableDate(item.getUpdatedOn()));
1992 ankur.sing 131
 
2066 ankur.sing 132
        bestDealsText.setText(item.getBestDealsText());
2489 ankur.sing 133
        bestDealsValue.setText(item.getBestDealsValue() != null ? item.getBestDealsValue()+"" : "");
134
        bestSellingRank.setText(item.getBestSellingRank() != null ? item.getBestSellingRank()+"" : "");
2066 ankur.sing 135
        defaultForEntity.setValue(item.isDefaultForEntity());
2252 ankur.sing 136
        risky.setValue(item.isRisky());
1992 ankur.sing 137
 
2066 ankur.sing 138
        itemStatus.setText(item.getItemStatus());
139
 
140
        updateAvailabilityTable(item.getAvailability());
2427 ankur.sing 141
        updateVendorKeysTable(item.getVendorKeysMap());
142
        updateVendorPricingTable(item.getVendorPricesMap());
1992 ankur.sing 143
    }
2066 ankur.sing 144
 
2427 ankur.sing 145
    /**
146
     * initialise item availability table header.
147
     */
2066 ankur.sing 148
    private void initAvailabilityHeader(){
149
        headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_ID, "128px");
2105 ankur.sing 150
        headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_DESC, "300px");
2066 ankur.sing 151
        headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_INV, "128px");
152
 
153
        headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_ID, "Warehouse Id");
154
        headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_DESC, "Warehouse Desc");
155
        headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_INV, "Availability");
1992 ankur.sing 156
 
157
    }
2066 ankur.sing 158
 
2427 ankur.sing 159
    /**
160
     * initialises vendor item key table header. Creates an Add button and
161
     * adds click event listener to it to create and pop up a dialog for adding 
162
     * a new vendor item key. 
163
     */
164
    private void initVendorKeysHeader(){
165
        headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDORID, VENDOR_ID_WIDTH);
166
        headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDOR_DESC, VENDOR_DESC_WIDTH);
167
        headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY, ITEM_KEY_WIDTH);
168
        headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY_OLD, ITEM_KEY_WIDTH);
169
        headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_BUTTON, BUTTON_WIDTH);
2119 ankur.sing 170
 
2427 ankur.sing 171
        headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_VENDORID, "Vendor Id");
172
        headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_VENDOR_DESC, "Vendor");
173
        headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_ITEM_KEY, "Item Key");
174
        headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, "Prev Item Key");
2119 ankur.sing 175
 
2427 ankur.sing 176
        headerVendorItemKey.getCellFormatter().setVisible(0, TABLE_INDEX_MAPPING_VENDORID, false);
177
        headerVendorItemKey.getCellFormatter().setVisible(0, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, false);
2359 ankur.sing 178
 
2119 ankur.sing 179
        Button addButton = new Button("Add");
2427 ankur.sing 180
        headerVendorItemKey.setWidget(0, TABLE_INDEX_MAPPING_BUTTON, addButton);
2119 ankur.sing 181
        addButton.addClickHandler(new ClickHandler() {
182
            @Override
183
            public void onClick(ClickEvent event) {
2126 ankur.sing 184
                VendorMappingDialog vendorMappingDialog = new VendorMappingDialog(productGroup.getText().trim(), brand.getText().trim(), 
185
                        modelNumber.getText().trim(), color.getText().trim());
2119 ankur.sing 186
                vendorMappingDialog.updateButton.setText("Add");
187
                vendorMappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {
188
                    @Override
189
                    public boolean onUpdate(String key, long vendorId) {
2427 ankur.sing 190
                        int row = tableVendorItemKey.getRowCount();
191
                        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDORID, VENDOR_ID_WIDTH);
192
                        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDOR_DESC, VENDOR_DESC_WIDTH);
193
                        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY, ITEM_KEY_WIDTH);
194
                        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY_OLD, ITEM_KEY_WIDTH);
2119 ankur.sing 195
 
2427 ankur.sing 196
                        tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_VENDORID, vendorId + "");
197
                        tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_VENDOR_DESC, Utils.getVendorDesc(vendorId));
198
                        tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_ITEM_KEY, key);
199
                        tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, key);
2359 ankur.sing 200
 
2427 ankur.sing 201
                        tableVendorItemKey.getCellFormatter().setVisible(row, TABLE_INDEX_MAPPING_VENDORID, false);
202
                        tableVendorItemKey.getCellFormatter().setVisible(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, false);
2119 ankur.sing 203
                        return true;
204
                    }
205
                });
206
                vendorMappingDialog.show();
207
            }
208
        });
209
    }
210
 
2427 ankur.sing 211
    /**
212
     * initialises vendor prices table header. Creates an Add button and
213
     * adds click event listener to it to create and pop up a dialog for adding 
214
     * a prices for a new vendor 
215
     */
216
    private void initVendorPricingHeader(){
217
        headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDORID, VENDOR_ID_WIDTH);
218
        headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDOR_DESC, VENDOR_DESC_WIDTH);
219
        headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_MOP, PRICE_WIDTH);
220
        headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_DP, PRICE_WIDTH);
221
        headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_TP, PRICE_WIDTH);
222
        headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_BUTTON, BUTTON_WIDTH);
2066 ankur.sing 223
 
2427 ankur.sing 224
        headerVendorPrices.setText(0, TABLE_INDEX_PRICING_VENDORID, "Vendor Id");
225
        headerVendorPrices.setText(0, TABLE_INDEX_PRICING_VENDOR_DESC, "Vendor");
226
        headerVendorPrices.setText(0, TABLE_INDEX_PRICING_MOP, "MOP");
227
        headerVendorPrices.setText(0, TABLE_INDEX_PRICING_DP, "Dealer Price");
228
        headerVendorPrices.setText(0, TABLE_INDEX_PRICING_TP, "Transfer Price");
2105 ankur.sing 229
 
2427 ankur.sing 230
        headerVendorPrices.getCellFormatter().setVisible(0, TABLE_INDEX_PRICING_VENDORID, false);
2359 ankur.sing 231
 
2105 ankur.sing 232
        Button addButton = new Button("Add");
2427 ankur.sing 233
        headerVendorPrices.setWidget(0, TABLE_INDEX_PRICING_BUTTON, addButton);
2105 ankur.sing 234
        addButton.addClickHandler(new ClickHandler() {
235
            @Override
236
            public void onClick(ClickEvent event) {
2119 ankur.sing 237
                VendorPricesDialog vendorPricesDialog = new VendorPricesDialog();
238
                vendorPricesDialog.updateButton.setText("Add");
239
                vendorPricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
2105 ankur.sing 240
                    @Override
2119 ankur.sing 241
                    public boolean onUpdate(double mop, double dp, double tp, long vendorId) {
2105 ankur.sing 242
                        if(!vendorExists(vendorId)) {
243
                            Window.alert("Vendor already exists");
244
                            return false;
245
                        }
2119 ankur.sing 246
                        /*if(!validateVendorPrices(mop, dp, tp)) {
2105 ankur.sing 247
                            return false;
2119 ankur.sing 248
                        }*/
2427 ankur.sing 249
                        int row = tableVendorPrices.getRowCount();
250
                        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDORID, VENDOR_ID_WIDTH);
251
                        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDOR_DESC, VENDOR_DESC_WIDTH);
252
                        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_MOP, PRICE_WIDTH);
253
                        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_DP, PRICE_WIDTH);
254
                        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_TP, PRICE_WIDTH);
2105 ankur.sing 255
 
2427 ankur.sing 256
                        tableVendorPrices.setText(row, TABLE_INDEX_PRICING_VENDORID, vendorId + "");
257
                        tableVendorPrices.setText(row, TABLE_INDEX_PRICING_VENDOR_DESC, Utils.getVendorDesc(vendorId));
258
                        tableVendorPrices.setText(row, TABLE_INDEX_PRICING_MOP, mop + "");
259
                        tableVendorPrices.setText(row, TABLE_INDEX_PRICING_DP, dp + "");
260
                        tableVendorPrices.setText(row, TABLE_INDEX_PRICING_TP, tp + "");
2359 ankur.sing 261
 
2427 ankur.sing 262
                        tableVendorPrices.getCellFormatter().setVisible(row, TABLE_INDEX_PRICING_VENDORID, false);
2105 ankur.sing 263
                        return true;
264
                    }
265
                });
2119 ankur.sing 266
                vendorPricesDialog.show();
2105 ankur.sing 267
            }
268
        });
2066 ankur.sing 269
    }
2105 ankur.sing 270
 
2427 ankur.sing 271
    /**
272
     * Clear and populate item availability table.
273
     * @param availabilityMap
274
     */
1992 ankur.sing 275
    private void updateAvailabilityTable(Map<Long, Long> availabilityMap){
276
        availabilityTable.removeAllRows();
277
        if(availabilityMap == null) {
278
            return;
279
        }
2066 ankur.sing 280
        availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_ID, "128px");
2105 ankur.sing 281
        availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_DESC, "300px");
2066 ankur.sing 282
        availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_INV, "128px");
283
 
1992 ankur.sing 284
        int i=0;
285
        for(Entry<Long, Long> availability : availabilityMap.entrySet()){
2066 ankur.sing 286
            availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_ID, availability.getKey() + "");
287
            availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_DESC, Utils.getWarehouseDesc(availability.getKey()));
288
            availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_INV, availability.getValue() + "");
1992 ankur.sing 289
            i++;
290
        }
291
    }
2119 ankur.sing 292
 
2427 ankur.sing 293
    /**
294
     * Clear and populate vendor item key table with keys in the passed argument.
295
     * With each row in the table, an edit button is created and click event listener 
296
     * is added to it to edit that vendor item key row.
297
     * @param vendorKeysMap
298
     */
299
    private void updateVendorKeysTable(Map<String, VendorItemMapping> vendorKeysMap){
300
        tableVendorItemKey.removeAllRows();
2119 ankur.sing 301
 
2427 ankur.sing 302
        if(vendorKeysMap == null || vendorKeysMap.isEmpty()) {
2119 ankur.sing 303
            return;
304
        }
2427 ankur.sing 305
        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDORID, VENDOR_ID_WIDTH);
306
        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDOR_DESC, VENDOR_DESC_WIDTH);
307
        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY, ITEM_KEY_WIDTH);
308
        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY_OLD, ITEM_KEY_WIDTH);
309
        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_BUTTON, BUTTON_WIDTH);
2066 ankur.sing 310
 
2119 ankur.sing 311
        int i=0;
2427 ankur.sing 312
        for(Entry<String, VendorItemMapping> e : vendorKeysMap.entrySet()){
2359 ankur.sing 313
            VendorItemMapping vendorMapping = e.getValue();
2427 ankur.sing 314
            tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_VENDORID, vendorMapping.getVendorId() + "");
315
            tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_VENDOR_DESC, Utils.getVendorDesc(vendorMapping.getVendorId()));
316
            tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_ITEM_KEY, vendorMapping.getItemKey());
317
            tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, e.getKey().substring(e.getKey().indexOf(Item.KEY_SEPARATOR)+1));
2119 ankur.sing 318
            Button editButton = new Button("Edit");
2427 ankur.sing 319
            tableVendorItemKey.setWidget(i, TABLE_INDEX_MAPPING_BUTTON, editButton);
2119 ankur.sing 320
            editButton.addClickHandler(new ClickHandler() {
321
                @Override
322
                public void onClick(ClickEvent event) {
2427 ankur.sing 323
                    Cell cell = tableVendorItemKey.getCellForEvent(event);
2119 ankur.sing 324
                    int row = cell.getRowIndex();
2427 ankur.sing 325
                    long vendorId = Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID));
326
                    editVendorKey(vendorId, row);
2119 ankur.sing 327
                }
328
            });
2427 ankur.sing 329
            tableVendorItemKey.getCellFormatter().setVisible(i, TABLE_INDEX_MAPPING_VENDORID, false);
330
            tableVendorItemKey.getCellFormatter().setVisible(i, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, false);
2359 ankur.sing 331
            i++;
2119 ankur.sing 332
        }
333
    }
334
 
2427 ankur.sing 335
    /**
336
     * Clear and populate vendor prices table with prices in the passed argument.
337
     * With each row in the table, an edit button is created and click event listener 
338
     * is added to it to edit that vendor prices row.
339
     * @param vendorPricingMap
340
     */
341
    private void updateVendorPricingTable(Map<Long, VendorPricings> vendorPricingMap){
342
        tableVendorPrices.removeAllRows();
2105 ankur.sing 343
 
2119 ankur.sing 344
        if(vendorPricingMap == null || vendorPricingMap.isEmpty()) {
1992 ankur.sing 345
            return;
346
        }
2427 ankur.sing 347
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDORID, VENDOR_ID_WIDTH);
348
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDOR_DESC, VENDOR_DESC_WIDTH);
349
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_MOP, PRICE_WIDTH);
350
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_DP, PRICE_WIDTH);
351
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_TP, PRICE_WIDTH);
352
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_BUTTON, BUTTON_WIDTH);
2066 ankur.sing 353
 
354
 
1992 ankur.sing 355
        int i=0;
2119 ankur.sing 356
        for(VendorPricings vendorDetail : vendorPricingMap.values()){
2427 ankur.sing 357
            tableVendorPrices.setText(i, TABLE_INDEX_PRICING_VENDORID, vendorDetail.getVendorId() + "");
358
            tableVendorPrices.setText(i, TABLE_INDEX_PRICING_VENDOR_DESC, Utils.getVendorDesc(vendorDetail.getVendorId()));
359
            tableVendorPrices.setText(i, TABLE_INDEX_PRICING_MOP, vendorDetail.getMop() + "");
360
            tableVendorPrices.setText(i, TABLE_INDEX_PRICING_DP, vendorDetail.getDealerPrice() + "");
361
            tableVendorPrices.setText(i, TABLE_INDEX_PRICING_TP, vendorDetail.getTransferPrice() + "");
1992 ankur.sing 362
            Button editButton = new Button("Edit");
2427 ankur.sing 363
            tableVendorPrices.setWidget(i, TABLE_INDEX_PRICING_BUTTON, editButton);
1992 ankur.sing 364
            editButton.addClickHandler(new ClickHandler() {
365
                @Override
366
                public void onClick(ClickEvent event) {
2427 ankur.sing 367
                    Cell cell = tableVendorPrices.getCellForEvent(event);
1992 ankur.sing 368
                    int row = cell.getRowIndex();
2427 ankur.sing 369
                    long vendorId = Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID));
370
                    editVendorPrices(vendorId, row);
1992 ankur.sing 371
                }
372
            });
2427 ankur.sing 373
            tableVendorPrices.getCellFormatter().setVisible(i, TABLE_INDEX_PRICING_VENDORID, false);
2359 ankur.sing 374
            i++;
1992 ankur.sing 375
        }
376
    }
2066 ankur.sing 377
 
2427 ankur.sing 378
    /**
379
     * called on the click event of update item button in ItemActions
380
     */
2126 ankur.sing 381
    void updateItem() {
382
        if(item == null) {
383
            Window.alert("Please select an item to update.");
384
            return;
385
        }
2066 ankur.sing 386
        try {
2126 ankur.sing 387
            if(!createNewItem()) {
388
                return;
389
            }
2252 ankur.sing 390
            String paramsChanged = isItemChanged();
391
            if(paramsChanged.equals("")) {
2066 ankur.sing 392
                Window.alert("Nothing to update. Please change intended item parameters and try again.");
393
                return;
2252 ankur.sing 394
            } else {
395
                paramsChanged = "You have changed following items.\n" + paramsChanged;
396
                Window.alert(paramsChanged);
2066 ankur.sing 397
            }
398
        } catch(NumberFormatException ex) {
2126 ankur.sing 399
            ex.printStackTrace();
400
            GWT.log("Number format exception");
401
        }
402
        if(!Utils.validateItem(newItem)) {
2066 ankur.sing 403
            return;
404
        }
2126 ankur.sing 405
 
406
        /*if(!validatePrices()) {
407
            return;
408
        }*/
409
        catalogService.updateItem(newItem, new AsyncCallback<Boolean>() {
410
            @Override
411
            public void onSuccess(Boolean result) {
412
                if(result) {
413
                    item = newItem;
414
                    GWT.log("Item updated. Id = " + item.getId());
2489 ankur.sing 415
                    catalogDashboardPanel.getItemListWidget().updateItem(item);
416
                    getFreshItemFromDB(item.getId());
2126 ankur.sing 417
                    Window.alert("Item updated successfully.");
418
                }
419
                else {
420
                    GWT.log("Error updating item");
421
                    Window.alert("Error updating item");
422
                }
423
            }
424
            @Override
425
            public void onFailure(Throwable caught) {
426
                caught.printStackTrace();
427
                Window.alert("Error while updating item");
428
            }
429
        });
2066 ankur.sing 430
    }
2126 ankur.sing 431
 
2489 ankur.sing 432
    private void getFreshItemFromDB(long id) {
433
        catalogService.getItem(id, new AsyncCallback<Item>() {
434
            @Override
435
            public void onSuccess(Item result) {
436
                setItemDetails(result);
437
            }
438
            @Override
439
            public void onFailure(Throwable caught) {
440
                caught.printStackTrace();
441
                Window.alert("Unable to fetch item details.");
442
            }
443
        });
444
    }
445
 
2427 ankur.sing 446
    /**
447
     * This method is called while updating item.<br> It will create a new Item object and set 
448
     * its editable attributes with UI fields values and non-editable attributes with old Item
449
     * object attributes. This new Item object is then passed to the service to update item in the database.
450
     * <br>If update is successful, the old Item object is replaced with the new Item object. 
451
     * @return true if new Item object is created successfully
452
     *     <br>false if some error occurs due to NumberFormatException
453
     */
2126 ankur.sing 454
    private boolean createNewItem() {
2066 ankur.sing 455
        newItem = new Item();
2489 ankur.sing 456
        newItem.setId(item.getId());
457
        newItem.setVendorCategory(item.getVendorCategory());
2066 ankur.sing 458
        newItem.setProductGroup(productGroup.getText().trim());
459
        newItem.setBrand(brand.getText().trim());
460
        newItem.setModelNumber(modelNumber.getText().trim());
461
        newItem.setModelName(modelName.getText().trim());
462
        newItem.setColor(color.getText().trim());
2119 ankur.sing 463
        newItem.setContentCategory(contentCategory.getText());
2066 ankur.sing 464
        newItem.setComments(comments.getText().trim());
465
        newItem.setCatalogItemId(Long.parseLong(catalogItemId.getText()));
2126 ankur.sing 466
 
2068 ankur.sing 467
        try {
2126 ankur.sing 468
            if(!mrp.getText().trim().isEmpty()) {
469
                double mrpValue = Double.parseDouble(mrp.getText().trim());
470
                if(mrpValue <= 0) {
471
                    throw new NumberFormatException("Negative value of MRP");
472
                }
473
                newItem.setMrp(mrpValue);
474
            }
2068 ankur.sing 475
        } catch(NumberFormatException ex) {
2126 ankur.sing 476
            Window.alert("Invalid MRP format/value. Value shoule be greater than zero");
477
            return false;
2068 ankur.sing 478
        }
479
        try {
2126 ankur.sing 480
            if(!sellingPrice.getText().trim().isEmpty()) {
481
            double spValue = Double.parseDouble(sellingPrice.getText().trim());
482
            if(spValue <= 0) {
483
                throw new NumberFormatException("Negative value of Selling price");
484
            }
485
            newItem.setSellingPrice(spValue);
486
            }
487
        } catch(NumberFormatException ex) {
488
            Window.alert("Invalid Selling Price format/value. Value shoule be greater than zero");
489
            return false;
2068 ankur.sing 490
        }
491
        try {
2126 ankur.sing 492
            if(!weight.getText().trim().isEmpty()) {
493
                double wtValue = Double.parseDouble(weight.getText().trim());
494
                if(wtValue <= 0) {
495
                    throw new NumberFormatException("Negative value of Weight");
496
                }
497
                newItem.setWeight(wtValue);
498
            }
2068 ankur.sing 499
        } catch(NumberFormatException ex) {
2126 ankur.sing 500
            Window.alert("Invalid weight format/value. Value shoule be greater than zero");
501
            return false;
2068 ankur.sing 502
        }
2126 ankur.sing 503
        try {
504
            if(!startDate.getTextBox().getText().trim().equals("")) {
505
                newItem.setStartDate(startDate.getValue().getTime());
506
            }
507
        } catch(Exception ex) {
508
            Window.alert("Invalid start date format");
509
            return false;
510
        }
2066 ankur.sing 511
        newItem.setBestDealsText(bestDealsText.getText().trim());
2068 ankur.sing 512
        try {
2126 ankur.sing 513
            if(!bestDealsValue.getText().trim().equals("")) {
514
                double bdValue = Double.parseDouble(bestDealsValue.getText().trim());
515
                if(bdValue < 0) {
516
                    throw new NumberFormatException("Negative value of BestDealValue");
517
                }
518
                newItem.setBestDealsValue(bdValue);
519
            }
2068 ankur.sing 520
        } catch(NumberFormatException ex) {
2126 ankur.sing 521
            Window.alert("Invalid best deal value format");
522
            return false;
2068 ankur.sing 523
        }
524
        try {
2126 ankur.sing 525
            if(!bestSellingRank.getText().trim().equals("")) {
526
                long bsrValue = Long.parseLong(bestSellingRank.getText().trim());
527
                if(bsrValue < 0) {
528
                    throw new NumberFormatException("Negative value of Best Selling Rank");
529
                }
530
                newItem.setBestSellingRank(bsrValue);
531
            }
532
        } catch(NumberFormatException ex) {
533
            Window.alert("Invalid best selling rank format");
534
            return false;
2068 ankur.sing 535
        }
2066 ankur.sing 536
        newItem.setDefaultForEntity(defaultForEntity.getValue());
2252 ankur.sing 537
        newItem.setRisky(risky.getValue());
2119 ankur.sing 538
 
2126 ankur.sing 539
        /*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
540
          Add the instance to map and set the map to the item instance created above.*/
541
        Map<Long, VendorPricings> vendorPrices = new HashMap<Long, VendorPricings>();
2119 ankur.sing 542
        VendorPricings v;
2427 ankur.sing 543
        for(int row = 0; row < tableVendorPrices.getRowCount(); row++) {
2119 ankur.sing 544
            v = new VendorPricings();
2427 ankur.sing 545
            v.setMop(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP)));
546
            v.setDealerPrice(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP)));
547
            v.setTransferPrice(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP)));
548
            v.setVendorId(Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID)));
2126 ankur.sing 549
            vendorPrices.put(v.getVendorId(), v);
2105 ankur.sing 550
            newItem.setMop(v.getMop());
551
            newItem.setDealerPrice(v.getDealerPrice());
552
            newItem.setTransferPrice(v.getTransferPrice());
2066 ankur.sing 553
        }
2126 ankur.sing 554
        newItem.setVendorPricesMap(vendorPrices);
2359 ankur.sing 555
        newItem.setItemStatusDesc(statusDesc.getText().trim());
2427 ankur.sing 556
 
2126 ankur.sing 557
        /*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
558
        Add the instance to map and set the map to the item instance created above.*/
2359 ankur.sing 559
        Map<String, VendorItemMapping> vendorMappings = new HashMap<String, VendorItemMapping>();
2126 ankur.sing 560
        VendorItemMapping vMapping;
2427 ankur.sing 561
        for(int row = 0; row < tableVendorItemKey.getRowCount(); row++) {
2126 ankur.sing 562
            vMapping = new VendorItemMapping();
2427 ankur.sing 563
            vMapping.setItemKey(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY));
564
            vMapping.setVendorId(Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID)));
565
            vendorMappings.put(vMapping.getVendorId() + Item.KEY_SEPARATOR + tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD), vMapping);
2119 ankur.sing 566
        }
2359 ankur.sing 567
        newItem.setVendorKeysMap(vendorMappings);
2119 ankur.sing 568
 
2126 ankur.sing 569
        newItem.setContentCategoryId(item.getContentCategoryId());
570
        newItem.setFeatureId(item.getFeatureId());
571
        newItem.setFeatureDescription(item.getFeatureDescription());
572
        newItem.setAddedOn(item.getAddedOn());
573
        newItem.setRetireDate(item.getRetireDate());
574
        newItem.setUpdatedOn(item.getUpdatedOn());
575
        newItem.setItemStatus(item.getItemStatus());
576
        newItem.setOtherInfo(item.getOtherInfo());
577
        newItem.setAvailability(item.getAvailability());
2119 ankur.sing 578
 
2126 ankur.sing 579
        return true;
2066 ankur.sing 580
    }
581
 
2427 ankur.sing 582
    /**
583
     * This method is called when Edit button is clicked corresponding to a row in 
584
     * vendor prices table. It will pop up a form to edit the vendor prices.
585
     * @param vendorId
586
     * @param row
587
     */
588
    private void editVendorPrices(final long vendorId, final int row) {
589
        String mop = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP);
590
        String dp = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP);
591
        String tp = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP);
2119 ankur.sing 592
        VendorPricesDialog pricesDialog = new VendorPricesDialog(mop, dp, tp);
2105 ankur.sing 593
        pricesDialog.updateButton.setText("Update");
2119 ankur.sing 594
        pricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
2066 ankur.sing 595
            @Override
2119 ankur.sing 596
            public boolean onUpdate(double mop, double dp, double tp, long vendorId) {
597
                if(!validateVendorPrices(mop, dp, tp)) {
2105 ankur.sing 598
                    return false;
599
                }
2427 ankur.sing 600
                tableVendorPrices.setText(row, TABLE_INDEX_PRICING_MOP, mop + "");
601
                tableVendorPrices.setText(row, TABLE_INDEX_PRICING_DP, dp + "");
602
                tableVendorPrices.setText(row, TABLE_INDEX_PRICING_TP, tp + "");
2105 ankur.sing 603
                return true;
2066 ankur.sing 604
            }
605
        });
606
        pricesDialog.show();
607
    }
2119 ankur.sing 608
 
2427 ankur.sing 609
    /**
610
     * This method is called when Edit button is clicked corresponding to a row in 
611
     * vendor item key table. It will pop up a form to edit the item key.
612
     * @param vendorId
613
     * @param row
614
     */
615
    private void editVendorKey(final long vendorId, final int row) {
616
        String key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY);
2126 ankur.sing 617
        VendorMappingDialog mappingDialog = new VendorMappingDialog(productGroup.getText().trim(), brand.getText().trim(), 
618
                modelNumber.getText().trim(), color.getText().trim(), key);
2119 ankur.sing 619
        mappingDialog.updateButton.setText("Update");
620
        mappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {
621
            @Override
622
            public boolean onUpdate(String itemKey, long vendorId) {
623
                if(itemKey == null || itemKey.equals("")) {
624
                    Window.alert("Item key cannot be empty.");
625
                    return false;
626
                }
2427 ankur.sing 627
                tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_ITEM_KEY, itemKey);
2119 ankur.sing 628
                return true;
629
            }
630
        });
631
        mappingDialog.show();
632
    }
2066 ankur.sing 633
 
2427 ankur.sing 634
    /**
635
     * This method compares all the editable UI fields values with attributes in the item object.
636
     * If they differ, the attribute name is appended to a string.
637
     * @return String showing attributes which are changed by the user for confirmation.
638
     *      <br>Empty string if nothing is changed.
639
     */
2252 ankur.sing 640
    private String isItemChanged() {
641
        StringBuilder sb = new StringBuilder("");
2489 ankur.sing 642
        if(!checkParameterIfEqual(productGroup.getText().trim(), item.getProductGroup())) {
2387 ankur.sing 643
            sb.append("\n-Product Group");
2066 ankur.sing 644
        }
2489 ankur.sing 645
        if(!checkParameterIfEqual(brand.getText().trim(), item.getBrand())) {
2387 ankur.sing 646
            sb.append("\n-Brand");
2066 ankur.sing 647
        }
2489 ankur.sing 648
        if(!checkParameterIfEqual(modelNumber.getText().trim(), item.getModelNumber())) {
2387 ankur.sing 649
            sb.append("\n-Model Number");
2066 ankur.sing 650
        }
2489 ankur.sing 651
        if(!checkParameterIfEqual(modelName.getText().trim(), item.getModelName())) {
2387 ankur.sing 652
            sb.append("\n-Model Name");
2066 ankur.sing 653
        }
2489 ankur.sing 654
        if(!checkParameterIfEqual(color.getText().trim(), item.getColor())) {
2387 ankur.sing 655
            sb.append("\n-Color");
2066 ankur.sing 656
        }
2489 ankur.sing 657
        if(!checkParameterIfEqual(statusDesc.getText().trim(), item.getItemStatusDesc())) {
2387 ankur.sing 658
            sb.append("\n-Status Description");
2359 ankur.sing 659
        }
2489 ankur.sing 660
        if(!checkParameterIfEqual(comments.getText().trim(), item.getComments())) {
2387 ankur.sing 661
            sb.append("\n-Comments");
2066 ankur.sing 662
        }
2489 ankur.sing 663
        if(!checkParameterIfEqual(newItem.getMrp(), item.getMrp())) {
2387 ankur.sing 664
            sb.append("\n-MRP");
2066 ankur.sing 665
        }
2489 ankur.sing 666
        if(!checkParameterIfEqual(newItem.getSellingPrice(), item.getSellingPrice())) {
2387 ankur.sing 667
            sb.append("\n-Selling Price");
2027 ankur.sing 668
        }
2489 ankur.sing 669
        if(!checkParameterIfEqual(newItem.getWeight(), item.getWeight())) {
2387 ankur.sing 670
            sb.append("\n-Weight");
2027 ankur.sing 671
        }
2489 ankur.sing 672
        if(!checkParameterIfEqual(bestDealsText.getText().trim(), item.getBestDealsText())) {
2387 ankur.sing 673
            sb.append("\n-Best Deal Text");
2066 ankur.sing 674
        }
2489 ankur.sing 675
        if(!checkParameterIfEqual(newItem.getBestDealsValue(), item.getBestDealsValue())) {
2387 ankur.sing 676
            sb.append("\n-Best Deal Value");
2027 ankur.sing 677
        }
2489 ankur.sing 678
        if(!checkParameterIfEqual(newItem.getBestSellingRank(), item.getBestSellingRank())) {
2387 ankur.sing 679
            sb.append("\n-Best Selling Rank");
2066 ankur.sing 680
        }
681
        if(item.isDefaultForEntity() != defaultForEntity.getValue()) {
2387 ankur.sing 682
            sb.append("\n-Default For Entity Flag");
2066 ankur.sing 683
        }
2252 ankur.sing 684
        if(item.isRisky() != risky.getValue()) {
2387 ankur.sing 685
            sb.append("\n-Risky Flag");
2252 ankur.sing 686
        }
2489 ankur.sing 687
        if(!checkParameterIfEqual(newItem.getStartDate(), item.getStartDate())) {
2387 ankur.sing 688
            sb.append("\n-Start Date");
2068 ankur.sing 689
        }
2126 ankur.sing 690
        VendorPricings vendorPricings;
2066 ankur.sing 691
        long vendorId;
2427 ankur.sing 692
        for(int row = 0; row < tableVendorPrices.getRowCount(); row++) {
693
            vendorId = Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID));
2126 ankur.sing 694
            vendorPricings = item.getVendorPricesMap().get(vendorId);
2359 ankur.sing 695
            if(vendorPricings == null) {
2387 ankur.sing 696
                sb.append("\n-Vendor Prices (Vendor:" + vendorId + ")");
2359 ankur.sing 697
                continue;
698
            }
2427 ankur.sing 699
            if(vendorPricings.getMop() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP))) {
2387 ankur.sing 700
                sb.append("\n-MOP (Vendor:" + vendorId + ")");
2066 ankur.sing 701
            }
2427 ankur.sing 702
            if(vendorPricings.getDealerPrice() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP))) {
2387 ankur.sing 703
                sb.append("\n-Dealer Price (Vendor:" + vendorId + ")");
2066 ankur.sing 704
            }
2427 ankur.sing 705
            if(vendorPricings.getTransferPrice() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP))) {
2387 ankur.sing 706
                sb.append("\n-Transfer Price (Vendor:" + vendorId + ")");
2066 ankur.sing 707
            }
708
        }
2387 ankur.sing 709
 
710
        VendorItemMapping mapping;
711
        String old_key, new_key;
2427 ankur.sing 712
        for(int row = 0; row < tableVendorItemKey.getRowCount(); row++) {
713
            vendorId = Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID));
714
            old_key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD);
715
            new_key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY);
2387 ankur.sing 716
            mapping = item.getVendorKeysMap().get(vendorId + Item.KEY_SEPARATOR + old_key);
717
            if(mapping == null || !old_key.equals(new_key)) {
718
                sb.append("\n-Vendor Key (Vendor:" + vendorId + ",Key: = " + old_key + ")");
719
                continue;
720
            }
721
        }
2252 ankur.sing 722
        return sb.toString();
2066 ankur.sing 723
    }
724
 
725
    private boolean validatePrices() {
726
        if(newItem.getSellingPrice() > newItem.getMrp()) {
727
            Window.alert("Selling price cannot be more than MRP");
728
            return false;
729
        }
2119 ankur.sing 730
        for(VendorPricings v : newItem.getVendorPricesMap().values()) {
2105 ankur.sing 731
            if(newItem.getMrp() < v.getMop()) {
732
                Window.alert("MRP cannot be less than MOP. Vendor: " + v.getVendorId());
2066 ankur.sing 733
                return false;
734
            }
2105 ankur.sing 735
            if(v.getTransferPrice() > v.getMop()) {
736
                Window.alert("Transfer Price cannot be more than MOP. Vendor: " + v.getVendorId());
2066 ankur.sing 737
                return false;
738
            }
739
        }
740
        return true;
741
    }
2105 ankur.sing 742
 
2119 ankur.sing 743
    private boolean validateVendorPrices(double mop, double dp, double tp) {
2489 ankur.sing 744
        if(item.getMrp() != null && item.getMrp() < mop) {
2105 ankur.sing 745
            Window.alert("MOP cannot be more than MRP.");
746
            return false;
1992 ankur.sing 747
        }
2105 ankur.sing 748
        if(tp > mop) {
749
            Window.alert("Transfer Price cannot be more than MOP.");
750
            return false;
1992 ankur.sing 751
        }
2105 ankur.sing 752
        return true;
1992 ankur.sing 753
    }
2105 ankur.sing 754
 
755
    public long getItemId() {
756
        return item == null ? 0 : item.getId();
757
    }
758
 
759
    public Item getItem() {
760
        return item;
761
    }
762
 
2427 ankur.sing 763
    /**
764
     * This method is used while adding vendor prices to ensure that there is only one row in the table for a vendor.
765
     * @param vendorId
766
     * @return true if parameter vendor Id is already added to vendor prices table.
767
     *      <br>else false
768
     */
2105 ankur.sing 769
    private boolean vendorExists(long vendorId) {
770
        long id;
2427 ankur.sing 771
        for(int i = 0; i < tableVendorPrices.getRowCount(); i++) {
772
            id = Long.parseLong(tableVendorPrices.getText(i, TABLE_INDEX_PRICING_VENDORID));
2105 ankur.sing 773
            if(vendorId == id) {
774
                return false;
775
            }
1992 ankur.sing 776
        }
2105 ankur.sing 777
        return true;
1992 ankur.sing 778
    }
2387 ankur.sing 779
 
2427 ankur.sing 780
    /**
781
     * This method is used to check if any of the string item attributes is changed by the user.
2489 ankur.sing 782
     * @param o1
783
     * @param o2
2427 ankur.sing 784
     * @return true if two strings are equal
785
     *      <br>true if one of them is null and another is empty.
786
     *      <br>false otherwise
787
     */
2489 ankur.sing 788
    private boolean checkParameterIfEqual(Object o1, Object o2) {
789
        if(o1 == o2) {
2387 ankur.sing 790
            return true;
791
        }
2489 ankur.sing 792
        if(o1 != null && o2 != null && o1.equals(o2)) {
2387 ankur.sing 793
            return true;
794
        }
2489 ankur.sing 795
        if((o1 == null && o2.equals("")) || (o2 == null && o1.equals(""))) {
2387 ankur.sing 796
            return true;
797
        }
798
        return false;
799
    }
2489 ankur.sing 800
 
801
    public void setCatalogDashboardPanel(CatalogDashboard catalogDashboardPanel) {
802
        this.catalogDashboardPanel = catalogDashboardPanel;
803
    }
1961 ankur.sing 804
}