From d7e92845b51a52ef88b660c052a89abe06f40ae6 Mon Sep 17 00:00:00 2001 From: Willem Date: Sat, 15 Oct 2022 06:22:53 +0200 Subject: [PATCH] Added mm-doc screen --- gdxapp4d-app-mmdoc/pom.xml | 45 +----- .../gdxapp4d/app/mmdoc/MMDocComponent.java | 6 +- .../gdxapp4d/app/mmdoc/MMDocDeskApp.java | 132 +++++++++++++++--- .../gdxapp4d/app/mmdoc/MMDocManager.java | 80 ++++------- .../metamodel/doc/DocModelDataStore.java | 3 +- gdxapp4d-tos4/pom.xml | 33 ++++- .../gdxapp4d/tos4/GDXAppTos4BootFactory.java | 57 +++++++- pom.xml | 74 ++++++++-- 8 files changed, 301 insertions(+), 129 deletions(-) diff --git a/gdxapp4d-app-mmdoc/pom.xml b/gdxapp4d-app-mmdoc/pom.xml index 145d8259..3b3961bf 100644 --- a/gdxapp4d-app-mmdoc/pom.xml +++ b/gdxapp4d-app-mmdoc/pom.xml @@ -15,48 +15,6 @@ ${project.version} provided - - org.x4o - x4o-eld-doc - - - org.x4o - x4o-html - - - org.eobjects.metamodel - MetaModel-full - - - MetaModel-openoffice - org.eobjects.metamodel - - - MetaModel-excel - org.eobjects.metamodel - - - MetaModel-couchdb - org.eobjects.metamodel - - - org.mongodb - mongo-java-driver - - - - - org.mongodb - mongo-java-driver - - - postgresql - postgresql - - - com.h2database - h2 - @@ -73,7 +31,8 @@ <_metatypeannotations>* ${tos4.packages}, - ${vrgem4.packages} + ${vrgem4.packages}, + ${mmdoc.packages} distributedrebirth.love diff --git a/gdxapp4d-app-mmdoc/src/main/java/love/distributedrebirth/gdxapp4d/app/mmdoc/MMDocComponent.java b/gdxapp4d-app-mmdoc/src/main/java/love/distributedrebirth/gdxapp4d/app/mmdoc/MMDocComponent.java index 84104b9c..2123cfaf 100644 --- a/gdxapp4d-app-mmdoc/src/main/java/love/distributedrebirth/gdxapp4d/app/mmdoc/MMDocComponent.java +++ b/gdxapp4d-app-mmdoc/src/main/java/love/distributedrebirth/gdxapp4d/app/mmdoc/MMDocComponent.java @@ -6,6 +6,7 @@ import org.osgi.service.component.annotations.Deactivate; import org.osgi.service.component.annotations.Reference; import love.distributedrebirth.bassboonyd.info.BãßBȍőnAuthor注; +import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxBootArgs; import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxLog; import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4DeskAppService; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppLauncher; @@ -21,10 +22,13 @@ public class MMDocComponent { @Reference private VrGem4DeskAppService deskAppService; + @Reference + private SystemGdxBootArgs bootArgs; + private final DeskAppLauncher launcher; public MMDocComponent() { - launcher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "MMDoc", () -> new MMDocDeskApp()); + launcher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "MMDoc", () -> new MMDocDeskApp(bootArgs.getFileChooser())); } @Activate diff --git a/gdxapp4d-app-mmdoc/src/main/java/love/distributedrebirth/gdxapp4d/app/mmdoc/MMDocDeskApp.java b/gdxapp4d-app-mmdoc/src/main/java/love/distributedrebirth/gdxapp4d/app/mmdoc/MMDocDeskApp.java index 7db22863..a09a1c7c 100644 --- a/gdxapp4d-app-mmdoc/src/main/java/love/distributedrebirth/gdxapp4d/app/mmdoc/MMDocDeskApp.java +++ b/gdxapp4d-app-mmdoc/src/main/java/love/distributedrebirth/gdxapp4d/app/mmdoc/MMDocDeskApp.java @@ -1,58 +1,154 @@ package love.distributedrebirth.gdxapp4d.app.mmdoc; +import java.io.File; +import java.sql.SQLException; +import java.util.Map.Entry; +import java.util.function.Consumer; + +import org.eobjects.metamodel.DataContext; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.files.FileHandle; + import imgui.ImGui; import imgui.flag.ImGuiTableFlags; +import imgui.type.ImString; import love.distributedrebirth.bassboonyd.info.BãßBȍőnAuthor注; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.AbstractDeskApp; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppContourSection; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppRenderer; +import net.spookygames.gdx.nativefilechooser.NativeFileChooser; +import net.spookygames.gdx.nativefilechooser.NativeFileChooserCallback; +import net.spookygames.gdx.nativefilechooser.NativeFileChooserConfiguration; @BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") public class MMDocDeskApp extends AbstractDeskApp implements DeskAppRenderer { + private final NativeFileChooser fileChooser; + private final NativeFileChooserConfiguration fileChooserConfig; + private final MMDocManager docManager = new MMDocManager(); + private final ImString dbHost = new ImString(); + private final ImString dbName = new ImString(); + private final ImString dbUser = new ImString(); + private final ImString dbPass = new ImString(); + private final ImString docTarget = new ImString(); + private String result = ""; + + public MMDocDeskApp(NativeFileChooser fileChooser) { + this.fileChooser = fileChooser; + fileChooserConfig = new NativeFileChooserConfiguration(); + fileChooserConfig.directory = Gdx.files.absolute(System.getProperty("user.home")); + fileChooserConfig.title = "Choose file"; + } + public void create() { getContours().setTitle("MMDoc"); getContours().registrateContour(DeskAppContourSection.MAIN, this); + + dbHost.set("localhost"); + dbName.set("test"); + dbUser.set("user"); + dbPass.set("pass"); + docTarget.set("target/mm-doc"); } @Override public void render() { - ImGui.text("Current amount:"); - ImGui.sameLine(); - ImGui.text("0000"); + ImGui.inputText("docTarget", docTarget); + ImGui.separator(); + ImGui.inputText("dbHost", dbHost); + ImGui.inputText("dbName", dbName); + ImGui.inputText("dbUser", dbUser); + ImGui.inputText("dbPass", dbPass); ImGui.separator(); - if (ImGui.button("Add")) { - + if (ImGui.button("Add XML")) { + fileChooser.chooseFile(fileChooserConfig, NativeFileChooserCallbackAdapter.onFileChosen(v -> { + docManager.addDocModelXml(v.file()); + result = "Added XML file"; + })); } ImGui.sameLine(); + if (ImGui.button("Add CSV")) { + fileChooser.chooseFile(fileChooserConfig, NativeFileChooserCallbackAdapter.onFileChosen(v -> { + docManager.addDocModelCsv(v.file()); + result = "Added CSV file"; + })); + } + ImGui.sameLine(); + if (ImGui.button("Add PG")) { + try { + docManager.addDocModelJdbcPg(dbHost.get(), dbName.get(), dbUser.get(), dbPass.get()); + result = "Added PG DB"; + } catch (SQLException e) { + e.printStackTrace(); + result = e.getMessage(); + } + } + if (ImGui.button("Generate")) { - + try { + docManager.generate(new File(docTarget.get())); + result = "done"; + } catch (Exception e) { + e.printStackTrace(); + result = e.getMessage(); + } } + ImGui.sameLine(); + ImGui.text("Result: "+result); - ImGui.separator(); ImGui.text("DataSources:"); int flags = ImGuiTableFlags.ScrollX | ImGuiTableFlags.RowBg | ImGuiTableFlags.BordersOuter | ImGuiTableFlags.BordersV | ImGuiTableFlags.Resizable; ImGui.beginTable("DataSources", 4, flags); - ImGui.tableSetupColumn("In/Out"); - ImGui.tableSetupColumn("Amount"); - ImGui.tableSetupColumn("Fraction"); - ImGui.tableSetupColumn("Decimal"); + ImGui.tableSetupColumn("Id"); + ImGui.tableSetupColumn("Type"); + ImGui.tableSetupColumn("TableCount"); + ImGui.tableSetupColumn("Remove"); ImGui.tableHeadersRow(); - String[] walletData = {"test", "test", "test"}; - - for (String data:walletData) { + String removeId = null; + for (Entry data:docManager.getDataStore().entrySet()) { ImGui.tableNextRow(); ImGui.tableNextColumn(); - ImGui.text(data); + ImGui.text(data.getKey()); ImGui.tableNextColumn(); - ImGui.text(data); + ImGui.text(data.getValue().getClass().getSimpleName()); ImGui.tableNextColumn(); - ImGui.text(data); + ImGui.text(Integer.toString(data.getValue().getDefaultSchema().getTableCount())); ImGui.tableNextColumn(); - ImGui.text(data); + if (ImGui.smallButton("Remove")) { + removeId = data.getKey(); + } } ImGui.endTable(); + + if (removeId != null) { + docManager.getDataStore().removeDataContext(removeId); + } + } + + static class NativeFileChooserCallbackAdapter implements NativeFileChooserCallback { + + @Override + public void onFileChosen(FileHandle file) { + } + + @Override + public void onCancellation() { + } + + @Override + public void onError(Exception exception) { + } + + static NativeFileChooserCallbackAdapter onFileChosen(Consumer eater) { + return new NativeFileChooserCallbackAdapter() { + @Override + public void onFileChosen(FileHandle file) { + eater.accept(file); + } + }; + } } } diff --git a/gdxapp4d-app-mmdoc/src/main/java/love/distributedrebirth/gdxapp4d/app/mmdoc/MMDocManager.java b/gdxapp4d-app-mmdoc/src/main/java/love/distributedrebirth/gdxapp4d/app/mmdoc/MMDocManager.java index 5672756a..76e0408a 100644 --- a/gdxapp4d-app-mmdoc/src/main/java/love/distributedrebirth/gdxapp4d/app/mmdoc/MMDocManager.java +++ b/gdxapp4d-app-mmdoc/src/main/java/love/distributedrebirth/gdxapp4d/app/mmdoc/MMDocManager.java @@ -4,86 +4,56 @@ import java.io.File; import java.sql.DriverManager; import java.sql.SQLException; +import org.eobjects.metamodel.csv.CsvDataContext; import org.eobjects.metamodel.doc.DocModelDataStore; import org.eobjects.metamodel.doc.DocModelWriter; import org.eobjects.metamodel.jdbc.JdbcDataContext; -import org.eobjects.metamodel.mongodb.MongoDbDataContext; +import org.eobjects.metamodel.xml.XmlDomDataContext; -import com.mongodb.Mongo; -import com.mongodb.MongoOptions; -import com.mongodb.ServerAddress; - -public enum MMDocManager { - - INSTANCE; +public class MMDocManager { - private String DB_URL = "jdbc:mariadb://localhost/"; - private String DB_USER = "test"; - private String DB_PASS = "test"; - private String PDB_URL = "jdbc:postgresql:"; - private String PDB_USER = "postgres"; - private String PDB_PASS = "postgresql"; - private String MONGO_HOST = "localhost"; - private String MS_URL = "jdbc:sqlserver://localhost"; - private String MS_USER = "sa"; - private String MS_PASS = "admin123"; - private Mongo mongo = null; + private final DocModelDataStore dms = new DocModelDataStore(); - private MMDocManager() { + public DocModelDataStore getDataStore() { + return dms; } - public void testWriteDocModel() throws Exception { + public void generate(File targetPath) throws Exception { Class.forName(org.postgresql.Driver.class.getName()); - Class.forName(org.h2.Driver.class.getName()); + //Class.forName(org.h2.Driver.class.getName()); //Class.forName(com.microsoft.sqlserver.jdbc.SQLServerDriver.class.getName()); - mongo = new Mongo(new ServerAddress(MONGO_HOST),new MongoOptions()); - File targetPath = new File("target/mm-doc2"); - DocModelDataStore dms = buildDocModelStore(); try { DocModelWriter writer = new DocModelWriter(dms); writer.writeModelDoc(targetPath); } finally { - dms.clearAndCloseAllSafe(); + //dms.clearAndCloseAllSafe(); } - //assertTrue(targetPath.exists()); } - private DocModelDataStore buildDocModelStore() throws SQLException { - DocModelDataStore dms = new DocModelDataStore(); - - //buildDocModelStoreJdbcPg(dms,"dellstore2"); - - buildDocModelStoreJdbcPg(dms,"fsim"); - buildDocModelStoreJdbcPg(dms,"openbravo"); - buildDocModelStoreJdbcPg(dms,"dellstore2"); - buildDocModelStoreJdbcPg(dms,"pagila"); - - /* - buildDocModelStoreMongoDB(dms,"lia"); - buildDocModelStoreMongoDB(dms,"lefiona"); - - dms.addDataContext("xml-pom-doc",new XmlDomDataContext(new File("pom.xml"),false)); - - dms.addDataContext("csv-people",new CsvDataContext(new File("src/test/resources/junit/csv-data/meta-people.csv"))); - dms.addDataContext("csv-project",new CsvDataContext(new File("src/test/resources/junit/csv-data/meta-project.csv"))); - */ - return dms; + public void addDocModelXml(File file) { + dms.addDataContext("xml-"+file.getName(),new XmlDomDataContext(file,false)); } - private void buildDocModelStoreJdbcMy(DocModelDataStore ds,String dbName) throws SQLException { - ds.addDataContext("my-"+dbName,new JdbcDataContext(DriverManager.getConnection(DB_URL+dbName,DB_USER,DB_PASS))); + public void addDocModelCsv(File file) { + dms.addDataContext("csv-"+file.getName(),new CsvDataContext(file)); } - private void buildDocModelStoreJdbcPg(DocModelDataStore ds,String dbName) throws SQLException { - ds.addDataContext("pg-"+dbName,new JdbcDataContext(DriverManager.getConnection(PDB_URL+dbName,PDB_USER,PDB_PASS))); + public void addDocModelJdbcMy(String host, String dbName, String user, String pass) throws SQLException { + dms.addDataContext("my-"+dbName,new JdbcDataContext(DriverManager.getConnection("jdbc:mariadb://"+host+"/"+dbName,user,pass))); } - private void buildDocModelStoreMongoDB(DocModelDataStore ds,String dbName) { - ds.addDataContext("mongo-"+dbName,new MongoDbDataContext(mongo.getDB(dbName))); + public void addDocModelJdbcPg(String host, String dbName, String user, String pass) throws SQLException { + dms.addDataContext("pg-"+dbName,new JdbcDataContext(DriverManager.getConnection("jdbc:postgresql://"+host+"/"+dbName,user,pass))); } - private void buildDocModelStoreJdbcMs(DocModelDataStore ds,String dbName) throws SQLException { - ds.addDataContext("ms-"+dbName,new JdbcDataContext(DriverManager.getConnection(MS_URL+";databaseName="+dbName,MS_USER,MS_PASS))); + public void addDocModelJdbcMs(String host, String dbName, String user, String pass) throws SQLException { + dms.addDataContext("ms-"+dbName,new JdbcDataContext(DriverManager.getConnection("jdbc:sqlserver://"+host+";databaseName="+dbName,user,pass))); } + +// @SuppressWarnings("deprecation") +// public void addDocModelMongoDB(String host, String dbName, String user, String pass) { +// Mongo mongo = new Mongo(new ServerAddress(host),new MongoOptions()); +// dms.addDataContext("mongo-"+dbName,new MongoDbDataContext(mongo.getDB(dbName))); +// } } diff --git a/gdxapp4d-app-mmdoc/src/main/java/org/eobjects/metamodel/doc/DocModelDataStore.java b/gdxapp4d-app-mmdoc/src/main/java/org/eobjects/metamodel/doc/DocModelDataStore.java index 0bc12249..190b695c 100644 --- a/gdxapp4d-app-mmdoc/src/main/java/org/eobjects/metamodel/doc/DocModelDataStore.java +++ b/gdxapp4d-app-mmdoc/src/main/java/org/eobjects/metamodel/doc/DocModelDataStore.java @@ -6,11 +6,12 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; -import java.util.Map.Entry; import org.eobjects.metamodel.DataContext; import org.eobjects.metamodel.jdbc.JdbcDataContext; +import java.util.Map.Entry; + public class DocModelDataStore { private Map dataContexts = null; diff --git a/gdxapp4d-tos4/pom.xml b/gdxapp4d-tos4/pom.xml index f644e1b6..98a810db 100644 --- a/gdxapp4d-tos4/pom.xml +++ b/gdxapp4d-tos4/pom.xml @@ -58,6 +58,36 @@ gdx-freetype-platform natives-desktop + + org.x4o + x4o-eld-doc + + + org.x4o + x4o-html + + + org.eobjects.metamodel + MetaModel-csv + + + org.eobjects.metamodel + MetaModel-jdbc + + + commons-pool + commons-pool + + + + + org.eobjects.metamodel + MetaModel-xml + + + postgresql + postgresql + @@ -71,7 +101,8 @@ <_donotcopy>(.git) org.osgi.framework,org.osgi.service.packageadmin,org.osgi.service.url,org.osgi.service.startlevel,org.osgi.util.tracker,* - ${tos4.packages} + ${tos4.packages}, + ${mmdoc.packages} love.distributedrebirth.gdxapp4d.tos4.GDXAppTos4Activator distributedrebirth.love diff --git a/gdxapp4d-tos4/src/main/java/love/distributedrebirth/gdxapp4d/tos4/GDXAppTos4BootFactory.java b/gdxapp4d-tos4/src/main/java/love/distributedrebirth/gdxapp4d/tos4/GDXAppTos4BootFactory.java index a2c05e01..e3af3cf0 100644 --- a/gdxapp4d-tos4/src/main/java/love/distributedrebirth/gdxapp4d/tos4/GDXAppTos4BootFactory.java +++ b/gdxapp4d-tos4/src/main/java/love/distributedrebirth/gdxapp4d/tos4/GDXAppTos4BootFactory.java @@ -134,7 +134,62 @@ public class GDXAppTos4BootFactory { "love.distributedrebirth.warpme.ship,"+ "love.distributedrebirth.unicode4d,"+ "love.distributedrebirth.unicode4d.atlas,"+ - "love.distributedrebirth.unicode4d.draw" + "love.distributedrebirth.unicode4d.draw,"+ + "org.x4o.html,"+ + "org.x4o.html.spec,"+ + "org.x4o.xml.eld.doc,"+ + "org.x4o.xml.eld.doc.api,"+ + "org.x4o.xml.eld.doc.api.dom,"+ + "org.x4o.xml.eld.doc.theme.base,"+ + "org.x4o.xml.eld.doc.theme.jdk6,"+ + "org.x4o.xml.eld.doc.theme.jdk7,"+ + "org.eobjects.metamodel,"+ + "org.eobjects.metamodel.convert,"+ + "org.eobjects.metamodel.create,"+ + "org.eobjects.metamodel.data,"+ + "org.eobjects.metamodel.delete,"+ + "org.eobjects.metamodel.drop,"+ + "org.eobjects.metamodel.insert,"+ + "org.eobjects.metamodel.intercept,"+ + "org.eobjects.metamodel.query,"+ + "org.eobjects.metamodel.query.builder,"+ + "org.eobjects.metamodel.query.parser,"+ + "org.eobjects.metamodel.schema,"+ + "org.eobjects.metamodel.update,"+ + "org.eobjects.metamodel.util,"+ + "org.eobjects.metamodel.csv,"+ + "org.eobjects.metamodel.xml,"+ + "org.eobjects.metamodel.mongodb,"+ + "org.eobjects.metamodel.jdbc,"+ + "org.eobjects.metamodel.jdbc.dialects,"+ + "au.com.bytecode.opencsv,"+ + "au.com.bytecode.opencsv.bean,"+ + "org.postgresql,"+ + "org.postgresql.copy,"+ + "org.postgresql.core,"+ + "org.postgresql.core.types,"+ + "org.postgresql.core.v2,"+ + "org.postgresql.core.v3,"+ + "org.postgresql.ds,"+ + "org.postgresql.ds.common,"+ + "org.postgresql.ds.jdbc23,"+ + "org.postgresql.db.jdbc4,"+ + "org.postgresql.fastpath,"+ + "org.postgresql.geometric,"+ + "org.postgresql.gss,"+ + "org.postgresql.jdbc2,"+ + "org.postgresql.jdbc2.optional,"+ + "org.postgresql.jdbc3,"+ + "org.postgresql.jdbc3g,"+ + "org.postgresql.jdbc4,"+ + "org.postgresql.largeobject,"+ + "org.postgresql.ssl,"+ + "org.postgresql.translation,"+ + "org.postgresql.util,"+ + "org.postgresql.xa,"+ + "org.postgresql.xa.jdbc3,"+ + "org.postgresql.xa.jdbc4" + ); // ; version=1.0.0 if (cachedir != null) { diff --git a/pom.xml b/pom.xml index 97ee9532..d58c6472 100644 --- a/pom.xml +++ b/pom.xml @@ -176,6 +176,62 @@ org.apache.commons.lang3.time, org.apache.commons.lang3.tuple + + org.x4o.html, + org.x4o.html.spec, + org.x4o.xml.eld.doc, + org.x4o.xml.eld.doc.api, + org.x4o.xml.eld.doc.api.dom, + org.x4o.xml.eld.doc.theme.base, + org.x4o.xml.eld.doc.theme.jdk6, + org.x4o.xml.eld.doc.theme.jdk7, + org.eobjects.metamodel, + org.eobjects.metamodel.convert, + org.eobjects.metamodel.create, + org.eobjects.metamodel.data, + org.eobjects.metamodel.delete, + org.eobjects.metamodel.drop, + org.eobjects.metamodel.insert, + org.eobjects.metamodel.intercept, + org.eobjects.metamodel.query, + org.eobjects.metamodel.query.builder, + org.eobjects.metamodel.query.parser, + org.eobjects.metamodel.schema, + org.eobjects.metamodel.update, + org.eobjects.metamodel.util, + org.eobjects.metamodel.csv, + org.eobjects.metamodel.xml, + org.eobjects.metamodel.mongodb, + org.eobjects.metamodel.jdbc, + org.eobjects.metamodel.jdbc.dialects, + au.com.bytecode.opencsv, + au.com.bytecode.opencsv.bean, + org.postgresql, + org.postgresql.copy, + org.postgresql.core, + org.postgresql.core.types, + org.postgresql.core.v2, + org.postgresql.core.v3, + org.postgresql.ds, + org.postgresql.ds.common, + org.postgresql.ds.jdbc23, + org.postgresql.db.jdbc4, + org.postgresql.fastpath, + org.postgresql.geometric, + org.postgresql.gss, + org.postgresql.jdbc2, + org.postgresql.jdbc2.optional, + org.postgresql.jdbc3, + org.postgresql.jdbc3g, + org.postgresql.jdbc4, + org.postgresql.largeobject, + org.postgresql.ssl, + org.postgresql.translation, + org.postgresql.util, + org.postgresql.xa, + org.postgresql.xa.jdbc3, + org.postgresql.xa.jdbc4 + @@ -292,24 +348,24 @@ org.eobjects.metamodel - MetaModel-full + MetaModel-jdbc 3.4.11 - org.mongodb - mongo-java-driver - 3.10.2 + org.eobjects.metamodel + MetaModel-csv + 3.4.11 + + + org.eobjects.metamodel + MetaModel-xml + 3.4.11 postgresql postgresql 9.1-901-1.jdbc4 - - com.h2database - h2 - 1.3.170 -