SlideShare a Scribd company logo
SQLite & ORM Binding - Part II
Integrating Persistence
✦If there are no dishes we load them from the app
storage in the dishes list
© Codename One 2017 all rights reserved
if(Restaurant.getInstance().menu.get().dishes.size() == 0) {
for(PropertyBusinessObject d : AppStorage.getInstance().fetchDishes()) {
Restaurant.getInstance().menu.get().dishes.add((Dish)d);
}
}
for(Dish d : Restaurant.getInstance().menu.get().dishes) {
addDish(app, d);
}
Integrating Persistence
✦We use the delete listener to refresh the UI after
deletion
© Codename One 2017 all rights reserved
AppStorage.getInstance().addDeleteListener(e -> {
for(Component cmp : getContentPane()) {
Dish d = (Dish)cmp.getClientProperty("dish");
if(d == e.getSource()) {
cmp.remove();
revalidate();
return;
}
}
});
Property Binding
✦If the properties change (when data is persisted) we
map that to the UI of the dish in the main dish list
© Codename One 2017 all rights reserved
public void addDish(AppSettings app, Dish d) {
ScaleImageButton sb = new ScaleImageButton(d.getFullSize());
sb.setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FILL);
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()));
delete.addActionListener(e -> {
previous.addShowListener(prev -> {
previous.removeAllShowListeners();
ToastBar.showMessage("Deleted " + d.name.get() + ". Undo?”,
FontImage.MATERIAL_UNDO, ee -> {
DishListForm dlf = (DishListForm)previous;
dlf.addDish(app, d);
d.id.set(null);
bld.addDish(app, d);
d.id.addChangeListener(pl -> AppStorage.getInstance().insert(d));
});
});
previous.showBack();
bld.deleteDish(app, d);
AppStorage.getInstance().delete(d);
});
DishEditForm
delete.addActionListener(e -> {
previous.addShowListener(prev -> {
previous.removeAllShowListeners();
ToastBar.showMessage("Deleted " + d.name.get() + ". Undo?”,
FontImage.MATERIAL_UNDO, ee -> {
DishListForm dlf = (DishListForm)previous;
dlf.addDish(app, d);
d.id.set(null);
bld.addDish(app, d);
d.id.addChangeListener(pl -> AppStorage.getInstance().insert(d));
});
});
previous.showBack();
bld.deleteDish(app, d);
AppStorage.getInstance().delete(d);
});
DishEditForm
delete.addActionListener(e -> {
previous.addShowListener(prev -> {
previous.removeAllShowListeners();
ToastBar.showMessage("Deleted " + d.name.get() + ". Undo?”,
FontImage.MATERIAL_UNDO, ee -> {
DishListForm dlf = (DishListForm)previous;
dlf.addDish(app, d);
d.id.set(null);
bld.addDish(app, d);
d.id.addChangeListener(pl -> AppStorage.getInstance().insert(d));
});
});
previous.showBack();
bld.deleteDish(app, d);
AppStorage.getInstance().delete(d);
});
DishEditForm
delete.addActionListener(e -> {
previous.addShowListener(prev -> {
previous.removeAllShowListeners();
ToastBar.showMessage("Deleted " + d.name.get() + ". Undo?”,
FontImage.MATERIAL_UNDO, ee -> {
DishListForm dlf = (DishListForm)previous;
dlf.addDish(app, d);
d.id.set(null);
bld.addDish(app, d);
d.id.addChangeListener(pl -> AppStorage.getInstance().insert(d));
});
});
previous.showBack();
bld.deleteDish(app, d);
AppStorage.getInstance().delete(d);
});
DishEditForm
delete.addActionListener(e -> {
previous.addShowListener(prev -> {
previous.removeAllShowListeners();
ToastBar.showMessage("Deleted " + d.name.get() + ". Undo?”,
FontImage.MATERIAL_UNDO, ee -> {
DishListForm dlf = (DishListForm)previous;
dlf.addDish(app, d);
d.id.set(null);
bld.addDish(app, d);
d.id.addChangeListener(pl -> AppStorage.getInstance().insert(d));
});
});
previous.showBack();
bld.deleteDish(app, d);
AppStorage.getInstance().delete(d);
});
DishEditForm
ok.addActionListener(e -> {
previous.showBack();
d.name.set(title.getText());
d.description.set(description.getText());
try {
d.price.set(Double.parseDouble(price.getText()));
} catch(NumberFormatException err) {
Log.e(err);
ToastBar.showErrorMessage("Malformed price");
}
bld.updateDish(app, d);
Restaurant.getInstance().menu.get().dishes.add(d);
if(d.id.get() != null) {
AppStorage.getInstance().update(d);
}
//bld.updateDishImage(app, d);
});
DishEditForm
TextField title = new TextField(app.name.get());
title.setUIID("NavigationTitle");
title.addActionListener(a -> {
app.name.set(title.getText());
AppStorage.getInstance().update(app);
});
TextField tagline = new TextField(app.tagline.get());
tagline.setUIID("Tagline");
tagline.addActionListener(a -> {
app.tagline.set(tagline.getText());
AppStorage.getInstance().update(app);
});
BaseNavigationForm
Thank You

