Skip to content
This repository has been archived by the owner on Mar 15, 2022. It is now read-only.

HAL-1052 Disable filtering before changing column's data #139

Merged
merged 1 commit into from
Mar 2, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public class ColumnFilter<T> {
private CellTable<T> delegate;
private final Predicate predicate;
private List<T> origValues = Collections.EMPTY_LIST;
private boolean isFilterActive = false;
private LayoutPanel panel;
private TextBox textBox;
private String currentFilterExpression = null;

public ColumnFilter(SingleSelectionModel<T> selection, CellTable<T> delegate, Predicate predicate) {
this.selection = selection;
Expand All @@ -37,7 +37,7 @@ public ColumnFilter(SingleSelectionModel<T> selection, CellTable<T> delegate, Pr
delegate.addRowCountChangeHandler(new RowCountChangeEvent.Handler() {
@Override
public void onRowCountChange(RowCountChangeEvent event) {
if (!isFilterActive) {
if (!isFilterActive()) {
origValues = delegate.getVisibleItems();
}
}
Expand All @@ -50,30 +50,21 @@ public Widget asWidget() {
textBox = new TextBox();
textBox.setMaxLength(30);
textBox.setVisibleLength(20);
textBox.addKeyUpHandler(new KeyUpHandler() {
textBox.addKeyUpHandler(keyUpEvent -> {

private String prevValue = null;
String token = textBox.getText();
if (token != null
&& !token.equals("")) {

@Override
public void onKeyUp(KeyUpEvent keyUpEvent) {

String token = textBox.getText();
if (token != null
&& !token.equals("")) {

if (!token.equals(prevValue)) { // prevent keyUp w/o value change
prevValue = token;
selection.clear();
isFilterActive = true;
applyFilter(token);
}

} else {
prevValue = null;
if (!token.equals(currentFilterExpression)) { // prevent keyUp w/o value change
currentFilterExpression = token;
selection.clear();
clear();
isFilterActive = false;
applyFilter(token);
}

} else {
selection.clear();
clear();
}
});

Expand Down Expand Up @@ -104,11 +95,17 @@ private void applyFilter(String token) {

public void clear() {
textBox.setText("");
this.currentFilterExpression = null;

delegate.setRowCount(origValues.size(), true);
delegate.setRowData(0, origValues);
}

public interface Predicate<T> {
boolean matches(T item, String token);
}

private boolean isFilterActive() {
return this.currentFilterExpression != null;
}
}