Subversion Repositories SmartDukaan

Rev

Rev 2359 | Rev 2489 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2359 Rev 2427
Line 24... Line 24...
24
import com.google.gwt.user.client.ui.ListBox;
24
import com.google.gwt.user.client.ui.ListBox;
25
import com.google.gwt.user.client.ui.TextBox;
25
import com.google.gwt.user.client.ui.TextBox;
26
import com.google.gwt.user.client.ui.Widget;
26
import com.google.gwt.user.client.ui.Widget;
27
import com.google.gwt.user.datepicker.client.DateBox;
27
import com.google.gwt.user.datepicker.client.DateBox;
28
 
28
 
-
 
29
/**
-
 
30
 * ItemForm is a DialogBox which is created on the click of Add Item button in ItemActions.
-
 
31
 * This contains UI fields to fill up item attributes. It also contains tables for adding
-
 
32
 * vendor prices and vendor mapping keys.
-
 
33
 *
-
 
34
 */
29
public class ItemForm extends DialogBox {
35
public class ItemForm extends DialogBox {
30
 
36
 
31
    interface ItemFormUiBinder extends UiBinder<Widget, ItemForm> {}
37
    interface ItemFormUiBinder extends UiBinder<Widget, ItemForm> {}
32
    private static ItemFormUiBinder uiBinder = GWT.create(ItemFormUiBinder.class);
38
    private static ItemFormUiBinder uiBinder = GWT.create(ItemFormUiBinder.class);
33
    
39
    
Line 53... Line 59...
53
    @UiField FlexTable headerVendorM, vendorTableM;
59
    @UiField FlexTable headerVendorM, vendorTableM;
54
    
60
    
55
    public ItemForm(){
61
    public ItemForm(){
56
        setText("Add New Item");
62
        setText("Add New Item");
57
        setWidget(uiBinder.createAndBindUi(this));
63
        setWidget(uiBinder.createAndBindUi(this));
58
        initMappingHeader();
64
        initVendorKeysHeader();
59
        initPricingHeader();
65
        initVendorPricesHeader();
60
        vendorCategory.addItem(HANDSETS);
66
        vendorCategory.addItem(HANDSETS);
61
        vendorCategory.addItem(ACCESSORIES);
67
        vendorCategory.addItem(ACCESSORIES);
62
        productGroup.setText(HANDSETS);
68
        productGroup.setText(HANDSETS);
63
    }
69
    }
64
    
70
    
-
 
71
    /**
-
 
72
     * initialises vendor item key table header. Creates an Add button and
-
 
73
     * adds click event listener to it to create and pop up a dialog for adding 
65
    private void initMappingHeader(){
74
     * a new vendor item key. 
-
 
75
     */
66
        // Initialize the header.
76
    private void initVendorKeysHeader(){
67
        headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
77
        headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
68
        headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
78
        headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
69
        headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY, "400px");
79
        headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY, "400px");
70
        headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY + 1, "50px");
80
        headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY + 1, "50px");
71
 
81
 
Line 111... Line 121...
111
                vendorMappingDialog.show();
121
                vendorMappingDialog.show();
112
            }
122
            }
113
        });
123
        });
114
    }
124
    }
115
    
125
    
-
 
126
    /**
-
 
127
     * initialises vendor prices table header. Creates an Add button and
-
 
128
     * adds click event listener to it to create and pop up a dialog for adding 
116
    private void initPricingHeader(){
129
     * a prices for a new vendor 
-
 
130
     */
117
        // Initialize the header.
131
    private void initVendorPricesHeader(){
118
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
132
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
119
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
133
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
120
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_MOP, "128px");
134
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_MOP, "128px");
121
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_DP, "128px");
135
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_DP, "128px");
122
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_TP, "128px");
136
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_TP, "128px");
Line 180... Line 194...
180
    }
194
    }
181
 
195
 
182
    @UiHandler("addButton")
196
    @UiHandler("addButton")
183
    /**
197
    /**
184
     * On add button click a new Item instance is created and all the information from UI fields is dumped in this item instance.
198
     * On add button click a new Item instance is created and all the information from UI fields is dumped in this item instance.
185
     * This item instance is then passed to service implementation.
199
     * This item instance is then passed to the service to be added to the database.
186
     */
200
     */
