Skip to content

Commit 80bd5d0

Browse files
committed
First part of check update feature: UI part
1 parent 5f516a5 commit 80bd5d0

File tree

9 files changed

+177
-31
lines changed

9 files changed

+177
-31
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2023-2024 Dmitry Chubrick
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.github.introfog.gitwave.controller;
18+
19+
import com.github.introfog.gitwave.model.AppConfig;
20+
import com.github.introfog.gitwave.model.AppConstants;
21+
import com.github.introfog.gitwave.model.StageFactory.FxmlStageHolder;
22+
23+
import javafx.fxml.FXML;
24+
import javafx.scene.control.Button;
25+
import javafx.scene.control.Label;
26+
27+
public class UpdateController extends BaseController {
28+
@FXML
29+
private Label currentVersion;
30+
@FXML
31+
private Button update;
32+
33+
@Override
34+
public void initialize(FxmlStageHolder fxmlStageHolder) {
35+
super.initialize(fxmlStageHolder);
36+
super.setClosingOnEscapePressing(fxmlStageHolder);
37+
currentVersion.setText("Current: " + AppConstants.VERSION);
38+
update.requestFocus();
39+
}
40+
41+
@FXML
42+
protected void updateNow() {
43+
AppConfig.getInstance().getHostServices().showDocument(AppConstants.LINK_TO_GIT_RELEASES);
44+
closeStage();
45+
}
46+
47+
@FXML
48+
protected void later() {
49+
closeStage();
50+
}
51+
}

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@
2121
import com.github.introfog.gitwave.model.AppConstants;
2222
import com.github.introfog.gitwave.model.CommandExecutor;
2323
import com.github.introfog.gitwave.model.DialogFactory;
24-
import com.github.introfog.gitwave.model.StageFactory;
2524
import com.github.introfog.gitwave.model.StageFactory.FxmlStageHolder;
2625
import com.github.introfog.gitwave.model.dto.ParameterDto;
2726

