Example usage for javafx.scene.control TableColumn editCommitEvent

List of usage examples for javafx.scene.control TableColumn editCommitEvent

Introduction

In this page you can find the example usage for javafx.scene.control TableColumn editCommitEvent.

Prototype

@SuppressWarnings("unchecked")
public static <S, T> EventType<CellEditEvent<S, T>> editCommitEvent() 

Source Link

Document

Indicates that the editing has been committed by the user, meaning that a change should be made to the backing data source to reflect the new data.

Usage

From source file:com.panemu.tiwulfx.table.TableControl.java

private void initColumn(TableColumn<R, ?> clm) {
    List<TableColumn<R, ?>> lstColumn = new ArrayList<>();
    lstColumn.add(clm);//  w  w  w .  j a  v  a 2  s. co m
    lstColumn = getColumnsRecursively(lstColumn);
    for (TableColumn column : lstColumn) {
        if (column instanceof BaseColumn) {
            final BaseColumn baseColumn = (BaseColumn) column;
            baseColumn.tableCriteriaProperty().addListener(tableCriteriaListener);
            baseColumn.sortTypeProperty().addListener(sortTypeChangeListener);
            baseColumn.addEventHandler(TableColumn.editCommitEvent(),
                    new EventHandler<TableColumn.CellEditEvent<R, ?>>() {
                        @Override
                        public void handle(CellEditEvent<R, ?> t) {
                            try {
                                if (!(t.getTablePosition().getRow() < t.getTableView().getItems().size())) {
                                    return;
                                }
                                Object persistentObj = t.getTableView().getItems()
                                        .get(t.getTablePosition().getRow());
                                if ((t.getNewValue() == null && t.getOldValue() == null)
                                        || (t.getNewValue() != null
                                                && t.getNewValue().equals(t.getOldValue()))) {
                                }
                                if (mode.get().equals(Mode.EDIT) && t.getOldValue() != t.getNewValue()
                                        && (t.getOldValue() == null
                                                || !t.getOldValue().equals(t.getNewValue()))) {
                                    if (!lstChangedRow.contains((R) persistentObj)) {
                                        lstChangedRow.add((R) persistentObj);
                                    }
                                    baseColumn.addRecordChange(persistentObj, t.getOldValue(), t.getNewValue());
                                }
                                PropertyUtils.setSimpleProperty(persistentObj, baseColumn.getPropertyName(),
                                        t.getNewValue());
                                baseColumn.validate(persistentObj);
                            } catch (IllegalAccessException | InvocationTargetException
                                    | NoSuchMethodException ex) {
                                throw new RuntimeException(ex);
                            }
                        }
                    });

        }
    }
}