Browse Source

refactor

develop
Robin Thoni 7 years ago
parent
commit
2693a1d5a6
1 changed files with 32 additions and 31 deletions
  1. 32
    31
      src/com/rthoni/intellij/codefromds/ui/dialogs/GenerateDialog.java

+ 32
- 31
src/com/rthoni/intellij/codefromds/ui/dialogs/GenerateDialog.java View File

@@ -32,14 +32,15 @@ import java.util.function.Consumer;
32 32
 import java.util.stream.Collectors;
33 33
 
34 34
 /**
35
+ *
35 36
  * Created by robin on 11/14/16.
36 37
  */
37 38
 public class GenerateDialog extends DialogWrapper {
38 39
 
39 40
     private JPanel _panel;
40
-    private JBList _listDatasources;
41
-    private JBList _listTables;
42
-    private JBList _listColumns;
41
+    private JBList<String> _listDatasources;
42
+    private JBList<String> _listTables;
43
+    private JBList<String> _listColumns;
43 44
     private TextFieldWithBrowseButton _textModels;
44 45
     private TextFieldWithBrowseButton _textDataSource;
45 46
     private TextFieldWithBrowseButton _textDataSourceTemplate;
@@ -52,7 +53,7 @@ public class GenerateDialog extends DialogWrapper {
52 53
     private JLabel _lblModelsTemplatePath;
53 54
     private TextFieldWithBrowseButton _textCastFile;
54 55
     private JLabel _lblCastFile;
55
-    private JBList _listStoredProcedure;
56
+    private JBList<String> _listStoredProcedure;
56 57
 
57 58
     private GenerateOptions _options;
58 59
 
@@ -61,7 +62,7 @@ public class GenerateDialog extends DialogWrapper {
61 62
     public GenerateDialog(Project project) {
62 63
         super(project);
63 64
         _project = project;
64
-        setTitle("Code FROM data source");
65
+        setTitle("Code FROM Data Source");
65 66
         setOptions(null);
66 67
         init();
67 68
     }
@@ -97,20 +98,20 @@ public class GenerateDialog extends DialogWrapper {
97 98
     @Nullable
98 99
     @Override
99 100
     protected ValidationInfo doValidate() {
100
-        ValidationInfo info = null;
101
-        File modelDir = _options == null ? null : new File(Helper.getAbsolutePath(_project, _options.getModelsRelativePath()));
102
-        File dataSourcePath = _options == null ? null : new File(Helper.getAbsolutePath(_project, _options.getDataSourceRelativePath()));
103
-        File dataSourceDir = _options == null ? null : new File(dataSourcePath.getParent());
104
-        File dataSourceTemplatePath = _options == null ? null : new File(Helper.getAbsolutePath(_project, _options.getDataSourceTemplateRelativePath()));
105
-        File modelsTemplatePath = _options == null ? null : new File(Helper.getAbsolutePath(_project, _options.getModelsTemplateRelativePath()));
106
-        File configPath = _options == null ? null : new File(_options.getConfigAbsolutePath());
107
-        File configDir = _options == null ? null : new File(configPath.getParent());
108
-        String extension = _options == null ? null : _options.getFilesExtension();
109
-        File castFilePath = _options == null ? null : new File(Helper.getAbsolutePath(_project, _options.getCastFileRelativePath()));
110 101
         if (_options == null) {
111
-            info = new ValidationInfo("No Data Source Selected", _listDatasources);
102
+            return new ValidationInfo("No Data Source Selected", _listDatasources);
112 103
         }
113
-        else if (!modelDir.exists() || !modelDir.isDirectory()) {
104
+        ValidationInfo info = null;
105
+        File modelDir = new File(Helper.getAbsolutePath(_project, _options.getModelsRelativePath()));
106
+        File dataSourcePath = new File(Helper.getAbsolutePath(_project, _options.getDataSourceRelativePath()));
107
+        File dataSourceDir = new File(dataSourcePath.getParent());
108
+        File dataSourceTemplatePath = new File(Helper.getAbsolutePath(_project, _options.getDataSourceTemplateRelativePath()));
109
+        File modelsTemplatePath = new File(Helper.getAbsolutePath(_project, _options.getModelsTemplateRelativePath()));
110
+        File configPath = new File(_options.getConfigAbsolutePath());
111
+        File configDir = new File(configPath.getParent());
112
+        String extension = _options.getFilesExtension();
113
+        File castFilePath = new File(Helper.getAbsolutePath(_project, _options.getCastFileRelativePath()));
114
+        if (!modelDir.exists() || !modelDir.isDirectory()) {
114 115
             info = new ValidationInfo("Models folder does not exists", _textModels.getTextField());
115 116
         }
116 117
         else if (!dataSourceDir.exists() || !dataSourceDir.isDirectory()) {
@@ -169,12 +170,12 @@ public class GenerateDialog extends DialogWrapper {
169 170
             }
170 171
         });
171 172
 
172
-        setupTextField(_textModels, null, true, "Models");
173
-        setupTextField(_textDataSource, null, false, "Data Source");
174
-        setupTextField(_textDataSourceTemplate, null, false, "Data Source Template");
175
-        setupTextField(_textModelsTemplate, null, false, "Models Template");
176
-        setupTextField(_textConfigPath, null, false, "Configuration");
177
-        setupTextField(_textCastFile, null, false, "Types Cast");
173
+        setupTextField(_textModels, true, "Models");
174
+        setupTextField(_textDataSource, false, "Data Source");
175
+        setupTextField(_textDataSourceTemplate, false, "Data Source Template");
176
+        setupTextField(_textModelsTemplate, false, "Models Template");
177
+        setupTextField(_textConfigPath, false, "Configuration");
178
+        setupTextField(_textCastFile, false, "Types Cast");
178 179
 
179 180
         setupTextFieldListener(_textModels.getTextField(), s -> {
180 181
             _options.setModelsRelativePath(Helper.getRelativePath(_project, s));
@@ -200,9 +201,9 @@ public class GenerateDialog extends DialogWrapper {
200 201
             _lblCastFile.setText("$ProjectRoot/" + _options.getCastFileRelativePath());
201 202
         });
202 203
 
203
-        _listTables.setCellRenderer(new ColoredListCellRenderer() {
204
+        _listTables.setCellRenderer(new ColoredListCellRenderer<String>() {
204 205
             @Override
205
-            protected void customizeCellRenderer(@NotNull JList jList, Object o, int i, boolean b, boolean b1) {
206
+            protected void customizeCellRenderer(@NotNull JList jList, String o, int i, boolean b, boolean b1) {
206 207
                 TableDataSourceDbo tableSelection = _options.getDataSource().getTables().get(i);
207 208
                 if (tableSelection.hasAll()) {
208 209
                     setBackground(JBColor.GREEN);
@@ -256,19 +257,19 @@ public class GenerateDialog extends DialogWrapper {
256 257
                 changed();
257 258
             }
258 259
 
259
-            public void changed() {
260
+            void changed() {
260 261
                 consumer.accept(field.getText());
261 262
             }
262 263
         });
263 264
     }
264 265
 
265
-    private void setupTextField(TextFieldWithBrowseButton field, Project project, boolean dirsOnly, String title)
266
+    private void setupTextField(TextFieldWithBrowseButton field, boolean dirsOnly, String title)
266 267
     {
267 268
         for (ActionListener l : field.getButton().getActionListeners()) {
268 269
             field.getButton().removeActionListener(l);
269 270
         }
270 271
         field.addBrowseFolderListener("Choose " + title + " " + (dirsOnly ? "Folder" : "File"),
271
-                "Choose " + (dirsOnly ? "Folder" : "File"), project,
272
+                "Choose " + (dirsOnly ? "Folder" : "File"), null,
272 273
                 dirsOnly ? FileChooserDescriptorFactory.createSingleFolderDescriptor() : FileChooserDescriptorFactory.createSingleFileDescriptor());
273 274
     }
274 275
 
@@ -279,7 +280,7 @@ public class GenerateDialog extends DialogWrapper {
279 280
         }
280 281
         if (source != null) {
281 282
 
282
-            List<String> tables = source.getTables().stream().map(t -> t.getName()).collect(Collectors.toList());
283
+            List<String> tables = source.getTables().stream().map(TableDataSourceDbo::getName).collect(Collectors.toList());
283 284
             _listTables.setListData(tables.toArray(new String[tables.size()]));
284 285
             if (tables.size() > 0) {
285 286
                 showTable(source.getTables().get(0));
@@ -287,7 +288,7 @@ public class GenerateDialog extends DialogWrapper {
287 288
             else {
288 289
                 showTable(null);
289 290
             }
290
-            List<String> sps = source.getStoredProcedures().stream().map(t -> t.getFullName()).collect(Collectors.toList());
291
+            List<String> sps = source.getStoredProcedures().stream().map(StoredProcedureDbo::getFullName).collect(Collectors.toList());
291 292
             _listStoredProcedure.setListData(sps.toArray(new String[sps.size()]));
292 293
             int[] indices = getSpSelectedIndices(source);
293 294
             _listStoredProcedure.setSelectedIndices(indices);
@@ -352,7 +353,7 @@ public class GenerateDialog extends DialogWrapper {
352 353
             _listColumns.removeListSelectionListener(e);
353 354
         }
354 355
         if (table != null) {
355
-            _listColumns.setListData(table.getColumns().stream().map(c -> c.getName()).toArray(String[]::new));
356
+            _listColumns.setListData(table.getColumns().stream().map(ColumnDataSourceDbo::getName).toArray(String[]::new));
356 357
             int[] indices = getColumnsSelectedIndices(table);
357 358
             _listColumns.setSelectedIndices(indices);
358 359
             _listColumns.addListSelectionListener(e -> {

Loading…
Cancel
Save