Added mm-doc screen

This commit is contained in:
Willem Cazander 2022-10-15 06:22:53 +02:00
parent c8905bfabf
commit d7e92845b5
8 changed files with 301 additions and 129 deletions

View file

@ -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

View file

@ -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<String,DataContext> 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<FileHandle> eater) {
return new NativeFileChooserCallbackAdapter() {
@Override
public void onFileChosen(FileHandle file) {
eater.accept(file);
}
};
}
}
}

View file

@ -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)));
// }
}

View file

@ -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<String,DataContext> dataContexts = null;