Skip to content

Commit 948a6a2

Browse files
authored
Merge pull request #520 from digital-preservation/DR2-2042_removePathSubstitutionButton
DR2 2042 Add Remove path substitution button
2 parents 9686104 + 7fd9f13 commit 948a6a2

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ object CsvValidatorUi extends SimpleSwingApplication {
532532
Row("From", List(fromPathText)),
533533
Row("To", List(fileTextField, fileButton))
534534
)
535-
addToTableDialog(parentFrame, "Add path substitution...", rows, tblPathSubstitutions.addRow)
535+
addToTableDialog(parentFrame, "Add Path Substitution...", rows, tblPathSubstitutions.addRow)
536536
}
537537

538538
private val tblPathSubstitutions = new Table(0, 2) {
@@ -543,24 +543,20 @@ object CsvValidatorUi extends SimpleSwingApplication {
543543
model.asInstanceOf[DefaultTableModel].addRow(rowData.asInstanceOf[Array[AnyRef]])
544544
}
545545

546-
def removeSelectedRow() : Unit = {
547-
model.asInstanceOf[DefaultTableModel].removeRow(peer.getSelectedRow)
546+
def removeSelectedRows() : Unit = peer.getSelectedRows.zipWithIndex.foreach { case (row, index) =>
547+
model.asInstanceOf[DefaultTableModel]removeRow(row - index) // when you delete a row, the index of next row to delete shifts down by 1
548548
}
549549

550550
def pathSubstitutions : List[(String, String)] = {
551551
for(rowIdx <- (0 to model.getRowCount - 1)) yield (model.getValueAt(rowIdx, 0).asInstanceOf[String], model.getValueAt(rowIdx, 1).asInstanceOf[String])
552552
}.toList
553553
}
554554

555-
private val popupMenu = new PopupMenu
556-
private val miRemove = new MenuItem("Remove Path Substitution")
557-
miRemove.reactions += onClick(tblPathSubstitutions.removeSelectedRow())
558-
popupMenu.contents += miRemove
559-
tblPathSubstitutions.popupMenu(popupMenu)
560-
561555
private val spTblPathSubstitutions = new ScrollPane(tblPathSubstitutions)
556+
private val btnRemovePathSubstitution = new Button("Remove Path Substitution")
562557
private val btnAddPathSubstitution = new Button("Add Path Substitution...")
563558

559+
btnRemovePathSubstitution.reactions += onClick(tblPathSubstitutions.removeSelectedRows())
564560
btnAddPathSubstitution.reactions += onClick(tablePathDialog())
565561

566562
private val settingsGroupLayout = new GridBagPanel {
@@ -605,6 +601,11 @@ object CsvValidatorUi extends SimpleSwingApplication {
605601
c.gridwidth = 2
606602
layout(spTblPathSubstitutions) = c
607603

604+
c.gridx = 0
605+
c.gridy = 7
606+
c.anchor = Anchor.LineStart
607+
layout(btnRemovePathSubstitution) = c
608+
608609
c.gridx = 1
609610
c.gridy = 7
610611
c.anchor = Anchor.LastLineEnd

0 commit comments

Comments
 (0)