|
@@ -15,6 +15,7 @@ import com.intellij.openapi.ui.ValidationInfo;
|
15
|
15
|
import com.intellij.ui.ColoredListCellRenderer;
|
16
|
16
|
import com.intellij.ui.JBColor;
|
17
|
17
|
import com.intellij.ui.components.JBList;
|
|
18
|
+import com.rthoni.intellij.codefromds.business.Helper;
|
18
|
19
|
import com.rthoni.intellij.codefromds.dbo.ColumnSelection;
|
19
|
20
|
import com.rthoni.intellij.codefromds.dbo.DataSourceSelection;
|
20
|
21
|
import com.rthoni.intellij.codefromds.dbo.GenerateOptions;
|
|
@@ -32,6 +33,7 @@ import java.util.Arrays;
|
32
|
33
|
import java.util.Collection;
|
33
|
34
|
import java.util.List;
|
34
|
35
|
import java.util.Vector;
|
|
36
|
+import java.util.function.Consumer;
|
35
|
37
|
import java.util.stream.Collectors;
|
36
|
38
|
|
37
|
39
|
/**
|
|
@@ -53,7 +55,7 @@ public class GenerateDialog extends DialogWrapper {
|
53
|
55
|
public GenerateDialog(@Nullable Project project) {
|
54
|
56
|
super(project);
|
55
|
57
|
setTitle("Code FROM data source");
|
56
|
|
- showSource(null);
|
|
58
|
+ setOptions(null);
|
57
|
59
|
init();
|
58
|
60
|
}
|
59
|
61
|
|
|
@@ -65,11 +67,6 @@ public class GenerateDialog extends DialogWrapper {
|
65
|
67
|
_options = options;
|
66
|
68
|
if (_options != null) {
|
67
|
69
|
showSource(_options.getSelection());
|
68
|
|
- Project project = _options.getSelection().getSource().getProject();
|
69
|
|
- setupTextField(_textModels, project);
|
70
|
|
- setupTextField(_textDataSOurceTemplate, project);
|
71
|
|
- setupTextField(_textModelsTemplate, project);
|
72
|
|
- setupTextField(_textConfigPath, project);
|
73
|
70
|
_textModels.setText(_options.getModelsPath());
|
74
|
71
|
_textDataSOurceTemplate.setText(_options.getDataSourceTemplatePath());
|
75
|
72
|
_textModelsTemplate.setText(_options.getModelsTemplatePath());
|
|
@@ -77,10 +74,6 @@ public class GenerateDialog extends DialogWrapper {
|
77
|
74
|
}
|
78
|
75
|
else {
|
79
|
76
|
showSource(null);
|
80
|
|
- setupTextField(_textModels, null);
|
81
|
|
- setupTextField(_textDataSOurceTemplate, null);
|
82
|
|
- setupTextField(_textModelsTemplate, null);
|
83
|
|
- setupTextField(_textConfigPath, null);
|
84
|
77
|
_textModels.setText("");
|
85
|
78
|
_textDataSOurceTemplate.setText("");
|
86
|
79
|
_textModelsTemplate.setText("");
|
|
@@ -93,11 +86,24 @@ public class GenerateDialog extends DialogWrapper {
|
93
|
86
|
protected ValidationInfo doValidate() {
|
94
|
87
|
ValidationInfo info = null;
|
95
|
88
|
File modelDir = _options == null ? null : new File(_options.getModelsPath());
|
|
89
|
+ File dataSourceTemplatePath = _options == null ? null : new File(_options.getDataSourceTemplatePath());
|
|
90
|
+ File modelsTemplatePath = _options == null ? null : new File(_options.getModelsTemplatePath());
|
|
91
|
+ File configPath = _options == null ? null : new File(_options.getConfigPath());
|
|
92
|
+ File configDir = _options == null ? null : new File(configPath.getParent());
|
96
|
93
|
if (_options == null) {
|
97
|
94
|
info = new ValidationInfo("No Data Source Selected", _listDatasources);
|
98
|
95
|
}
|
99
|
96
|
else if (!modelDir.exists() || !modelDir.isDirectory()) {
|
100
|
|
- info = new ValidationInfo("Bad Model Folder", _textModels.getTextField());
|
|
97
|
+ info = new ValidationInfo("Models folder does not exists", _textModels.getTextField());
|
|
98
|
+ }
|
|
99
|
+ else if (!dataSourceTemplatePath.exists() || !dataSourceTemplatePath.isFile()) {
|
|
100
|
+ info = new ValidationInfo("Data source template file does not exists", _textDataSOurceTemplate.getTextField());
|
|
101
|
+ }
|
|
102
|
+ else if (!modelsTemplatePath.exists() || !modelsTemplatePath.isFile()) {
|
|
103
|
+ info = new ValidationInfo("Models template file does not exists", _textModelsTemplate.getTextField());
|
|
104
|
+ }
|
|
105
|
+ else if (!configDir.exists() || !configDir.isDirectory()) {
|
|
106
|
+ info = new ValidationInfo("Configuration file parent folder does not exists", _textConfigPath.getTextField());
|
101
|
107
|
}
|
102
|
108
|
|
103
|
109
|
return info;
|
|
@@ -106,10 +112,8 @@ public class GenerateDialog extends DialogWrapper {
|
106
|
112
|
@Nullable
|
107
|
113
|
@Override
|
108
|
114
|
protected JComponent createCenterPanel() {
|
109
|
|
- ProjectManager pm = ProjectManager.getInstance();
|
110
|
|
- Project[] projects = pm.getOpenProjects();
|
111
|
115
|
|
112
|
|
- List<DbDataSource> dataSources = Arrays.stream(projects).map(project -> DbPsiFacade.getInstance(project).getDataSources()).flatMap(Collection::stream).collect(Collectors.toList());
|
|
116
|
+ List<DbDataSource> dataSources = Helper.getDataSources();
|
113
|
117
|
|
114
|
118
|
_listDatasources.setListData(dataSources.stream().map(DasObject::getName).toArray(String[]::new));
|
115
|
119
|
_listDatasources.addListSelectionListener(e -> {
|
|
@@ -134,26 +138,16 @@ public class GenerateDialog extends DialogWrapper {
|
134
|
138
|
}
|
135
|
139
|
}
|
136
|
140
|
});
|
137
|
|
- _textModels.getTextField().getDocument().addDocumentListener(new DocumentListener() {
|
138
|
|
- @Override
|
139
|
|
- public void insertUpdate(DocumentEvent e) {
|
140
|
|
- changed();
|
141
|
|
- }
|
142
|
|
-
|
143
|
|
- @Override
|
144
|
|
- public void removeUpdate(DocumentEvent e) {
|
145
|
|
- changed();
|
146
|
|
- }
|
147
|
141
|
|
148
|
|
- @Override
|
149
|
|
- public void changedUpdate(DocumentEvent e) {
|
150
|
|
- changed();
|
151
|
|
- }
|
|
142
|
+ setupTextField(_textModels, null, true);
|
|
143
|
+ setupTextField(_textDataSOurceTemplate, null, false);
|
|
144
|
+ setupTextField(_textModelsTemplate, null, false);
|
|
145
|
+ setupTextField(_textConfigPath, null, false);
|
152
|
146
|
|
153
|
|
- public void changed() {
|
154
|
|
- _options.setModelsPath(_textModels.getText());
|
155
|
|
- }
|
156
|
|
- });
|
|
147
|
+ setupTextFieldListener(_textModels.getTextField(), s -> _options.setModelsPath(s));
|
|
148
|
+ setupTextFieldListener(_textDataSOurceTemplate.getTextField(), s -> _options.setDataSourceTemplatePath(s));
|
|
149
|
+ setupTextFieldListener(_textModelsTemplate.getTextField(), s -> _options.setModelsTemplatePath(s));
|
|
150
|
+ setupTextFieldListener(_textConfigPath.getTextField(), s -> _options.setConfigPath(s));
|
157
|
151
|
|
158
|
152
|
_listTables.setCellRenderer(new ColoredListCellRenderer() {
|
159
|
153
|
@Override
|
|
@@ -179,13 +173,37 @@ public class GenerateDialog extends DialogWrapper {
|
179
|
173
|
return _panel;
|
180
|
174
|
}
|
181
|
175
|
|
182
|
|
- private void setupTextField(TextFieldWithBrowseButton field, Project project)
|
|
176
|
+ private void setupTextFieldListener(JTextField field, Consumer<String> consumer)
|
|
177
|
+ {
|
|
178
|
+ field.getDocument().addDocumentListener(new DocumentListener() {
|
|
179
|
+ @Override
|
|
180
|
+ public void insertUpdate(DocumentEvent e) {
|
|
181
|
+ changed();
|
|
182
|
+ }
|
|
183
|
+
|
|
184
|
+ @Override
|
|
185
|
+ public void removeUpdate(DocumentEvent e) {
|
|
186
|
+ changed();
|
|
187
|
+ }
|
|
188
|
+
|
|
189
|
+ @Override
|
|
190
|
+ public void changedUpdate(DocumentEvent e) {
|
|
191
|
+ changed();
|
|
192
|
+ }
|
|
193
|
+
|
|
194
|
+ public void changed() {
|
|
195
|
+ consumer.accept(field.getText());
|
|
196
|
+ }
|
|
197
|
+ });
|
|
198
|
+ }
|
|
199
|
+
|
|
200
|
+ private void setupTextField(TextFieldWithBrowseButton field, Project project, boolean dirsOnly)
|
183
|
201
|
{
|
184
|
202
|
for (ActionListener l : field.getButton().getActionListeners()) {
|
185
|
203
|
field.getButton().removeActionListener(l);
|
186
|
204
|
}
|
187
|
|
- field.addBrowseFolderListener("Choose Models Destination Folder", "Choose folder",
|
188
|
|
- project, FileChooserDescriptorFactory.createSingleFolderDescriptor());
|
|
205
|
+ field.addBrowseFolderListener("Choose Models Destination Folder", "Choose folder", project,
|
|
206
|
+ dirsOnly ? FileChooserDescriptorFactory.createSingleFolderDescriptor() : FileChooserDescriptorFactory.createSingleFileDescriptor());
|
189
|
207
|
}
|
190
|
208
|
|
191
|
209
|
private void showSource(DataSourceSelection source)
|