Skip to content

Commit 550b81e

Browse files
committed
IPTE-22: added more logstatements and user feedback
* introduced new application.properties * reading properties file now with spring tools * adapted layout to have same button size for buttons
1 parent 454cd95 commit 550b81e

File tree

7 files changed

+136
-37
lines changed

7 files changed

+136
-37
lines changed

pom.xml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>de.doubleslash</groupId>
77
<artifactId>keeptime</artifactId>
8-
<version>1.1.0-SNAPSHOT</version>
8+
<version>1.2.0-SNAPSHOT</version>
99
<packaging>jar</packaging>
1010

1111
<name>KeepTime</name>
@@ -173,13 +173,6 @@
173173
</plugin>
174174

175175
</plugins>
176-
177-
<!-- resources>
178-
<resource>
179-
<filtering>true</filtering>
180-
<directory>src/main/resources</directory>
181-
</resource>
182-
</resources -->
183176
</build>
184177

185178
<reporting>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package de.doubleslash.keeptime;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.stereotype.Service;
5+
6+
@Service
7+
public class ApplicationProperties {
8+
9+
private String buildVersion;
10+
private String buildTimestamp;
11+
12+
private String h2Version;
13+
14+
private String springDataSourceUrl;
15+
private String springDataSourceUserName;
16+
private String springDataSourcePassword;
17+
18+
public String getBuildVersion() {
19+
return buildVersion;
20+
}
21+
22+
@Value("${build.version}")
23+
private void setBuildVersion(String projectVersion) {
24+
this.buildVersion = projectVersion;
25+
}
26+
27+
public String getBuildTimestamp() {
28+
return buildTimestamp;
29+
}
30+
31+
@Value("${build.timestamp}")
32+
public void setBuildTimestamp(String buildTimestamp) {
33+
this.buildTimestamp = buildTimestamp;
34+
}
35+
36+
public String getH2Version() {
37+
return this.h2Version;
38+
}
39+
40+
@Value("${h2.version}")
41+
private void setH2Version(final String h2Version) {
42+
this.h2Version = h2Version;
43+
}
44+
45+
public String getSpringDataSourceUrl() {
46+
return springDataSourceUrl;
47+
}
48+
49+
@Value("${spring.datasource.url}")
50+
private void setSpringDataSourceUrl(String springDataSourceUrl) {
51+
this.springDataSourceUrl = springDataSourceUrl;
52+
}
53+
54+
public String getSpringDataSourceUserName() {
55+
return springDataSourceUserName;
56+
}
57+
58+
@Value("${spring.datasource.username}")
59+
private void setSpringDataSourceUserName(String springDataSourceUserName) {
60+
this.springDataSourceUserName = springDataSourceUserName;
61+
}
62+
63+
public String getSpringDataSourcePassword() {
64+
return springDataSourcePassword;
65+
}
66+
67+
@Value("${spring.datasource.password}")
68+
private void setSpringDataSourcePassword(String springDataSourcePassword) {
69+
this.springDataSourcePassword = springDataSourcePassword;
70+
}
71+
}