More Related Content

Similar to SQLite and ORM Binding - Part 2.pdf

Neues aus dem Tindergarten: Auswertung "privater" APIs mit Apache Ignite
Neues aus dem Tindergarten: Auswertung "privater" APIs mit Apache IgniteNeues aus dem Tindergarten: Auswertung "privater" APIs mit Apache Ignite
Neues aus dem Tindergarten: Auswertung "privater" APIs mit Apache Ignite
QAware GmbH
 
Android app development basics
Android app development basicsAndroid app development basics
Android app development basics
Anton Narusberg
 

Similar to SQLite and ORM Binding - Part 2.pdf (18)

Android workshop
Android workshopAndroid workshop
Android workshop
 
Introduction toandroid
Introduction toandroidIntroduction toandroid
Introduction toandroid
 
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
 
React hooks
React hooksReact hooks
React hooks
 
Backendless apps
Backendless appsBackendless apps
Backendless apps
 
Lviv MDDay 2014. Ігор Коробка “забезпечення базової безпеки в андроїд аплікац...
Lviv MDDay 2014. Ігор Коробка “забезпечення базової безпеки в андроїд аплікац...Lviv MDDay 2014. Ігор Коробка “забезпечення базової безпеки в андроїд аплікац...
Lviv MDDay 2014. Ігор Коробка “забезпечення базової безпеки в андроїд аплікац...
 
Neues aus dem Tindergarten: Auswertung "privater" APIs mit Apache Ignite
Neues aus dem Tindergarten: Auswertung "privater" APIs mit Apache IgniteNeues aus dem Tindergarten: Auswertung "privater" APIs mit Apache Ignite
Neues aus dem Tindergarten: Auswertung "privater" APIs mit Apache Ignite
 
Firebase & SwiftUI Workshop
Firebase & SwiftUI WorkshopFirebase & SwiftUI Workshop
Firebase & SwiftUI Workshop
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
 
ngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency InjectionngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency Injection
 
Let's your users share your App with Friends: App Invites for Android
 Let's your users share your App with Friends: App Invites for Android Let's your users share your App with Friends: App Invites for Android
Let's your users share your App with Friends: App Invites for Android
 
SharePoint Conference 2018 - APIs, APIs everywhere!
SharePoint Conference 2018 - APIs, APIs everywhere!SharePoint Conference 2018 - APIs, APIs everywhere!
SharePoint Conference 2018 - APIs, APIs everywhere!
 
Apresentação firebase
Apresentação firebaseApresentação firebase
Apresentação firebase
 
Google Fit, Android Wear & Xamarin
Google Fit, Android Wear & XamarinGoogle Fit, Android Wear & Xamarin
Google Fit, Android Wear & Xamarin
 
Unit5 Mobile Application Development.doc
Unit5 Mobile Application Development.docUnit5 Mobile Application Development.doc
Unit5 Mobile Application Development.doc
 
Rntb20200805
Rntb20200805Rntb20200805
Rntb20200805
 
Android app development basics
Android app development basicsAndroid app development basics
Android app development basics
 
Adapting to Tablets and Desktops - Part 3 - Transcript.pdf
Adapting to Tablets and Desktops - Part 3 - Transcript.pdfAdapting to Tablets and Desktops - Part 3 - Transcript.pdf
Adapting to Tablets and Desktops - Part 3 - Transcript.pdf
 

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

Recently uploaded (20)

UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 

