|
@@ -61,6 +61,33 @@ public class GenerateDialog extends DialogWrapper {
|
61
|
61
|
return _options;
|
62
|
62
|
}
|
63
|
63
|
|
|
64
|
+ public void setOptions(GenerateOptions options) {
|
|
65
|
+ _options = options;
|
|
66
|
+ if (_options != null) {
|
|
67
|
+ 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
|
+ _textModels.setText(_options.getModelsPath());
|
|
74
|
+ _textDataSOurceTemplate.setText(_options.getDataSourceTemplatePath());
|
|
75
|
+ _textModelsTemplate.setText(_options.getModelsTemplatePath());
|
|
76
|
+ _textConfigPath.setText(_options.getConfigPath());
|
|
77
|
+ }
|
|
78
|
+ else {
|
|
79
|
+ showSource(null);
|
|
80
|
+ setupTextField(_textModels, null);
|
|
81
|
+ setupTextField(_textDataSOurceTemplate, null);
|
|
82
|
+ setupTextField(_textModelsTemplate, null);
|
|
83
|
+ setupTextField(_textConfigPath, null);
|
|
84
|
+ _textModels.setText("");
|
|
85
|
+ _textDataSOurceTemplate.setText("");
|
|
86
|
+ _textModelsTemplate.setText("");
|
|
87
|
+ _textConfigPath.setText("");
|
|
88
|
+ }
|
|
89
|
+ }
|
|
90
|
+
|
64
|
91
|
@Nullable
|
65
|
92
|
@Override
|
66
|
93
|
protected ValidationInfo doValidate() {
|
|
@@ -89,10 +116,10 @@ public class GenerateDialog extends DialogWrapper {
|
89
|
116
|
if (!e.getValueIsAdjusting()) {
|
90
|
117
|
int index = _listDatasources.getSelectedIndex();
|
91
|
118
|
if (index == -1) {
|
92
|
|
- showSource(null);
|
|
119
|
+ setOptions(null);
|
93
|
120
|
}
|
94
|
121
|
else {
|
95
|
|
- showSource(dataSources.get(index));
|
|
122
|
+ setOptions(new GenerateOptions(dataSources.get(index)));
|
96
|
123
|
}
|
97
|
124
|
}
|
98
|
125
|
});
|
|
@@ -128,6 +155,23 @@ public class GenerateDialog extends DialogWrapper {
|
128
|
155
|
}
|
129
|
156
|
});
|
130
|
157
|
|
|
158
|
+ _listTables.setCellRenderer(new ColoredListCellRenderer() {
|
|
159
|
+ @Override
|
|
160
|
+ protected void customizeCellRenderer(@NotNull JList jList, Object o, int i, boolean b, boolean b1) {
|
|
161
|
+ TableSelection tableSelection = _options.getSelection().getTables().get(i);
|
|
162
|
+ if (tableSelection.hasAll()) {
|
|
163
|
+ setBackground(JBColor.GREEN);
|
|
164
|
+ }
|
|
165
|
+ else if (tableSelection.hasNone()) {
|
|
166
|
+ setBackground(JBColor.RED);
|
|
167
|
+ }
|
|
168
|
+ else {
|
|
169
|
+ setBackground(JBColor.ORANGE);
|
|
170
|
+ }
|
|
171
|
+ append(tableSelection.getTable().getName());
|
|
172
|
+ }
|
|
173
|
+ });
|
|
174
|
+
|
131
|
175
|
if (dataSources.size() > 0) {
|
132
|
176
|
_listDatasources.setSelectedIndices(new int[]{0});
|
133
|
177
|
}
|
|
@@ -135,58 +179,30 @@ public class GenerateDialog extends DialogWrapper {
|
135
|
179
|
return _panel;
|
136
|
180
|
}
|
137
|
181
|
|
138
|
|
- private void showSource(DbDataSource source)
|
|
182
|
+ private void setupTextField(TextFieldWithBrowseButton field, Project project)
|
139
|
183
|
{
|
140
|
|
- showTable(null);
|
141
|
|
- for (ActionListener l : _textModels.getButton().getActionListeners()) {
|
142
|
|
- _textModels.getButton().removeActionListener(l);
|
|
184
|
+ for (ActionListener l : field.getButton().getActionListeners()) {
|
|
185
|
+ field.getButton().removeActionListener(l);
|
143
|
186
|
}
|
144
|
|
- if (source != null) {
|
145
|
|
- _options = new GenerateOptions();
|
146
|
|
-
|
147
|
|
- _listTables.setCellRenderer(new ColoredListCellRenderer() {
|
148
|
|
- @Override
|
149
|
|
- protected void customizeCellRenderer(@NotNull JList jList, Object o, int i, boolean b, boolean b1) {
|
150
|
|
- TableSelection tableSelection = _options.getSelection().getTables().get(i);
|
151
|
|
- if (tableSelection.hasAll()) {
|
152
|
|
- setBackground(JBColor.GREEN);
|
153
|
|
- }
|
154
|
|
- else if (tableSelection.hasNone()) {
|
155
|
|
- setBackground(JBColor.RED);
|
156
|
|
- }
|
157
|
|
- else {
|
158
|
|
- setBackground(JBColor.ORANGE);
|
159
|
|
- }
|
160
|
|
- append(tableSelection.getTable().getName());
|
161
|
|
- }
|
162
|
|
- });
|
|
187
|
+ field.addBrowseFolderListener("Choose Models Destination Folder", "Choose folder",
|
|
188
|
+ project, FileChooserDescriptorFactory.createSingleFolderDescriptor());
|
|
189
|
+ }
|
163
|
190
|
|
164
|
|
- _textModels.setText(source.getProject().getBasePath() + File.separator + "Models");
|
165
|
|
- _textModels.addBrowseFolderListener("Choose Models Destination Folder", "Choose folder",
|
166
|
|
- source.getProject(), FileChooserDescriptorFactory.createSingleFolderDescriptor());
|
167
|
|
-
|
168
|
|
- _options.setSelection(new DataSourceSelection());
|
169
|
|
- _options.getSelection().setSource(source);
|
170
|
|
- final List<? extends DasTable> tables = DasUtil.getTables(source).toList();
|
171
|
|
- List<TableSelection> tableSelections = new Vector<>();
|
172
|
|
- for (DasTable table : tables) {
|
173
|
|
- TableSelection tableSelection = new TableSelection();
|
174
|
|
- tableSelection.setTable(table);
|
175
|
|
- tableSelection.setColumns(DasUtil.getColumns(table).toList().stream().map(c -> {
|
176
|
|
- ColumnSelection selection = new ColumnSelection();
|
177
|
|
- selection.setColumn(c);
|
178
|
|
- selection.setSelected(true);
|
179
|
|
- return selection;
|
180
|
|
- }).collect(Collectors.toList()));
|
181
|
|
- tableSelections.add(tableSelection);
|
|
191
|
+ private void showSource(DataSourceSelection source)
|
|
192
|
+ {
|
|
193
|
+ if (source != null) {
|
|
194
|
+ List<String> tables = source.getTables().stream().map(t -> t.getTable().getName()).collect(Collectors.toList());
|
|
195
|
+ _listTables.setListData(tables.toArray(new String[tables.size()]));
|
|
196
|
+ if (tables.size() > 0) {
|
|
197
|
+ showTable(source.getTables().get(0));
|
|
198
|
+ }
|
|
199
|
+ else {
|
|
200
|
+ showTable(null);
|
182
|
201
|
}
|
183
|
|
- _options.getSelection().setTables(tableSelections);
|
184
|
|
-
|
185
|
|
- _listTables.setListData(tables.stream().map(DasObject::getName).toArray(String[]::new));
|
186
|
202
|
}
|
187
|
203
|
else {
|
188
|
|
- _options = null;
|
189
|
204
|
_listTables.setListData(new String[]{});
|
|
205
|
+ showTable(null);
|
190
|
206
|
}
|
191
|
207
|
}
|
192
|
208
|
|
|
@@ -212,10 +228,10 @@ public class GenerateDialog extends DialogWrapper {
|
212
|
228
|
|
213
|
229
|
private void showTable(TableSelection table)
|
214
|
230
|
{
|
|
231
|
+ for (ListSelectionListener e : _listColumns.getListSelectionListeners()) {
|
|
232
|
+ _listColumns.removeListSelectionListener(e);
|
|
233
|
+ }
|
215
|
234
|
if (table != null) {
|
216
|
|
- for (ListSelectionListener e : _listColumns.getListSelectionListeners()) {
|
217
|
|
- _listColumns.removeListSelectionListener(e);
|
218
|
|
- }
|
219
|
235
|
_listColumns.setListData(table.getColumns().stream().map(c -> c.getColumn().getName()).toArray(String[]::new));
|
220
|
236
|
int[] indices = getSelectedIndices(table);
|
221
|
237
|
_listColumns.setSelectedIndices(indices);
|