4. CategoryEntity ce = null;
for(CategoryEntity current : e.getCategories()) {
if(current.getName().equals(d.getCategory())) {
ce = current;
break;
}
}
if(ce == null && d.getCategory() != null) {
ce = new CategoryEntity(d.getCategory());
categoryRepository.save(ce);
}
CategoryEntity oe = de.getCategory();
de.setCategory(ce);
dishRepository.save(de);
if(d.getId() == null) {
Set<DishEntity> dishes = new HashSet<>(e.getDishes());
dishes.add(de);
e.setDishes(dishes);
restaurantRepository.save(e);
}
if(oe != null) {
cullCategory(e, oe);
}
Server - DishService Put Dish
5. private void cullCategory(RestaurantEntity e, CategoryEntity ce) {
for(DishEntity de : e.getDishes()) {
if(ce.equals(de.getCategory())) {
return;
}
}
categoryRepository.delete(ce);
}
@RequestMapping(method = RequestMethod.DELETE)
public @ResponseBody String delete(@RequestBody(required = true) Dish dsh) throws IOException {
RestaurantEntity e = restaurantRepository.findBySecret(dsh.getSecret());
for(DishEntity d : e.getDishes()) {
if(d.getId().equals(dsh.getId())) {
HashSet<DishEntity> de = new HashSet<>(e.getDishes());
de.remove(d);
e.setDishes(de);
e.setDishListUpdateTimestamp(System.currentTimeMillis());
restaurantRepository.save(e);
d.setDeleteTime(System.currentTimeMillis());
if(d.getCategory() != null) {
CategoryEntity ce = d.getCategory();
d.setCategory(null);
dishRepository.save(d);
cullCategory(e, ce);
} else {
dishRepository.save(d);
}
Server - cullCategory
6. Validator val = new Validator();
val.addConstraint(category,
new LengthConstraint(1, "Category is required"));
val.addConstraint(price,
new NumericConstraint(true, 0, 1000000,
"Price must be a positive number"));
val.addSubmitButtons(ok);
Validation
7. Label price = new Label(Restaurant.getInstance().formatCurrency(d.price.get()),
"PriceBadge");
d.price.addChangeListener(pl ->
price.setText(Restaurant.getInstance().formatCurrency(d.price.get())));
Label title = new Label(d.name.get(), “DishName");
d.name.addChangeListener(pl -> title.setText(d.name.get()));
Label description = new Label(d.description.get(), "DishDescription");
d.description.addChangeListener(pl -> description.setText(d.description.get()));
Container titleAndDescription = BoxLayout.encloseY(title, description);
titleAndDescription.setUIID("BlackGradient");
Container cnt = LayeredLayout.encloseIn(sb,
BorderLayout.south(titleAndDescription),
FlowLayout.encloseRight(price)
);
DishListForm
UIID
Foreground white
background 3f51b5
Transparency 200
Alignment right
padding 1mm
margin 0
Margin top 4mm
8. public class DetailsForm extends BaseNavigationForm {
private Builder bld = new Builder();
public DetailsForm(AppSettings app) {
super(app, BoxLayout.y());
TextField emailField = addTextAndLabel(
"E-mail - will receive purchases from the generated app", "", TextField.EMAILADDR);
emailField.addActionListener(e -> {
app.restaurantEmail.set(emailField.getText());
AppStorage.getInstance().update(app);
bld.updateRestaurantSettings(app);
});
TextField urlField = addTextAndLabel("Website URL", "", TextField.URL);
urlField.addActionListener(e -> {
Restaurant.getInstance().website.set(urlField.getText());
bld.updateRestaurantSettings(app);
});
MultiButton address = new MultiButton("Address & Location");
if(Restaurant.getInstance().navigationAddress.get() != null &&
Restaurant.getInstance().navigationAddress.get().length() > 0) {
address.setTextLine2(Restaurant.getInstance().navigationAddress.get());
} else {
address.setTextLine2("...");
}
add(address);
address.addActionListener(e -> new AddressForm().show());
DetailsForm
9. public class DetailsForm extends BaseNavigationForm {
private Builder bld = new Builder();
public DetailsForm(AppSettings app) {
super(app, BoxLayout.y());
TextField emailField = addTextAndLabel(
"E-mail - will receive purchases from the generated app", "", TextField.EMAILADDR);
emailField.addActionListener(e -> {
app.restaurantEmail.set(emailField.getText());
AppStorage.getInstance().update(app);
bld.updateRestaurantSettings(app);
});
TextField urlField = addTextAndLabel("Website URL", "", TextField.URL);
urlField.addActionListener(e -> {
Restaurant.getInstance().website.set(urlField.getText());
bld.updateRestaurantSettings(app);
});
MultiButton address = new MultiButton("Address & Location");
if(Restaurant.getInstance().navigationAddress.get() != null &&
Restaurant.getInstance().navigationAddress.get().length() > 0) {
address.setTextLine2(Restaurant.getInstance().navigationAddress.get());
} else {
address.setTextLine2("...");
}
add(address);
address.addActionListener(e -> new AddressForm().show());
DetailsForm
10. public class DetailsForm extends BaseNavigationForm {
private Builder bld = new Builder();
public DetailsForm(AppSettings app) {
super(app, BoxLayout.y());
TextField emailField = addTextAndLabel(
"E-mail - will receive purchases from the generated app", "", TextField.EMAILADDR);
emailField.addActionListener(e -> {
app.restaurantEmail.set(emailField.getText());
AppStorage.getInstance().update(app);
bld.updateRestaurantSettings(app);
});
TextField urlField = addTextAndLabel("Website URL", "", TextField.URL);
urlField.addActionListener(e -> {
Restaurant.getInstance().website.set(urlField.getText());
bld.updateRestaurantSettings(app);
});
MultiButton address = new MultiButton("Address & Location");
if(Restaurant.getInstance().navigationAddress.get() != null &&
Restaurant.getInstance().navigationAddress.get().length() > 0) {
address.setTextLine2(Restaurant.getInstance().navigationAddress.get());
} else {
address.setTextLine2("...");
}
add(address);
address.addActionListener(e -> new AddressForm().show());
DetailsForm
11. MultiButton styles = new MultiButton("Colors & Fonts");
styles.setTextLine2("...");
add(styles);
styles.addActionListener(e -> new StyleForm().show());
MultiButton about = new MultiButton("About Page");
styles.setTextLine2("...");
add(about);
styles.addActionListener(e -> new AboutRestaurantForm().show());
}
private TextField addTextAndLabel(String label, String value) {
TextField tf = new TextField(value);
tf.setHint(label);
add(new Label(label, "TextFieldLabel")).
add(tf);
return tf;
}
DetailsForm