187
    void addItem(ClickEvent event) {
201
    void addItem(ClickEvent event) {
188
        //TODO: validate UI fields
202
        //TODO: validate UI fields
189
        catalogService.checkSimilarItem(productGroup.getText().trim(), brand.getText().trim(),
203
        catalogService.checkSimilarItem(productGroup.getText().trim(), brand.getText().trim(),
190
                modelNumber.getText().trim(), color.getText().trim(), new AsyncCallback<Long>() {
204
                modelNumber.getText().trim(), color.getText().trim(), new AsyncCallback<Long>() {
Line 230... Line 244...
230
            Window.alert("Invalid MRP format/value. Value shoule be greater than zero");
244
            Window.alert("Invalid MRP format/value. Value shoule be greater than zero");
231
            return;
245
            return;
232
        }
246
        }
233
        try {
247
        try {
234
            if(!sellingPrice.getText().trim().isEmpty()) {
248
            if(!sellingPrice.getText().trim().isEmpty()) {
235
            double spValue = Double.parseDouble(sellingPrice.getText().trim());
249
                double spValue = Double.parseDouble(sellingPrice.getText().trim());
236
            if(spValue <= 0) {
250
                if(spValue <= 0) {
237
                throw new NumberFormatException("Negative value of Selling price");
251
                    throw new NumberFormatException("Negative value of Selling price");
238
            }
252
                }
239
            item.setSellingPrice(spValue);
253
                item.setSellingPrice(spValue);
240
            } else {
254
            } else {
241
                item.setSellingPrice(-1);
255
                item.setSellingPrice(-1);
242
            }
256
            }
243
        } catch(NumberFormatException ex) {
257
        } catch(NumberFormatException ex) {
244
            Window.alert("Invalid Selling Price format/value. Value shoule be greater than zero");
258
            Window.alert("Invalid Selling Price format/value. Value shoule be greater than zero");
Line 330... Line 344...
330
        
344
        
331
        if(!Utils.validateItem(item)) {
345
        if(!Utils.validateItem(item)) {
332
            return;
346
            return;
333
        }
347
        }
334
        
348
        
335
        /*Service method to add item to DB. */
349
        /*Service method to add item. */
336
        catalogService.addItem(item, new AsyncCallback<Long>() {
350
        catalogService.addItem(item, new AsyncCallback<Long>() {
337
            @Override
351
            @Override
338
            public void onSuccess(Long result) {
352
            public void onSuccess(Long result) {
339
                if(result == null || result == 0) {
353
                if(result == null || result == 0) {
340
                    Window.alert("Error while adding item");
354
                    Window.alert("Error while adding item");
Line 343... Line 357...
343
                Window.alert("Item added successfully. Id = " + result);
357
                Window.alert("Item added successfully. Id = " + result);
344
                hide();
358
                hide();
345
            }
359
            }
346
            @Override
360
            @Override
347
            public void onFailure(Throwable caught) {
361
            public void onFailure(Throwable caught) {
-
 
362
                caught.printStackTrace();
348
                Window.alert("Error while adding item");
363
                Window.alert("Error while adding item");
349
            }
364
            }
350
        });
365
        });
351
    }
366
    }
352
    
367
    
Line 361... Line 376...
361
    
376
    
362
    @UiHandler("cancelButton")
377
    @UiHandler("cancelButton")
363
    void closeForm(ClickEvent event) {
378
    void closeForm(ClickEvent event) {
364
        this.hide();
379
        this.hide();
365
    }
380
    }
366
    
-
 
367
    /**
-
 
368
     * This will pop up a dialog box for adding vendor details. 
-
 
369
     * @param event
-
 
370
     */
-
 
371
    /*@UiHandler("addVendorPrices")
-
 
372
    void addVendorPrices(ClickEvent event) {
-
 
373
        VendorPricesDialog pricesDialog = new VendorPricesDialog();
-
 
374
        pricesDialog.updateButton.setText("Add");
-
 
375
        pricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
-
 
376
            @Override
-
 
377
            public boolean onUpdate(double mop, double dp, double tp, long vendorId) {
-
 
378
                if(!vendorExists(vendorId)) {
-
 
379
                    Window.alert("Vendor already exists");
-
 
380
                    return false;
-
 
381
                }   
-
 
382
                if(!validateVendorPrices(mop, dp, tp)) {
-
 
383
                    return false;
-
 
384
                }
-
 
385
                vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
-
 
386
                vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
-
 
387
                vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_MOP, "128px");
-
 
388
                vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_DP, "128px");
-
 
389
                vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_TP, "128px");
-
 
390
                
-
 
391
                int row = vendorTable.getRowCount();
-
 
392
                vendorTable.setText(row, TABLE_INDEX_VENDORID, vendorId+"");
-
 
393
                vendorTable.setText(row, TABLE_INDEX_VENDOR_DESC, Utils.getVendorDesc(vendorId));
-
 
394
                vendorTable.setText(row, TABLE_INDEX_MOP, mop + "");
-
 
395
                vendorTable.setText(row, TABLE_INDEX_DP, dp + "");
-
 
396
                vendorTable.setText(row, TABLE_INDEX_TP, tp + "");
-
 
397
                Button removeButton = new Button("Remove");
-
 
398
                vendorTable.setWidget(row, TABLE_INDEX_TP + 1, removeButton);
-
 
399
                removeButton.addClickHandler(new ClickHandler() {
-
 
400
                    @Override
-
 
401
                    public void onClick(ClickEvent event) {
-
 
402
                        Cell cell = vendorTable.getCellForEvent(event);
-
 
403
                        int row = cell.getRowIndex();
-
 
404
                        vendorTable.removeRow(row);
-
 
405
                    }
-
 
406
                });
-
 
407
                return true;
-
 
408
            }
-
 
409
        });
-
 
410
        pricesDialog.center();
-
 
411
        pricesDialog.show();
-
 
412
    }*/
-
 
413
    
381
 
414
    /**
382
    /**
415
     * Checks if vendor details already exists corresponding to the vendor Id parameter. 
383
     * Checks if vendor details already exists corresponding to the vendor Id parameter. 
416
     */
384
     */
417
    private boolean vendorExists(long vendorId) {
385
    private boolean vendorExists(long vendorId) {
418
        long id;
386
        long id;