Skip to content

Commit 454cd95

Browse files
author
Martin Plieske
committed
IPTE-22: add static h2 version to application Properties and add export button with save file dialog
1 parent 8396ed5 commit 454cd95

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

pom.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
<maven.compiler.source>1.8</maven.compiler.source>
5656
<maven.compiler.target>1.8</maven.compiler.target>
5757

58+
<h2.version>1.4.197</h2.version>
59+
5860
<maven-dependency-check.version>6.0.5</maven-dependency-check.version>
5961
<!-- USING HTML,XML (comma-separated list) did not work with plugin version 5.1.0 -->
6062
<maven-dependency-check.format>ALL</maven-dependency-check.format>
@@ -72,7 +74,7 @@
7274
<dependency>
7375
<groupId>com.h2database</groupId>
7476
<artifactId>h2</artifactId>
75-
<version>1.4.197</version>
77+
<version>${h2.version}</version>
7678
</dependency>
7779
<dependency>
7880
<groupId>org.springframework.boot</groupId>
@@ -171,6 +173,13 @@
171173
</plugin>
172174

173175
</plugins>
176+
177+
<!-- resources>
178+
<resource>
179+
<filtering>true</filtering>
180+
<directory>src/main/resources</directory>
181+
</resource>
182+
</resources -->
174183
</build>
175184

176185
<reporting>

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,15 @@
1616

1717
package de.doubleslash.keeptime.view;
1818

19+
import java.io.File;
1920
import java.io.IOException;
21+
import java.io.InputStream;
22+
import java.nio.file.Files;
23+
import java.nio.file.Paths;
24+
import java.sql.SQLException;
25+
import java.util.Properties;
2026

27+
import org.h2.tools.Script;
2128
import org.slf4j.Logger;
2229
import org.slf4j.LoggerFactory;
2330
import org.springframework.beans.factory.annotation.Autowired;
@@ -43,6 +50,8 @@
4350
import javafx.scene.layout.AnchorPane;
4451
import javafx.scene.layout.Region;
4552
import javafx.scene.paint.Color;
53+
import javafx.stage.FileChooser;
54+
import javafx.stage.FileChooser.ExtensionFilter;
4655
import javafx.stage.Modality;
4756
import javafx.stage.Stage;
4857

@@ -91,6 +100,9 @@ public class SettingsController {
91100
@FXML
92101
private Button cancelButton;
93102

103+
@FXML
104+
private Button exportButton;
105+
94106
@FXML
95107
private Button aboutButton;
96108

@@ -136,6 +148,8 @@ private void initialize() {
136148
globalKeyloggerLabel.setDisable(true);
137149
}
138150

151+
initExportButton();
152+
139153
LOG.debug("saveButton.setOnAction");
140154
saveButton.setOnAction(ae -> {
141155
LOG.info("Save clicked");
@@ -218,6 +232,35 @@ private void initialize() {
218232
});
219233
}
220234

235+
private void initExportButton() {
236+
LOG.debug("Initialize exportButton.");
237+
exportButton.setOnAction(actionEvent -> {
238+
LOG.info("Button pressed: exportButton");
239+
240+
final Properties properties = new Properties();
241+
try (InputStream resourceStream = SettingsController.class.getResourceAsStream("/application.properties")) {
242+
properties.load(resourceStream);
243+
244+
final FileChooser fileChooser = new FileChooser();
245+
fileChooser.setInitialDirectory(Paths.get(".").toFile());
246+
final String h2Version = properties.getProperty("h2.version");
247+
fileChooser.setInitialFileName(String.format("KeepTime_database-export_H2-version-%s.sql", h2Version));
248+
fileChooser.getExtensionFilters().add(new ExtensionFilter("SQL scrip files.", "*.sql"));
249+
250+
final File fileToSave = fileChooser.showSaveDialog(thisStage);
251+
Files.deleteIfExists(Paths.get(fileToSave.getAbsolutePath()));
252+
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");
256+
257+
Script.process(url, username, password, fileToSave.getAbsolutePath(), "", "");
258+
} catch (final SQLException | IOException e) {
259+
LOG.error("Could not export db to script file.", e);
260+
}
261+
});
262+
}
263+
221264
void update() {
222265
// needed to close stage on esc
223266
settingsRoot.requestFocus();

src/main/resources/application.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
spring.h2.console.enabled=true
33
spring.h2.console.path=/h2
44

5+
h2.version=1.4.197
6+
57
# Datasource
68
spring.datasource.url=jdbc:h2:file:./db/keeptime-h2-db;DB_CLOSE_ON_EXIT=FALSE
79
spring.datasource.username=sa

src/main/resources/layouts/settings.fxml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@
296296
<Font name="Open Sans Regular" size="12.0" />
297297
</font>
298298
</Button>
299+
<Button fx:id="exportButton" mnemonicParsing="false" text="Export" />
299300
<Region HBox.hgrow="ALWAYS" />
300301
<Button fx:id="aboutButton" mnemonicParsing="false" prefHeight="25.0" prefWidth="70.0" text="About" HBox.hgrow="ALWAYS" />
301302
</children>

0 commit comments

Comments
 (0)