src/main/java/de/doubleslash/keeptime/Main.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ public class Main extends Application {
6565

6666
private static final Logger LOG = LoggerFactory.getLogger(Main.class);
6767

68-
public static final String VERSION = "v1.1.0";
69-
7068
private ConfigurableApplicationContext springContext;
7169

7270
private Stage popupViewStage;
@@ -81,12 +79,14 @@ public class Main extends Application {
8179

8280
@Override
8381
public void init() throws Exception {
84-
LOG.info("Starting KeepTime {}", VERSION);
82+
LOG.info("Starting KeepTime.");
8583
final DefaultExceptionHandler defaultExceptionHandler = new DefaultExceptionHandler();
8684
defaultExceptionHandler.register();
8785

8886
springContext = SpringApplication.run(Main.class);
89-
// TODO test if everywhere is used the same model
87+
ApplicationProperties applicationProperties = springContext.getBean(ApplicationProperties.class);
88+
LOG.info("KeepTime Version: '{}'.", applicationProperties.getBuildVersion());
89+
LOG.info("KeepTime Build Timestamp: '{}'.", applicationProperties.getBuildTimestamp());
9090
model = springContext.getBean(Model.class);
9191
controller = springContext.getBean(Controller.class);
9292
model.setSpringContext(springContext);

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.slf4j.LoggerFactory;
2323
import org.springframework.stereotype.Component;
2424

25+
import de.doubleslash.keeptime.ApplicationProperties;
2526
import de.doubleslash.keeptime.Main;
2627
import de.doubleslash.keeptime.common.BrowserHelper;
2728
import de.doubleslash.keeptime.common.FileOpenHelper;
@@ -67,10 +68,16 @@ public class AboutController {
6768

6869
private static final Logger LOG = LoggerFactory.getLogger(AboutController.class);
6970

71+
private final ApplicationProperties applicationProperties;
72+
73+
public AboutController (ApplicationProperties applicationProperties) {
74+
this.applicationProperties = applicationProperties;
75+
}
76+
7077
@FXML
7178
public void initialize() {
7279
LOG.debug("set version label");
73-
versionNumberLabel.setText(Main.VERSION);
80+
versionNumberLabel.setText(applicationProperties.getBuildVersion());
7481

7582
ourLicenseHyperLink.setFocusTraversable(false);
7683
ourLicenseHyperLink.setOnAction(ae -> showLicense(Licenses.GPLV3));

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

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,16 @@
1818

1919
import java.io.File;
2020
import java.io.IOException;
21-
import java.io.InputStream;
22-
import java.nio.file.Files;
2321
import java.nio.file.Paths;
2422
import java.sql.SQLException;
25-
import java.util.Properties;
2623

2724
import org.h2.tools.Script;
2825
import org.slf4j.Logger;
2926
import org.slf4j.LoggerFactory;
3027
import org.springframework.beans.factory.annotation.Autowired;
3128
import org.springframework.stereotype.Component;
3229

30+
import de.doubleslash.keeptime.ApplicationProperties;
3331
import de.doubleslash.keeptime.common.OS;
3432
import de.doubleslash.keeptime.common.Resources;
3533
import de.doubleslash.keeptime.common.Resources.RESOURCE;
@@ -118,6 +116,7 @@ public class SettingsController {
118116

119117
private final Controller controller;
120118
private final Model model;
119+
private final ApplicationProperties applicationProperties;
121120

122121
private Stage thisStage;
123122

@@ -127,9 +126,11 @@ public class SettingsController {
127126
ViewController mainscreen;
128127

129128
@Autowired
130-
public SettingsController(final Model model, final Controller controller) {
129+
public SettingsController(final Model model, final Controller controller,
130+
ApplicationProperties applicationProperties) {
131131
this.model = model;
132132
this.controller = controller;
133+
this.applicationProperties = applicationProperties;
133134
}
134135

135136
@FXML
@@ -217,11 +218,11 @@ private void initialize() {
217218
});
218219

219220
LOG.debug("resetButton.setOnAction");
220-
resetHoverBackgroundButton
221-
.setOnAction(ae -> hoverBackgroundColor.setValue(Model.ORIGINAL_HOVER_BACKGROUND_COLOR));
221+
resetHoverBackgroundButton.setOnAction(
222+
ae -> hoverBackgroundColor.setValue(Model.ORIGINAL_HOVER_BACKGROUND_COLOR));
222223
resetHoverFontButton.setOnAction(ae -> hoverFontColor.setValue(Model.ORIGINAL_HOVER_Font_COLOR));
223-
resetDefaultBackgroundButton
224-
.setOnAction(ae -> defaultBackgroundColor.setValue(Model.ORIGINAL_DEFAULT_BACKGROUND_COLOR));
224+
resetDefaultBackgroundButton.setOnAction(
225+
ae -> defaultBackgroundColor.setValue(Model.ORIGINAL_DEFAULT_BACKGROUND_COLOR));
225226
resetDefaultFontButton.setOnAction(ae -> defaultFontColor.setValue(Model.ORIGINAL_DEFAULT_FONT_COLOR));
226227
resetTaskBarFontButton.setOnAction(ae -> taskBarColor.setValue(Model.ORIGINAL_TASK_BAR_FONT_COLOR));
227228

@@ -237,26 +238,42 @@ private void initExportButton() {
237238
exportButton.setOnAction(actionEvent -> {
238239
LOG.info("Button pressed: exportButton");
239240

240-
final Properties properties = new Properties();
241-
try (InputStream resourceStream = SettingsController.class.getResourceAsStream("/application.properties")) {
242-
properties.load(resourceStream);
241+
try {
242+
final String h2Version = applicationProperties.getH2Version();
243243

244244
final FileChooser fileChooser = new FileChooser();
245245
fileChooser.setInitialDirectory(Paths.get(".").toFile());
246-
final String h2Version = properties.getProperty("h2.version");
247246
fileChooser.setInitialFileName(String.format("KeepTime_database-export_H2-version-%s.sql", h2Version));
248-
fileChooser.getExtensionFilters().add(new ExtensionFilter("SQL scrip files.", "*.sql"));
249-
247+
fileChooser.getExtensionFilters().add(new ExtensionFilter("SQL script files.", "*.sql"));
250248
final File fileToSave = fileChooser.showSaveDialog(thisStage);
251-
Files.deleteIfExists(Paths.get(fileToSave.getAbsolutePath()));
249+
if (fileToSave == null) {
250+
LOG.info("User canceled export.");
251+
return;
252+
}
252253

253-
final String url = properties.getProperty("spring.datasource.url");
254-
final String username = properties.getProperty("spring.datasource.username");
255-
final String password = properties.getProperty("spring.datasource.password");
254+
final String url = applicationProperties.getSpringDataSourceUrl();
255+
final String username = applicationProperties.getSpringDataSourceUserName();
256+
final String password = applicationProperties.getSpringDataSourcePassword();
256257

258+
LOG.info("Exporting database to '{}'.", fileToSave);
257259
Script.process(url, username, password, fileToSave.getAbsolutePath(), "", "");
258-
} catch (final SQLException | IOException e) {
260+
LOG.info("Export done.");
261+
262+
Alert informationDialog = new Alert(AlertType.INFORMATION);
263+
informationDialog.setTitle("Export done");
264+
informationDialog.setHeaderText("The current data was exported.");
265+
informationDialog.setContentText("The data was exported to '" + fileToSave + "'.");
266+
267+
informationDialog.showAndWait();
268+
} catch (final SQLException e) {
259269
LOG.error("Could not export db to script file.", e);
270+
271+
Alert errorDialog = new Alert(AlertType.ERROR);
272+
errorDialog.setTitle("Export failed");
273+
errorDialog.setHeaderText("The current data could not be exported.");
274+
errorDialog.setContentText("Please inform a developer and provide your log file.");
275+
276+
errorDialog.showAndWait();
260277
}
261278
});
262279
}

src/main/resources/application.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
spring.h2.console.enabled=true
33
spring.h2.console.path=/h2
44

5-
h2.version=1.4.197
5+
h2.version=@h2.version@
6+
7+
build.version=@project.version@
8+
build.timestamp=@maven.build.timestamp@
69

710
# Datasource
811
spring.datasource.url=jdbc:h2:file:./db/keeptime-h2-db;DB_CLOSE_ON_EXIT=FALSE

src/main/resources/layouts/settings.fxml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<?import javafx.scene.layout.VBox?>
2929
<?import javafx.scene.text.Font?>
3030

31-
<AnchorPane fx:id="settingsRoot" focusTraversable="true" xmlns="http://javafx.com/javafx/8.0.202-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.doubleslash.keeptime.view.SettingsController">
31+
<AnchorPane fx:id="settingsRoot" focusTraversable="true" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.doubleslash.keeptime.view.SettingsController">
3232
<children>
3333
<VBox spacing="10.0" stylesheets="@../css/menu.css">
3434
<children>
@@ -291,14 +291,22 @@
291291
<Font name="Open Sans Regular" size="12.0" />
292292
</font>
293293
</Button>
294-
<Button fx:id="cancelButton" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" text="Cancel">
294+
<Button fx:id="cancelButton" mnemonicParsing="false" text="Cancel">
295295
<font>
296296
<Font name="Open Sans Regular" size="12.0" />
297297
</font>
298298
</Button>
299-
<Button fx:id="exportButton" mnemonicParsing="false" text="Export" />
300299
<Region HBox.hgrow="ALWAYS" />
301-
<Button fx:id="aboutButton" mnemonicParsing="false" prefHeight="25.0" prefWidth="70.0" text="About" HBox.hgrow="ALWAYS" />
300+
<Button fx:id="exportButton" mnemonicParsing="false" text="Export">
301+
<font>
302+
<Font name="Open Sans Regular" size="12.0" />
303+
</font>
304+
</Button>
305+
<Button fx:id="aboutButton" mnemonicParsing="false" text="About">
306+
<font>
307+
<Font name="Open Sans Regular" size="12.0" />
308+
</font>
309+
</Button>
302310
</children>
303311
</HBox>
304312
</children>

0 commit comments

Comments
 (0)