Skip to content

Commit e194f69

Browse files
author
Martin Plieske
committed
added alert if license file was not found
1 parent 324ae25 commit e194f69

File tree

4 files changed

+45
-17
lines changed

4 files changed

+45
-17
lines changed

src/main/java/de/doubleslash/keeptime/common/FileOpenHelper.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,21 @@ public class FileOpenHelper {
2727

2828
private FileOpenHelper() {}
2929

30-
public static void openFile(final String fileString) {
30+
public static boolean openFile(final String fileString) {
3131
final File file = new File(fileString);
3232
final Runtime rt = Runtime.getRuntime();
3333

34-
if (OS.isWindows()) {
35-
executeCommandWindows(rt, file);
36-
} else if (OS.isLinux()) {
37-
executeCommandLinux(rt, file);
34+
if (file.exists() && file.isFile()) {
35+
if (OS.isWindows()) {
36+
executeCommandWindows(rt, file);
37+
} else if (OS.isLinux()) {
38+
executeCommandLinux(rt, file);
39+
} else {
40+
LOG.warn("OS is not supported");
41+
}
42+
return true;
3843
} else {
39-
LOG.warn("OS is not supported");
44+
return false;
4045
}
4146
}
4247

src/main/java/de/doubleslash/keeptime/common/Licenses.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,29 @@
1818

1919
public enum Licenses {
2020

21-
GPLV3("./licenses/GNU General Public License (GPL), Version 3.0.txt", "GNU General Public License Version 3.0"),
22-
EPLV1("./licenses/EPL 1.0.txt", "Eclipse Public License 1.0"),
23-
APACHEV2("./licenses/Apache License, Version 2.0.txt", "Apache License Version 2.0"),
21+
GPLV3(
22+
"./licenses/GNU General Public License (GPL), Version 3.0.txt",
23+
"GNU General Public License Version 3.0",
24+
"https://www.gnu.org/licenses/gpl-3.0.de.html"),
25+
EPLV1("./licenses/EPL 1.0.txt", "Eclipse Public License 1.0", "https://www.eclipse.org/legal/epl-v10.html"),
26+
APACHEV2(
27+
"./licenses/Apache License, Version 2.0.txt",
28+
"Apache License Version 2.0",
29+
"https://www.apache.org/licenses/LICENSE-2.0"),
2430
LGPLV3(
2531
"./licenses/GNU Lesser General Public License (LGPL), Version 3.0.txt",
26-
"GNU Lesser General Public License Version 3.0"),
27-
MIT("./licenses/The MIT License.txt", "The MIT License");
32+
"GNU Lesser General Public License Version 3.0",
33+
"https://www.gnu.org/licenses/lgpl-3.0.de.html"),
34+
MIT("./licenses/The MIT License.txt", "The MIT License", "https://opensource.org/licenses/MIT");
2835

2936
private final String path;
3037
private final String name;
38+
private final String url;
3139

32-
private Licenses(final String licensePath, final String licenseName) {
40+
private Licenses(final String licensePath, final String licenseName, final String urlWebsite) {
3341
path = licensePath;
3442
name = licenseName;
43+
url = urlWebsite;
3544
}
3645

3746
public String getPath() {
@@ -41,4 +50,8 @@ public String getPath() {
4150
public String getName() {
4251
return name;
4352
}
53+
54+
public String getUrl() {
55+
return url;
56+
}
4457
}

src/main/java/de/doubleslash/keeptime/view/AboutController.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import javafx.collections.FXCollections;
2828
import javafx.collections.ObservableList;
2929
import javafx.fxml.FXML;
30+
import javafx.scene.control.Alert;
31+
import javafx.scene.control.Alert.AlertType;
3032
import javafx.scene.control.Button;
3133
import javafx.scene.control.Hyperlink;
3234
import javafx.scene.control.Label;
@@ -85,14 +87,22 @@ protected void updateItem(final String item, final boolean empty) {
8587

8688
setOnMouseExited(e -> setUnderline(false));
8789

88-
setOnMouseClicked(e -> {
89-
if (!empty && e.getButton() == MouseButton.PRIMARY) {
90+
setOnMouseClicked(eventOnMouseClicked -> {
91+
if (!empty && eventOnMouseClicked.getButton() == MouseButton.PRIMARY) {
9092
final LicenceTableRow row = (LicenceTableRow) getTableRow().getItem();
9193
final Licenses license = row.getLicense();
9294
LOG.debug("License file name: {}", license);
9395

94-
FileOpenHelper.openFile(license.getPath());
95-
// TODO show error if file does not exist
96+
if (!FileOpenHelper.openFile(license.getPath())) {
97+
final Alert alert = new Alert(AlertType.ERROR);
98+
alert.setTitle("Ooops");
99+
alert.setHeaderText("Could not find the license file");
100+
alert.setContentText(
101+
String.format("We could not find the license file at \"%s\".%nPlease visit \"%s\".",
102+
license.getPath(), license.getUrl()));
103+
104+
alert.show();
105+
}
96106
}
97107
});
98108
}

src/main/java/de/doubleslash/keeptime/view/SettingsController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ private void loadSubStages() {
256256
aboutStage.setOnHiding(e -> this.thisStage.setAlwaysOnTop(true));
257257
aboutStage.setOnShowing(e -> {
258258
this.thisStage.setAlwaysOnTop(false);
259-
aboutStage.setAlwaysOnTop(true);
259+
aboutStage.setAlwaysOnTop(false);
260260
});
261261

262262
LOG.debug("done setting up stage");

0 commit comments

Comments
 (0)