17
17
package com .github .introfog .gitwave .controller ;
18
18
19
19
import com .github .introfog .gitwave .model .AppConfig ;
20
- import com .github .introfog .gitwave .model .DialogFactory ;
21
- import com .github .introfog .gitwave .model .StageFactory ;
22
20
import com .github .introfog .gitwave .model .StageFactory .FxmlStageHolder ;
23
21
import com .github .introfog .gitwave .model .dto .CommandDto ;
24
22
25
23
import java .util .List ;
26
- import javafx .application .Platform ;
27
24
import javafx .collections .FXCollections ;
28
25
import javafx .collections .ObservableList ;
29
26
import javafx .fxml .FXML ;
30
27
import javafx .scene .control .Button ;
28
+ import javafx .scene .control .TableCell ;
31
29
import javafx .scene .control .TableColumn ;
32
- import javafx .scene .control .TableColumn .CellEditEvent ;
33
30
import javafx .scene .control .TableView ;
34
31
import javafx .scene .control .cell .PropertyValueFactory ;
35
32
import javafx .scene .control .cell .TextFieldTableCell ;
36
33
import javafx .scene .input .KeyCode ;
34
+ import javafx .scene .input .MouseEvent ;
37
35
38
36
public class ExploreController extends BaseController {
39
37
@ FXML
@@ -54,54 +52,19 @@ public void initialize(FxmlStageHolder fxmlStageHolder) {
54
52
fxmlStageHolder .getStage ().close ();
55
53
}
56
54
});
57
- Platform .runLater (() -> addNew .requestFocus ());
58
55
}
59
56
60
57
@ FXML
61
- protected void commitCommand (CellEditEvent <CommandDto , String > event ) {
62
- event .getRowValue ().setCommand (event .getNewValue ());
63
- AppConfig .getInstance ().updateCommandScript (event .getRowValue (), event .getNewValue ());
64
- }
65
-
66
- @ FXML
67
- protected void commitDescription (CellEditEvent <CommandDto , String > event ) {
68
- event .getRowValue ().setDescription (event .getNewValue ());
69
- AppConfig .getInstance ().updateCommandDescription (event .getRowValue (), event .getNewValue ());
70
- }
71
-
72
- @ FXML
73
- protected void removeSelectedCommand () {
74
- CommandDto selectedItem = commandsTable .getSelectionModel ().getSelectedItem ();
75
- if (selectedItem != null ) {
76
- commandsTable .getItems ().remove (selectedItem );
77
- executeController .removeSavedCommand (selectedItem );
78
- AppConfig .getInstance ().removeCommand (selectedItem );
79
- } else {
80
- DialogFactory .createErrorAlert ("No row selected" , "Please select a row to remove." );
81
- }
82
- }
83
-
84
- @ FXML
85
- protected void runSelectedCommand () {
86
- CommandDto selectedItem = commandsTable .getSelectionModel ().getSelectedItem ();
87
- if (selectedItem != null ) {
88
- executeController .setCommand (selectedItem );
89
- closeStage ();
90
- } else {
91
- DialogFactory .createErrorAlert ("No row selected" , "Please select a row to run." );
58
+ protected void mouseClick (MouseEvent event ) {
59
+ if (event .getClickCount () >= 2 ) {
60
+ final CommandDto selectedItem = commandsTable .getSelectionModel ().getSelectedItem ();
61
+ if (selectedItem != null ) {
62
+ executeController .setCommand (selectedItem );
63
+ closeStage ();
64
+ }
92
65
}
93
66
}
94
67
95
- @ FXML
96
- protected void addNewCommand () {
97
- FxmlStageHolder holder = StageFactory .createModalSaveWindow ();
98
-
99
- SaveController saveController = holder .getFxmlLoader ().getController ();
100
- saveController .setExploreController (this );
101
-
102
- holder .getStage ().showAndWait ();
103
- }
104
-
105
68
void setExecuteController (ExecuteController executeController ) {
106
69
this .executeController = executeController ;
107
70
}
@@ -111,6 +74,15 @@ void addNewCommand(CommandDto commandDto) {
111
74
commandsTable .getItems ().add (commandDto );
112
75
}
113
76
77
+ private void removeCommand (CommandDto item ) {
78
+ if (item == null ) {
79
+ return ;
80
+ }
81
+ commandsTable .getItems ().remove (item );
82
+ executeController .removeSavedCommand (item );
83
+ AppConfig .getInstance ().removeCommand (item );
84
+ }
85
+
114
86
private void fillTable () {
115
87
List <CommandDto > commandsDtoList = AppConfig .getInstance ().getCommands ();
116
88
ObservableList <CommandDto > itemList = FXCollections .observableArrayList (commandsDtoList );
@@ -123,5 +95,34 @@ private void fillTable() {
123
95
final TableColumn <CommandDto , String > descriptionTableColumn = (TableColumn <CommandDto , String >) commandsTable .getColumns ().get (1 );
124
96
descriptionTableColumn .setCellValueFactory (new PropertyValueFactory <>("description" ));
125
97
descriptionTableColumn .setCellFactory (TextFieldTableCell .forTableColumn ());
98
+
99
+ TableColumn <CommandDto , String > removeTableColumn = (TableColumn <CommandDto , String >) commandsTable .getColumns ().get (2 );
100
+ removeTableColumn .setCellValueFactory (new PropertyValueFactory <>("description" ));
101
+ removeTableColumn .setCellFactory (column -> new RemoveTableCell (this ));
102
+ }
103
+
104
+ private static class RemoveTableCell extends TableCell <CommandDto , String > {
105
+ private final Button removeButton = new Button ("X" );
106
+
107
+ private final ExploreController exploreController ;
108
+
109
+ public RemoveTableCell (ExploreController exploreController ) {
110
+ this .exploreController = exploreController ;
111
+ }
112
+
113
+ @ Override
114
+ protected void updateItem (String item , boolean empty ) {
115
+ super .updateItem (item , empty );
116
+ if (item == null || empty ) {
117
+ setGraphic (null );
118
+ setText (null );
119
+ } else {
120
+ setGraphic (removeButton );
121
+ removeButton .setOnAction (event -> {
122
+ CommandDto selectedItem = getTableView ().getItems ().get (getIndex ());
123
+ exploreController .removeCommand (selectedItem );
124
+ });
125
+ }
126
+ }
126
127
}
127
128
}
0 commit comments