You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GenerateOptions.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package com.rthoni.intellij.codefromds.dbo.options;
  2. import com.intellij.database.psi.DbDataSource;
  3. import com.rthoni.intellij.codefromds.business.Helper;
  4. import org.json.JSONObject;
  5. import java.io.File;
  6. import java.util.HashMap;
  7. /**
  8. * Created by robin on 11/15/16.
  9. */
  10. public class GenerateOptions {
  11. private DataSourceSelection _selection;
  12. private String _dataSourceRelativePath;
  13. private String _modelsRelativePath;
  14. private String _dataSourceTemplateRelativePath;
  15. private String _modelsTemplateRelativePath;
  16. private String _configAbsolutePath;
  17. private String _filesExtension;
  18. private String _castFileRelativePath;
  19. public GenerateOptions(DbDataSource source) {
  20. _filesExtension = "cs";
  21. _dataSourceRelativePath = "DataAccess/Database." + _filesExtension;
  22. _modelsRelativePath = "Models";
  23. _dataSourceTemplateRelativePath = "code-from-ds" + File.separator + "DataSource.twig";
  24. _modelsTemplateRelativePath = "code-from-ds" + File.separator + "Models.twig";
  25. _configAbsolutePath = source.getProject().getBasePath() + File.separator + "code-from-ds" + File.separator + "code-from-ds.json";
  26. _castFileRelativePath = "code-from-ds" + File.separator + "types-cast.json";
  27. _selection = new DataSourceSelection(source);
  28. }
  29. public HashMap<String, Object> toMap()
  30. {
  31. HashMap<String, Object> map = new HashMap<>();
  32. map.put("dataSourceRelativePath", _dataSourceRelativePath);
  33. map.put("modelsRelativePath", _modelsRelativePath);
  34. map.put("dataSourceTemplateRelativePath", _dataSourceTemplateRelativePath);
  35. map.put("modelsTemplateRelativePath", _modelsTemplateRelativePath);
  36. map.put("filesExtension", _filesExtension);
  37. map.put("castFileRelativePath", _castFileRelativePath);
  38. map.put("selection", _selection == null ? null : new JSONObject(_selection.toMap()));
  39. return map;
  40. }
  41. public void fromJson(JSONObject json)
  42. {
  43. _dataSourceRelativePath = Helper.getJsonString(json, "dataSourceRelativePath");
  44. _modelsRelativePath = Helper.getJsonString(json, "modelsRelativePath");
  45. _dataSourceTemplateRelativePath = Helper.getJsonString(json, "dataSourceTemplateRelativePath");
  46. _modelsTemplateRelativePath = Helper.getJsonString(json, "modelsTemplateRelativePath");
  47. _filesExtension = Helper.getJsonString(json, "filesExtension");
  48. _castFileRelativePath = Helper.getJsonString(json, "castFileRelativePath");
  49. _selection.fromJson(json.getJSONObject("selection"));
  50. }
  51. public DataSourceSelection getSelection() {
  52. return _selection;
  53. }
  54. public void setSelection(DataSourceSelection selection) {
  55. _selection = selection;
  56. }
  57. public String getModelsRelativePath() {
  58. return _modelsRelativePath;
  59. }
  60. public void setModelsRelativePath(String modelsRelativePath) {
  61. _modelsRelativePath = modelsRelativePath;
  62. }
  63. public String getDataSourceTemplateRelativePath() {
  64. return _dataSourceTemplateRelativePath;
  65. }
  66. public void setDataSourceTemplateRelativePath(String dataSourceTemplateRelativePath) {
  67. _dataSourceTemplateRelativePath = dataSourceTemplateRelativePath;
  68. }
  69. public String getModelsTemplateRelativePath() {
  70. return _modelsTemplateRelativePath;
  71. }
  72. public void setModelsTemplateRelativePath(String modelsTemplateRelativePath) {
  73. _modelsTemplateRelativePath = modelsTemplateRelativePath;
  74. }
  75. public String getConfigAbsolutePath() {
  76. return _configAbsolutePath;
  77. }
  78. public void setConfigAbsolutePath(String configAbsolutePath) {
  79. _configAbsolutePath = configAbsolutePath;
  80. }
  81. public String getFilesExtension() {
  82. return _filesExtension;
  83. }
  84. public void setFilesExtension(String filesExtension) {
  85. _filesExtension = filesExtension;
  86. }
  87. public String getCastFileRelativePath() {
  88. return _castFileRelativePath;
  89. }
  90. public void setCastFileRelativePath(String castFileRelativePath) {
  91. _castFileRelativePath = castFileRelativePath;
  92. }
  93. public String getDataSourceRelativePath() {
  94. return _dataSourceRelativePath;
  95. }
  96. public void setDataSourceRelativePath(String dataSourceRelativePath) {
  97. _dataSourceRelativePath = dataSourceRelativePath;
  98. }
  99. }