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
 import java.util.stream.Collectors;
32
 import java.util.stream.Collectors;
33
 
33
 
34
 /**
34
 /**
35
+ *
35
  * Created by robin on 11/14/16.
36
  * Created by robin on 11/14/16.
36
  */
37
  */
37
 public class GenerateDialog extends DialogWrapper {
38
 public class GenerateDialog extends DialogWrapper {
38
 
39
 
39
     private JPanel _panel;
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
     private TextFieldWithBrowseButton _textModels;
44
     private TextFieldWithBrowseButton _textModels;
44
     private TextFieldWithBrowseButton _textDataSource;
45
     private TextFieldWithBrowseButton _textDataSource;
45
     private TextFieldWithBrowseButton _textDataSourceTemplate;
46
     private TextFieldWithBrowseButton _textDataSourceTemplate;
52
     private JLabel _lblModelsTemplatePath;
53
     private JLabel _lblModelsTemplatePath;
53
     private TextFieldWithBrowseButton _textCastFile;
54
     private TextFieldWithBrowseButton _textCastFile;
54
     private JLabel _lblCastFile;
55
     private JLabel _lblCastFile;
55
-    private JBList _listStoredProcedure;
56
+    private JBList<String> _listStoredProcedure;
56
 
57
 
57
     private GenerateOptions _options;
58
     private GenerateOptions _options;
58
 
59
 
61
     public GenerateDialog(Project project) {
62
     public GenerateDialog(Project project) {
62
         super(project);
63
         super(project);
63
         _project = project;
64
         _project = project;
64
-        setTitle("Code FROM data source");
65
+        setTitle("Code FROM Data Source");
65
         setOptions(null);
66
         setOptions(null);
66
         init();
67
         init();
67
     }
68
     }
97
     @Nullable
98
     @Nullable
98
     @Override
99
     @Override
99
     protected ValidationInfo doValidate() {
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
         if (_options == null) {
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
             info = new ValidationInfo("Models folder does not exists", _textModels.getTextField());
115
             info = new ValidationInfo("Models folder does not exists", _textModels.getTextField());
115
         }
116
         }
116
         else if (!dataSourceDir.exists() || !dataSourceDir.isDirectory()) {
117
         else if (!dataSourceDir.exists() || !dataSourceDir.isDirectory()) {
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
         setupTextFieldListener(_textModels.getTextField(), s -> {
180
         setupTextFieldListener(_textModels.getTextField(), s -> {
180
             _options.setModelsRelativePath(Helper.getRelativePath(_project, s));
181
             _options.setModelsRelativePath(Helper.getRelativePath(_project, s));
200
             _lblCastFile.setText("$ProjectRoot/" + _options.getCastFileRelativePath());
201
             _lblCastFile.setText("$ProjectRoot/" + _options.getCastFileRelativePath());
201
         });
202
         });
202
 
203
 
203
-        _listTables.setCellRenderer(new ColoredListCellRenderer() {
204
+        _listTables.setCellRenderer(new ColoredListCellRenderer<String>() {
204
             @Override
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
                 TableDataSourceDbo tableSelection = _options.getDataSource().getTables().get(i);
207
                 TableDataSourceDbo tableSelection = _options.getDataSource().getTables().get(i);
207
                 if (tableSelection.hasAll()) {
208
                 if (tableSelection.hasAll()) {
208
                     setBackground(JBColor.GREEN);
209
                     setBackground(JBColor.GREEN);
256
                 changed();
257
                 changed();
257
             }
258
             }
258
 
259
 
259
-            public void changed() {
260
+            void changed() {
260
                 consumer.accept(field.getText());
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
         for (ActionListener l : field.getButton().getActionListeners()) {
268
         for (ActionListener l : field.getButton().getActionListeners()) {
268
             field.getButton().removeActionListener(l);
269
             field.getButton().removeActionListener(l);
269
         }
270
         }
270
         field.addBrowseFolderListener("Choose " + title + " " + (dirsOnly ? "Folder" : "File"),
271
         field.addBrowseFolderListener("Choose " + title + " " + (dirsOnly ? "Folder" : "File"),
271
-                "Choose " + (dirsOnly ? "Folder" : "File"), project,
272
+                "Choose " + (dirsOnly ? "Folder" : "File"), null,
272
                 dirsOnly ? FileChooserDescriptorFactory.createSingleFolderDescriptor() : FileChooserDescriptorFactory.createSingleFileDescriptor());
273
                 dirsOnly ? FileChooserDescriptorFactory.createSingleFolderDescriptor() : FileChooserDescriptorFactory.createSingleFileDescriptor());
273
     }
274
     }
274
 
275
 
279
         }
280
         }
280
         if (source != null) {
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
             _listTables.setListData(tables.toArray(new String[tables.size()]));
284
             _listTables.setListData(tables.toArray(new String[tables.size()]));
284
             if (tables.size() > 0) {
285
             if (tables.size() > 0) {
285
                 showTable(source.getTables().get(0));
286
                 showTable(source.getTables().get(0));
287
             else {
288
             else {
288
                 showTable(null);
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
             _listStoredProcedure.setListData(sps.toArray(new String[sps.size()]));
292
             _listStoredProcedure.setListData(sps.toArray(new String[sps.size()]));
292
             int[] indices = getSpSelectedIndices(source);
293
             int[] indices = getSpSelectedIndices(source);
293
             _listStoredProcedure.setSelectedIndices(indices);
294
             _listStoredProcedure.setSelectedIndices(indices);
352
             _listColumns.removeListSelectionListener(e);
353
             _listColumns.removeListSelectionListener(e);
353
         }
354
         }
354
         if (table != null) {
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
             int[] indices = getColumnsSelectedIndices(table);
357
             int[] indices = getColumnsSelectedIndices(table);
357
             _listColumns.setSelectedIndices(indices);
358
             _listColumns.setSelectedIndices(indices);
358
             _listColumns.addListSelectionListener(e -> {
359
             _listColumns.addListSelectionListener(e -> {

Loading…
Cancel
Save