| Line 3... |
Line 3... |
| 3 |
import in.shop2020.catalog.dashboard.shared.Item;
|
3 |
import in.shop2020.catalog.dashboard.shared.Item;
|
| 4 |
|
4 |
|
| 5 |
import java.util.List;
|
5 |
import java.util.List;
|
| 6 |
|
6 |
|
| 7 |
import com.google.gwt.core.client.GWT;
|
7 |
import com.google.gwt.core.client.GWT;
|
| 8 |
import com.google.gwt.event.dom.client.ClickEvent;
|
8 |
import com.google.gwt.dom.client.Style.Unit;
|
| 9 |
import com.google.gwt.resources.client.CssResource;
|
9 |
import com.google.gwt.resources.client.CssResource;
|
| 10 |
import com.google.gwt.uibinder.client.UiBinder;
|
10 |
import com.google.gwt.uibinder.client.UiBinder;
|
| 11 |
import com.google.gwt.uibinder.client.UiField;
|
11 |
import com.google.gwt.uibinder.client.UiField;
|
| - |
|
12 |
import com.google.gwt.user.cellview.client.CellTable;
|
| 12 |
import com.google.gwt.uibinder.client.UiHandler;
|
13 |
import com.google.gwt.user.cellview.client.SimplePager;
|
| - |
|
14 |
import com.google.gwt.user.cellview.client.TextColumn;
|
| 13 |
import com.google.gwt.user.client.Window;
|
15 |
import com.google.gwt.user.client.Window;
|
| 14 |
import com.google.gwt.user.client.rpc.AsyncCallback;
|
16 |
import com.google.gwt.user.client.rpc.AsyncCallback;
|
| 15 |
import com.google.gwt.user.client.ui.FlexTable;
|
- |
|
| 16 |
import com.google.gwt.user.client.ui.HTMLTable.Cell;
|
- |
|
| 17 |
import com.google.gwt.user.client.ui.Label;
|
17 |
import com.google.gwt.user.client.ui.Label;
|
| 18 |
import com.google.gwt.user.client.ui.ResizeComposite;
|
18 |
import com.google.gwt.user.client.ui.ResizeComposite;
|
| 19 |
import com.google.gwt.user.client.ui.Widget;
|
19 |
import com.google.gwt.user.client.ui.Widget;
|
| - |
|
20 |
import com.google.gwt.view.client.ListDataProvider;
|
| - |
|
21 |
import com.google.gwt.view.client.SelectionChangeEvent;
|
| - |
|
22 |
import com.google.gwt.view.client.SingleSelectionModel;
|
| 20 |
|
23 |
|
| 21 |
/**
|
24 |
/**
|
| 22 |
* List of items. List contains item Id, product group, brand, model number, model name, color and category
|
25 |
* List of items. List contains item Id, product group, brand, model number, model name, color and category
|
| 23 |
* Dashboard user can select an item in this list and its details are shown in ItemDetails widget.
|
26 |
* Dashboard user can select an item in this list and its details are shown in ItemDetails widget.
|
| 24 |
*
|
27 |
*
|
| 25 |
*/
|
28 |
*/
|
| 26 |
public class ItemList extends ResizeComposite{
|
29 |
public class ItemList extends ResizeComposite{
|
| 27 |
|
30 |
|
| 28 |
private static final int INDEX_ID = 0,
|
- |
|
| 29 |
INDEX_PRODUCT_GROUP = 1,
|
- |
|
| 30 |
INDEX_BRAND = 2,
|
- |
|
| 31 |
INDEX_MODEL_NUMBER = 3,
|
- |
|
| 32 |
INDEX_MODEL_NAME = 4,
|
- |
|
| 33 |
INDEX_COLOR = 5,
|
- |
|
| 34 |
INDEX_CATEGORY = 6;
|
- |
|
| 35 |
private static String LEGEND = "Currently Showing: ";
|
31 |
private static String LEGEND = "Currently Showing: ";
|
| 36 |
private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
|
32 |
private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
|
| 37 |
|
33 |
|
| 38 |
interface ItemListUiBinder extends UiBinder<Widget, ItemList> { }
|
34 |
interface ItemListUiBinder extends UiBinder<Widget, ItemList> { }
|
| 39 |
private static final ItemListUiBinder uiBinder = GWT.create(ItemListUiBinder.class);
|
35 |
private static final ItemListUiBinder uiBinder = GWT.create(ItemListUiBinder.class);
|
| Line 41... |
Line 37... |
| 41 |
interface SelectionStyle extends CssResource{
|
37 |
interface SelectionStyle extends CssResource{
|
| 42 |
String selectedRow();
|
38 |
String selectedRow();
|
| 43 |
String alertsRow();
|
39 |
String alertsRow();
|
| 44 |
}
|
40 |
}
|
| 45 |
|
41 |
|
| 46 |
@UiField FlexTable header;
|
42 |
@UiField CellTable<Item> itemDescriptionTable;
|
| - |
|
43 |
// Create paging controls.
|
| 47 |
@UiField FlexTable itemDescriptionTable;
|
44 |
@UiField SimplePager pager = new SimplePager();
|
| - |
|
45 |
|
| 48 |
@UiField SelectionStyle selectionStyle;
|
46 |
@UiField SelectionStyle selectionStyle;
|
| 49 |
@UiField Label currentlyShowing;
|
47 |
@UiField Label currentlyShowing;
|
| 50 |
private int selectedRow = -1;
|
48 |
private int selectedRow = -1;
|
| 51 |
|
49 |
|
| 52 |
private ItemDetails itemDetails;
|
50 |
private ItemDetails itemDetails;
|
| 53 |
|
51 |
|
| - |
|
52 |
// Create a data provider.
|
| - |
|
53 |
ListDataProvider<Item> dataProvider = new ListDataProvider<Item>();
|
| - |
|
54 |
|
| 54 |
public ItemList() {
|
55 |
public ItemList() {
|
| 55 |
initWidget(uiBinder.createAndBindUi(this));
|
56 |
initWidget(uiBinder.createAndBindUi(this));
|
| 56 |
initHeader();
|
- |
|
| 57 |
initItemList();
|
57 |
initItemList();
|
| 58 |
}
|
58 |
}
|
| 59 |
|
59 |
|
| 60 |
private void initItemList() {
|
60 |
private void initItemList() {
|
| - |
|
61 |
TextColumn<Item> idColumn = new TextColumn<Item>() {
|
| 61 |
loadAllRiskyItems();
|
62 |
@Override
|
| - |
|
63 |
public String getValue(Item item) {
|
| - |
|
64 |
return item.getId() + "";
|
| - |
|
65 |
}
|
| - |
|
66 |
};
|
| 62 |
|
67 |
|
| - |
|
68 |
TextColumn<Item> pgColumn = new TextColumn<Item>() {
|
| 63 |
/*For testing
|
69 |
@Override
|
| - |
|
70 |
public String getValue(Item item) {
|
| - |
|
71 |
return item.getProductGroup();
|
| - |
|
72 |
}
|
| - |
|
73 |
};
|
| - |
|
74 |
|
| - |
|
75 |
TextColumn<Item> brandColumn = new TextColumn<Item>(){
|
| 64 |
loadDummyItems();
|
76 |
@Override
|
| 65 |
updateItemDescriptionTable(items);
|
77 |
public String getValue(Item item) {
|
| - |
|
78 |
return item.getBrand();
|
| - |
|
79 |
}
|
| 66 |
*/
|
80 |
};
|
| 67 |
}
|
81 |
|
| - |
|
82 |
TextColumn<Item> modelNumberColumn = new TextColumn<Item>(){
|
| - |
|
83 |
@Override
|
| - |
|
84 |
public String getValue(Item item) {
|
| - |
|
85 |
return item.getModelNumber();
|
| - |
|
86 |
}
|
| - |
|
87 |
};
|
| 68 |
|
88 |
|
| - |
|
89 |
TextColumn<Item> modelNameColumn = new TextColumn<Item>(){
|
| - |
|
90 |
@Override
|
| - |
|
91 |
public String getValue(Item item) {
|
| - |
|
92 |
return item.getModelName();
|
| - |
|
93 |
}
|
| - |
|
94 |
};
|
| 69 |
/**
|
95 |
|
| - |
|
96 |
TextColumn<Item> colorColumn = new TextColumn<Item>(){
|
| - |
|
97 |
@Override
|
| - |
|
98 |
public String getValue(Item item) {
|
| 70 |
* Initialise header of item list table.
|
99 |
return item.getColor();
|
| - |
|
100 |
}
|
| - |
|
101 |
};
|
| 71 |
*/
|
102 |
|
| - |
|
103 |
TextColumn<Item> categoryColumn = new TextColumn<Item>(){
|
| - |
|
104 |
@Override
|
| - |
|
105 |
public String getValue(Item item) {
|
| - |
|
106 |
return item.getContentCategory()+"";
|
| - |
|
107 |
}
|
| - |
|
108 |
};
|
| - |
|
109 |
|
| - |
|
110 |
// Add the columns.
|
| - |
|
111 |
itemDescriptionTable.addColumn(idColumn, "Item Id");
|
| - |
|
112 |
itemDescriptionTable.addColumn(pgColumn, "Product Group");
|
| - |
|
113 |
itemDescriptionTable.addColumn(brandColumn, "Brand");
|
| - |
|
114 |
itemDescriptionTable.addColumn(modelNumberColumn, "Model Number");
|
| - |
|
115 |
itemDescriptionTable.addColumn(modelNameColumn, "Model Name");
|
| - |
|
116 |
itemDescriptionTable.addColumn(colorColumn, "Color");
|
| - |
|
117 |
itemDescriptionTable.addColumn(categoryColumn, "Category");
|
| - |
|
118 |
|
| 72 |
private void initHeader(){
|
119 |
//Set the widths
|
| 73 |
header.getColumnFormatter().setWidth(INDEX_ID, "80px");
|
120 |
itemDescriptionTable.setWidth("100%");
|
| 74 |
header.getColumnFormatter().setWidth(INDEX_PRODUCT_GROUP, "128px");
|
121 |
itemDescriptionTable.setColumnWidth(idColumn, 80.0, Unit.PX);
|
| 75 |
header.getColumnFormatter().setWidth(INDEX_BRAND, "150px");
|
122 |
itemDescriptionTable.setColumnWidth(pgColumn, 128.0, Unit.PX);
|
| 76 |
header.getColumnFormatter().setWidth(INDEX_MODEL_NUMBER, "200px");
|
123 |
itemDescriptionTable.setColumnWidth(brandColumn, 150.0, Unit.PX);
|
| - |
|
124 |
itemDescriptionTable.setColumnWidth(modelNumberColumn, 200.0, Unit.PX);
|
| 77 |
header.getColumnFormatter().setWidth(INDEX_MODEL_NAME, "200px");
|
125 |
itemDescriptionTable.setColumnWidth(modelNameColumn, 200.0, Unit.PX);
|
| 78 |
header.getColumnFormatter().setWidth(INDEX_COLOR, "128px");
|
126 |
itemDescriptionTable.setColumnWidth(colorColumn, 128.0, Unit.PX);
|
| 79 |
header.getColumnFormatter().setWidth(INDEX_CATEGORY, "220px");
|
127 |
itemDescriptionTable.setColumnWidth(categoryColumn, 220.0, Unit.PX);
|
| - |
|
128 |
|
| - |
|
129 |
// Connect the table to the data provider.
|
| - |
|
130 |
dataProvider.addDataDisplay(itemDescriptionTable);
|
| 80 |
|
131 |
|
| - |
|
132 |
//Add paging support
|
| 81 |
header.setText(0, INDEX_ID, "Item Id");
|
133 |
pager.setDisplay(itemDescriptionTable);
|
| - |
|
134 |
|
| 82 |
header.setText(0, INDEX_PRODUCT_GROUP, "Product Group");
|
135 |
// Add a selection model to handle item selection.
|
| - |
|
136 |
final SingleSelectionModel<Item> selectionModel = new SingleSelectionModel<Item>();
|
| 83 |
header.setText(0, INDEX_BRAND, "Brand");
|
137 |
itemDescriptionTable.setSelectionModel(selectionModel);
|
| - |
|
138 |
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
|
| - |
|
139 |
|
| - |
|
140 |
@Override
|
| - |
|
141 |
public void onSelectionChange(SelectionChangeEvent event) {
|
| 84 |
header.setText(0, INDEX_MODEL_NUMBER, "Model Number");
|
142 |
Item selectedItem = selectionModel.getSelectedObject();
|
| - |
|
143 |
catalogService.getItem(selectedItem.getId(), new AsyncCallback<Item>() {
|
| - |
|
144 |
@Override
|
| - |
|
145 |
public void onSuccess(Item result) {
|
| 85 |
header.setText(0, INDEX_MODEL_NAME, "Model Name");
|
146 |
itemDetails.setItemDetails(result);
|
| - |
|
147 |
}
|
| - |
|
148 |
@Override
|
| - |
|
149 |
public void onFailure(Throwable caught) {
|
| 86 |
header.setText(0, INDEX_COLOR, "Color");
|
150 |
caught.printStackTrace();
|
| 87 |
header.setText(0, INDEX_CATEGORY, "Category");
|
151 |
Window.alert("Unable to fetch item details.");
|
| - |
|
152 |
}
|
| - |
|
153 |
});
|
| - |
|
154 |
}
|
| - |
|
155 |
});
|
| - |
|
156 |
|
| - |
|
157 |
|
| - |
|
158 |
loadAllRiskyItems();
|
| 88 |
}
|
159 |
}
|
| 89 |
|
160 |
|
| 90 |
private void updateItemDescriptionTable(List<Item> items){
|
161 |
private void updateItemDescriptionTable(List<Item> items){
|
| 91 |
itemDescriptionTable.removeAllRows();
|
- |
|
| 92 |
itemDescriptionTable.getColumnFormatter().setWidth(INDEX_ID, "80px");
|
- |
|
| 93 |
itemDescriptionTable.getColumnFormatter().setWidth(INDEX_PRODUCT_GROUP, "128px");
|
162 |
// Add the data to the data provider, which automatically pushes it to the
|
| 94 |
itemDescriptionTable.getColumnFormatter().setWidth(INDEX_BRAND, "150px");
|
163 |
// widget.
|
| 95 |
itemDescriptionTable.getColumnFormatter().setWidth(INDEX_MODEL_NUMBER, "200px");
|
- |
|
| 96 |
itemDescriptionTable.getColumnFormatter().setWidth(INDEX_MODEL_NAME, "200px");
|
164 |
List<Item> list = dataProvider.getList();
|
| 97 |
itemDescriptionTable.getColumnFormatter().setWidth(INDEX_COLOR, "128px");
|
165 |
list.clear();
|
| 98 |
itemDescriptionTable.getColumnFormatter().setWidth(INDEX_CATEGORY, "220px");
|
166 |
list.addAll(items);
|
| 99 |
|
167 |
|
| 100 |
int i=0;
|
168 |
pager.firstPage();
|
| 101 |
for(final Item item : items){
|
- |
|
| 102 |
itemDescriptionTable.setText(i, INDEX_ID, item.getId() + "");
|
- |
|
| 103 |
itemDescriptionTable.setText(i, INDEX_PRODUCT_GROUP, item.getProductGroup());
|
- |
|
| 104 |
itemDescriptionTable.setText(i, INDEX_BRAND, item.getBrand());
|
- |
|
| 105 |
itemDescriptionTable.setText(i, INDEX_MODEL_NUMBER, item.getModelNumber());
|
- |
|
| 106 |
itemDescriptionTable.setText(i, INDEX_MODEL_NAME, item.getModelName());
|
- |
|
| 107 |
itemDescriptionTable.setText(i, INDEX_COLOR, item.getColor());
|
- |
|
| 108 |
itemDescriptionTable.setText(i, INDEX_CATEGORY, item.getContentCategory()+"");
|
- |
|
| 109 |
i++;
|
- |
|
| 110 |
}
|
- |
|
| 111 |
}
|
169 |
}
|
| 112 |
|
170 |
|
| 113 |
/**
|
171 |
/**
|
| 114 |
* On click of an item in the list, a fresh call is made to the service to fetch item details, vendor prices
|
172 |
* On click of an item in the list, a fresh call is made to the service to fetch item details, vendor prices
|
| 115 |
* and vendor item keys. The item object is then passed to ItemDetails to set the values in UI fields
|
173 |
* and vendor item keys. The item object is then passed to ItemDetails to set the values in UI fields
|
| 116 |
* @param event
|
174 |
* @param event
|
| 117 |
*/
|
175 |
*/
|
| 118 |
@UiHandler("itemDescriptionTable")
|
176 |
// @UiHandler("itemDescriptionTable")
|
| 119 |
void onClick(ClickEvent event) {
|
177 |
// void onClick(ClickEvent event) {
|
| 120 |
|
178 |
//
|
| 121 |
Cell cell = itemDescriptionTable.getCellForEvent(event);
|
179 |
// Cell cell = itemDescriptionTable.getCellForEvent(event);
|
| 122 |
int newRowIndex = cell.getRowIndex();
|
180 |
// int newRowIndex = cell.getRowIndex();
|
| 123 |
selectRow(newRowIndex);
|
181 |
// selectRow(newRowIndex);
|
| 124 |
String itemId = itemDescriptionTable.getText(newRowIndex, INDEX_ID);
|
182 |
// String itemId = itemDescriptionTable.getText(newRowIndex, INDEX_ID);
|
| 125 |
|
183 |
//
|
| 126 |
catalogService.getItem(Long.parseLong(itemId), new AsyncCallback<Item>() {
|
184 |
// catalogService.getItem(Long.parseLong(itemId), new AsyncCallback<Item>() {
|
| 127 |
@Override
|
185 |
// @Override
|
| 128 |
public void onSuccess(Item result) {
|
186 |
// public void onSuccess(Item result) {
|
| 129 |
itemDetails.setItemDetails(result);
|
187 |
// itemDetails.setItemDetails(result);
|
| 130 |
}
|
188 |
// }
|
| 131 |
@Override
|
189 |
// @Override
|
| 132 |
public void onFailure(Throwable caught) {
|
190 |
// public void onFailure(Throwable caught) {
|
| 133 |
caught.printStackTrace();
|
191 |
// caught.printStackTrace();
|
| 134 |
Window.alert("Unable to fetch item details.");
|
192 |
// Window.alert("Unable to fetch item details.");
|
| 135 |
}
|
193 |
// }
|
| 136 |
});
|
194 |
// });
|
| 137 |
}
|
195 |
// }
|
| 138 |
|
196 |
|
| 139 |
private void selectRow(int row) {
|
197 |
private void selectRow(int row) {
|
| - |
|
198 |
//TODO: Change the style of the selected row
|
| 140 |
String style = selectionStyle.selectedRow();
|
199 |
// String style = selectionStyle.selectedRow();
|
| 141 |
if(selectedRow != -1){
|
200 |
// if(selectedRow != -1){
|
| 142 |
itemDescriptionTable.getRowFormatter().removeStyleName(selectedRow, style);
|
201 |
// itemDescriptionTable.getRowElement(row)owFormatter().removeStyleName(selectedRow, style);
|
| 143 |
}
|
202 |
// }
|
| 144 |
|
203 |
//
|
| 145 |
itemDescriptionTable.getRowFormatter().addStyleName(row, style);
|
204 |
// itemDescriptionTable.getRowFormatter().addStyleName(row, style);
|
| 146 |
selectedRow = row;
|
205 |
// selectedRow = row;
|
| 147 |
}
|
206 |
}
|
| 148 |
|
207 |
|
| 149 |
/* For testing
|
208 |
/* For testing
|
| 150 |
private HashMap map;
|
209 |
private HashMap map;
|
| 151 |
private List<Item> items;
|
210 |
private List<Item> items;
|
| Line 298... |
Line 357... |
| 298 |
* This method is called when item is updated in ItemDetails.java to update
|
357 |
* This method is called when item is updated in ItemDetails.java to update
|
| 299 |
* attributes in the list also.
|
358 |
* attributes in the list also.
|
| 300 |
* @param item
|
359 |
* @param item
|
| 301 |
*/
|
360 |
*/
|
| 302 |
public void updateItem(Item item) {
|
361 |
public void updateItem(Item item) {
|
| - |
|
362 |
//TODO: Update the item in the list when its details are updated
|
| 303 |
itemDescriptionTable.setText(selectedRow, INDEX_PRODUCT_GROUP, item.getProductGroup());
|
363 |
// itemDescriptionTable.setText(selectedRow, INDEX_PRODUCT_GROUP, item.getProductGroup());
|
| 304 |
itemDescriptionTable.setText(selectedRow, INDEX_BRAND, item.getBrand());
|
364 |
// itemDescriptionTable.setText(selectedRow, INDEX_BRAND, item.getBrand());
|
| 305 |
itemDescriptionTable.setText(selectedRow, INDEX_MODEL_NUMBER, item.getModelNumber());
|
365 |
// itemDescriptionTable.setText(selectedRow, INDEX_MODEL_NUMBER, item.getModelNumber());
|
| 306 |
itemDescriptionTable.setText(selectedRow, INDEX_MODEL_NAME, item.getModelName());
|
366 |
// itemDescriptionTable.setText(selectedRow, INDEX_MODEL_NAME, item.getModelName());
|
| 307 |
itemDescriptionTable.setText(selectedRow, INDEX_COLOR, item.getColor());
|
367 |
// itemDescriptionTable.setText(selectedRow, INDEX_COLOR, item.getColor());
|
| 308 |
}
|
368 |
}
|
| 309 |
}
|
369 |
}
|