Subversion Repositories SmartDukaan

Rev

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