1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
| public class FoodPanel extends LayoutContainer {
private ContentPanel foodPanel;
private CRCServiceAsync serviceAsync;
private AsyncCallback callBack;
List<ColumnConfig> configs;
@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
setLayout(new FlowLayout());
configs = new ArrayList<ColumnConfig>();
ColumnConfig column = new ColumnConfig();
column.setId("id");
column.setHeader("id");
column.setWidth(100);
TextField<String> text = new TextField<String>();
text.setAllowBlank(false);
column.setEditor(new CellEditor(text));
configs.add(column);
column = new ColumnConfig();
column.setId("locale");
column.setHeader("locale");
column.setWidth(100);
text = new TextField<String>();
text.setAllowBlank(false);
column.setEditor(new CellEditor(text));
configs.add(column);
column = new ColumnConfig();
column.setId("label");
column.setHeader("label");
column.setWidth(100);
text = new TextField<String>();
text.setAllowBlank(false);
column.setEditor(new CellEditor(text));
configs.add(column);
serviceAsync = GWT.create(CRCService.class);
final ListStore<FoodType> store = new ListStore<FoodType>();
callBack = new AsyncCallback<List<FoodType>>() {
public void onFailure(final Throwable throwable) {
System.out.println("failure");
}
public void onSuccess(List<FoodType> foodTypes) {
System.out.println("ok");
store.add(foodTypes);
ColumnModel cm = new ColumnModel(configs);
foodPanel = new ContentPanel();
foodPanel.setIcon(MyIcons.ICONS.food());
foodPanel.setHeading("Foods' list");
foodPanel.setFrame(true);
foodPanel.setHeight(600);
foodPanel.setWidth(600);
foodPanel.setLayout(new FitLayout());
final RowEditor<FoodType> re = new RowEditor<FoodType>();
final Grid<FoodType> grid = new Grid<FoodType>(store, cm);
grid.setBorders(true);
grid.addPlugin(re);
grid.setSize(300,600);
foodPanel.add(grid);
ToolBar toolBar = new ToolBar();
Button add = new Button("Ajouter une caractéristique d'aliment");
add.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
FoodType food = new FoodType();
re.stopEditing(false);
store.insert(food, 0);
re.startEditing(store.indexOf(food), true);
}
});
toolBar.add(add);
foodPanel.setTopComponent(toolBar);
foodPanel.setButtonAlign(Style.HorizontalAlignment.CENTER);
foodPanel.addButton(new Button("Reset", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
store.rejectChanges();
}
}));
foodPanel.addButton(new Button("Save", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
store.commitChanges();
}
}));
add(foodPanel);
}
};
serviceAsync.getAllFoodType(callBack);
}
public ContentPanel getPanel() {
return foodPanel;
}
public void setPanel(final ContentPanel foodPanel) {
this.foodPanel = foodPanel;
}
} |
Partager