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 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 _modelsRelativePath;
  13. private String _dataSourceTemplateRelativePath;
  14. private String _modelsTemplateRelativePath;
  15. private String _configAbsolutePath;
  16. private String _filesExtension;
  17. private String _castFileRelativePath;
  18. public GenerateOptions(DbDataSource source) {
  19. _modelsRelativePath = "Models";
  20. _dataSourceTemplateRelativePath = "code-from-ds" + File.separator + "DataSource.twig";
  21. _modelsTemplateRelativePath = "code-from-ds" + File.separator + "Models.twig";
  22. _configAbsolutePath = source.getProject().getBasePath() + File.separator + "code-from-ds" + File.separator + "code-from-ds.json";
  23. _filesExtension = "cs";
  24. _castFileRelativePath = "code-from-ds" + File.separator + "types-cast.json";
  25. _selection = new DataSourceSelection(source);
  26. }
  27. public HashMap<String, Object> toMap()
  28. {
  29. HashMap<String, Object> map = new HashMap<>();
  30. map.put("modelsRelativePath", _modelsRelativePath);
  31. map.put("dataSourceTemplateRelativePath", _dataSourceTemplateRelativePath);
  32. map.put("modelsTemplateRelativePath", _modelsTemplateRelativePath);
  33. map.put("filesExtension", _filesExtension);
  34. map.put("castFileRelativePath", _castFileRelativePath);
  35. map.put("selection", _selection == null ? null : new JSONObject(_selection.toMap()));
  36. return map;
  37. }
  38. public void fromJson(JSONObject json)
  39. {
  40. _modelsRelativePath = Helper.getJsonString(json, "modelsRelativePath");
  41. _dataSourceTemplateRelativePath = Helper.getJsonString(json, "dataSourceTemplateRelativePath");
  42. _modelsTemplateRelativePath = Helper.getJsonString(json, "modelsTemplateRelativePath");
  43. _filesExtension = Helper.getJsonString(json, "filesExtension");
  44. _castFileRelativePath = Helper.getJsonString(json, "castFileRelativePath");
  45. _selection.fromJson(json.getJSONObject("selection"));
  46. }
  47. public DataSourceSelection getSelection() {
  48. return _selection;
  49. }
  50. public void setSelection(DataSourceSelection selection) {
  51. _selection = selection;
  52. }
  53. public String getModelsRelativePath() {
  54. return _modelsRelativePath;
  55. }
  56. public void setModelsRelativePath(String modelsRelativePath) {
  57. _modelsRelativePath = modelsRelativePath;
  58. }
  59. public String getDataSourceTemplateRelativePath() {
  60. return _dataSourceTemplateRelativePath;
  61. }
  62. public void setDataSourceTemplateRelativePath(String dataSourceTemplateRelativePath) {
  63. _dataSourceTemplateRelativePath = dataSourceTemplateRelativePath;
  64. }
  65. public String getModelsTemplateRelativePath() {
  66. return _modelsTemplateRelativePath;
  67. }
  68. public void setModelsTemplateRelativePath(String modelsTemplateRelativePath) {
  69. _modelsTemplateRelativePath = modelsTemplateRelativePath;
  70. }
  71. public String getConfigAbsolutePath() {
  72. return _configAbsolutePath;
  73. }
  74. public void setConfigAbsolutePath(String configAbsolutePath) {
  75. _configAbsolutePath = configAbsolutePath;
  76. }
  77. public String getFilesExtension() {
  78. return _filesExtension;
  79. }
  80. public void setFilesExtension(String filesExtension) {
  81. _filesExtension = filesExtension;
  82. }
  83. public String getCastFileRelativePath() {
  84. return _castFileRelativePath;
  85. }
  86. public void setCastFileRelativePath(String castFileRelativePath) {
  87. _castFileRelativePath = castFileRelativePath;
  88. }
  89. }