Skip to content

Commit 87d39f6

Browse files
authored
Merge pull request #460 from digital-preservation/bug-453-result-pane-goes-blank
Bug 453 result pane goes blank
2 parents 4a5ff45 + e4e8bee commit 87d39f6

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

csv-validator-ui/src/main/scala/uk/gov/nationalarchives/csv/validator/ui/CsvValidatorUi.scala

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import scala.util.Using
4040
* @author Adam Retter <[email protected]>
4141
*/
4242
object CsvValidatorUi extends SimpleSwingApplication {
43-
4443
override def startup(args: Array[String]) : Unit = {
4544
try {
4645
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName)
@@ -51,11 +50,12 @@ object CsvValidatorUi extends SimpleSwingApplication {
5150
super.startup(args)
5251
}
5352

54-
def top = new SJXFrame {
53+
def top: SJXFrame = new SJXFrame {
54+
5555
title = "CSV Validator"
5656
peer.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
5757
contents = {
58-
val settings = new SettingsPanel
58+
val settings = new SettingsPanel(this)
5959

6060
//handle resizing the main window, when resizing the settings panel
6161
settings.settingsGroup.reactions += SJXTaskPane.onViewStateChanged {
@@ -64,22 +64,21 @@ object CsvValidatorUi extends SimpleSwingApplication {
6464
} else {
6565
new Dimension(this.size.getWidth.toInt, (this.size.getHeight + settings.size.getHeight).toInt)
6666
}
67-
this.size = newSize
67+
this.preferredSize = newSize
6868
this.pack()
6969
}
70-
7170
new ContentPanel(settings)
7271
}
7372
}
7473

75-
private def getShortVersion(): String = {
74+
private def getShortVersion: String = {
7675
extractFromManifest {
7776
attributes =>
7877
attributes.getValue("Implementation-Version")
7978
}.getOrElse("UNKNOWN")
8079
}
8180

82-
private def getLongVersion(): Seq[(String, String)] = {
81+
private def getLongVersion: Seq[(String, String)] = {
8382
extractFromManifest {
8483
attributes =>
8584
Seq(
@@ -129,7 +128,7 @@ object CsvValidatorUi extends SimpleSwingApplication {
129128

130129
private def validate(csvFilePath: String, csvEncoding: Charset, csvSchemaFilePath: String, csvSchemaEncoding: Charset, failOnFirstError: Boolean, pathSubstitutions: List[(String, String)], enforceCaseSensitivePathChecks: Boolean, progress: Option[ProgressCallback], validateEncoding: Boolean)(output: String => Unit) : Unit = {
131130

132-
def toConsole(msg: String) = Swing.onEDT {
131+
def toConsole(msg: String): Unit = Swing.onEDT {
133132
output(msg)
134133
}
135134

@@ -159,7 +158,7 @@ object CsvValidatorUi extends SimpleSwingApplication {
159158
failOnFirstError,
160159
pathSubstitutions,
161160
enforceCaseSensitivePathChecks,
162-
false,
161+
trace = false,
163162
progress,
164163
rowCallback
165164
)._2 match {
@@ -173,8 +172,8 @@ object CsvValidatorUi extends SimpleSwingApplication {
173172
/**
174173
* Saves a String to a File
175174
*
176-
* @param s
177-
* @param f
175+
* @param s String to save to the file
176+
* @param f File to which the associated string is saved
178177
*/
179178
private def saveToFile(s: String, f: Path) : Option[IOException] = {
180179
val data : Array[Byte] = s.getBytes(UTF_8)
@@ -189,7 +188,7 @@ object CsvValidatorUi extends SimpleSwingApplication {
189188
case class Settings(lastCsvPath: Path, lastCsvSchemaPath: Path, lastReportPath: Path)
190189

191190
lazy val settingsFile : Path = Paths.get(System.getProperty("user.home")).resolve(".csv-validator").resolve("csv-validator.properties")
192-
lazy val userDir = Paths.get(System.getProperty("user.dir"))
191+
lazy val userDir: Path = Paths.get(System.getProperty("user.dir"))
193192

194193
private def loadSettings: Option[Settings] = {
195194
if(Files.exists(settingsFile)) {
@@ -299,7 +298,7 @@ object CsvValidatorUi extends SimpleSwingApplication {
299298

300299
override def update(total: Int, processed: Int) : Unit = {
301300
Swing.onEDT {
302-
progressBar.max = total.toInt
301+
progressBar.max = total
303302
progressBar.value = processed
304303
progressBar.label = s"Line ${processed} of ${total}"
305304
}
@@ -367,11 +366,11 @@ object CsvValidatorUi extends SimpleSwingApplication {
367366
})
368367
}
369368

370-
private val lblVersion = new Label(s"Version: ${getShortVersion()}")
369+
private val lblVersion = new Label(s"Version: ${getShortVersion}")
371370
lblVersion.listenTo(lblVersion.mouse.clicks)
372371
lblVersion.font = lblVersion.font.deriveFont(9)
373372
lblVersion.reactions += onClick {
374-
Dialog.showMessage(this, getLongVersion().map(x => s"${x._1}: ${x._2}").mkString(System.getProperty("line.separator")), "Version Details")
373+
Dialog.showMessage(this, getLongVersion.map(x => s"${x._1}: ${x._2}").mkString(System.getProperty("line.separator")), "Version Details")
375374
}
376375

377376
layout.row.grid(lblCsvFile).add(txtCsvFile, 5).add(btnChooseCsvFile)
@@ -408,7 +407,7 @@ object CsvValidatorUi extends SimpleSwingApplication {
408407
* us to break up the code easily, hopefully
409408
* making it more understandable.
410409
*/
411-
private class SettingsPanel extends SJXTaskPaneContainer {
410+
private class SettingsPanel(parentFrame: SJXFrame) extends SJXTaskPaneContainer {
412411

413412
private lazy val CHARACTER_ENCODINGS =
414413
if(Charset.defaultCharset.name == "UTF-8") {
@@ -455,7 +454,7 @@ object CsvValidatorUi extends SimpleSwingApplication {
455454

456455
private val spTblPathSubstitutions = new ScrollPane(tblPathSubstitutions)
457456
private val btnAddPathSubstitution = new Button("Add Path Substitution...")
458-
btnAddPathSubstitution.reactions += onClick(addToTableDialog(top, "Add Path Substitution...", tblPathSubstitutions, tblPathSubstitutions.addRow))
457+
btnAddPathSubstitution.reactions += onClick(addToTableDialog(parentFrame, "Add Path Substitution...", tblPathSubstitutions, tblPathSubstitutions.addRow))
459458

460459
private val settingsGroupLayout = new GridBagPanel {
461460
private val c = new Constraints

csv-validator-ui/src/main/scala/uk/gov/nationalarchives/csv/validator/ui/ScalaSwingHelpers.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ object ScalaSwingHelpers {
2626
/**
2727
* Opens a FileChooser and sets the path of the chosen file as the text of a Text Component
2828
*
29-
* @param fileChooser
29+
* @param fileChooser FileChooser which is Used to open file dialogs
3030
* @param output A text component which displays the absolute path of the chosen file
3131
* @param locateOver A component over which the FileChooser dialog should be located
3232
*/
@@ -37,7 +37,7 @@ object ScalaSwingHelpers {
3737
/**
3838
* Opens a FileChooser and sends the result to a function
3939
*
40-
* @param fileChooser
40+
* @param fileChooser FileChooser which is Used to open file dialogs
4141
* @param result A function which takes the chosen file
4242
* @param locateOver A component over which the FileChooser dialog should be located
4343
*/
@@ -67,10 +67,10 @@ object ScalaSwingHelpers {
6767

6868
val btnOk = new Button("Ok")
6969

70-
val optionLayout = new GridBagPanel {
70+
val optionLayout: GridBagPanel = new GridBagPanel {
7171
val c = new Constraints
7272

73-
for(colIdx <- (0 to table.model.getColumnCount - 1)) {
73+
for(colIdx <- 0 to table.model.getColumnCount - 1) {
7474
c.gridx = 0
7575
c.gridy = colIdx
7676
c.anchor = Anchor.LineStart
@@ -93,6 +93,7 @@ object ScalaSwingHelpers {
9393
dialog.modal = true
9494
dialog.title = title
9595
dialog.contents = optionLayout
96+
dialog.setLocationRelativeTo(owner)
9697

9798
btnOk.reactions += onClick(result({
9899
val textValues = for{
@@ -130,7 +131,7 @@ object ScalaSwingHelpers {
130131
action
131132
}
132133

133-
def PropertyChangeListener(f: PropertyChangeEvent => Unit) = new PropertyChangeListener {
134+
def PropertyChangeListener(f: PropertyChangeEvent => Unit): PropertyChangeListener = new PropertyChangeListener {
134135
def propertyChange(e: PropertyChangeEvent) : Unit = {
135136
f(e)
136137
}

0 commit comments

Comments
 (0)