mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-07-07 14:29:16 +00:00
Enter is no longer required to keep changes when editing spreadsheet cells
This commit is contained in:
parent
641e8750d8
commit
dc81bbc8aa
@ -18,17 +18,18 @@ package org.badvision.outlaweditor.ui.impl;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.control.ContextMenu;
|
||||
import javafx.scene.control.MenuItem;
|
||||
import javafx.scene.control.TableCell;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.control.cell.TextFieldTableCell;
|
||||
import org.badvision.outlaweditor.Application;
|
||||
import javafx.util.Callback;
|
||||
import javafx.util.converter.DefaultStringConverter;
|
||||
import org.badvision.outlaweditor.SheetEditor;
|
||||
import static org.badvision.outlaweditor.data.DataUtilities.getValue;
|
||||
import static org.badvision.outlaweditor.data.DataUtilities.setValue;
|
||||
@ -108,9 +109,31 @@ public class SheetEditorControllerImpl extends SheetEditorController {
|
||||
}
|
||||
return new SimpleObjectProperty(val);
|
||||
});
|
||||
tableCol.setCellFactory(TextFieldTableCell.forTableColumn());
|
||||
tableCol.setOnEditCommit((event)
|
||||
-> setValue(event.getRowValue().getOtherAttributes(), col.getName(), event.getNewValue()));
|
||||
|
||||
tableCol.setCellFactory((TableColumn<Row, String> param) -> {
|
||||
TextFieldTableCell<Row, String> myCell = new TextFieldTableCell<Row, String>(new DefaultStringConverter()) {
|
||||
@Override
|
||||
/**
|
||||
* Patch behavior so that any change is immediately persisted, enter is not required.
|
||||
*/
|
||||
public void startEdit() {
|
||||
super.startEdit();
|
||||
TextField textField = (TextField) getGraphic();
|
||||
textField.textProperty().addListener((p,o,n)->{
|
||||
setItem(n);
|
||||
int index = this.getTableRow().getIndex();
|
||||
Row row = tableData.get(index);
|
||||
setValue(row.getOtherAttributes(), col.getName(), n);
|
||||
});
|
||||
}
|
||||
};
|
||||
return myCell;
|
||||
});
|
||||
|
||||
tableCol.setOnEditCommit((event) -> {
|
||||
table.requestFocus();
|
||||
table.getSelectionModel().clearSelection();
|
||||
});
|
||||
tableCol.setEditable(true);
|
||||
tableCol.setContextMenu(new ContextMenu(
|
||||
createMenuItem("Rename Column", () -> renameColumn(col)),
|
||||
|
Loading…
Reference in New Issue
Block a user