use of javafx.scene.input.KeyEvent in project trex-stateless-gui by cisco-system-traffic-generator.
the class TextFieldTableViewCell method call.
@Override
public TableCell call(TableColumn param) {
return new TableCell<S, T>() {
private TextField textField;
{
textField = new TextField();
textField.setPrefSize(158, 22);
textField.setOnKeyPressed((KeyEvent event) -> {
if (event.getCode().equals(KeyCode.ENTER)) {
commitEdit((T) textField.getText());
}
});
textField.focusedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
if (!newValue) {
commitEdit((T) textField.getText());
}
});
textField.textProperty().bindBidirectional(textProperty());
}
@Override
public void updateItem(final T item, final boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText(null);
setGraphic(null);
} else {
setGraphic(textField);
setText((String) getItem());
}
}
@Override
public void commitEdit(T item) {
if (!isEditing() && !item.equals(getItem())) {
TableView<S> table = getTableView();
if (table != null) {
TableColumn<S, T> column = getTableColumn();
CellEditEvent<S, T> event = new CellEditEvent<>(table, new TablePosition<S, T>(table, getIndex(), column), TableColumn.editCommitEvent(), item);
Event.fireEvent(column, event);
}
}
super.commitEdit(item);
}
};
}
Aggregations