Browse Source

save/load options; removed old options

develop
Robin Thoni 7 years ago
parent
commit
c2ae71b336

+ 1
- 1
TODO View File

@@ -2,4 +2,4 @@ proc stock
2 2
 many to many
3 3
 table inheritance
4 4
 generate custom types (sp return)
5
-UI for sp selection
5
+UI for sp dataSource

+ 1
- 1
src/com/rthoni/intellij/codefromds/DataAccess/DataSourcesDataAccess.java View File

@@ -102,7 +102,7 @@ public class DataSourcesDataAccess {
102 102
             else if (dasObject instanceof DbRoutine) {
103 103
                 DbRoutine sp = (DbRoutine) dasObject;
104 104
                 StoredProcedureDbo spDbo = new StoredProcedureDbo();
105
-                spDbo.setSelected(true);
105
+                spDbo.setSelected(false);
106 106
                 spDbo.setName(sp.getName());
107 107
                 spDbo.setFullName(sp.getText());
108 108
                 dataSourceDbo.addStoredProcedure(spDbo);

+ 11
- 27
src/com/rthoni/intellij/codefromds/business/Generator.java View File

@@ -20,7 +20,6 @@ import java.io.IOException;
20 20
 import java.util.HashMap;
21 21
 import java.util.List;
22 22
 import java.util.Vector;
23
-import java.util.function.Consumer;
24 23
 
25 24
 /**
26 25
  * Created by robin on 11/15/16.
@@ -48,7 +47,7 @@ public abstract class Generator {
48 47
             throw new Exception("Data source " + src + " not found");
49 48
         }
50 49
 
51
-        GenerateOptions options = new GenerateOptions(dataSource);
50
+        GenerateOptions options = new GenerateOptions(DataSourcesBusiness.getDataSourceDbo(src), configPath);
52 51
         options.setConfigAbsolutePath(configPath);
53 52
         options.fromJson(obj);
54 53
         return options;
@@ -126,39 +125,24 @@ public abstract class Generator {
126 125
 //        return list1.equals(list2);
127 126
 //    }
128 127
 
129
-    public static DataSourceDbo convertOptions(GenerateOptions options, TypesCastOptions types)
128
+    public static void convertOptions(GenerateOptions options, TypesCastOptions types)
130 129
     {
131
-        String dataSourceName = options.getSelection().getSource().getName();
132
-        DataSourceDbo dataSourceDbo = DataSourcesBusiness.getDataSourceDbo(dataSourceName);
133 130
 
134
-        for (TableDataSourceDbo table : dataSourceDbo.getTables())
131
+        for (TableDataSourceDbo table : options.getDataSource().getTables())
135 132
         {
136
-            TableSelection tableSelection = options.getSelection().getTables().stream()
137
-                    .filter(t -> t.getTable().getName().equals(table.getName()))
138
-                    .findFirst().orElse(null);
139 133
             for (ColumnDataSourceDbo column : table.getColumns())
140 134
             {
141
-                ColumnSelection columnSelection = tableSelection.getColumns().stream()
142
-                        .filter(c -> c.getColumn().getName().equals(column.getName()))
143
-                        .findFirst().orElse(null);
144
-                convertSqlType(column.getSqlType(), types, dataSourceDbo);
145
-                column.setSelected(columnSelection.isSelected());
135
+                convertSqlType(column.getSqlType(), types, options.getDataSource());
146 136
             }
147 137
         }
148 138
 
149
-        for (StoredProcedureDbo spDbo : dataSourceDbo.getStoredProcedures())
139
+        for (StoredProcedureDbo spDbo : options.getDataSource().getStoredProcedures())
150 140
         {
151
-            StoredProcedureSelection sp = options.getSelection().getStoredProcedures().stream()
152
-                    .filter(s -> s.getStoredProcedure().getText().equals(spDbo.getFullName()))
153
-                    .findFirst().orElse(null);
154
-            convertSqlType(spDbo.getSqlType(), types, dataSourceDbo);
155
-            spDbo.setSelected(sp.isSelected());
141
+            convertSqlType(spDbo.getSqlType(), types, options.getDataSource());
156 142
             for (StoredProcedureArgDbo arg : spDbo.getArguments()) {
157
-                convertSqlType(arg.getSqlType(), types, dataSourceDbo);
143
+                convertSqlType(arg.getSqlType(), types, options.getDataSource());
158 144
             }
159 145
         }
160
-
161
-        return dataSourceDbo;
162 146
     }
163 147
 
164 148
     public static TypesCastOptions loadTypesCast(String file) throws IOException
@@ -280,13 +264,13 @@ public abstract class Generator {
280 264
 
281 265
         TypesCastOptions types = loadTypesCast(typesCastAbsolutePath);
282 266
 
283
-        DataSourceDbo dbo = convertOptions(options, types);
267
+        convertOptions(options, types);
284 268
 
285
-        generateFile(dataSourceTemplateAbsolutePath, dataSourceAbsolutePath, dbo, null, types);
286
-        for (TableDataSourceDbo table : dbo.getTables()) {
269
+        generateFile(dataSourceTemplateAbsolutePath, dataSourceAbsolutePath, options.getDataSource(), null, types);
270
+        for (TableDataSourceDbo table : options.getDataSource().getTables()) {
287 271
             if (table.hasAny()) {
288 272
                 String filename = modelsAbsolutePath + File.separator + table.getName() + "." + options.getFilesExtension();
289
-                generateFile(modelsTemplateAbsolutePath, filename, dbo, table, types);
273
+                generateFile(modelsTemplateAbsolutePath, filename, options.getDataSource(), table, types);
290 274
             }
291 275
         }
292 276
     }

+ 0
- 52
src/com/rthoni/intellij/codefromds/dbo/options/ColumnSelection.java View File

@@ -1,52 +0,0 @@
1
-package com.rthoni.intellij.codefromds.dbo.options;
2
-
3
-import com.intellij.database.model.DasColumn;
4
-import org.json.JSONObject;
5
-
6
-import java.util.HashMap;
7
-
8
-/**
9
- * Created by robin on 11/15/16.
10
- */
11
-public class ColumnSelection {
12
-
13
-    private DasColumn _column;
14
-
15
-    private boolean _selected;
16
-
17
-    public ColumnSelection(DasColumn column) {
18
-        _column = column;
19
-        _selected = true;
20
-    }
21
-
22
-    public HashMap<String, Object> toMap()
23
-    {
24
-        HashMap<String, Object> map = new HashMap<>();
25
-
26
-        map.put("column", _column == null ? null : _column.getName());
27
-        map.put("selected", _selected);
28
-
29
-        return map;
30
-    }
31
-
32
-    public void fromJson(JSONObject json)
33
-    {
34
-        _selected = json.getBoolean("selected");
35
-    }
36
-
37
-    public DasColumn getColumn() {
38
-        return _column;
39
-    }
40
-
41
-    public void setColumn(DasColumn column) {
42
-        _column = column;
43
-    }
44
-
45
-    public boolean isSelected() {
46
-        return _selected;
47
-    }
48
-
49
-    public void setSelected(boolean selected) {
50
-        _selected = selected;
51
-    }
52
-}

+ 0
- 98
src/com/rthoni/intellij/codefromds/dbo/options/DataSourceSelection.java View File

@@ -1,98 +0,0 @@
1
-package com.rthoni.intellij.codefromds.dbo.options;
2
-
3
-import com.intellij.database.psi.DbDataSource;
4
-import com.intellij.database.util.DasUtil;
5
-import com.rthoni.intellij.codefromds.business.Helper;
6
-import org.json.JSONArray;
7
-import org.json.JSONObject;
8
-
9
-import java.util.HashMap;
10
-import java.util.List;
11
-import java.util.Vector;
12
-import java.util.stream.Collectors;
13
-
14
-/**
15
- * Created by robin on 11/15/16.
16
- */
17
-public class DataSourceSelection {
18
-
19
-    private DbDataSource _source;
20
-
21
-    private List<TableSelection> _tables;
22
-
23
-    private List<StoredProcedureSelection> _storedProcedures;
24
-
25
-    public DataSourceSelection(DbDataSource source) {
26
-        _source = source;
27
-        _tables = DasUtil.getTables(source).toList().stream().map(TableSelection::new).collect(Collectors.toList());
28
-        _storedProcedures = Helper.getRoutines(source).stream().map(StoredProcedureSelection::new).collect(Collectors.toList());
29
-    }
30
-
31
-    public HashMap<String, Object> toMap()
32
-    {
33
-        HashMap<String, Object> map = new HashMap<>();
34
-
35
-        map.put("source", _source == null ? null : _source.getName());
36
-
37
-        List<Object> tables = new Vector<>();
38
-        for (TableSelection table : _tables) {
39
-            tables.add(table.toMap());
40
-        }
41
-        map.put("tables", tables);
42
-
43
-        List<Object> sps = new Vector<>();
44
-        for (StoredProcedureSelection sp : _storedProcedures) {
45
-            sps.add(sp.toMap());
46
-        }
47
-        map.put("storedProcedures", sps);
48
-
49
-        return map;
50
-    }
51
-
52
-    public void fromJson(JSONObject json)
53
-    {
54
-        JSONArray array = json.getJSONArray("tables");
55
-        for (TableSelection table : _tables) {
56
-            JSONObject obj = Helper.findInJson(array, "table", table.getTable().getName());
57
-            if (obj != null) {
58
-                table.fromJson(obj);
59
-            } else {
60
-                for (ColumnSelection column : table.getColumns()) {
61
-                    column.setSelected(false);
62
-                }
63
-            }
64
-        }
65
-
66
-        array = json.getJSONArray("storedProcedures");
67
-        for (StoredProcedureSelection sp : _storedProcedures) {
68
-            JSONObject obj = Helper.findInJson(array, "name", sp.getStoredProcedure().getText());
69
-            if (obj != null) {
70
-                sp.fromJson(obj);
71
-            }
72
-        }
73
-    }
74
-
75
-    public DbDataSource getSource() {
76
-        return _source;
77
-    }
78
-
79
-    public void setSource(DbDataSource source) {
80
-        _source = source;
81
-    }
82
-
83
-    public List<TableSelection> getTables() {
84
-        return _tables;
85
-    }
86
-
87
-    public void setTables(List<TableSelection> tables) {
88
-        _tables = tables;
89
-    }
90
-
91
-    public List<StoredProcedureSelection> getStoredProcedures() {
92
-        return _storedProcedures;
93
-    }
94
-
95
-    public void setStoredProcedures(List<StoredProcedureSelection> storedProcedures) {
96
-        _storedProcedures = storedProcedures;
97
-    }
98
-}

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

@@ -1,7 +1,13 @@
1 1
 package com.rthoni.intellij.codefromds.dbo.options;
2 2
 
3 3
 import com.intellij.database.psi.DbDataSource;
4
+import com.rthoni.intellij.codefromds.business.DataSourcesBusiness;
4 5
 import com.rthoni.intellij.codefromds.business.Helper;
6
+import com.rthoni.intellij.codefromds.dbo.template.ColumnDataSourceDbo;
7
+import com.rthoni.intellij.codefromds.dbo.template.DataSourceDbo;
8
+import com.rthoni.intellij.codefromds.dbo.template.StoredProcedureDbo;
9
+import com.rthoni.intellij.codefromds.dbo.template.TableDataSourceDbo;
10
+import org.json.JSONArray;
5 11
 import org.json.JSONObject;
6 12
 
7 13
 import java.io.File;
@@ -12,7 +18,7 @@ import java.util.HashMap;
12 18
  */
13 19
 public class GenerateOptions {
14 20
 
15
-    private DataSourceSelection _selection;
21
+    private DataSourceDbo _dataSource;
16 22
 
17 23
     private String _dataSourceRelativePath;
18 24
 
@@ -28,15 +34,15 @@ public class GenerateOptions {
28 34
 
29 35
     private String _castFileRelativePath;
30 36
 
31
-    public GenerateOptions(DbDataSource source) {
37
+    public GenerateOptions(DataSourceDbo dataSource, String configAbsolutePath) {
32 38
         _filesExtension = "cs";
33 39
         _dataSourceRelativePath = "DataAccess/Database." + _filesExtension;
34 40
         _modelsRelativePath = "Models";
35 41
         _dataSourceTemplateRelativePath = "code-from-ds" + File.separator + "DataSource.twig";
36 42
         _modelsTemplateRelativePath = "code-from-ds" + File.separator + "Models.twig";
37
-        _configAbsolutePath = source.getProject().getBasePath() + File.separator + "code-from-ds" + File.separator + "code-from-ds.json";
43
+        _configAbsolutePath = configAbsolutePath;
38 44
         _castFileRelativePath = "code-from-ds" + File.separator + "types-cast.json";
39
-        _selection = new DataSourceSelection(source);
45
+        _dataSource = dataSource;
40 46
     }
41 47
 
42 48
     public HashMap<String, Object> toMap()
@@ -49,7 +55,35 @@ public class GenerateOptions {
49 55
         map.put("modelsTemplateRelativePath", _modelsTemplateRelativePath);
50 56
         map.put("filesExtension", _filesExtension);
51 57
         map.put("castFileRelativePath", _castFileRelativePath);
52
-        map.put("selection", _selection == null ? null : new JSONObject(_selection.toMap()));
58
+        JSONObject selectionObj = new JSONObject();
59
+        selectionObj.put("source", _dataSource.getName());
60
+        JSONArray tablesObj = new JSONArray();
61
+        selectionObj.put("tables", tablesObj);
62
+        for (TableDataSourceDbo table : _dataSource.getTables()) {
63
+            JSONObject tableObj = new JSONObject();
64
+            tablesObj.put(tableObj);
65
+            tableObj.put("table", table.getName());
66
+
67
+            JSONArray columnsObj = new JSONArray();
68
+            tableObj.put("columns", columnsObj);
69
+            for (ColumnDataSourceDbo column : table.getColumns()) {
70
+                JSONObject columnObj = new JSONObject();
71
+                columnsObj.put(columnObj);
72
+                columnObj.put("column", column.getName());
73
+                columnObj.put("selected", column.isSelected());
74
+            }
75
+        }
76
+
77
+        JSONArray spsObj = new JSONArray();
78
+        selectionObj.put("storedProcedures", spsObj);
79
+        for (StoredProcedureDbo sp : _dataSource.getStoredProcedures()) {
80
+            JSONObject spObj = new JSONObject();
81
+            spsObj.put(spObj);
82
+            spObj.put("storedProcedure", sp.getFullName());
83
+            spObj.put("selected", sp.isSelected());
84
+        }
85
+
86
+        map.put("selection", selectionObj);
53 87
 
54 88
         return map;
55 89
     }
@@ -62,15 +96,49 @@ public class GenerateOptions {
62 96
         _modelsTemplateRelativePath = Helper.getJsonString(json, "modelsTemplateRelativePath");
63 97
         _filesExtension = Helper.getJsonString(json, "filesExtension");
64 98
         _castFileRelativePath = Helper.getJsonString(json, "castFileRelativePath");
65
-        _selection.fromJson(json.getJSONObject("selection"));
66
-    }
67
-
68
-    public DataSourceSelection getSelection() {
69
-        return _selection;
70
-    }
71
-
72
-    public void setSelection(DataSourceSelection selection) {
73
-        _selection = selection;
99
+        JSONObject selectionObj = json.optJSONObject("selection");
100
+        if (selectionObj != null) {
101
+            JSONArray tablesObj = selectionObj.optJSONArray("tables");
102
+            if (tablesObj != null) {
103
+                for (int i = 0; i < tablesObj.length(); ++i) {
104
+                    JSONObject tableObj = tablesObj.optJSONObject(i);
105
+                    if (tableObj != null) {
106
+                        TableDataSourceDbo table = _dataSource.findTable(tableObj.getString("table"));
107
+                        if (table != null) {
108
+                            JSONArray columnsObj = tableObj.optJSONArray("columns");
109
+                            if (columnsObj != null) {
110
+                                for (int j = 0; j < columnsObj.length(); ++j) {
111
+                                    JSONObject columnObj = columnsObj.optJSONObject(j);
112
+                                    if (columnObj != null) {
113
+                                        ColumnDataSourceDbo column = table.findColumn(columnObj.getString("column"));
114
+                                        if (column != null) {
115
+                                            column.setSelected(columnObj.getBoolean("selected"));
116
+                                        }
117
+                                    }
118
+                                }
119
+                            }
120
+                        }
121
+                    }
122
+                }
123
+            }
124
+
125
+            JSONArray spsObj = selectionObj.optJSONArray("storedProcedures");
126
+            if (spsObj != null) {
127
+                for (int i = 0; i < spsObj.length(); ++i) {
128
+                    JSONObject spObj = spsObj.optJSONObject(i);
129
+                    if (spObj != null) {
130
+                        StoredProcedureDbo sp = _dataSource.findStoredProcedure(spObj.getString("storedProcedure"));
131
+                        if (sp != null) {
132
+                            sp.setSelected(spObj.getBoolean("selected"));
133
+                        }
134
+                    }
135
+                }
136
+            }
137
+        }
138
+    }
139
+
140
+    public DataSourceDbo getDataSource() {
141
+        return _dataSource;
74 142
     }
75 143
 
76 144
     public String getModelsRelativePath() {

+ 0
- 52
src/com/rthoni/intellij/codefromds/dbo/options/StoredProcedureSelection.java View File

@@ -1,52 +0,0 @@
1
-package com.rthoni.intellij.codefromds.dbo.options;
2
-
3
-import com.intellij.database.psi.DbRoutine;
4
-import org.json.JSONObject;
5
-
6
-import java.util.HashMap;
7
-
8
-/**
9
- * Created by robin on 4/14/17.
10
- */
11
-public class StoredProcedureSelection {
12
-
13
-    private DbRoutine _storedProcedure;
14
-
15
-    private boolean _isSelected;
16
-
17
-    public StoredProcedureSelection(DbRoutine storedProcedure) {
18
-        _storedProcedure = storedProcedure;
19
-        _isSelected = true;
20
-    }
21
-
22
-    public DbRoutine getStoredProcedure() {
23
-        return _storedProcedure;
24
-    }
25
-
26
-    public void setStoredProcedure(DbRoutine storedProcedure) {
27
-        _storedProcedure = storedProcedure;
28
-    }
29
-
30
-    public boolean isSelected() {
31
-        return _isSelected;
32
-    }
33
-
34
-    public void setSelected(boolean selected) {
35
-        _isSelected = selected;
36
-    }
37
-
38
-    public HashMap<String, Object> toMap()
39
-    {
40
-        HashMap<String, Object> map = new HashMap<>();
41
-
42
-        map.put("name", _storedProcedure == null ? null : _storedProcedure.getText());
43
-        map.put("selected", _isSelected);
44
-
45
-        return map;
46
-    }
47
-
48
-    public void fromJson(JSONObject json)
49
-    {
50
-        _isSelected = json.getBoolean("selected");
51
-    }
52
-}

+ 0
- 81
src/com/rthoni/intellij/codefromds/dbo/options/TableSelection.java View File

@@ -1,81 +0,0 @@
1
-package com.rthoni.intellij.codefromds.dbo.options;
2
-
3
-import com.intellij.database.model.DasTable;
4
-import com.intellij.database.util.DasUtil;
5
-import com.rthoni.intellij.codefromds.business.Helper;
6
-import org.json.JSONArray;
7
-import org.json.JSONObject;
8
-
9
-import java.util.HashMap;
10
-import java.util.List;
11
-import java.util.Vector;
12
-import java.util.stream.Collectors;
13
-
14
-/**
15
- * Created by robin on 11/15/16.
16
- */
17
-public class TableSelection {
18
-
19
-    private DasTable _table;
20
-
21
-    private List<ColumnSelection> _columns;
22
-
23
-    public TableSelection(DasTable table)
24
-    {
25
-        _table = table;
26
-        _columns = DasUtil.getColumns(table).toList().stream().map(ColumnSelection::new).collect(Collectors.toList());
27
-    }
28
-
29
-    public HashMap<String, Object> toMap()
30
-    {
31
-        HashMap<String, Object> map = new HashMap<>();
32
-
33
-        map.put("table", _table == null ? null : _table.getName());
34
-        List<Object> tables = new Vector<>();
35
-        for (ColumnSelection col : _columns) {
36
-            tables.add(col.toMap());
37
-        }
38
-        map.put("columns", tables);
39
-
40
-        return map;
41
-    }
42
-
43
-    public void fromJson(JSONObject json)
44
-    {
45
-        JSONArray array = json.getJSONArray("columns");
46
-        for (ColumnSelection column : _columns) {
47
-            JSONObject obj = Helper.findInJson(array, "column", column.getColumn().getName());
48
-            if (obj != null) {
49
-                column.fromJson(obj);
50
-            } else {
51
-                column.setSelected(false);
52
-            }
53
-        }
54
-    }
55
-
56
-    public DasTable getTable() {
57
-        return _table;
58
-    }
59
-
60
-    public void setTable(DasTable table) {
61
-        _table = table;
62
-    }
63
-
64
-    public List<ColumnSelection> getColumns() {
65
-        return _columns;
66
-    }
67
-
68
-    public void setColumns(List<ColumnSelection> columns) {
69
-        _columns = columns;
70
-    }
71
-
72
-    public boolean hasNone()
73
-    {
74
-        return _columns != null && _columns.stream().filter(ColumnSelection::isSelected).count() == 0;
75
-    }
76
-
77
-    public boolean hasAll()
78
-    {
79
-        return _columns != null && _columns.stream().filter(ColumnSelection::isSelected).count() == _columns.size();
80
-    }
81
-}

+ 10
- 0
src/com/rthoni/intellij/codefromds/dbo/template/DataSourceDbo.java View File

@@ -47,4 +47,14 @@ public class DataSourceDbo {
47 47
         }
48 48
         return null;
49 49
     }
50
+
51
+    public StoredProcedureDbo findStoredProcedure(String name)
52
+    {
53
+        for (StoredProcedureDbo sp : _storedProcedures) {
54
+            if (sp.getFullName().equals(name)) {
55
+                return sp;
56
+            }
57
+        }
58
+        return null;
59
+    }
50 60
 }

+ 10
- 0
src/com/rthoni/intellij/codefromds/dbo/template/TableDataSourceDbo.java View File

@@ -56,6 +56,16 @@ public class TableDataSourceDbo {
56 56
         return false;
57 57
     }
58 58
 
59
+    public boolean hasAll()
60
+    {
61
+        for (ColumnDataSourceDbo column : _columns) {
62
+            if (!column.isSelected()) {
63
+                return false;
64
+            }
65
+        }
66
+        return true;
67
+    }
68
+
59 69
     public List<ForeignKeyDbo> getSourceForeignKeys() {
60 70
         return _sourceForeignKeys;
61 71
     }

+ 27
- 20
src/com/rthoni/intellij/codefromds/ui/dialogs/GenerateDialog.java View File

@@ -10,8 +10,13 @@ import com.intellij.openapi.ui.ValidationInfo;
10 10
 import com.intellij.ui.ColoredListCellRenderer;
11 11
 import com.intellij.ui.JBColor;
12 12
 import com.intellij.ui.components.JBList;
13
+import com.rthoni.intellij.codefromds.business.DataSourcesBusiness;
13 14
 import com.rthoni.intellij.codefromds.business.Helper;
14 15
 import com.rthoni.intellij.codefromds.dbo.options.*;
16
+import com.rthoni.intellij.codefromds.dbo.template.ColumnDataSourceDbo;
17
+import com.rthoni.intellij.codefromds.dbo.template.DataSourceDbo;
18
+import com.rthoni.intellij.codefromds.dbo.template.StoredProcedureDbo;
19
+import com.rthoni.intellij.codefromds.dbo.template.TableDataSourceDbo;
15 20
 import org.jetbrains.annotations.NotNull;
16 21
 import org.jetbrains.annotations.Nullable;
17 22
 
@@ -68,7 +73,7 @@ public class GenerateDialog extends DialogWrapper {
68 73
     public void setOptions(GenerateOptions options) {
69 74
         _options = options;
70 75
         if (_options != null) {
71
-            showSource(_options.getSelection());
76
+            showSource(_options.getDataSource());
72 77
             _textModels.setText(Helper.getAbsolutePath(_project, _options.getModelsRelativePath()));
73 78
             _textDataSource.setText(Helper.getAbsolutePath(_project, _options.getDataSourceRelativePath()));
74 79
             _textDataSourceTemplate.setText(Helper.getAbsolutePath(_project, _options.getDataSourceTemplateRelativePath()));
@@ -147,7 +152,8 @@ public class GenerateDialog extends DialogWrapper {
147 152
                     setOptions(null);
148 153
                 }
149 154
                 else {
150
-                    setOptions(new GenerateOptions(dataSources.get(index)));
155
+                    setOptions(new GenerateOptions(DataSourcesBusiness.getDataSourcesDbo().get(index),
156
+                            "code-from-ds" + File.separator + "code-from-ds.json"));
151 157
                 }
152 158
             }
153 159
         });
@@ -158,7 +164,7 @@ public class GenerateDialog extends DialogWrapper {
158 164
                     showTable(null);
159 165
                 }
160 166
                 else {
161
-                    showTable(_options.getSelection().getTables().get(index));
167
+                    showTable(_options.getDataSource().getTables().get(index));
162 168
                 }
163 169
             }
164 170
         });
@@ -197,24 +203,24 @@ public class GenerateDialog extends DialogWrapper {
197 203
         _listTables.setCellRenderer(new ColoredListCellRenderer() {
198 204
             @Override
199 205
             protected void customizeCellRenderer(@NotNull JList jList, Object o, int i, boolean b, boolean b1) {
200
-                TableSelection tableSelection = _options.getSelection().getTables().get(i);
206
+                TableDataSourceDbo tableSelection = _options.getDataSource().getTables().get(i);
201 207
                 if (tableSelection.hasAll()) {
202 208
                     setBackground(JBColor.GREEN);
203 209
                 }
204
-                else if (tableSelection.hasNone()) {
210
+                else if (!tableSelection.hasAny()) {
205 211
                     setBackground(JBColor.RED);
206 212
                 }
207 213
                 else {
208 214
                     setBackground(JBColor.ORANGE);
209 215
                 }
210
-                append(tableSelection.getTable().getName());
216
+                append(tableSelection.getName());
211 217
             }
212 218
         });
213 219
 
214 220
 //        _listStoredProcedure.setCellRenderer(new ColoredListCellRenderer() {
215 221
 //            @Override
216 222
 //            protected void customizeCellRenderer(@NotNull JList jList, Object o, int i, boolean b, boolean b1) {
217
-//                StoredProcedureSelection spSelection = _options.getSelection().getStoredProcedures().get(i);
223
+//                StoredProcedureSelection spSelection = _options.getDataSource().getStoredProcedures().get(i);
218 224
 //                if (spSelection.isSelected()) {
219 225
 //                    setBackground(JBColor.GREEN);
220 226
 //                }
@@ -261,18 +267,19 @@ public class GenerateDialog extends DialogWrapper {
261 267
         for (ActionListener l : field.getButton().getActionListeners()) {
262 268
             field.getButton().removeActionListener(l);
263 269
         }
264
-        field.addBrowseFolderListener("Choose " + title + " " + (dirsOnly ? "Folder" : "File"), "Choose " + (dirsOnly ? "Folder" : "File"), project,
270
+        field.addBrowseFolderListener("Choose " + title + " " + (dirsOnly ? "Folder" : "File"),
271
+                "Choose " + (dirsOnly ? "Folder" : "File"), project,
265 272
                 dirsOnly ? FileChooserDescriptorFactory.createSingleFolderDescriptor() : FileChooserDescriptorFactory.createSingleFileDescriptor());
266 273
     }
267 274
 
268
-    private void showSource(DataSourceSelection source)
275
+    private void showSource(DataSourceDbo source)
269 276
     {
270 277
         for (ListSelectionListener e : _listStoredProcedure.getListSelectionListeners()) {
271 278
             _listStoredProcedure.removeListSelectionListener(e);
272 279
         }
273 280
         if (source != null) {
274 281
 
275
-            List<String> tables = source.getTables().stream().map(t -> t.getTable().getName()).collect(Collectors.toList());
282
+            List<String> tables = source.getTables().stream().map(t -> t.getName()).collect(Collectors.toList());
276 283
             _listTables.setListData(tables.toArray(new String[tables.size()]));
277 284
             if (tables.size() > 0) {
278 285
                 showTable(source.getTables().get(0));
@@ -280,7 +287,7 @@ public class GenerateDialog extends DialogWrapper {
280 287
             else {
281 288
                 showTable(null);
282 289
             }
283
-            List<String> sps = source.getStoredProcedures().stream().map(t -> t.getStoredProcedure().getText()).collect(Collectors.toList());
290
+            List<String> sps = source.getStoredProcedures().stream().map(t -> t.getFullName()).collect(Collectors.toList());
284 291
             _listStoredProcedure.setListData(sps.toArray(new String[sps.size()]));
285 292
             int[] indices = getSpSelectedIndices(source);
286 293
             _listStoredProcedure.setSelectedIndices(indices);
@@ -300,9 +307,9 @@ public class GenerateDialog extends DialogWrapper {
300 307
         }
301 308
     }
302 309
 
303
-    private int[] getSpSelectedIndices(final DataSourceSelection dataSource)
310
+    private int[] getSpSelectedIndices(final DataSourceDbo dataSource)
304 311
     {
305
-        List<StoredProcedureSelection> columns = dataSource.getStoredProcedures();
312
+        List<StoredProcedureDbo> columns = dataSource.getStoredProcedures();
306 313
         List<Integer> indices = new Vector<>();
307 314
         for (int i = 0; i < columns.size(); ++i) {
308 315
             if (columns.get(i).isSelected()) {
@@ -312,9 +319,9 @@ public class GenerateDialog extends DialogWrapper {
312 319
         return indices.stream().mapToInt(Integer::intValue).toArray();
313 320
     }
314 321
 
315
-    private int[] getColumnsSelectedIndices(final TableSelection table)
322
+    private int[] getColumnsSelectedIndices(final TableDataSourceDbo table)
316 323
     {
317
-        List<ColumnSelection> columns = table.getColumns();
324
+        List<ColumnDataSourceDbo> columns = table.getColumns();
318 325
         List<Integer> indices = new Vector<>();
319 326
         for (int i = 0; i < columns.size(); ++i) {
320 327
             if (columns.get(i).isSelected()) {
@@ -324,9 +331,9 @@ public class GenerateDialog extends DialogWrapper {
324 331
         return indices.stream().mapToInt(Integer::intValue).toArray();
325 332
     }
326 333
 
327
-    private void updateColumnSelection(final TableSelection table)
334
+    private void updateColumnSelection(final TableDataSourceDbo table)
328 335
     {
329
-        List<ColumnSelection> columns = table.getColumns();
336
+        List<ColumnDataSourceDbo> columns = table.getColumns();
330 337
         for (int i = 0; i < columns.size(); ++i) {
331 338
             columns.get(i).setSelected(_listColumns.isSelectedIndex(i));
332 339
         }
@@ -334,19 +341,19 @@ public class GenerateDialog extends DialogWrapper {
334 341
 
335 342
     private void updateSpSelection()
336 343
     {
337
-        List<StoredProcedureSelection> sps = _options.getSelection().getStoredProcedures();
344
+        List<StoredProcedureDbo> sps = _options.getDataSource().getStoredProcedures();
338 345
         for (int i = 0; i < sps.size(); ++i) {
339 346
             sps.get(i).setSelected(_listStoredProcedure.isSelectedIndex(i));
340 347
         }
341 348
     }
342 349
 
343
-    private void showTable(TableSelection table)
350
+    private void showTable(TableDataSourceDbo table)
344 351
     {
345 352
         for (ListSelectionListener e : _listColumns.getListSelectionListeners()) {
346 353
             _listColumns.removeListSelectionListener(e);
347 354
         }
348 355
         if (table != null) {
349
-            _listColumns.setListData(table.getColumns().stream().map(c -> c.getColumn().getName()).toArray(String[]::new));
356
+            _listColumns.setListData(table.getColumns().stream().map(c -> c.getName()).toArray(String[]::new));
350 357
             int[] indices = getColumnsSelectedIndices(table);
351 358
             _listColumns.setSelectedIndices(indices);
352 359
             _listColumns.addListSelectionListener(e -> {

Loading…
Cancel
Save