Also, if the browser's not showing what's it supposed to...
JUST RESTART THE DAMN THING!
My constant battle with ERROS and of course, my love for 'em... 'coz they teach me so much... sometimes more than textbooks!
require 'active_support/secure_random'
random_string = ActiveSupport::SecureRandom.hex(16)
compoundRowFilter = RowFilter.andFilter(compoundFilterList);
rowSorter.setRowFilter(compoundRowFilter);
Where compoundFilterList is a list of filters you are trying to make work together.
So, what you can do instead of the following:
protected void newFilter(String filterRegExp) {
textFilter = null;
// If current expression doesn't parse, don't update.
try {
textFilter = RowFilter.regexFilter(filterRegExp);
} catch (java.util.regex.PatternSyntaxException e) {
return;
}
rowSorter.setRowFilter(textFilter);
}protected void newFilter(String filterRegExp) {
textFilter = null;
// If current expression doesn't parse, don't update.
try {
textFilter = RowFilter.regexFilter(filterRegExp);
} catch (java.util.regex.PatternSyntaxException e) {
return;
}
filterList.add(textFilter);
compoundRowFilter = RowFilter.andFilter(filterList);
rowSorter.setRowFilter(compoundRowFilter);
}private RowFilter
And later in the filter code:
protected void newFilter(String filterRegExp) {
textFilter = null;
// If current expression doesn't parse, don't update.
try {
textFilter = RowFilter.regexFilter(filterRegExp);
} catch (java.util.regex.PatternSyntaxException e) {
return;
}
this.compoundFilterArray[1] = textFilter;
applyCompoundFilter();
}
protected void newFilter(final int userAnswerColumnIndex,
final int expectedAnswerColumnIndex) {
incorrectResponseFilter = new RowFilter
@Override
public boolean include(Entry entry) {
String actualResponse = entry
.getStringValue(userAnswerColumnIndex);
String expectedResponse = entry
.getStringValue(expectedAnswerColumnIndex);
return expectedResponse.contains(actualResponse);
}
};
// replace the filter with new object, each time the filter is updated
this.compoundFilterArray[0] = incorrectResponseFilter;
applyCompoundFilter();
}
where:
private void applyCompoundFilter() {
ArrayList
for(int i = 0; i< compoundFilterArray.length; i++){
if(compoundFilterArray[i] != null){
compoundFilterList.add(compoundFilterArray[i]);
}
}
compoundRowFilter = RowFilter.andFilter(compoundFilterList);
rowSorter.setRowFilter(compoundRowFilter);
}
filterText.getDocument().addDocumentListener(
new DocumentListener() {
public void changedUpdate(DocumentEvent e) {
newFilter();
}
public void insertUpdate(DocumentEvent e) {
newFilter();
}
public void removeUpdate(DocumentEvent e) {
newFilter();
}
});
filterText.getDocument().addDocumentListener(new YourListenerImplementation(Object1, Object2...));
and
class YourListenerImplementation{
public YourListenerImplementation(Object1, Object2....){
}
@Override
public void changedUpdate(DocumentEvent event) {
// do stuff here
//create new filter each time
}
@Override
public void insertUpdate(DocumentEvent event) {
//do stuff here
// create new filter each time
}
@Override
public void removeUpdate(DocumentEvent event) {
// do stuff here
// create new filter each time
}
}
private static final String COMMA = ",";
private static final String OR = "|";
private String getSearchRegularExpression(){
String filterText = filterControlsPanelHandlerObject.getFilterText();
return filterText.replace(COMMA, OR);
}
// call the filter in update methods
@Override
public void changedUpdate(DocumentEvent event) {
yourTableClassWithFilterMethod.newFilter(getSearchRegularExpression());
}
private TableRowSorter
/*
* initialize rowsorter etc...
*/
protected void newFilter(String filterRegExp) {
RowFilter
//If current expression doesn't parse, don't update.
try {
rowFilter = RowFilter.regexFilter(filterRegExp);
} catch (java.util.regex.PatternSyntaxException e) {
return;
}
rowSorter.setRowFilter(rowFilter);
}