| 2105 |
ankur.sing |
1 |
|
|
|
2 |
package in.shop2020.catalog.dashboard.client;
|
|
|
3 |
|
|
|
4 |
import in.shop2020.catalog.dashboard.shared.Utils;
|
|
|
5 |
|
|
|
6 |
import java.util.Map.Entry;
|
|
|
7 |
|
|
|
8 |
import com.google.gwt.core.client.GWT;
|
|
|
9 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
10 |
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
11 |
import com.google.gwt.uibinder.client.UiField;
|
|
|
12 |
import com.google.gwt.uibinder.client.UiHandler;
|
|
|
13 |
import com.google.gwt.user.client.Window;
|
|
|
14 |
import com.google.gwt.user.client.ui.Button;
|
|
|
15 |
import com.google.gwt.user.client.ui.DialogBox;
|
|
|
16 |
import com.google.gwt.user.client.ui.ListBox;
|
|
|
17 |
import com.google.gwt.user.client.ui.TextBox;
|
|
|
18 |
import com.google.gwt.user.client.ui.Widget;
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
public class VendorMappingDialog extends DialogBox {
|
|
|
22 |
|
|
|
23 |
interface Binder extends UiBinder<Widget, VendorMappingDialog> { }
|
|
|
24 |
private static final Binder binder = GWT.create(Binder.class);
|
|
|
25 |
|
|
|
26 |
public interface VendorMappingUpdateListener{
|
|
|
27 |
boolean onUpdate(String itemKey, long vendorId);
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
private VendorMappingUpdateListener vendorMappingUpdateListener;
|
|
|
31 |
|
|
|
32 |
@UiField Button closeButton, updateButton;
|
|
|
33 |
@UiField TextBox itemKey;
|
|
|
34 |
@UiField ListBox vendor;
|
|
|
35 |
|
|
|
36 |
public VendorMappingDialog() {
|
|
|
37 |
setText("Vendor Item Mapping");
|
|
|
38 |
setWidget(binder.createAndBindUi(this));
|
|
|
39 |
setAnimationEnabled(true);
|
|
|
40 |
//setGlassEnabled(true);
|
|
|
41 |
center();
|
|
|
42 |
for(Entry<Long, String> e : Utils.getAllVendors().entrySet()){
|
|
|
43 |
vendor.addItem(e.getValue());
|
|
|
44 |
}
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
public VendorMappingDialog(String itemKey) {
|
|
|
48 |
this();
|
|
|
49 |
setKey(itemKey);
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
public void setKey(String itemKey) {
|
|
|
53 |
this.itemKey.setText(itemKey);
|
|
|
54 |
this.vendor.setEnabled(false);
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
public void setVendorMappingUpdateListener(VendorMappingUpdateListener vMappingUpdateListener) {
|
|
|
58 |
this.vendorMappingUpdateListener = vMappingUpdateListener;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
@UiHandler("closeButton")
|
|
|
62 |
void onCloseClicked(ClickEvent event) {
|
|
|
63 |
hide();
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
@UiHandler("updateButton")
|
|
|
67 |
void onEditClicked(ClickEvent event) {
|
|
|
68 |
long vendorId;
|
|
|
69 |
String key;
|
|
|
70 |
vendorId = Utils.getVendorId(this.vendor.getItemText(this.vendor.getSelectedIndex()));
|
|
|
71 |
key = itemKey.getText().trim();
|
|
|
72 |
if(key.isEmpty()) {
|
|
|
73 |
Window.alert("Item key cannot be empty");
|
|
|
74 |
return;
|
|
|
75 |
}
|
|
|
76 |
if(vendorMappingUpdateListener.onUpdate(key, vendorId)) {
|
|
|
77 |
hide();
|
|
|
78 |
}
|
|
|
79 |
}
|
|
|
80 |
}
|