From 0397262e8488f7101eb7c88200b930fa3fcc7eff Mon Sep 17 00:00:00 2001 From: Osiris Team Date: Thu, 9 May 2024 22:22:06 +0200 Subject: [PATCH] 1.56 - add vaadin listeners --- pom.xml | 2 +- .../jsqlgen/generator/GenVaadinFlow.java | 4 ++-- .../jsqlgen/generator/JavaCodeGenerator.java | 24 ++++++++++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 09144c0..2ac0473 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.osiris.jsqlgen jSQL-Gen - 1.55 + 1.56 jSQL-Gen diff --git a/src/main/java/com/osiris/jsqlgen/generator/GenVaadinFlow.java b/src/main/java/com/osiris/jsqlgen/generator/GenVaadinFlow.java index 288f178..9e827c6 100644 --- a/src/main/java/com/osiris/jsqlgen/generator/GenVaadinFlow.java +++ b/src/main/java/com/osiris/jsqlgen/generator/GenVaadinFlow.java @@ -55,7 +55,7 @@ public static String s(Database db, Table t, LinkedHashSet importsList) "\n" + genBooleanSelectClass(importsList) + "\n" + - " public " + t.name + " "+firstToLowerCase(t.name)+";\n" + + " public " + t.name + " data"+t.name+";\n" + " public " + t.name + " data;\n" + "\n" + " // Form and fields\n" + @@ -146,7 +146,7 @@ public static String s(Database db, Table t, LinkedHashSet importsList) "\n" + " public Comp(" + t.name + " data) {\n" + " this.data = data;\n" + - " this."+firstToLowerCase(t.name)+" = this.data;\n" + + " this.data"+t.name+" = this.data;\n" + " setWidthFull();\n" + " setPadding(false);\n" + "\n" + diff --git a/src/main/java/com/osiris/jsqlgen/generator/JavaCodeGenerator.java b/src/main/java/com/osiris/jsqlgen/generator/JavaCodeGenerator.java index b36d0f5..0ea5449 100644 --- a/src/main/java/com/osiris/jsqlgen/generator/JavaCodeGenerator.java +++ b/src/main/java/com/osiris/jsqlgen/generator/JavaCodeGenerator.java @@ -128,7 +128,29 @@ public static String generateTableFile(File oldGeneratedClass, Table t, Database "public static CopyOnWriteArrayList> onCreate = new CopyOnWriteArrayList>();\n" + "public static CopyOnWriteArrayList> onAdd = new CopyOnWriteArrayList>();\n" + "public static CopyOnWriteArrayList> onUpdate = new CopyOnWriteArrayList>();\n" + - "public static CopyOnWriteArrayList> onRemove = new CopyOnWriteArrayList>();\n"); + "public static CopyOnWriteArrayList> onRemove = new CopyOnWriteArrayList>();\n" + + "\n" + + "private static boolean isEqual("+t.name+" obj1, "+t.name+" obj2){ return obj1.equals(obj2) || obj1.id == obj2.id; }\n"); + if(t.isVaadinFlowUI){ + importsList.add("import com.vaadin.flow.component.UI;"); + classContentBuilder.append("" + + "public Consumer<"+t.name+"> onCreateV(Consumer<"+t.name+"> code){\n" + + "UI ui = UI.getCurrent(); Consumer<"+t.name+"> code2 = (obj) -> {if(!isEqual(this, obj)) return; ui.access(() -> {code.accept(obj);});};" + + " ui.addDetachListener(e -> {"+t.name+".onCreate.remove(code2);}); "+t.name+".onCreate.add(code2); return code2;\n}\n"+ + + "public Consumer<"+t.name+"> onAddV(Consumer<"+t.name+"> code){\n"+ + "UI ui = UI.getCurrent(); Consumer<"+t.name+"> code2 = (obj) -> {if(!isEqual(this, obj)) return; ui.access(() -> {code.accept(obj);});};" + + " ui.addDetachListener(e -> {"+t.name+".onAdd.remove(code2);}); "+t.name+".onAdd.add(code2); return code2;\n}\n"+ + + "public Consumer<"+t.name+"> onUpdateV(Consumer<"+t.name+"> code){\n"+ + "UI ui = UI.getCurrent(); Consumer<"+t.name+"> code2 = (obj) -> {if(!isEqual(this, obj)) return; ui.access(() -> {code.accept(obj);});};" + + " ui.addDetachListener(e -> {"+t.name+".onUpdate.remove(code2);}); "+t.name+".onUpdate.add(code2); return code2;\n}\n"+ + + "public Consumer<"+t.name+"> onRemoveV(Consumer<"+t.name+"> code){\n"+ + "UI ui = UI.getCurrent(); Consumer<"+t.name+"> code2 = (obj) -> {if(!isEqual(this, obj)) return; ui.access(() -> {code.accept(obj);});};" + + " ui.addDetachListener(e -> {"+t.name+".onRemove.remove(code2);}); "+t.name+".onRemove.add(code2); return code2;\n}\n"+ + "\n\n"); + } if (t.isDebug) classContentBuilder.append(" /**\n" +