2827
import javafx.fxml.FXML;
2928
import javafx.scene.control.Button;
29+
import javafx.scene.control.ButtonType;
3030
import javafx.scene.control.Label;
31+
import javafx.scene.control.Menu;
32+
import javafx.scene.control.MenuItem;
33+
import javafx.scene.control.SeparatorMenuItem;
3134
import javafx.scene.control.TableView;
3235
import javafx.scene.control.TextField;
3336
import javafx.stage.Stage;
@@ -52,21 +55,29 @@ public class MainController extends BaseController {
5255
@FXML
5356
private TableView<ParameterDto> parametersTable;
5457

55-
private SettingsController settingsController;
58+
private MenuController menuController;
59+
@FXML
60+
private Menu menu;
61+
@FXML
62+
private MenuItem updateMenuItem;
63+
@FXML
64+
private SeparatorMenuItem updateMenuItemSeparator;
5665

5766
@Override
5867
public void initialize(FxmlStageHolder fxmlStageHolder) {
5968
super.initialize(fxmlStageHolder);
6069
final Stage primaryStage = fxmlStageHolder.getStage();
6170
primaryStage.setOnCloseRequest(event -> {
6271
event.consume();
63-
DialogFactory.createCloseConfirmationAlert(primaryStage);
72+
if (DialogFactory.createCloseConfirmationAlert() == ButtonType.OK) {
73+
primaryStage.close();
74+
};
6475
});
6576
directoryTabController = new DirectoryTabController(fxmlStageHolder, directory);
6677
parametersTabController = new ParametersTabController(fxmlStageHolder, parametersTable, parametersText);
6778
commandTabController = new CommandTabController(fxmlStageHolder, command, description, save,
6879
parametersTabController);
69-
settingsController = new SettingsController(fxmlStageHolder);
80+
menuController = new MenuController(fxmlStageHolder, menu, updateMenuItem, updateMenuItemSeparator);
7081
}
7182

7283
@FXML
@@ -91,7 +102,8 @@ protected void saveCommand() {
91102

92103
@FXML
93104
protected void runCommand() {
94-
if (settingsController.isValid() && directoryTabController.isValid()
105+
// TODO MINOR: it is possible to define all action in code, consider is it worth to do it in that way, or leave @FXML methods
106+
if (menuController.isValid() && directoryTabController.isValid()
95107
&& commandTabController.isValid() && parametersTabController.isValid()) {
96108

97109
AppConfig.getInstance().setLastRunFolder(directoryTabController.getDirectory());
@@ -105,12 +117,17 @@ protected void runCommand() {
105117

106118
@FXML
107119
protected void openSettings() {
108-
settingsController.openSettings();
120+
menuController.openSettings();
109121
}
110122

111123
@FXML
112124
protected void openAbout() {
113-
StageFactory.createModalAboutWindow().getStage().showAndWait();
125+
menuController.openAbout();
126+
}
127+
128+
@FXML
129+
protected void openUpdate() {
130+
menuController.openUpdate();
114131
}
115132

116133
@FXML

src/main/java/com/github/introfog/gitwave/controller/main/SettingsController.java renamed to src/main/java/com/github/introfog/gitwave/controller/main/MenuController.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,33 @@
55
import com.github.introfog.gitwave.model.DialogFactory;
66
import com.github.introfog.gitwave.model.StageFactory;
77
import com.github.introfog.gitwave.model.StageFactory.FxmlStageHolder;
8+
import com.github.introfog.gitwave.model.UpdateChecker;
89

910
import java.io.File;
11+
import javafx.scene.control.Menu;
12+
import javafx.scene.control.MenuItem;
13+
import javafx.scene.control.SeparatorMenuItem;
1014
import org.slf4j.Logger;
1115
import org.slf4j.LoggerFactory;
1216

13-
public class SettingsController extends SupportController {
14-
private static final Logger LOGGER = LoggerFactory.getLogger(SettingsController.class);
17+
public class MenuController extends SupportController {
18+
private static final Logger LOGGER = LoggerFactory.getLogger(MenuController.class);
19+
private Menu menu;
20+
private MenuItem updateMenuItem;
21+
private SeparatorMenuItem updateMenuItemSeparator;
1522

16-
public SettingsController(FxmlStageHolder fxmlStageHolder) {
23+
public MenuController(FxmlStageHolder fxmlStageHolder, Menu menu, MenuItem updateMenuItem, SeparatorMenuItem updateMenuItemSeparator) {
1724
super(fxmlStageHolder);
25+
this.menu = menu;
26+
this.updateMenuItem = updateMenuItem;
27+
this.updateMenuItemSeparator = updateMenuItemSeparator;
28+
if (UpdateChecker.isNewReleaseAvailable()) {
29+
this.menu.setText("Menu*");
30+
this.updateMenuItem.setDisable(false);
31+
this.updateMenuItem.setVisible(true);
32+
this.updateMenuItemSeparator.setDisable(false);
33+
this.updateMenuItemSeparator.setVisible(true);
34+
}
1835
}
1936

2037
@Override
@@ -35,4 +52,12 @@ public boolean isValid() {
3552
public void openSettings() {
3653
StageFactory.createModalSettingsWindow().getStage().showAndWait();
3754
}
55+
56+
public void openAbout() {
57+
StageFactory.createModalAboutWindow().getStage().showAndWait();
58+
}
59+
60+
public void openUpdate() {
61+
StageFactory.createModalUpdateWindow().getStage().showAndWait();
62+
}
3863
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public final class AppConstants {
2020
public static final String VERSION = "1.0.0-SNAPSHOT";
2121
public static final String LINK_TO_GIT_CONTRIBUTING_FILE = "https://github.com/introfog/GitWave/blob/master/CONTRIBUTING.md";
2222
public static final String LINK_TO_GIT_REPO = "https://github.com/introfog/GitWave";
23+
public static final String LINK_TO_GIT_RELEASES = "https://github.com/introfog/GitWave/releases";
2324
public static final String PATH_TO_LOGO = "/logo.png";
2425
// TODO make pretty logo
2526

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import javafx.stage.Stage;
2424

2525
public final class DialogFactory {
26+
private static final String COMMON_STYLES = "-fx-font-family: verdana; -fx-font-size: 12";
2627
private DialogFactory() {
2728
// private constructor
2829
}
@@ -34,37 +35,36 @@ public static void createErrorAlert(String header, String msg) {
3435
alert.setTitle("GitWave error");
3536
alert.setHeaderText(header);
3637
alert.setContentText(msg);
37-
alert.getDialogPane().setStyle("-fx-font-family: verdana; -fx-font-size: 12");
38+
alert.getDialogPane().setStyle(COMMON_STYLES);
3839
alert.showAndWait();
3940
}
4041

41-
public static void createCloseConfirmationAlert(Stage primaryStage) {
42-
Alert confirmationDialog = new Alert(AlertType.CONFIRMATION);
43-
Stage stage = (Stage) confirmationDialog.getDialogPane().getScene().getWindow();
42+
public static ButtonType createCloseConfirmationAlert() {
43+
Alert dialog = new Alert(AlertType.CONFIRMATION);
44+
Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
4445
stage.getIcons().add(new Image(StageFactory.class.getResourceAsStream(AppConstants.PATH_TO_LOGO)));
45-
confirmationDialog.setTitle("Confirmation");
46-
confirmationDialog.setHeaderText("Do you really want to close the application?");
47-
confirmationDialog.getButtonTypes().setAll(ButtonType.OK, ButtonType.CANCEL);
46+
dialog.setTitle("Confirmation");
47+
dialog.setHeaderText("Do you really want to close the application?");
48+
dialog.getButtonTypes().setAll(ButtonType.OK, ButtonType.CANCEL);
4849

49-
confirmationDialog.getDialogPane().setStyle("-fx-font-family: verdana; -fx-font-size: 12");
50-
confirmationDialog.showAndWait().ifPresent(response -> {
51-
if (response == ButtonType.OK) {
52-
primaryStage.close();
53-
}
54-
});
50+
dialog.getDialogPane().setStyle(COMMON_STYLES);
51+
ButtonType[] pressedButton = {null};
52+
dialog.showAndWait().ifPresent(response -> pressedButton[0] = response);
53+
return pressedButton[0];
5554
}
5655

5756
public static ButtonType createSaveOrUpdateAlert() {
58-
Alert confirmationDialog = new Alert(AlertType.CONFIRMATION);
59-
Stage stage = (Stage) confirmationDialog.getDialogPane().getScene().getWindow();
57+
Alert dialog = new Alert(AlertType.CONFIRMATION);
58+
Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
6059
stage.getIcons().add(new Image(StageFactory.class.getResourceAsStream(AppConstants.PATH_TO_LOGO)));
61-
confirmationDialog.setTitle("Confirmation");
62-
confirmationDialog.setHeaderText("Do you want to save command as a new instance?\nSelect 'No' if update existed.");
63-
confirmationDialog.getButtonTypes().setAll(ButtonType.YES, ButtonType.NO, ButtonType.CANCEL);
6460

65-
confirmationDialog.getDialogPane().setStyle("-fx-font-family: verdana; -fx-font-size: 12");
61+
dialog.setTitle("Confirmation");
62+
dialog.setHeaderText("Do you want to save command as a new instance?\nSelect 'No' if update existed.");
63+
dialog.getButtonTypes().setAll(ButtonType.YES, ButtonType.NO, ButtonType.CANCEL);
64+
65+
dialog.getDialogPane().setStyle(COMMON_STYLES);
6666
ButtonType[] pressedButton = {null};
67-
confirmationDialog.showAndWait().ifPresent(response -> pressedButton[0] = response);
67+
dialog.showAndWait().ifPresent(response -> pressedButton[0] = response);
6868
return pressedButton[0];
6969
}
7070
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ public static FxmlStageHolder createModalAboutWindow() {
5555
return holder;
5656
}
5757

58+
public static FxmlStageHolder createModalUpdateWindow() {
59+
FxmlStageHolder holder = StageFactory.createModalStage("view/update.fxml", "New Version Available!");
60+
holder.getStage().setResizable(false);
61+
return holder;
62+
}
63+
5864
public static FxmlStageHolder createPrimaryExecuteWindow(Stage stage) {
5965
final FxmlStageHolder holder = creteStage("view/main.fxml", "GitWave", stage);
6066
holder.getStage().setMinWidth(400);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2023-2024 Dmitry Chubrick
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.github.introfog.gitwave.model;
18+
19+
public final class UpdateChecker {
20+
private UpdateChecker() {
21+
// Do nothing
22+
}
23+
24+
public static boolean isNewReleaseAvailable() {
25+
return true;
26+
}
27+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@
3232
<children>
3333
<MenuBar prefHeight="25.0" prefWidth="450.0" GridPane.vgrow="NEVER">
3434
<menus>
35-
<Menu mnemonicParsing="false" text="Menu">
35+
<Menu fx:id="menu" mnemonicParsing="false" text="Menu">
3636
<items>
3737
<MenuItem mnemonicParsing="false" onAction="#openSettings" text="Settings" />
3838
<SeparatorMenuItem mnemonicParsing="false" />
3939
<MenuItem mnemonicParsing="false" onAction="#openAbout" text="About" />
40+
<SeparatorMenuItem fx:id="updateMenuItemSeparator" disable="true" mnemonicParsing="false" visible="false" />
41+
<MenuItem fx:id="updateMenuItem" disable="true" mnemonicParsing="false" onAction="#openUpdate" text="Update*" visible="false" />
4042
</items>
4143
</Menu>
4244
</menus>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<?import javafx.geometry.Insets?>
4+
<?import javafx.scene.control.Button?>
5+
<?import javafx.scene.control.Label?>
6+
<?import javafx.scene.layout.AnchorPane?>
7+
<AnchorPane prefHeight="140.0" prefWidth="400.0" style="-fx-font-family: verdana; -fx-font-size: 12;" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.github.introfog.gitwave.controller.UpdateController">
8+
<padding>
9+
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
10+
</padding>
11+
<children>
12+
<Label layoutX="40.0" layoutY="40.0" prefHeight="55.0" prefWidth="360.0" text="Please manually download the latest version from GitHub. Remember to copy current config folder to the folder with the new version of app." wrapText="true" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
13+
<Button layoutX="328.0" layoutY="161.0" mnemonicParsing="false" onAction="#later" text="Later" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0" />
14+
<Button fx:id="update" defaultButton="true" layoutX="238.0" layoutY="160.0" mnemonicParsing="false" onAction="#updateNow" text="Update Now" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="60.0" />
15+
<Label fx:id="currentVersion" layoutX="30.0" layoutY="100.0" text="Current: " AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" />
16+
</children>
17+
</AnchorPane>

0 commit comments

Comments
 (0)