Browse Source

added option for data source file path

tags/v1.1.0
Robin THONI 2 years ago
parent
commit
941ef0ba04

+ 1
- 1
.idea/misc.xml View File

@@ -13,7 +13,7 @@
13 13
     <ConfirmationsSetting value="0" id="Add" />
14 14
     <ConfirmationsSetting value="0" id="Remove" />
15 15
   </component>
16
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_3" default="false" assert-keyword="false" jdk-15="false" project-jdk-name="IntelliJ IDEA RS-163.7608" project-jdk-type="IDEA JDK">
16
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" assert-keyword="true" jdk-15="true" project-jdk-name="IntelliJ IDEA IU-162.2032.8" project-jdk-type="IDEA JDK">
17 17
     <output url="file://$PROJECT_DIR$/out" />
18 18
   </component>
19 19
 </project>

+ 1
- 2
src/com/rthoni/intellij/codefromds/business/Generator.java View File

@@ -207,8 +207,7 @@ public abstract class Generator {
207 207
 
208 208
         DataSourceDbo dbo = convertOptions(options, types);
209 209
 
210
-        generateFile(dataSourceTemplateAbsolutePath, modelsAbsolutePath + File.separator +
211
-                "Database." + options.getFilesExtension(), dbo, null);
210
+        generateFile(dataSourceTemplateAbsolutePath, Helper.getAbsolutePath(project, options.getDataSourceRelativePath()), dbo, null);
212 211
         for (TableDataSourceDbo table : dbo.getTables()) {
213 212
             if (table.hasAny()) {
214 213
                 generateFile(modelsTemplateAbsolutePath, modelsAbsolutePath + File.separator +

+ 14
- 1
src/com/rthoni/intellij/codefromds/dbo/options/GenerateOptions.java View File

@@ -14,6 +14,8 @@ public class GenerateOptions {
14 14
 
15 15
     private DataSourceSelection _selection;
16 16
 
17
+    private String _dataSourceRelativePath;
18
+
17 19
     private String _modelsRelativePath;
18 20
 
19 21
     private String _dataSourceTemplateRelativePath;
@@ -27,11 +29,12 @@ public class GenerateOptions {
27 29
     private String _castFileRelativePath;
28 30
 
29 31
     public GenerateOptions(DbDataSource source) {
32
+        _filesExtension = "cs";
33
+        _dataSourceRelativePath = "DataAccess/Database." + _filesExtension;
30 34
         _modelsRelativePath = "Models";
31 35
         _dataSourceTemplateRelativePath = "code-from-ds" + File.separator + "DataSource.twig";
32 36
         _modelsTemplateRelativePath = "code-from-ds" + File.separator + "Models.twig";
33 37
         _configAbsolutePath = source.getProject().getBasePath() + File.separator + "code-from-ds" + File.separator + "code-from-ds.json";
34
-        _filesExtension = "cs";
35 38
         _castFileRelativePath = "code-from-ds" + File.separator + "types-cast.json";
36 39
         _selection = new DataSourceSelection(source);
37 40
     }
@@ -40,6 +43,7 @@ public class GenerateOptions {
40 43
     {
41 44
         HashMap<String, Object> map = new HashMap<>();
42 45
 
46
+        map.put("dataSourceRelativePath", _dataSourceRelativePath);
43 47
         map.put("modelsRelativePath", _modelsRelativePath);
44 48
         map.put("dataSourceTemplateRelativePath", _dataSourceTemplateRelativePath);
45 49
         map.put("modelsTemplateRelativePath", _modelsTemplateRelativePath);
@@ -52,6 +56,7 @@ public class GenerateOptions {
52 56
 
53 57
     public void fromJson(JSONObject json)
54 58
     {
59
+        _dataSourceRelativePath = Helper.getJsonString(json, "dataSourceRelativePath");
55 60
         _modelsRelativePath = Helper.getJsonString(json, "modelsRelativePath");
56 61
         _dataSourceTemplateRelativePath = Helper.getJsonString(json, "dataSourceTemplateRelativePath");
57 62
         _modelsTemplateRelativePath = Helper.getJsonString(json, "modelsTemplateRelativePath");
@@ -115,4 +120,12 @@ public class GenerateOptions {
115 120
     public void setCastFileRelativePath(String castFileRelativePath) {
116 121
         _castFileRelativePath = castFileRelativePath;
117 122
     }
123
+
124
+    public String getDataSourceRelativePath() {
125
+        return _dataSourceRelativePath;
126
+    }
127
+
128
+    public void setDataSourceRelativePath(String dataSourceRelativePath) {
129
+        _dataSourceRelativePath = dataSourceRelativePath;
130
+    }
118 131
 }

+ 16
- 1
src/com/rthoni/intellij/codefromds/ui/dialogs/GenerateDialog.java View File

@@ -39,12 +39,14 @@ public class GenerateDialog extends DialogWrapper {
39 39
     private JBList _listTables;
40 40
     private JBList _listColumns;
41 41
     private TextFieldWithBrowseButton _textModels;
42
+    private TextFieldWithBrowseButton _textDataSource;
42 43
     private TextFieldWithBrowseButton _textDataSourceTemplate;
43 44
     private TextFieldWithBrowseButton _textModelsTemplate;
44 45
     private TextFieldWithBrowseButton _textConfigPath;
45 46
     private JTextField _textFilesExtension;
46
-    private JLabel _lblDataSourceTemplatePath;
47 47
     private JLabel _lblModelsPath;
48
+    private JLabel _lblDataSourcePath;
49
+    private JLabel _lblDataSourceTemplatePath;
48 50
     private JLabel _lblModelsTemplatePath;
49 51
     private TextFieldWithBrowseButton _textCastFile;
50 52
     private JLabel _lblCastFile;
@@ -70,6 +72,7 @@ public class GenerateDialog extends DialogWrapper {
70 72
         if (_options != null) {
71 73
             showSource(_options.getSelection());
72 74
             _textModels.setText(Helper.getAbsolutePath(_project, _options.getModelsRelativePath()));
75
+            _textDataSource.setText(Helper.getAbsolutePath(_project, _options.getDataSourceRelativePath()));
73 76
             _textDataSourceTemplate.setText(Helper.getAbsolutePath(_project, _options.getDataSourceTemplateRelativePath()));
74 77
             _textModelsTemplate.setText(Helper.getAbsolutePath(_project, _options.getModelsTemplateRelativePath()));
75 78
             _textFilesExtension.setText(_options.getFilesExtension());
@@ -79,6 +82,7 @@ public class GenerateDialog extends DialogWrapper {
79 82
         else {
80 83
             showSource(null);
81 84
             _textModels.setText("");
85
+            _textDataSource.setText("");
82 86
             _textDataSourceTemplate.setText("");
83 87
             _textModelsTemplate.setText("");
84 88
             _textFilesExtension.setText("");
@@ -92,6 +96,8 @@ public class GenerateDialog extends DialogWrapper {
92 96
     protected ValidationInfo doValidate() {
93 97
         ValidationInfo info = null;
94 98
         File modelDir = _options == null ? null : new File(Helper.getAbsolutePath(_project, _options.getModelsRelativePath()));
99
+        File dataSourcePath = _options == null ? null : new File(Helper.getAbsolutePath(_project, _options.getDataSourceRelativePath()));
100
+        File dataSourceDir = _options == null ? null : new File(dataSourcePath.getParent());
95 101
         File dataSourceTemplatePath = _options == null ? null : new File(Helper.getAbsolutePath(_project, _options.getDataSourceTemplateRelativePath()));
96 102
         File modelsTemplatePath = _options == null ? null : new File(Helper.getAbsolutePath(_project, _options.getModelsTemplateRelativePath()));
97 103
         File configPath = _options == null ? null : new File(_options.getConfigAbsolutePath());
@@ -104,6 +110,9 @@ public class GenerateDialog extends DialogWrapper {
104 110
         else if (!modelDir.exists() || !modelDir.isDirectory()) {
105 111
             info = new ValidationInfo("Models folder does not exists", _textModels.getTextField());
106 112
         }
113
+        else if (!dataSourceDir.exists() || !dataSourceDir.isDirectory()) {
114
+            info = new ValidationInfo("Data source folder does not exists", _textDataSource.getTextField());
115
+        }
107 116
         else if (!dataSourceTemplatePath.exists() || !dataSourceTemplatePath.isFile()) {
108 117
             info = new ValidationInfo("Data source template file does not exists", _textDataSourceTemplate.getTextField());
109 118
         }
@@ -157,6 +166,7 @@ public class GenerateDialog extends DialogWrapper {
157 166
         });
158 167
 
159 168
         setupTextField(_textModels, null, true, "Models");
169
+        setupTextField(_textDataSource, null, false, "Data Source");
160 170
         setupTextField(_textDataSourceTemplate, null, false, "Data Source Template");
161 171
         setupTextField(_textModelsTemplate, null, false, "Models Template");
162 172
         setupTextField(_textConfigPath, null, false, "Configuration");
@@ -166,6 +176,11 @@ public class GenerateDialog extends DialogWrapper {
166 176
             _options.setModelsRelativePath(Helper.getRelativePath(_project, s));
167 177
             _lblModelsPath.setText("$ProjectRoot/" + _options.getModelsRelativePath());
168 178
         });
179
+
180
+        setupTextFieldListener(_textDataSource.getTextField(), s -> {
181
+            _options.setDataSourceRelativePath(Helper.getRelativePath(_project, s));
182
+            _lblDataSourcePath.setText("$ProjectRoot/" + _options.getDataSourceRelativePath());
183
+        });
169 184
         setupTextFieldListener(_textDataSourceTemplate.getTextField(), s -> {
170 185
             _options.setDataSourceTemplateRelativePath(Helper.getRelativePath(_project, s));
171 186
             _lblDataSourceTemplatePath.setText("$ProjectRoot/" + _options.getDataSourceTemplateRelativePath());

+ 36
- 14
src/com/rthoni/intellij/codefromds/ui/forms/GenerateForm.form View File

@@ -13,7 +13,7 @@
13 13
           <grid row="3" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
14 14
         </constraints>
15 15
       </vspacer>
16
-      <grid id="6946b" layout-manager="GridLayoutManager" row-count="10" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
16
+      <grid id="6946b" layout-manager="GridLayoutManager" row-count="12" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
17 17
         <margin top="0" left="0" bottom="0" right="0"/>
18 18
         <constraints>
19 19
           <grid row="2" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -37,7 +37,7 @@
37 37
           </component>
38 38
           <component id="f3fdd" class="javax.swing.JLabel">
39 39
             <constraints>
40
-              <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
40
+              <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
41 41
             </constraints>
42 42
             <properties>
43 43
               <text value="Data Source Template:"/>
@@ -45,7 +45,7 @@
45 45
           </component>
46 46
           <component id="91f63" class="javax.swing.JLabel">
47 47
             <constraints>
48
-              <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
48
+              <grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
49 49
             </constraints>
50 50
             <properties>
51 51
               <text value="Models Template:"/>
@@ -53,19 +53,19 @@
53 53
           </component>
54 54
           <component id="a074b" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="_textDataSourceTemplate">
55 55
             <constraints>
56
-              <grid row="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
56
+              <grid row="4" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
57 57
             </constraints>
58 58
             <properties/>
59 59
           </component>
60 60
           <component id="88c45" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="_textModelsTemplate">
61 61
             <constraints>
62
-              <grid row="4" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
62
+              <grid row="6" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
63 63
             </constraints>
64 64
             <properties/>
65 65
           </component>
66 66
           <component id="22d0d" class="javax.swing.JLabel">
67 67
             <constraints>
68
-              <grid row="9" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
68
+              <grid row="11" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
69 69
             </constraints>
70 70
             <properties>
71 71
               <text value="Configuration File:"/>
@@ -73,7 +73,7 @@
73 73
           </component>
74 74
           <component id="4c3cb" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="_textConfigPath">
75 75
             <constraints>
76
-              <grid row="9" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
76
+              <grid row="11" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
77 77
             </constraints>
78 78
             <properties/>
79 79
           </component>
@@ -87,7 +87,7 @@
87 87
           </component>
88 88
           <component id="1ec86" class="javax.swing.JLabel" binding="_lblDataSourceTemplatePath">
89 89
             <constraints>
90
-              <grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
90
+              <grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
91 91
             </constraints>
92 92
             <properties>
93 93
               <text value="$ProjectRoot/"/>
@@ -95,7 +95,7 @@
95 95
           </component>
96 96
           <component id="fab09" class="javax.swing.JLabel" binding="_lblModelsTemplatePath">
97 97
             <constraints>
98
-              <grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
98
+              <grid row="7" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
99 99
             </constraints>
100 100
             <properties>
101 101
               <text value="$ProjectRoot/"/>
@@ -103,7 +103,7 @@
103 103
           </component>
104 104
           <component id="c0c9e" class="javax.swing.JLabel">
105 105
             <constraints>
106
-              <grid row="8" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
106
+              <grid row="10" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
107 107
             </constraints>
108 108
             <properties>
109 109
               <text value="Files extension:"/>
@@ -111,7 +111,7 @@
111 111
           </component>
112 112
           <component id="880ce" class="javax.swing.JTextField" binding="_textFilesExtension">
113 113
             <constraints>
114
-              <grid row="8" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
114
+              <grid row="10" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
115 115
                 <preferred-size width="150" height="-1"/>
116 116
               </grid>
117 117
             </constraints>
@@ -119,7 +119,7 @@
119 119
           </component>
120 120
           <component id="3cbf6" class="javax.swing.JLabel">
121 121
             <constraints>
122
-              <grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
122
+              <grid row="8" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
123 123
             </constraints>
124 124
             <properties>
125 125
               <text value="Type Cast File:"/>
@@ -127,13 +127,35 @@
127 127
           </component>
128 128
           <component id="853dd" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="_textCastFile">
129 129
             <constraints>
130
-              <grid row="6" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
130
+              <grid row="8" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
131 131
             </constraints>
132 132
             <properties/>
133 133
           </component>
134 134
           <component id="8682b" class="javax.swing.JLabel" binding="_lblCastFile">
135 135
             <constraints>
136
-              <grid row="7" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
136
+              <grid row="9" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
137
+            </constraints>
138
+            <properties>
139
+              <text value="$ProjectRoot/"/>
140
+            </properties>
141
+          </component>
142
+          <component id="e6ec4" class="javax.swing.JLabel">
143
+            <constraints>
144
+              <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
145
+            </constraints>
146
+            <properties>
147
+              <text value="Data Source File:"/>
148
+            </properties>
149
+          </component>
150
+          <component id="69ea" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="_textDataSource">
151
+            <constraints>
152
+              <grid row="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
153
+            </constraints>
154
+            <properties/>
155
+          </component>
156
+          <component id="334c0" class="javax.swing.JLabel" binding="_lblDataSourcePath">
157
+            <constraints>
158
+              <grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
137 159
             </constraints>
138 160
             <properties>
139 161
               <text value="$ProjectRoot/"/>

Loading…
Cancel
Save