SlideShare a Scribd company logo
1 of 11
Download to read offline
Miscellaneous Features - Part I
Categories
✦We first need to load the categories which we do in
the dish list form together with the dish loop
© Codename One 2017 all rights reserved
Menu menu = Restaurant.getInstance().menu.get();
if(menu.dishes.size() == 0) {
for(PropertyBusinessObject d : AppStorage.getInstance().fetchDishes()) {
Dish dsh = (Dish)d;
menu.dishes.add(dsh);
if(!menu.categories.asList().contains(dsh.category.get())) {
menu.categories.add(dsh.category.get());
}
}
}
Adding/Setting a Category
✦In the dish edit form we can set the category with a
completion list
© Codename One 2017 all rights reserved
String[] cats = new String[Restaurant.getInstance().menu.get().categories.size()];
Restaurant.getInstance().menu.get().categories.asList().toArray(cats);
AutoCompleteTextField category = new AutoCompleteTextField(cats);
if(!Restaurant.getInstance().menu.get().categories.asList().contains(category.getText())) {
Restaurant.getInstance().menu.get().categories.add(category.getText());
}
d.category.set(category.getText());
✦When we handle the OK event we can just add the
category automatically if it’s missing
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
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
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
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
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
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
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
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

More Related Content

Similar to Miscellaneous Features - Part 1.pdf

Android tutorials8 todo_list
Android tutorials8 todo_listAndroid tutorials8 todo_list
Android tutorials8 todo_list
Vlad Kolesnyk
 
Testing persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitTesting persistence in PHP with DbUnit
Testing persistence in PHP with DbUnit
Peter Wilcsinszky
 
Android tutorials8 todo_list
Android tutorials8 todo_listAndroid tutorials8 todo_list
Android tutorials8 todo_list
Vlad Kolesnyk
 

Similar to Miscellaneous Features - Part 1.pdf (20)

SQLite and ORM Binding - Part 2.pdf
SQLite and ORM Binding - Part 2.pdfSQLite and ORM Binding - Part 2.pdf
SQLite and ORM Binding - Part 2.pdf
 
Initial UI Mockup - Part 2.pdf
Initial UI Mockup - Part 2.pdfInitial UI Mockup - Part 2.pdf
Initial UI Mockup - Part 2.pdf
 
Finishing the App - Part 1.pdf
Finishing the App - Part 1.pdfFinishing the App - Part 1.pdf
Finishing the App - Part 1.pdf
 
Creating a Facebook Clone - Part VI - Transcript.pdf
Creating a Facebook Clone - Part VI - Transcript.pdfCreating a Facebook Clone - Part VI - Transcript.pdf
Creating a Facebook Clone - Part VI - Transcript.pdf
 
Building complex User Interfaces with Sitecore and React
Building complex User Interfaces with Sitecore and ReactBuilding complex User Interfaces with Sitecore and React
Building complex User Interfaces with Sitecore and React
 
Creating a Facebook Clone - Part VI.pdf
Creating a Facebook Clone - Part VI.pdfCreating a Facebook Clone - Part VI.pdf
Creating a Facebook Clone - Part VI.pdf
 
Scala on Your Phone
Scala on Your PhoneScala on Your Phone
Scala on Your Phone
 
Initial UI Mockup - Part 2 - Transcript.pdf
Initial UI Mockup - Part 2 - Transcript.pdfInitial UI Mockup - Part 2 - Transcript.pdf
Initial UI Mockup - Part 2 - Transcript.pdf
 
Architecture - Part 2.pdf
Architecture - Part 2.pdfArchitecture - Part 2.pdf
Architecture - Part 2.pdf
 
Extracting ui Design - part 4 - transcript.pdf
Extracting ui Design - part 4 - transcript.pdfExtracting ui Design - part 4 - transcript.pdf
Extracting ui Design - part 4 - transcript.pdf
 
Creating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdfCreating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdf
 
Creating an Uber Clone - Part XXXX.pdf
Creating an Uber Clone - Part XXXX.pdfCreating an Uber Clone - Part XXXX.pdf
Creating an Uber Clone - Part XXXX.pdf
 
Adapting to Tablets and Desktops - Part 3.pdf
Adapting to Tablets and Desktops - Part 3.pdfAdapting to Tablets and Desktops - Part 3.pdf
Adapting to Tablets and Desktops - Part 3.pdf
 
Miscellaneous Features - Part 2 - Transcript.pdf
Miscellaneous Features - Part 2 - Transcript.pdfMiscellaneous Features - Part 2 - Transcript.pdf
Miscellaneous Features - Part 2 - Transcript.pdf
 
Android tutorials8 todo_list
Android tutorials8 todo_listAndroid tutorials8 todo_list
Android tutorials8 todo_list
 
Testing persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitTesting persistence in PHP with DbUnit
Testing persistence in PHP with DbUnit
 
Extracting ui Design - part 4.pdf
Extracting ui Design - part 4.pdfExtracting ui Design - part 4.pdf
Extracting ui Design - part 4.pdf
 
Android tutorials8 todo_list
Android tutorials8 todo_listAndroid tutorials8 todo_list
Android tutorials8 todo_list
 
Optimization in django orm
Optimization in django ormOptimization in django orm
Optimization in django orm
 
ACADGILD:: ANDROID LESSON
ACADGILD:: ANDROID LESSON ACADGILD:: ANDROID LESSON
ACADGILD:: ANDROID LESSON
 

More from ShaiAlmog1

More from ShaiAlmog1 (20)

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdf
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 

Miscellaneous Features - Part 1.pdf

  • 2. Categories ✦We first need to load the categories which we do in the dish list form together with the dish loop © Codename One 2017 all rights reserved Menu menu = Restaurant.getInstance().menu.get(); if(menu.dishes.size() == 0) { for(PropertyBusinessObject d : AppStorage.getInstance().fetchDishes()) { Dish dsh = (Dish)d; menu.dishes.add(dsh); if(!menu.categories.asList().contains(dsh.category.get())) { menu.categories.add(dsh.category.get()); } } }
  • 3. Adding/Setting a Category ✦In the dish edit form we can set the category with a completion list © Codename One 2017 all rights reserved String[] cats = new String[Restaurant.getInstance().menu.get().categories.size()]; Restaurant.getInstance().menu.get().categories.asList().toArray(cats); AutoCompleteTextField category = new AutoCompleteTextField(cats); if(!Restaurant.getInstance().menu.get().categories.asList().contains(category.getText())) { Restaurant.getInstance().menu.get().categories.add(category.getText()); } d.category.set(category.getText()); ✦When we handle the OK event we can just add the category automatically if it’s missing
  • 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