Skip to content

Commit 7289124

Browse files
committed
Get rid of dependency injection of controllers
1 parent b890aaf commit 7289124

File tree

2 files changed

+39
-35
lines changed

2 files changed

+39
-35
lines changed

src/main/java/com/github/introfog/gitwave/controller/ExecuteController.java

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,6 @@ public void initialize(FxmlStageHolder fxmlStageHolder) {
7878
});
7979
}
8080

81-
private void updateFields(String currentMainText, TextField field, boolean isCommand) {
82-
final String sourceMainText = isCommand ? sourceCommand.getCommand() : sourceCommand.getDescription();
83-
final String sourceSecText = isCommand ? sourceCommand.getDescription() : sourceCommand.getCommand();
84-
final String currentSecText = isCommand ? description.getText() : command.getText();
85-
86-
if (sourceMainText.equals(currentMainText)){
87-
field.setStyle(GREEN_TEXT_CSS_STYLE);
88-
if (sourceSecText.equals(currentSecText)) {
89-
save.setDisable(true);
90-
}
91-
} else {
92-
save.setDisable(false);
93-
field.setStyle(RED_TEXT_CSS_STYLE);
94-
}
95-
}
96-
9781
@FXML
9882
protected void browseDirectory() {
9983
DirectoryChooser directoryChooser = new DirectoryChooser();
@@ -119,11 +103,15 @@ protected void clean() {
119103
@FXML
120104
protected void chooseFromSaved() {
121105
FxmlStageHolder holder = StageFactory.createModalExploreWindow();
122-
123-
ExploreController exploreController = holder.getFxmlLoader().getController();
124-
exploreController.setExecuteController(this);
125-
126106
holder.getStage().showAndWait();
107+
ExploreController exploreController = holder.getFxmlLoader().getController();
108+
final CommandDto pickedItem = exploreController.getPickedItem();
109+
if (pickedItem != null) {
110+
specifySourceCommand(pickedItem);
111+
}
112+
for (CommandDto removed : exploreController.getRemovedItems()) {
113+
removeSourceCommand(removed);
114+
}
127115
}
128116

129117
@FXML
@@ -189,7 +177,23 @@ protected void foundIssue() {
189177
AppConfig.getInstance().getHostServices().showDocument(AppConstants.LINK_TO_GIT_CONTRIBUTING_FILE);
190178
}
191179

192-
void specifySourceCommand(CommandDto commandDto) {
180+
private void updateFields(String currentMainText, TextField field, boolean isCommand) {
181+
final String sourceMainText = isCommand ? sourceCommand.getCommand() : sourceCommand.getDescription();
182+
final String sourceSecText = isCommand ? sourceCommand.getDescription() : sourceCommand.getCommand();
183+
final String currentSecText = isCommand ? description.getText() : command.getText();
184+
185+
if (sourceMainText.equals(currentMainText)){
186+
field.setStyle(GREEN_TEXT_CSS_STYLE);
187+
if (sourceSecText.equals(currentSecText)) {
188+
save.setDisable(true);
189+
}
190+
} else {
191+
save.setDisable(false);
192+
field.setStyle(RED_TEXT_CSS_STYLE);
193+
}
194+
}
195+
196+
private void specifySourceCommand(CommandDto commandDto) {
193197
save.setDisable(true);
194198
sourceCommand = commandDto;
195199
if (commandDto == null) {
@@ -205,7 +209,8 @@ void specifySourceCommand(CommandDto commandDto) {
205209
}
206210
}
207211

208-
void removeSavedCommand(CommandDto commandDto) {
212+
private void removeSourceCommand(CommandDto commandDto) {
213+
AppConfig.getInstance().removeCommand(commandDto);
209214
if (Objects.equals(commandDto, sourceCommand)) {
210215
sourceCommand = null;
211216
command.setStyle(BLACK_TEXT_CSS_STYLE);

src/main/java/com/github/introfog/gitwave/controller/ExploreController.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.github.introfog.gitwave.model.StageFactory.FxmlStageHolder;
2121
import com.github.introfog.gitwave.model.dto.CommandDto;
2222

23+
import java.util.ArrayList;
2324
import java.util.List;
2425
import javafx.collections.FXCollections;
2526
import javafx.collections.ObservableList;
@@ -40,8 +41,8 @@ public class ExploreController extends BaseController {
4041

4142
@FXML
4243
private AnchorPane anchor;
43-
44-
private ExecuteController executeController;
44+
private CommandDto pickedItem;
45+
private final List<CommandDto> removedItems = new ArrayList<>();
4546

4647
@Override
4748
public void initialize(FxmlStageHolder fxmlStageHolder) {
@@ -60,23 +61,18 @@ protected void mouseClick(MouseEvent event) {
6061
if (event.getClickCount() >= 2) {
6162
final CommandDto selectedItem = commandsTable.getSelectionModel().getSelectedItem();
6263
if (selectedItem != null) {
63-
executeController.specifySourceCommand(selectedItem);
64+
pickedItem = selectedItem;
6465
closeStage();
6566
}
6667
}
6768
}
6869

69-
void setExecuteController(ExecuteController executeController) {
70-
this.executeController = executeController;
70+
public CommandDto getPickedItem() {
71+
return pickedItem;
7172
}
7273

73-
private void removeCommand(CommandDto item) {
74-
if (item == null) {
75-
return;
76-
}
77-
commandsTable.getItems().remove(item);
78-
executeController.removeSavedCommand(item);
79-
AppConfig.getInstance().removeCommand(item);
74+
public List<CommandDto> getRemovedItems() {
75+
return removedItems;
8076
}
8177

8278
private void setUpAndFillTable() {
@@ -124,7 +120,10 @@ protected void updateItem(String item, boolean empty) {
124120
setGraphic(removeButton);
125121
removeButton.setOnAction(event -> {
126122
CommandDto selectedItem = getTableView().getItems().get(getIndex());
127-
exploreController.removeCommand(selectedItem);
123+
if (selectedItem != null) {
124+
exploreController.commandsTable.getItems().remove(selectedItem);
125+
exploreController.removedItems.add(selectedItem);
126+
}
128127
});
129128
}
130129
}

0 commit comments

Comments
 (0)