23
23
import com .github .introfog .gitwave .model .StageFactory ;
24
24
import com .github .introfog .gitwave .model .StageFactory .FxmlStageHolder ;
25
25
import com .github .introfog .gitwave .model .dto .CommandDto ;
26
+ import com .github .introfog .gitwave .model .dto .ParameterDto ;
26
27
27
28
import java .io .File ;
29
+ import java .util .HashSet ;
28
30
import java .util .Objects ;
31
+ import java .util .Set ;
32
+ import java .util .regex .Matcher ;
33
+ import java .util .regex .Pattern ;
34
+ import javafx .collections .FXCollections ;
35
+ import javafx .collections .ObservableList ;
29
36
import javafx .fxml .FXML ;
30
37
import javafx .scene .control .Button ;
31
38
import javafx .scene .control .ButtonType ;
39
+ import javafx .scene .control .Label ;
40
+ import javafx .scene .control .TableColumn ;
41
+ import javafx .scene .control .TableView ;
32
42
import javafx .scene .control .TextField ;
43
+ import javafx .scene .control .cell .PropertyValueFactory ;
44
+ import javafx .scene .control .cell .TextFieldTableCell ;
33
45
import javafx .stage .DirectoryChooser ;
34
46
import javafx .stage .Stage ;
35
47
import org .slf4j .Logger ;
36
48
import org .slf4j .LoggerFactory ;
37
49
38
50
public class ExecuteController extends BaseController {
51
+ // TODO add opportunity to check if new release is available for GitWave
52
+ private static final Pattern CURL_BRACKETS_PATTERN = Pattern .compile ("\\ {(\\ S+)\\ }" );
39
53
private static final Logger LOGGER = LoggerFactory .getLogger (ExecuteController .class );
40
54
private static final String GREEN_TEXT_CSS_STYLE = "-fx-text-fill: green" ;
41
55
private static final String RED_TEXT_CSS_STYLE = "-fx-text-fill: red" ;
@@ -53,6 +67,12 @@ public class ExecuteController extends BaseController {
53
67
@ FXML
54
68
private Button save ;
55
69
70
+ @ FXML
71
+ private Label parametersText ;
72
+
73
+ @ FXML
74
+ private TableView <ParameterDto > parametersTable ;
75
+
56
76
private CommandDto sourceCommand ;
57
77
58
78
@ Override
@@ -64,18 +84,7 @@ public void initialize(FxmlStageHolder fxmlStageHolder) {
64
84
DialogFactory .createCloseConfirmationAlert (primaryStage );
65
85
});
66
86
67
- command .textProperty ().addListener ((obs , oldText , newText ) -> {
68
- if (sourceCommand != null ) {
69
- updateFields (newText , command , true );
70
- } else {
71
- save .setDisable (newText .isEmpty ());
72
- }
73
- });
74
- description .textProperty ().addListener ((obs , oldText , newText ) -> {
75
- if (sourceCommand != null ) {
76
- updateFields (newText , description , false );
77
- }
78
- });
87
+ setUpSaveIndication ();
79
88
}
80
89
81
90
@ FXML
@@ -177,7 +186,23 @@ protected void foundIssue() {
177
186
AppConfig .getInstance ().getHostServices ().showDocument (AppConstants .LINK_TO_GIT_CONTRIBUTING_FILE );
178
187
}
179
188
180
- private void updateFields (String currentMainText , TextField field , boolean isCommand ) {
189
+ private void setUpSaveIndication () {
190
+ command .textProperty ().addListener ((obs , oldText , newText ) -> {
191
+ parseCommandParameters ();
192
+ if (sourceCommand != null ) {
193
+ updateSaveIndication (newText , command , true );
194
+ } else {
195
+ save .setDisable (newText .isEmpty ());
196
+ }
197
+ });
198
+ description .textProperty ().addListener ((obs , oldText , newText ) -> {
199
+ if (sourceCommand != null ) {
200
+ updateSaveIndication (newText , description , false );
201
+ }
202
+ });
203
+ }
204
+
205
+ private void updateSaveIndication (String currentMainText , TextField field , boolean isCommand ) {
181
206
final String sourceMainText = isCommand ? sourceCommand .getCommand () : sourceCommand .getDescription ();
182
207
final String sourceSecText = isCommand ? sourceCommand .getDescription () : sourceCommand .getCommand ();
183
208
final String currentSecText = isCommand ? description .getText () : command .getText ();
@@ -193,6 +218,39 @@ private void updateFields(String currentMainText, TextField field, boolean isCom
193
218
}
194
219
}
195
220
221
+ private void parseCommandParameters () {
222
+ final Set <ParameterDto > parameters = new HashSet <>();
223
+ Matcher matcher = CURL_BRACKETS_PATTERN .matcher (command .getText ());
224
+ while (matcher .find ()) {
225
+ final String name = matcher .group (1 );
226
+ parameters .add (new ParameterDto (name , "" ));
227
+ }
228
+ if (parameters .isEmpty ()) {
229
+ parametersText .setVisible (true );
230
+
231
+ parametersTable .setDisable (true );
232
+ parametersTable .setVisible (false );
233
+ parametersTable .getItems ().clear ();
234
+ } else {
235
+ parametersText .setVisible (false );
236
+
237
+ parametersTable .setDisable (false );
238
+ parametersTable .setVisible (true );
239
+
240
+ ObservableList <ParameterDto > itemList = FXCollections .observableArrayList (parameters );
241
+ parametersTable .getItems ().clear ();
242
+ parametersTable .setItems (itemList );
243
+
244
+ final TableColumn <ParameterDto , String > nameTableColumn = (TableColumn <ParameterDto , String >) parametersTable .getColumns ().get (0 );
245
+ nameTableColumn .setCellValueFactory (new PropertyValueFactory <>("name" ));
246
+ nameTableColumn .setCellFactory (TextFieldTableCell .forTableColumn ());
247
+
248
+ final TableColumn <ParameterDto , String > valueTableColumn = (TableColumn <ParameterDto , String >) parametersTable .getColumns ().get (1 );
249
+ valueTableColumn .setCellValueFactory (new PropertyValueFactory <>("value" ));
250
+ valueTableColumn .setCellFactory (TextFieldTableCell .forTableColumn ());
251
+ }
252
+ }
253
+
196
254
private void specifySourceCommand (CommandDto commandDto ) {
197
255
save .setDisable (true );
198
256
sourceCommand = commandDto ;
@@ -203,6 +261,7 @@ private void specifySourceCommand(CommandDto commandDto) {
203
261
description .setStyle (BLACK_TEXT_CSS_STYLE );
204
262
} else {
205
263
command .setText (commandDto .getCommand ());
264
+ parseCommandParameters ();
206
265
command .setStyle (GREEN_TEXT_CSS_STYLE );
207
266
description .setText (commandDto .getDescription ());
208
267
description .setStyle (GREEN_TEXT_CSS_STYLE );
0 commit comments