Created
April 22, 2013 17:13
-
-
Save roberto-filho/5436826 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NotaFiscalFilter extends GermantechFilter{ | |
private boolean addTotalizador; | |
private String[] searchStrings; | |
public NotaFiscalFilter(boolean addTotalizador){ | |
this.addTotalizador = addTotalizador; | |
} | |
public NotaFiscalFilter() { | |
this(false); | |
} | |
@Override | |
public Object[] filter(Viewer viewer, Object parent, Object[] elements) { | |
if(addTotalizador){ | |
int size = elements.length; | |
BigDecimal valorTotal = BigDecimal.ZERO; | |
ArrayList<NotaFiscal> out = new ArrayList<NotaFiscal>(size); | |
for (int i = 0; i < size; ++i) { | |
NotaFiscal element = (NotaFiscal) elements[i]; | |
if (select(viewer, parent, element)) { | |
out.add(element); | |
valorTotal = valorTotal.add(element.getValorTotalNF()); | |
} | |
} | |
TotalizadorNotaFiscal totalizador = new TotalizadorNotaFiscal(); | |
totalizador.setValorTotalNotaFiscal(valorTotal); | |
out.add(totalizador); | |
return out.toArray(); | |
}else{ | |
return super.filter(viewer, parent, elements); | |
} | |
} | |
@Override | |
public void setSearchText(String s) { | |
searchStrings = s.split("\\+"); | |
} | |
@Override | |
protected boolean verificarNull() { | |
return searchStrings == null; | |
} | |
@Override | |
public boolean select(Viewer viewer, Object parentElement, Object element) { | |
if(verificarNull()) | |
return true; | |
NotaFiscal nota = (NotaFiscal) element; | |
for(String searchString : searchStrings){ | |
if(nota.getCliente() != null) | |
if(nota.getCliente().getRazaoSocial().toLowerCase().contains(searchString.toLowerCase())){ | |
return true; | |
} | |
if(nota.getFornecedor() != null) | |
if(nota.getFornecedor().getRazaoSocial().toLowerCase().contains(searchString.toLowerCase())){ | |
return true; | |
} | |
if(nota.getTipoFaturamentoExtenso().toLowerCase().contains(searchString.toLowerCase())){ | |
return true; | |
} | |
if(nota.getValorTotalNotaFiscal() != null){ | |
if(DecimalFormat.getInstance().format(nota.getValorTotalNotaFiscal()).contains(searchString)){ | |
return true; | |
} | |
} | |
if(nota.getNotaFiscalId().getNumero().toString().contains(searchString)){ | |
return true; | |
} | |
if(nota.getChaveAcesso() != null) | |
if(nota.getChaveAcesso().toString().contains(searchString)){ | |
return true; | |
} | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment