Subversion Repositories SmartDukaan

Rev

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

Rev 2119 Rev 2126
Line 22... Line 22...
22
 
22
 
23
public class ItemList extends ResizeComposite{
23
public class ItemList extends ResizeComposite{
24
 
24
 
25
    public static final int VISIBLE_ITEMS_COUNT = 10;
25
    public static final int VISIBLE_ITEMS_COUNT = 10;
26
    
26
    
27
    public interface Listener {
-
 
28
        void onItemSelected(long itemId);
-
 
29
      }
-
 
30
    
-
 
31
    //Map<Long, Item> itemsMap = new HashMap<Long, Item>();
-
 
32
    
-
 
33
    private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
27
    private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
34
    
28
    
35
    interface ItemListUiBinder extends UiBinder<Widget, ItemList> { }
29
    interface ItemListUiBinder extends UiBinder<Widget, ItemList> { }
36
    private static final ItemListUiBinder uiBinder = GWT.create(ItemListUiBinder.class);
30
    private static final ItemListUiBinder uiBinder = GWT.create(ItemListUiBinder.class);
37
    
31
    
Line 41... Line 35...
41
    }
35
    }
42
 
36
 
43
    @UiField FlexTable header;
37
    @UiField FlexTable header;
44
    @UiField FlexTable itemDescriptionTable;
38
    @UiField FlexTable itemDescriptionTable;
45
    @UiField SelectionStyle selectionStyle;
39
    @UiField SelectionStyle selectionStyle;
46
    private Listener listener;
-
 
47
    private int selectedRow = -1;
40
    private int selectedRow = -1;
48
    
41
    
49
    
42
    
50
    private List<Item> items;
43
    private List<Item> items;
51
    
44
    
-
 
45
    private ItemDetails itemDetails;
-
 
46
    
52
    public ItemList() {
47
    public ItemList() {
53
        initWidget(uiBinder.createAndBindUi(this));
48
        initWidget(uiBinder.createAndBindUi(this));
54
        initHeader();
49
        initHeader();
55
        initItemList();
50
        initItemList();
56
    }
51
    }
57
    
52
    
58
    private void initItemList() {
53
    private void initItemList() {
59
        loadBestDeals();
54
        loadBestSellers();
-
 
55
        
60
        //loadDummyItems();
56
        //loadDummyItems();
61
        //updateItemDescriptionTable(items);
57
        //updateItemDescriptionTable(items);
62
    }
58
    }
63
    
59
    
64
    private void initHeader(){
60
    private void initHeader(){
Line 103... Line 99...
103
            itemDescriptionTable.setText(i, col++, item.getContentCategory()+"");
99
            itemDescriptionTable.setText(i, col++, item.getContentCategory()+"");
104
            i++;
100
            i++;
105
        }
101
        }
106
    }
102
    }
107
    
103
    
108
    public void setListener(Listener listener) {
-
 
109
        this.listener = listener;
-
 
110
      }
-
 
111
    
-
 
112
    @UiHandler("itemDescriptionTable")
104
    @UiHandler("itemDescriptionTable")
113
    void onClick(ClickEvent event) {
105
    void onClick(ClickEvent event) {
114
 
106
 
115
        Cell cell = itemDescriptionTable.getCellForEvent(event);
107
        Cell cell = itemDescriptionTable.getCellForEvent(event);
116
        int newRowIndex = cell.getRowIndex();
108
        int newRowIndex = cell.getRowIndex();
117
        selectRow(newRowIndex);
109
        selectRow(newRowIndex);
118
        String itemId = itemDescriptionTable.getText(newRowIndex, 0);
110
        String itemId = itemDescriptionTable.getText(newRowIndex, 0);
-
 
111
        
119
        listener.onItemSelected(Long.parseLong(itemId));
112
        catalogService.getItem(Long.parseLong(itemId), new AsyncCallback<Item>() {
-
 
113
            @Override
-
 
114
            public void onSuccess(Item result) {
-
 
115
                itemDetails.setItemDetails(result);
-
 
116
            }
-
 
117
            @Override
-
 
118
            public void onFailure(Throwable caught) {
-
 
119
                Window.alert("Unable to fetch item details.");
-
 
120
            }
-
 
121
        });
120
    }
122
    }
121
 
123
 
