|  | @@ -1,14 +1,9 @@
 | 
		
	
		
			
			| 1 | 1 |  package com.rthoni.intellij.codefromds.ui.dialogs;
 | 
		
	
		
			
			| 2 | 2 |  
 | 
		
	
		
			
			| 3 | 3 |  import com.intellij.database.model.DasObject;
 | 
		
	
		
			
			| 4 |  | -import com.intellij.database.model.DasTable;
 | 
		
	
		
			
			| 5 | 4 |  import com.intellij.database.psi.DbDataSource;
 | 
		
	
		
			
			| 6 |  | -import com.intellij.database.psi.DbPsiFacade;
 | 
		
	
		
			
			| 7 |  | -import com.intellij.database.util.DasUtil;
 | 
		
	
		
			
			| 8 |  | -import com.intellij.openapi.actionSystem.ActionManager;
 | 
		
	
		
			
			| 9 | 5 |  import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
 | 
		
	
		
			
			| 10 | 6 |  import com.intellij.openapi.project.Project;
 | 
		
	
		
			
			| 11 |  | -import com.intellij.openapi.project.ProjectManager;
 | 
		
	
		
			
			| 12 | 7 |  import com.intellij.openapi.ui.DialogWrapper;
 | 
		
	
		
			
			| 13 | 8 |  import com.intellij.openapi.ui.TextFieldWithBrowseButton;
 | 
		
	
		
			
			| 14 | 9 |  import com.intellij.openapi.ui.ValidationInfo;
 | 
		
	
	
		
			
			|  | @@ -29,8 +24,6 @@ import javax.swing.event.DocumentListener;
 | 
		
	
		
			
			| 29 | 24 |  import javax.swing.event.ListSelectionListener;
 | 
		
	
		
			
			| 30 | 25 |  import java.awt.event.ActionListener;
 | 
		
	
		
			
			| 31 | 26 |  import java.io.File;
 | 
		
	
		
			
			| 32 |  | -import java.util.Arrays;
 | 
		
	
		
			
			| 33 |  | -import java.util.Collection;
 | 
		
	
		
			
			| 34 | 27 |  import java.util.List;
 | 
		
	
		
			
			| 35 | 28 |  import java.util.Vector;
 | 
		
	
		
			
			| 36 | 29 |  import java.util.function.Consumer;
 | 
		
	
	
		
			
			|  | @@ -46,14 +39,21 @@ public class GenerateDialog extends DialogWrapper {
 | 
		
	
		
			
			| 46 | 39 |      private JBList _listTables;
 | 
		
	
		
			
			| 47 | 40 |      private JBList _listColumns;
 | 
		
	
		
			
			| 48 | 41 |      private TextFieldWithBrowseButton _textModels;
 | 
		
	
		
			
			| 49 |  | -    private TextFieldWithBrowseButton _textDataSOurceTemplate;
 | 
		
	
		
			
			|  | 42 | +    private TextFieldWithBrowseButton _textDataSourceTemplate;
 | 
		
	
		
			
			| 50 | 43 |      private TextFieldWithBrowseButton _textModelsTemplate;
 | 
		
	
		
			
			| 51 | 44 |      private TextFieldWithBrowseButton _textConfigPath;
 | 
		
	
		
			
			|  | 45 | +    private JTextField _textFilesExtension;
 | 
		
	
		
			
			|  | 46 | +    private JLabel _lblDataSourceTemplatePath;
 | 
		
	
		
			
			|  | 47 | +    private JLabel _lblModelsPath;
 | 
		
	
		
			
			|  | 48 | +    private JLabel _lblModelsTemplatePath;
 | 
		
	
		
			
			| 52 | 49 |  
 | 
		
	
		
			
			| 53 | 50 |      private GenerateOptions _options;
 | 
		
	
		
			
			| 54 | 51 |  
 | 
		
	
		
			
			| 55 |  | -    public GenerateDialog(@Nullable Project project) {
 | 
		
	
		
			
			|  | 52 | +    private Project _project;
 | 
		
	
		
			
			|  | 53 | +
 | 
		
	
		
			
			|  | 54 | +    public GenerateDialog(Project project) {
 | 
		
	
		
			
			| 56 | 55 |          super(project);
 | 
		
	
		
			
			|  | 56 | +        _project = project;
 | 
		
	
		
			
			| 57 | 57 |          setTitle("Code FROM data source");
 | 
		
	
		
			
			| 58 | 58 |          setOptions(null);
 | 
		
	
		
			
			| 59 | 59 |          init();
 | 
		
	
	
		
			
			|  | @@ -67,16 +67,18 @@ public class GenerateDialog extends DialogWrapper {
 | 
		
	
		
			
			| 67 | 67 |          _options = options;
 | 
		
	
		
			
			| 68 | 68 |          if (_options != null) {
 | 
		
	
		
			
			| 69 | 69 |              showSource(_options.getSelection());
 | 
		
	
		
			
			| 70 |  | -            _textModels.setText(_options.getModelsPath());
 | 
		
	
		
			
			| 71 |  | -            _textDataSOurceTemplate.setText(_options.getDataSourceTemplatePath());
 | 
		
	
		
			
			| 72 |  | -            _textModelsTemplate.setText(_options.getModelsTemplatePath());
 | 
		
	
		
			
			| 73 |  | -            _textConfigPath.setText(_options.getConfigPath());
 | 
		
	
		
			
			|  | 70 | +            _textModels.setText(Helper.getAbsolutePath(_project, _options.getModelsRelativePath()));
 | 
		
	
		
			
			|  | 71 | +            _textDataSourceTemplate.setText(Helper.getAbsolutePath(_project, _options.getDataSourceTemplateRelativePath()));
 | 
		
	
		
			
			|  | 72 | +            _textModelsTemplate.setText(Helper.getAbsolutePath(_project, _options.getModelsTemplateRelativePath()));
 | 
		
	
		
			
			|  | 73 | +            _textFilesExtension.setText(_options.getFilesExtension());
 | 
		
	
		
			
			|  | 74 | +            _textConfigPath.setText(_options.getConfigAbsolutePath());
 | 
		
	
		
			
			| 74 | 75 |          }
 | 
		
	
		
			
			| 75 | 76 |          else {
 | 
		
	
		
			
			| 76 | 77 |              showSource(null);
 | 
		
	
		
			
			| 77 | 78 |              _textModels.setText("");
 | 
		
	
		
			
			| 78 |  | -            _textDataSOurceTemplate.setText("");
 | 
		
	
		
			
			|  | 79 | +            _textDataSourceTemplate.setText("");
 | 
		
	
		
			
			| 79 | 80 |              _textModelsTemplate.setText("");
 | 
		
	
		
			
			|  | 81 | +            _textFilesExtension.setText("");
 | 
		
	
		
			
			| 80 | 82 |              _textConfigPath.setText("");
 | 
		
	
		
			
			| 81 | 83 |          }
 | 
		
	
		
			
			| 82 | 84 |      }
 | 
		
	
	
		
			
			|  | @@ -85,11 +87,12 @@ public class GenerateDialog extends DialogWrapper {
 | 
		
	
		
			
			| 85 | 87 |      @Override
 | 
		
	
		
			
			| 86 | 88 |      protected ValidationInfo doValidate() {
 | 
		
	
		
			
			| 87 | 89 |          ValidationInfo info = null;
 | 
		
	
		
			
			| 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());
 | 
		
	
		
			
			|  | 90 | +        File modelDir = _options == null ? null : new File(Helper.getAbsolutePath(_project, _options.getModelsRelativePath()));
 | 
		
	
		
			
			|  | 91 | +        File dataSourceTemplatePath = _options == null ? null : new File(Helper.getAbsolutePath(_project, _options.getDataSourceTemplateRelativePath()));
 | 
		
	
		
			
			|  | 92 | +        File modelsTemplatePath = _options == null ? null : new File(Helper.getAbsolutePath(_project, _options.getModelsTemplateRelativePath()));
 | 
		
	
		
			
			|  | 93 | +        File configPath = _options == null ? null : new File(_options.getConfigAbsolutePath());
 | 
		
	
		
			
			| 92 | 94 |          File configDir = _options == null ? null : new File(configPath.getParent());
 | 
		
	
		
			
			|  | 95 | +        String extension = _options == null ? null : _options.getFilesExtension();
 | 
		
	
		
			
			| 93 | 96 |          if (_options == null) {
 | 
		
	
		
			
			| 94 | 97 |              info = new ValidationInfo("No Data Source Selected", _listDatasources);
 | 
		
	
		
			
			| 95 | 98 |          }
 | 
		
	
	
		
			
			|  | @@ -97,7 +100,7 @@ public class GenerateDialog extends DialogWrapper {
 | 
		
	
		
			
			| 97 | 100 |              info = new ValidationInfo("Models folder does not exists", _textModels.getTextField());
 | 
		
	
		
			
			| 98 | 101 |          }
 | 
		
	
		
			
			| 99 | 102 |          else if (!dataSourceTemplatePath.exists() || !dataSourceTemplatePath.isFile()) {
 | 
		
	
		
			
			| 100 |  | -            info = new ValidationInfo("Data source template file does not exists", _textDataSOurceTemplate.getTextField());
 | 
		
	
		
			
			|  | 103 | +            info = new ValidationInfo("Data source template file does not exists", _textDataSourceTemplate.getTextField());
 | 
		
	
		
			
			| 101 | 104 |          }
 | 
		
	
		
			
			| 102 | 105 |          else if (!modelsTemplatePath.exists() || !modelsTemplatePath.isFile()) {
 | 
		
	
		
			
			| 103 | 106 |              info = new ValidationInfo("Models template file does not exists", _textModelsTemplate.getTextField());
 | 
		
	
	
		
			
			|  | @@ -105,6 +108,12 @@ public class GenerateDialog extends DialogWrapper {
 | 
		
	
		
			
			| 105 | 108 |          else if (!configDir.exists() || !configDir.isDirectory()) {
 | 
		
	
		
			
			| 106 | 109 |              info = new ValidationInfo("Configuration file parent folder does not exists", _textConfigPath.getTextField());
 | 
		
	
		
			
			| 107 | 110 |          }
 | 
		
	
		
			
			|  | 111 | +        else if (extension == null || extension.isEmpty()) {
 | 
		
	
		
			
			|  | 112 | +            info = new ValidationInfo("Files extension is required", _textFilesExtension);
 | 
		
	
		
			
			|  | 113 | +        }
 | 
		
	
		
			
			|  | 114 | +        else if (extension.startsWith(".")) {
 | 
		
	
		
			
			|  | 115 | +            info = new ValidationInfo("Files extension must not include dot (.)", _textFilesExtension);
 | 
		
	
		
			
			|  | 116 | +        }
 | 
		
	
		
			
			| 108 | 117 |  
 | 
		
	
		
			
			| 109 | 118 |          return info;
 | 
		
	
		
			
			| 110 | 119 |      }
 | 
		
	
	
		
			
			|  | @@ -140,14 +149,24 @@ public class GenerateDialog extends DialogWrapper {
 | 
		
	
		
			
			| 140 | 149 |          });
 | 
		
	
		
			
			| 141 | 150 |  
 | 
		
	
		
			
			| 142 | 151 |          setupTextField(_textModels, null, true);
 | 
		
	
		
			
			| 143 |  | -        setupTextField(_textDataSOurceTemplate, null, false);
 | 
		
	
		
			
			|  | 152 | +        setupTextField(_textDataSourceTemplate, null, false);
 | 
		
	
		
			
			| 144 | 153 |          setupTextField(_textModelsTemplate, null, false);
 | 
		
	
		
			
			| 145 | 154 |          setupTextField(_textConfigPath, null, false);
 | 
		
	
		
			
			| 146 | 155 |  
 | 
		
	
		
			
			| 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));
 | 
		
	
		
			
			|  | 156 | +        setupTextFieldListener(_textModels.getTextField(), s -> {
 | 
		
	
		
			
			|  | 157 | +            _options.setModelsRelativePath(Helper.getRelativePath(_project, s));
 | 
		
	
		
			
			|  | 158 | +            _lblModelsTemplatePath.setText("$ProjectRoot/" + _options.getModelsRelativePath());
 | 
		
	
		
			
			|  | 159 | +        });
 | 
		
	
		
			
			|  | 160 | +        setupTextFieldListener(_textDataSourceTemplate.getTextField(), s -> {
 | 
		
	
		
			
			|  | 161 | +            _options.setDataSourceTemplateRelativePath(Helper.getRelativePath(_project, s));
 | 
		
	
		
			
			|  | 162 | +            _lblDataSourceTemplatePath.setText("$ProjectRoot/" + _options.getDataSourceTemplateRelativePath());
 | 
		
	
		
			
			|  | 163 | +        });
 | 
		
	
		
			
			|  | 164 | +        setupTextFieldListener(_textModelsTemplate.getTextField(), s -> {
 | 
		
	
		
			
			|  | 165 | +            _options.setModelsTemplateRelativePath(Helper.getRelativePath(_project, s));
 | 
		
	
		
			
			|  | 166 | +            _lblModelsPath.setText("$ProjectRoot/" + _options.getModelsTemplateRelativePath());
 | 
		
	
		
			
			|  | 167 | +        });
 | 
		
	
		
			
			|  | 168 | +        setupTextFieldListener(_textFilesExtension, s -> _options.setFilesExtension(s));
 | 
		
	
		
			
			|  | 169 | +        setupTextFieldListener(_textConfigPath.getTextField(), s -> _options.setConfigAbsolutePath(s));
 | 
		
	
		
			
			| 151 | 170 |  
 | 
		
	
		
			
			| 152 | 171 |          _listTables.setCellRenderer(new ColoredListCellRenderer() {
 | 
		
	
		
			
			| 153 | 172 |              @Override
 |