Skip to content

Commit

Permalink
added validation to nextEdit method in Editable cells (used for custo…
Browse files Browse the repository at this point in the history
…m edit traversal)
  • Loading branch information
Shadi Shaheen committed Sep 28, 2020
1 parent bbb653a commit 7f064ca
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,31 +216,37 @@ private void editNext(boolean forward) {
//There is no other column that supports editing.
int index = getIndex();
int nextIndex = columns.indexOf(getTableColumn());
if (forward) {
nextIndex++;
if (nextIndex > columns.size() - 1) {
nextIndex = 0;
index += stepFunction.apply(index, 1);
}
} else {
nextIndex--;
if (nextIndex < 0) {
nextIndex = columns.size() - 1;
index += stepFunction.apply(index, -1);
TableColumn<S, ?> nextColumn;
do {
if (forward) {
nextIndex++;
if (nextIndex > columns.size() - 1) {
nextIndex = 0;
index += stepFunction.apply(index, 1);
}
} else {
nextIndex--;
if (nextIndex < 0) {
nextIndex = columns.size() - 1;
index += stepFunction.apply(index, -1);
}
}
}

if (columns.size() < 2 && index == getIndex()) {
return;
}

TableColumn<S, ?> nextColumn = columns.get(nextIndex);
if (columns.size() < 2 && index == getIndex()) {
return;
}
nextColumn = columns.get(nextIndex);
} while (!isValidEdit(index, nextColumn));
if (nextColumn != null) {
getTableView().edit(index, nextColumn);
getTableView().scrollToColumn(nextColumn);
}
}

protected boolean isValidEdit(int row, TableColumn<S, ?> column) {
return true;
}

private List<TableColumn<S, ?>> getLeaves(TableColumn<S, ?> rootColumn) {
List<TableColumn<S, ?>> columns = new ArrayList<>();
if (rootColumn.getColumns().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,31 +240,39 @@ private void editNext(boolean forward) {
//There is no other column that supports editing.
int index = getIndex();
int nextIndex = columns.indexOf(getTableColumn());
if (forward) {
nextIndex++;
if (nextIndex > columns.size() - 1) {
nextIndex = 0;
index += stepFunction.apply(index, 1);
}
} else {
nextIndex--;
if (nextIndex < 0) {
nextIndex = columns.size() - 1;
index += stepFunction.apply(index, -1);

TreeTableColumn<S, ?> nextColumn;
do {
if (forward) {
nextIndex++;
if (nextIndex > columns.size() - 1) {
nextIndex = 0;
index += stepFunction.apply(index, 1);
}
} else {
nextIndex--;
if (nextIndex < 0) {
nextIndex = columns.size() - 1;
index += stepFunction.apply(index, -1);
}
}
}

if (columns.size() < 2 && index == getIndex()) {
return;
}
if (columns.size() < 2 && index == getIndex()) {
return;
}
nextColumn = columns.get(nextIndex);
} while (!isValidEdit(index, nextColumn));

TreeTableColumn<S, ?> nextColumn = columns.get(nextIndex);
if (nextColumn != null) {
getTreeTableView().edit(index, nextColumn);
getTreeTableView().scrollToColumn(nextColumn);
}
}

protected boolean isValidEdit(int row, TreeTableColumn<S, ?> column) {
return true;
}


private List<TreeTableColumn<S, ?>> getLeaves(TreeTableColumn<S, ?> root) {
List<TreeTableColumn<S, ?>> columns = new ArrayList<>();
Expand Down

0 comments on commit 7f064ca

Please sign in to comment.