122
    private void selectRow(int row) {
124
    private void selectRow(int row) {
123
        String style = selectionStyle.selectedRow();
125
        String style = selectionStyle.selectedRow();
124
        if(selectedRow != -1){
126
        if(selectedRow != -1){
Line 129... Line 131...
129
        selectedRow = row;
131
        selectedRow = row;
130
    }
132
    }
131
    
133
    
132
    private void loadDummyItems() {
134
    private void loadDummyItems() {
133
        
135
        
134
        Item i = new Item(1, "Handset", "Spice", "mi310", "phone", "White", "Business Phone", "comments", 1, 1, 
136
        Item i = new Item(1, "Handset", "Spice", "mi310", "phone", "White", "Business Phone",1, "comments", 1, 1, 
135
                "", 3000.50, 3000.00, 3000, 3000, 12, 12345, 12345, 12345, 12345, "status", null, "best", 2990, 1, true, null, null, null);
137
                "", 3000.50, 3000.00, 3000, 3000, 12, 12345, 12345, 12345, 12345, "status", 1,  null, "best", 2990, 1, true, null, null, null);
136
        List<Item> items = new ArrayList<Item>();
138
        List<Item> items = new ArrayList<Item>();
137
        items.add(i);
139
        items.add(i);
138
        this.items = items;
140
        this.items = items;
139
        //itemsMap.put(i.getId(), i);
141
        //itemsMap.put(i.getId(), i);
140
        
142
        
141
    }
143
    }
142
    
144
    
143
    public void loadAllItems() {
145
    public void loadAllItems() {
144
        catalogService.getAllItems(new AsyncCallback<List<Item>>() {
146
        catalogService.getAllItems(new AsyncCallback<List<Item>>() {
145
            public void onFailure(Throwable caught) {
147
            public void onFailure(Throwable caught) {
-
 
148
                caught.printStackTrace();
146
                Window.alert("Could not get all items...");
149
                Window.alert("Could not get all items...");
147
            }
150
            }
148
            public void onSuccess(List<Item> result) {
151
            public void onSuccess(List<Item> result) {
149
                updateItemDescriptionTable(result);
152
                updateItemDescriptionTable(result);
150
                //setItems(result);
153
                //setItems(result);
Line 153... Line 156...
153
    }
156
    }
154
    
157
    
155
    public void loadAllActiveItems() {
158
    public void loadAllActiveItems() {
156
        catalogService.getAllActiveItems(new AsyncCallback<List<Item>>() {
159
        catalogService.getAllActiveItems(new AsyncCallback<List<Item>>() {
157
            public void onFailure(Throwable caught) {
160
            public void onFailure(Throwable caught) {
-
 
161
                caught.printStackTrace();
158
                Window.alert("Could not get all active items...");
162
                Window.alert("Could not get all active items...");
159
            }
163
            }
160
            public void onSuccess(List<Item> result) {
164
            public void onSuccess(List<Item> result) {
161
                updateItemDescriptionTable(result);
165
                updateItemDescriptionTable(result);
162
                //setItems(result);
166
                //setItems(result);
Line 165... Line 169...
165
    }
169
    }
166
    
170
    
167
    public void loadBestDeals() {
171
    public void loadBestDeals() {
168
        catalogService.getBestDeals(new AsyncCallback<List<Item>>() {
172
        catalogService.getBestDeals(new AsyncCallback<List<Item>>() {
169
            public void onFailure(Throwable caught) {
173
            public void onFailure(Throwable caught) {
-
 
174
                caught.printStackTrace();
170
                Window.alert("Could not load best deals.");
175
                Window.alert("Could not load best deals.");
171
            }
176
            }
172
            public void onSuccess(List<Item> result) {
177
            public void onSuccess(List<Item> result) {
173
                updateItemDescriptionTable(result);
178
                updateItemDescriptionTable(result);
174
                //setItems(result);
179
                //setItems(result);
Line 177... Line 182...
177
    }
182
    }
178
    
183
    
179
    public void loadLatestArrivals() {
184
    public void loadLatestArrivals() {
180
        catalogService.getLatestArrivals(new AsyncCallback<List<Item>>() {
185
        catalogService.getLatestArrivals(new AsyncCallback<List<Item>>() {
181
            public void onFailure(Throwable caught) {
186
            public void onFailure(Throwable caught) {
-
 
187
                caught.printStackTrace();
182
                Window.alert("Could not load latest arrivals.");
188
                Window.alert("Could not load latest arrivals.");
183
            }
189
            }
184
            public void onSuccess(List<Item> result) {
190
            public void onSuccess(List<Item> result) {
185
                updateItemDescriptionTable(result);
191
                updateItemDescriptionTable(result);
186
                //setItems(result);
192
                //setItems(result);
Line 189... Line 195...
189
    }
195
    }
190
    
196
    
191
    public void loadBestSellers() {
197
    public void loadBestSellers() {
192
        catalogService.getBestSellers(new AsyncCallback<List<Item>>() {
198
        catalogService.getBestSellers(new AsyncCallback<List<Item>>() {
193
            public void onFailure(Throwable caught) {
199
            public void onFailure(Throwable caught) {
-
 
200
                caught.printStackTrace();
194
                Window.alert("Could not load best sellers.");
201
                Window.alert("Could not load best sellers.");
195
            }
202
            }
196
            public void onSuccess(List<Item> result) {
203
            public void onSuccess(List<Item> result) {
197
                updateItemDescriptionTable(result);
204
                updateItemDescriptionTable(result);
198
                //setItems(result);
205
                //setItems(result);
199
            }
206
            }
200
        });
207
        });
201
    }
208
    }
-
 
209
 
-
 
210
    public void setItemDetails(ItemDetails itemDetails) {
-
 
211
        this.itemDetails = itemDetails;
-
 
212
    }
202
    
213
    
203
}
214
}