|
18 | 18 |
|
19 | 19 | import java.io.File; |
20 | 20 | import java.io.IOException; |
| 21 | +import java.net.URL; |
| 22 | +import java.nio.charset.Charset; |
21 | 23 | import java.nio.file.Paths; |
22 | 24 | import java.sql.SQLException; |
23 | 25 | import java.util.Comparator; |
| 26 | +import java.time.LocalDate; |
| 27 | +import java.util.List; |
| 28 | +import java.util.stream.Collectors; |
24 | 29 |
|
25 | 30 | import de.doubleslash.keeptime.common.*; |
26 | 31 | import de.doubleslash.keeptime.view.license.LicenseTableRow; |
|
30 | 35 | import javafx.scene.control.cell.PropertyValueFactory; |
31 | 36 | import javafx.scene.input.MouseButton; |
32 | 37 | import javafx.scene.shape.SVGPath; |
| 38 | +import de.doubleslash.keeptime.Main; |
| 39 | +import de.doubleslash.keeptime.model.Project; |
| 40 | +import de.doubleslash.keeptime.model.Work; |
| 41 | +import javafx.application.Platform; |
| 42 | +import javafx.scene.control.*; |
| 43 | +import org.h2.tools.RunScript; |
33 | 44 | import org.h2.tools.Script; |
34 | 45 | import org.slf4j.Logger; |
35 | 46 | import org.slf4j.LoggerFactory; |
36 | 47 | import org.springframework.beans.factory.annotation.Autowired; |
37 | 48 | import org.springframework.stereotype.Component; |
38 | 49 |
|
39 | 50 | import de.doubleslash.keeptime.ApplicationProperties; |
| 51 | +import de.doubleslash.keeptime.common.OS; |
| 52 | +import de.doubleslash.keeptime.common.Resources; |
40 | 53 | import de.doubleslash.keeptime.common.Resources.RESOURCE; |
41 | 54 | import de.doubleslash.keeptime.controller.Controller; |
42 | 55 | import de.doubleslash.keeptime.exceptions.FXMLLoaderException; |
|
46 | 59 | import javafx.fxml.FXMLLoader; |
47 | 60 | import javafx.scene.Parent; |
48 | 61 | import javafx.scene.Scene; |
| 62 | +import javafx.scene.control.Alert; |
49 | 63 | import javafx.scene.control.Alert.AlertType; |
| 64 | +import javafx.scene.control.Button; |
| 65 | +import javafx.scene.control.CheckBox; |
| 66 | +import javafx.scene.control.ColorPicker; |
| 67 | +import javafx.scene.control.Label; |
50 | 68 | import javafx.scene.layout.AnchorPane; |
51 | 69 | import javafx.scene.layout.Region; |
52 | 70 | import javafx.scene.paint.Color; |
@@ -109,6 +127,9 @@ public class SettingsController { |
109 | 127 | @FXML |
110 | 128 | private Button exportButton; |
111 | 129 |
|
| 130 | + @FXML |
| 131 | + private Button importButton; |
| 132 | + |
112 | 133 | @FXML |
113 | 134 | private Button aboutButton; |
114 | 135 |
|
@@ -176,6 +197,7 @@ private void initialize() { |
176 | 197 | } |
177 | 198 |
|
178 | 199 | initExportButton(); |
| 200 | + initImportButton(); |
179 | 201 |
|
180 | 202 | LOG.debug("saveButton.setOnAction"); |
181 | 203 | saveButton.setOnAction(ae -> { |
@@ -322,6 +344,63 @@ protected void updateItem(final String item, final boolean empty) { |
322 | 344 | BrowserHelper.openURL(GITHUB_ISSUE_PAGE); |
323 | 345 | }); |
324 | 346 | } |
| 347 | + private void initImportButton(){ |
| 348 | + LOG.debug("Initialize importButton."); |
| 349 | + importButton.setOnAction(event ->{ |
| 350 | + |
| 351 | + try { |
| 352 | + Alert confirmationAlert = new Alert(AlertType.CONFIRMATION , "", ButtonType.YES, ButtonType.NO); |
| 353 | + confirmationAlert.setTitle("Import"); |
| 354 | + confirmationAlert.setHeaderText("Do you want to Override current Data ?"); |
| 355 | + confirmationAlert.setContentText("Import previously exported .sql file. This will overwrite the currently used database contents - all current data will be lost!\n" + |
| 356 | + "\n" + |
| 357 | + "If you do not have a .sql file yet you need to open the previous version of KeepTime and in the settings dialog press \"Export\".\n" + |
| 358 | + "\n" + |
| 359 | + "You will need to restart the application after this action. If you proceed you need to select the previouls exported .sql file."); |
| 360 | + confirmationAlert.showAndWait(); |
| 361 | + |
| 362 | + if(confirmationAlert.getResult()==ButtonType.NO){ |
| 363 | + LOG.info("User canceled import"); |
| 364 | + return; |
| 365 | + } |
| 366 | + |
| 367 | + final FileChooser fileChooser = new FileChooser(); |
| 368 | + fileChooser.setTitle("Open Exported SQl Script"); |
| 369 | + fileChooser.getExtensionFilters().add(new ExtensionFilter("SQL script files.", "*.sql")); |
| 370 | + File file = fileChooser.showOpenDialog(thisStage); |
| 371 | + if (file == null) { |
| 372 | + LOG.info("User canceled import."); |
| 373 | + return; |
| 374 | + } |
| 375 | + |
| 376 | + final String url = applicationProperties.getSpringDataSourceUrl(); |
| 377 | + final String username = applicationProperties.getSpringDataSourceUserName(); |
| 378 | + final String password = applicationProperties.getSpringDataSourcePassword(); |
| 379 | + //TODO: add an option at the next release to make the "FROM_1X flag" configurable. E.g. if we upgrade (in the release after) from H2 version 2.x to 2.x we must not set the "FROM_1X flag". |
| 380 | + new RunScript().runTool("-url", url, "-user",username,"-password",password,"-script",file.toString(),"-options", "FROM_1X"); |
| 381 | + |
| 382 | + Alert informationDialog = new Alert(AlertType.INFORMATION); |
| 383 | + informationDialog.setTitle("Import done"); |
| 384 | + informationDialog.setHeaderText("The data was imported."); |
| 385 | + informationDialog.setContentText("KeepTime will now be CLOSED! You have to RESTART it again to see the changes"); |
| 386 | + informationDialog.showAndWait(); |
| 387 | + Platform.exit(); |
| 388 | + |
| 389 | + |
| 390 | + } catch (SQLException e) { |
| 391 | + LOG.error("Could not import script file to db.", e); |
| 392 | + |
| 393 | + Alert errorDialog = new Alert(AlertType.ERROR); |
| 394 | + errorDialog.setTitle("Import failed"); |
| 395 | + errorDialog.setHeaderText("The current data could not be imported."); |
| 396 | + errorDialog.setContentText("Please inform a developer and provide your log file."); |
| 397 | + |
| 398 | + errorDialog.showAndWait(); |
| 399 | + } |
| 400 | + |
| 401 | + }); |
| 402 | + |
| 403 | + } |
325 | 404 |
|
326 | 405 | private void initExportButton() { |
327 | 406 | LOG.debug("Initialize exportButton."); |
|
0 commit comments