Skip to content

Commit c349596

Browse files
committed
Add indicate colors to execute window and simplify update/save/remove logic
1 parent 9377449 commit c349596

File tree

6 files changed

+91
-123
lines changed

6 files changed

+91
-123
lines changed

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

Lines changed: 64 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636

3737
public class ExecuteController extends BaseController {
3838
private static final Logger LOGGER = LoggerFactory.getLogger(ExecuteController.class);
39+
private static final String GREEN_TEXT_CSS_STYLE = "-fx-text-fill: green";
40+
private static final String RED_TEXT_CSS_STYLE = "-fx-text-fill: red";
41+
private static final String BLACK_TEXT_CSS_STYLE = "-fx-text-fill: black";
3942

4043
@FXML
4144
private TextField directory;
@@ -46,19 +49,10 @@ public class ExecuteController extends BaseController {
4649
@FXML
4750
private TextField description;
4851

49-
@FXML
50-
private Button run;
51-
52-
@FXML
53-
private Button update;
54-
55-
@FXML
56-
private Button clean;
57-
5852
@FXML
5953
private Button save;
6054

61-
private CommandDto savedCommand;
55+
private CommandDto sourceCommand;
6256

6357
@Override
6458
public void initialize(FxmlStageHolder fxmlStageHolder) {
@@ -68,6 +62,35 @@ public void initialize(FxmlStageHolder fxmlStageHolder) {
6862
event.consume();
6963
DialogFactory.createCloseConfirmationAlert(primaryStage);
7064
});
65+
66+
command.textProperty().addListener((obs, oldText, newText) -> {
67+
if (sourceCommand != null) {
68+
updateFields(newText, command, true);
69+
} else {
70+
save.setDisable(newText.isEmpty());
71+
}
72+
});
73+
description.textProperty().addListener((obs, oldText, newText) -> {
74+
if (sourceCommand != null) {
75+
updateFields(newText, description, false);
76+
}
77+
});
78+
}
79+
80+
private void updateFields(String currentMainText, TextField field, boolean isCommand) {
81+
final String sourceMainText = isCommand ? sourceCommand.getCommand() : sourceCommand.getDescription();
82+
final String sourceSecText = isCommand ? sourceCommand.getDescription() : sourceCommand.getCommand();
83+
final String currentSecText = isCommand ? description.getText() : command.getText();
84+
85+
if (sourceMainText.equals(currentMainText)){
86+
field.setStyle(GREEN_TEXT_CSS_STYLE);
87+
if (sourceSecText.equals(currentSecText)) {
88+
save.setDisable(true);
89+
}
90+
} else {
91+
save.setDisable(false);
92+
field.setStyle(RED_TEXT_CSS_STYLE);
93+
}
7194
}
7295

7396
@FXML
@@ -88,24 +111,8 @@ protected void browseDirectory() {
88111
}
89112

90113
@FXML
91-
protected void updateSavedCommand() {
92-
// TODO get rid of special window for updating saved command, just add buttons "update existed" and "save as new" to execute window
93-
// TODO when the saved command hasn't been changed, write it green, when you change it, write red, and show buttons "update existed" and "save as new"
94-
FxmlStageHolder holder = StageFactory.createModalStage("view/updater.fxml", "Command updater");
95-
96-
UpdateController updateController = holder.getFxmlLoader().getController();
97-
updateController.setExecuteController(this);
98-
updateController.setCommand(savedCommand);
99-
100-
holder.getStage().showAndWait();
101-
}
102-
103-
@FXML
104-
protected void cleanSavedCommand() {
105-
command.clear();
106-
description.clear();
107-
savedCommand = null;
108-
switchToSavedCommand(false);
114+
protected void clean() {
115+
specifySourceCommand(null);
109116
}
110117

111118
@FXML
@@ -120,12 +127,17 @@ protected void chooseFromSaved() {
120127

121128
@FXML
122129
protected void saveCommand() {
123-
if (command.getText().isEmpty()) {
124-
DialogFactory.createErrorAlert("Invalid command", "Command can't be empty");
125-
} else {
126-
final CommandDto commandDto = new CommandDto(command.getText(), description.getText());
130+
final CommandDto commandDto = new CommandDto(command.getText(), description.getText());
131+
if (sourceCommand == null) {
127132
AppConfig.getInstance().addCommand(commandDto);
128-
setCommand(commandDto);
133+
specifySourceCommand(commandDto);
134+
// TODO MINOR if DTO is already existed, nothing was happened, is it OK?
135+
} else {
136+
FxmlStageHolder holder = StageFactory.createModalStage("view/updater.fxml", "Command updater");
137+
UpdateController updateController = holder.getFxmlLoader().getController();
138+
// TODO add required methods for all stages where necessary
139+
updateController.setRequiredFields(this, sourceCommand, commandDto);
140+
holder.getStage().showAndWait();
129141
}
130142
}
131143

@@ -173,23 +185,28 @@ protected void foundIssue() {
173185
AppConfig.getInstance().getHostServices().showDocument(AppConstants.LINK_TO_GIT_CONTRIBUTING_FILE);
174186
}
175187

176-
void setCommand(CommandDto commandDto) {
177-
command.setText(commandDto.getCommand());
178-
description.setText(commandDto.getDescription());
179-
savedCommand = commandDto;
180-
switchToSavedCommand(true);
188+
void specifySourceCommand(CommandDto commandDto) {
189+
save.setDisable(true);
190+
sourceCommand = commandDto;
191+
if (commandDto == null) {
192+
command.clear();
193+
command.setStyle(BLACK_TEXT_CSS_STYLE);
194+
description.clear();
195+
description.setStyle(BLACK_TEXT_CSS_STYLE);
196+
} else {
197+
command.setText(commandDto.getCommand());
198+
command.setStyle(GREEN_TEXT_CSS_STYLE);
199+
description.setText(commandDto.getDescription());
200+
description.setStyle(GREEN_TEXT_CSS_STYLE);
201+
}
181202
}
182203

183204
void removeSavedCommand(CommandDto commandDto) {
184-
if (Objects.equals(commandDto, savedCommand)) {
185-
savedCommand = null;
186-
switchToSavedCommand(false);
205+
if (Objects.equals(commandDto, sourceCommand)) {
206+
sourceCommand = null;
207+
command.setStyle(BLACK_TEXT_CSS_STYLE);
208+
description.setStyle(BLACK_TEXT_CSS_STYLE);
209+
save.setDisable(false);
187210
}
188211
}
189-
190-
private void switchToSavedCommand(boolean switchToSavedCommand) {
191-
update.setDisable(!switchToSavedCommand);
192-
clean.setDisable(!switchToSavedCommand);
193-
save.setDisable(switchToSavedCommand);
194-
}
195212
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected void mouseClick(MouseEvent event) {
6060
if (event.getClickCount() >= 2) {
6161
final CommandDto selectedItem = commandsTable.getSelectionModel().getSelectedItem();
6262
if (selectedItem != null) {
63-
executeController.setCommand(selectedItem);
63+
executeController.specifySourceCommand(selectedItem);
6464
closeStage();
6565
}
6666
}

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

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,14 @@
1717
package com.github.introfog.gitwave.controller;
1818

1919
import com.github.introfog.gitwave.model.AppConfig;
20-
import com.github.introfog.gitwave.model.DialogFactory;
2120
import com.github.introfog.gitwave.model.StageFactory.FxmlStageHolder;
2221
import com.github.introfog.gitwave.model.dto.CommandDto;
2322

2423
import javafx.fxml.FXML;
25-
import javafx.scene.control.TextField;
26-
import org.slf4j.Logger;
27-
import org.slf4j.LoggerFactory;
2824

2925
public class UpdateController extends BaseController {
30-
private static final Logger LOGGER = LoggerFactory.getLogger(UpdateController.class);
31-
32-
@FXML
33-
private TextField command;
34-
35-
@FXML
36-
private TextField description;
37-
38-
private CommandDto initialCommand;
39-
26+
private CommandDto oldCommand;
27+
private CommandDto newCommand;
4028
private ExecuteController executeController;
4129

4230
@Override
@@ -52,43 +40,21 @@ protected void cancel() {
5240

5341
@FXML
5442
protected void saveAsNew() {
55-
if (command.getText().isEmpty()) {
56-
DialogFactory.createErrorAlert("Invalid command", "Command can't be empty");
57-
} else if (executeController != null) {
58-
final CommandDto commandDto = new CommandDto(command.getText(), description.getText());
59-
if (commandDto.equals(initialCommand)) {
60-
DialogFactory.createErrorAlert("Save error", "The same command already exists");
61-
} else {
62-
AppConfig.getInstance().addCommand(commandDto);
63-
executeController.setCommand(commandDto);
64-
closeStage();
65-
}
66-
} else {
67-
LOGGER.error("Edit controller isn't called correctly, execute controller are null.");
68-
}
43+
AppConfig.getInstance().addCommand(newCommand);
44+
executeController.specifySourceCommand(newCommand);
45+
closeStage();
6946
}
7047

7148
@FXML
7249
protected void updateExisted() {
73-
if (command.getText().isEmpty()) {
74-
DialogFactory.createErrorAlert("Invalid command", "Command can't be empty");
75-
} else if (executeController != null) {
76-
final CommandDto currentCommand = new CommandDto(command.getText(), description.getText());
77-
AppConfig.getInstance().updateExistedCommand(initialCommand, currentCommand);
78-
executeController.setCommand(currentCommand);
79-
closeStage();
80-
} else {
81-
LOGGER.error("Edit controller isn't called correctly, execute controller are null.");
82-
}
50+
AppConfig.getInstance().updateExistedCommand(oldCommand, newCommand);
51+
executeController.specifySourceCommand(newCommand);
52+
closeStage();
8353
}
8454

85-
void setExecuteController(ExecuteController executeController) {
55+
void setRequiredFields(ExecuteController executeController, CommandDto oldCommand, CommandDto newCommand) {
8656
this.executeController = executeController;
87-
}
88-
89-
void setCommand(CommandDto commandDto) {
90-
this.initialCommand = commandDto;
91-
command.setText(commandDto.getCommand());
92-
description.setText(commandDto.getDescription());
57+
this.oldCommand = oldCommand;
58+
this.newCommand = newCommand;
9359
}
9460
}

src/main/java/com/github/introfog/gitwave/model/AppConfig.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,6 @@ public void removeCommand(CommandDto commandDto) {
9494
saveConfig();
9595
}
9696

97-
public boolean containsCommand(CommandDto commandDto) {
98-
return config.getCommands().contains(commandDto);
99-
}
100-
101-
public void updateCommandScript(CommandDto commandDto, String newCommand) {
102-
final List<CommandDto> commands = config.getCommands();
103-
commands.get(commands.indexOf(commandDto)).setCommand(newCommand);
104-
saveConfig();
105-
}
106-
107-
public void updateCommandDescription(CommandDto commandDto, String newDescription) {
108-
final List<CommandDto> commands = config.getCommands();
109-
commands.get(commands.indexOf(commandDto)).setDescription(newDescription);
110-
saveConfig();
111-
}
112-
11397
public void updateExistedCommand(CommandDto initial, CommandDto current) {
11498
final List<CommandDto> commands = config.getCommands();
11599
if (initial != null && commands.contains(initial)) {

src/main/resources/com/github/introfog/gitwave/view/executor.fxml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<content>
6565
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
6666
<children>
67-
<Label text="Command" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="20.0">
67+
<Label text="Command*" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="20.0">
6868
<font>
6969
<Font name="Verdana" size="12.0" />
7070
</font></Label>
@@ -80,19 +80,15 @@
8080
<font>
8181
<Font name="Verdana" size="12.0" />
8282
</font></TextField>
83-
<Button fx:id="save" layoutX="48.0" layoutY="138.0" mnemonicParsing="false" onAction="#saveCommand" text="Save" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="140.0">
83+
<Button fx:id="save" disable="true" layoutX="48.0" layoutY="138.0" mnemonicParsing="false" onAction="#saveCommand" text="Save" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="140.0">
8484
<font>
8585
<Font name="Verdana" size="12.0" />
8686
</font></Button>
8787
<Button layoutX="130.0" layoutY="138.0" mnemonicParsing="false" onAction="#chooseFromSaved" text="Choose from saved" AnchorPane.rightAnchor="80.0" AnchorPane.topAnchor="140.0">
8888
<font>
8989
<Font name="Verdana" size="12.0" />
9090
</font></Button>
91-
<Button fx:id="update" disable="true" layoutX="351.0" layoutY="138.0" mnemonicParsing="false" onAction="#updateSavedCommand" text="Update" AnchorPane.leftAnchor="80.0" AnchorPane.topAnchor="140.0">
92-
<font>
93-
<Font name="Verdana" size="12.0" />
94-
</font></Button>
95-
<Button fx:id="clean" disable="true" layoutX="287.0" layoutY="138.0" mnemonicParsing="false" onAction="#cleanSavedCommand" text="Clean" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="140.0">
91+
<Button layoutX="287.0" layoutY="138.0" mnemonicParsing="false" onAction="#clean" text="Clean" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="140.0">
9692
<font>
9793
<Font name="Verdana" size="12.0" />
9894
</font></Button>
@@ -109,7 +105,7 @@
109105
</TabPane>
110106
<AnchorPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="2" GridPane.vgrow="NEVER">
111107
<children>
112-
<Button fx:id="run" layoutX="386.0" layoutY="36.0" mnemonicParsing="false" onAction="#runCommand" text="4. Run" AnchorPane.bottomAnchor="20.0" AnchorPane.rightAnchor="20.0">
108+
<Button layoutX="386.0" layoutY="36.0" mnemonicParsing="false" onAction="#runCommand" text="4. Run" AnchorPane.bottomAnchor="20.0" AnchorPane.rightAnchor="20.0">
113109
<font>
114110
<Font name="Verdana" size="12.0" />
115111
</font></Button>
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3+
<?import javafx.geometry.Insets?>
34
<?import javafx.scene.control.Button?>
45
<?import javafx.scene.control.Label?>
5-
<?import javafx.scene.control.TextField?>
66
<?import javafx.scene.layout.AnchorPane?>
7-
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="200.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.github.introfog.gitwave.controller.UpdateController">
7+
<?import javafx.scene.text.Font?>
8+
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="200.0" prefWidth="500.0" style="-fx-font-family: verdana;" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.github.introfog.gitwave.controller.UpdateController">
89
<children>
9-
<Label layoutX="26.0" layoutY="22.0" text="Command" />
10-
<TextField fx:id="command" layoutX="26.0" layoutY="39.0" prefHeight="25.0" prefWidth="448.0" />
11-
<Label layoutX="26.0" layoutY="75.0" text="Description" />
12-
<TextField fx:id="description" layoutX="26.0" layoutY="92.0" prefHeight="25.0" prefWidth="448.0" />
10+
<Label layoutX="26.0" layoutY="24.0" prefHeight="39.0" prefWidth="381.0" style="-fx-font-size: 20;" text="How do you want to save command?" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
11+
<font>
12+
<Font name="Verdana" size="36.0" />
13+
</font>
14+
</Label>
1315
<Button layoutX="26.0" layoutY="144.0" mnemonicParsing="false" onAction="#saveAsNew" text="Save as new" />
1416
<Button layoutX="422.0" layoutY="144.0" mnemonicParsing="false" onAction="#cancel" text="Cancel" />
1517
<Button layoutX="202.0" layoutY="144.0" mnemonicParsing="false" onAction="#updateExisted" text="Update existed" />
1618
</children>
19+
<padding>
20+
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
21+
</padding>
1722
</AnchorPane>

0 commit comments

Comments
 (0)