@@ -24,8 +24,9 @@ import java.net.URL
2424import java .nio .charset .Charset
2525import java .nio .charset .StandardCharsets .UTF_8
2626import java .nio .file .{Files , Path , Paths , StandardOpenOption }
27+ import java .text .SimpleDateFormat
2728import java .util
28- import java .util .Properties
29+ import java .util .{ Date , Properties }
2930import java .util .jar .{Attributes , Manifest }
3031import javax .swing .SpringLayout .Constraints
3132import javax .swing ._
@@ -187,14 +188,9 @@ object CsvValidatorUi extends SimpleSwingApplication {
187188 * @param s String to save to the file
188189 * @param f File to which the associated string is saved
189190 */
190- private def saveToFile (s : String , f : Path ) : Option [IOException ] = {
191- val data : Array [Byte ] = s.getBytes(UTF_8 )
192- try {
193- Files .write(f, data, StandardOpenOption .WRITE , StandardOpenOption .CREATE_NEW )
194- None
195- } catch {
196- case ioe : IOException => Some (ioe)
197- }
191+ private def saveToFile (s : String , f : Path ) : Try [String ] = {
192+ val data : Array [Byte ] = s.getBytes(UTF_8 )
193+ Try (Files .write(f, data, StandardOpenOption .WRITE , StandardOpenOption .CREATE_NEW )).map(_ => " s has been written to file" )
198194 }
199195
200196 case class Settings (lastCsvPath : Path , lastCsvSchemaPath : Path , lastReportPath : Path )
@@ -293,6 +289,7 @@ object CsvValidatorUi extends SimpleSwingApplication {
293289 case None =>
294290 userDir.toFile
295291 })
292+ csvFileChooser.title = " Select a .csv file"
296293 csvFileChooser.fileFilter = new FileNameExtensionFilter (" CSV file (*.csv)" , " csv" )
297294 private val btnChooseCsvFile = new Button (" ..." )
298295
@@ -318,6 +315,7 @@ object CsvValidatorUi extends SimpleSwingApplication {
318315 case None =>
319316 userDir.toFile
320317 })
318+ csvSchemaFileChooser.title = " Select a .csvs file"
321319 csvSchemaFileChooser.fileFilter = new FileNameExtensionFilter (" CSV Schema file (*.csvs)" , " csvs" +
322320 " " )
323321
@@ -423,9 +421,14 @@ object CsvValidatorUi extends SimpleSwingApplication {
423421 case None =>
424422 userDir.toFile
425423 })
426- private val btnSave = new Button (" Save" )
424+ val dateFormat = new SimpleDateFormat (" dd-mm-yy_HH-mm-ss" )
425+ reportFileChooser.selectedFile = new File (s " csv_validator_report_ ${dateFormat.format(new Date ())}.txt " )
426+
427+ val saveLabel = " Save Results"
428+ reportFileChooser.title = saveLabel
429+ private val btnSave = new Button (saveLabel)
427430 btnSave.reactions += onClick {
428- chooseFile (reportFileChooser, saveToFile(txtArReport.text, _), btnSave)
431+ saveFile (reportFileChooser, saveToFile(txtArReport.text, _), btnSave, btnSave.text )
429432 updateLastPath(reportFileChooser, {
430433 path =>
431434 loadSettings match {
@@ -515,19 +518,21 @@ object CsvValidatorUi extends SimpleSwingApplication {
515518 if (uri.endsWith(" /" )) uri else s " $uri/ "
516519 }
517520
518- def updateFileText (path : Path ): Option [ IOException ] = {
521+ def updateFileText (path : Path ): Try [ String ] = {
519522 fileTextField.text = pathToUri(path)
520- None
523+ Success ( " Text updated " )
521524 }
522525
523526 val okButton = new Button (" OK" )
524527 val fileButton = new Button (" ..." )
525528 fileButton.reactions += {
526529 case ev : ButtonClicked =>
527530 val startingDir = if (fileTextField.text.isEmpty) userDir.toFile else Path .of(fileTextField.text).toFile
531+ val helpText = s " Select the ${fromPath.split(" /" ).last} folder "
528532 val fileChooser = new FileChooser (startingDir)
533+ fileChooser.title = helpText
529534 fileChooser.fileSelectionMode = SelectionMode .FilesAndDirectories
530- chooseFile(fileChooser, f => updateFileText(f), fileButton, s " Select the ${fromPath.split( " / " ).last} folder " )
535+ chooseFile(fileChooser, f => updateFileText(f), fileButton, helpText )
531536 }
532537
533538 val rows = List (
0 commit comments