Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/main/java/edu/mills/cs180a/wordui/FXMLController.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,13 @@ public void initialize(URL url, ResourceBundle rb) {
addListeners();

// Pre-select the first item.
listView.getSelectionModel().selectFirst();
// listView.getSelectionModel().selectFirst();
}



private void populateChoiceBox() {
sortChoiceBox.setItems(FXCollections.observableArrayList(
WordRecord.SortOrder.values()));
sortChoiceBox.setItems(FXCollections.observableArrayList(WordRecord.SortOrder.values()));
sortChoiceBox.setValue(WordRecord.SortOrder.ALPHABETICALLY_FORWARD);
}

Expand All @@ -119,15 +118,19 @@ private void configureButtons() {

// Disable the Update button if nothing is selected, no modifications have
// been made, or any field is empty or invalid.
updateButton.disableProperty()
.bind(listView.getSelectionModel().selectedItemProperty().isNull()
updateButton.disableProperty().bind(
listView.getSelectionModel().selectedItemProperty().isNull()
.or(modifiedProperty.not())
.or(freqValidProperty.not())
.or(wordTextField.textProperty().isEmpty())
.or(freqValidProperty.not()).or(wordTextField.textProperty().isEmpty())
.or(definitionTextArea.textProperty().isEmpty()));

// TODO: Disable the Create button if an existing entry is selected or any
// Disable the Create button if anything is selected or any
// field is empty or invalid.
createButton.disableProperty()
.bind(listView.getSelectionModel().selectedItemProperty().isNotNull()
.or(wordTextField.textProperty().isEmpty()).or(freqValidProperty.not())
.or(wordTextField.textProperty().isEmpty())
.or(definitionTextArea.textProperty().isEmpty()));
}

// A frequency is valid if it is an integer and is at least 0.
Expand Down Expand Up @@ -156,11 +159,8 @@ private void handleKeyAction(KeyEvent keyEvent) {
@FXML
private void createButtonAction(ActionEvent actionEvent) {
System.out.println("Create");
WordRecord wordRecord =
new WordRecord(
wordTextField.getText(),
Integer.parseInt(frequencyTextField.getText()),
definitionTextArea.getText());
WordRecord wordRecord = new WordRecord(wordTextField.getText(),
Integer.parseInt(frequencyTextField.getText()), definitionTextArea.getText());
wordRecordList.add(wordRecord);
listView.getSelectionModel().select(wordRecord); // select the new item
}
Expand Down