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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package com.rthoni.intellij.codefromds.dbo;
  2. import com.intellij.database.model.DasTable;
  3. import com.intellij.database.psi.DbDataSource;
  4. import com.intellij.database.util.DasUtil;
  5. import java.io.File;
  6. import java.util.List;
  7. import java.util.Vector;
  8. import java.util.stream.Collectors;
  9. /**
  10. * Created by robin on 11/15/16.
  11. */
  12. public class GenerateOptions {
  13. public GenerateOptions() {
  14. }
  15. public GenerateOptions(DbDataSource source) {
  16. _modelsPath = source.getProject().getBasePath() + File.separator + "Models";
  17. _dataSourceTemplatePath = source.getProject().getBasePath() + File.separator + "Templates" + File.separator + "DataSource.twig";
  18. _modelsTemplatePath = source.getProject().getBasePath() + File.separator + "Templates" + File.separator + "Models.twig";
  19. _configPath = source.getProject().getBasePath() + File.separator + "code-from-ds.json";
  20. _selection = new DataSourceSelection(source);
  21. _selection.setSource(source);
  22. final List<? extends DasTable> tables = DasUtil.getTables(source).toList();
  23. List<TableSelection> tableSelections = new Vector<>();
  24. for (DasTable table : tables) {
  25. TableSelection tableSelection = new TableSelection();
  26. tableSelection.setTable(table);
  27. tableSelection.setColumns(DasUtil.getColumns(table).toList().stream().map(c -> {
  28. ColumnSelection selection = new ColumnSelection();
  29. selection.setColumn(c);
  30. selection.setSelected(true);
  31. return selection;
  32. }).collect(Collectors.toList()));
  33. tableSelections.add(tableSelection);
  34. }
  35. _selection.setTables(tableSelections);
  36. }
  37. private DataSourceSelection _selection;
  38. private String _modelsPath;
  39. private String _dataSourceTemplatePath;
  40. private String _modelsTemplatePath;
  41. private String _configPath;
  42. public DataSourceSelection getSelection() {
  43. return _selection;
  44. }
  45. public void setSelection(DataSourceSelection selection) {
  46. _selection = selection;
  47. }
  48. public String getModelsPath() {
  49. return _modelsPath;
  50. }
  51. public void setModelsPath(String modelsPath) {
  52. _modelsPath = modelsPath;
  53. }
  54. public String getDataSourceTemplatePath() {
  55. return _dataSourceTemplatePath;
  56. }
  57. public void setDataSourceTemplatePath(String dataSourceTemplatePath) {
  58. _dataSourceTemplatePath = dataSourceTemplatePath;
  59. }
  60. public String getModelsTemplatePath() {
  61. return _modelsTemplatePath;
  62. }
  63. public void setModelsTemplatePath(String modelsTemplatePath) {
  64. _modelsTemplatePath = modelsTemplatePath;
  65. }
  66. public String getConfigPath() {
  67. return _configPath;
  68. }
  69. public void setConfigPath(String configPath) {
  70. _configPath = configPath;
  71. }
  72. }