SQLite and ORM Binding - Part 2.pdf

  • 1. SQLite & ORM Binding - Part II
  • 2. Integrating Persistence ✦If there are no dishes we load them from the app storage in the dishes list © Codename One 2017 all rights reserved if(Restaurant.getInstance().menu.get().dishes.size() == 0) { for(PropertyBusinessObject d : AppStorage.getInstance().fetchDishes()) { Restaurant.getInstance().menu.get().dishes.add((Dish)d); } } for(Dish d : Restaurant.getInstance().menu.get().dishes) { addDish(app, d); }
  • 3. Integrating Persistence ✦We use the delete listener to refresh the UI after deletion © Codename One 2017 all rights reserved AppStorage.getInstance().addDeleteListener(e -> { for(Component cmp : getContentPane()) { Dish d = (Dish)cmp.getClientProperty("dish"); if(d == e.getSource()) { cmp.remove(); revalidate(); return; } } });
  • 4. Property Binding ✦If the properties change (when data is persisted) we map that to the UI of the dish in the main dish list © Codename One 2017 all rights reserved public void addDish(AppSettings app, Dish d) { ScaleImageButton sb = new ScaleImageButton(d.getFullSize()); sb.setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FILL); 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()));
  • 5. delete.addActionListener(e -> { previous.addShowListener(prev -> { previous.removeAllShowListeners(); ToastBar.showMessage("Deleted " + d.name.get() + ". Undo?”, FontImage.MATERIAL_UNDO, ee -> { DishListForm dlf = (DishListForm)previous; dlf.addDish(app, d); d.id.set(null); bld.addDish(app, d); d.id.addChangeListener(pl -> AppStorage.getInstance().insert(d)); }); }); previous.showBack(); bld.deleteDish(app, d); AppStorage.getInstance().delete(d); }); DishEditForm
  • 6. delete.addActionListener(e -> { previous.addShowListener(prev -> { previous.removeAllShowListeners(); ToastBar.showMessage("Deleted " + d.name.get() + ". Undo?”, FontImage.MATERIAL_UNDO, ee -> { DishListForm dlf = (DishListForm)previous; dlf.addDish(app, d); d.id.set(null); bld.addDish(app, d); d.id.addChangeListener(pl -> AppStorage.getInstance().insert(d)); }); }); previous.showBack(); bld.deleteDish(app, d); AppStorage.getInstance().delete(d); }); DishEditForm
  • 7. delete.addActionListener(e -> { previous.addShowListener(prev -> { previous.removeAllShowListeners(); ToastBar.showMessage("Deleted " + d.name.get() + ". Undo?”, FontImage.MATERIAL_UNDO, ee -> { DishListForm dlf = (DishListForm)previous; dlf.addDish(app, d); d.id.set(null); bld.addDish(app, d); d.id.addChangeListener(pl -> AppStorage.getInstance().insert(d)); }); }); previous.showBack(); bld.deleteDish(app, d); AppStorage.getInstance().delete(d); }); DishEditForm
  • 8. delete.addActionListener(e -> { previous.addShowListener(prev -> { previous.removeAllShowListeners(); ToastBar.showMessage("Deleted " + d.name.get() + ". Undo?”, FontImage.MATERIAL_UNDO, ee -> { DishListForm dlf = (DishListForm)previous; dlf.addDish(app, d); d.id.set(null); bld.addDish(app, d); d.id.addChangeListener(pl -> AppStorage.getInstance().insert(d)); }); }); previous.showBack(); bld.deleteDish(app, d); AppStorage.getInstance().delete(d); }); DishEditForm
  • 9. delete.addActionListener(e -> { previous.addShowListener(prev -> { previous.removeAllShowListeners(); ToastBar.showMessage("Deleted " + d.name.get() + ". Undo?”, FontImage.MATERIAL_UNDO, ee -> { DishListForm dlf = (DishListForm)previous; dlf.addDish(app, d); d.id.set(null); bld.addDish(app, d); d.id.addChangeListener(pl -> AppStorage.getInstance().insert(d)); }); }); previous.showBack(); bld.deleteDish(app, d); AppStorage.getInstance().delete(d); }); DishEditForm
  • 10. ok.addActionListener(e -> { previous.showBack(); d.name.set(title.getText()); d.description.set(description.getText()); try { d.price.set(Double.parseDouble(price.getText())); } catch(NumberFormatException err) { Log.e(err); ToastBar.showErrorMessage("Malformed price"); } bld.updateDish(app, d); Restaurant.getInstance().menu.get().dishes.add(d); if(d.id.get() != null) { AppStorage.getInstance().update(d); } //bld.updateDishImage(app, d); }); DishEditForm
  • 11. TextField title = new TextField(app.name.get()); title.setUIID("NavigationTitle"); title.addActionListener(a -> { app.name.set(title.getText()); AppStorage.getInstance().update(app); }); TextField tagline = new TextField(app.tagline.get()); tagline.setUIID("Tagline"); tagline.addActionListener(a -> { app.tagline.set(tagline.getText()); AppStorage.getInstance().update(app); }); BaseNavigationForm