Skip to content

Commit

Permalink
1.56
Browse files Browse the repository at this point in the history
- add vaadin listeners
  • Loading branch information
Osiris-Team committed May 9, 2024
1 parent 4d49ef0 commit 0397262
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.osiris.jsqlgen</groupId>
<artifactId>jSQL-Gen</artifactId>
<version>1.55</version>
<version>1.56</version>
<name>jSQL-Gen</name>
<!-- TODO add id reference deletion UI for vaadin -->

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/osiris/jsqlgen/generator/GenVaadinFlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static String s(Database db, Table t, LinkedHashSet<String> 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" +
Expand Down Expand Up @@ -146,7 +146,7 @@ public static String s(Database db, Table t, LinkedHashSet<String> 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" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,29 @@ public static String generateTableFile(File oldGeneratedClass, Table t, Database
"public static CopyOnWriteArrayList<Consumer<" + t.name + ">> onCreate = new CopyOnWriteArrayList<Consumer<" + t.name + ">>();\n" +
"public static CopyOnWriteArrayList<Consumer<" + t.name + ">> onAdd = new CopyOnWriteArrayList<Consumer<" + t.name + ">>();\n" +
"public static CopyOnWriteArrayList<Consumer<" + t.name + ">> onUpdate = new CopyOnWriteArrayList<Consumer<" + t.name + ">>();\n" +
"public static CopyOnWriteArrayList<Consumer<" + t.name + ">> onRemove = new CopyOnWriteArrayList<Consumer<" + t.name + ">>();\n");
"public static CopyOnWriteArrayList<Consumer<" + t.name + ">> onRemove = new CopyOnWriteArrayList<Consumer<" + t.name + ">>();\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" +
Expand Down

0 comments on commit 0397262

Please sign in to comment.