List<Account> acc = cpFacade.loadAccounts(user);
List decoratedAcc = ListDecorator.getInstance(new DropDownAccountDecorator(), acc);
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
public class DropDownAccountDecorator implements IListItemDecorator,Serializable {
private boolean hideBalance;
@Override
public Object decorate(final Object o) {
return Enhancer.create(o.getClass(), new MethodInterceptor() {
@Override
public Object intercept(Object obj, Method mth, Object[] args, MethodProxy mpx) throws Throwable {
Object res = mth.invoke(o, args);
String mname = mth.getName();
if (!mname.equals("getDisplay")) {
return res;
}
Account acc = (Account) obj;
String display;
if (AccStates.BLOCKED.equals(acc.getAccState())) {
display = String.format("%s (%1.2f %s blocked)", acc.getName(), acc.getTotalBalance(), acc.getCurrencyDetail().get(0).getCurrency().getCode());
} else {
if(hideBalance) {
display = String.format("%s %s", acc.getName(), acc.getCurrencyDetail().get(0).getCurrency().getCode());
} else {
display = String.format("%s (%1.2f %s)", acc.getName(), acc.getTotalBalance(), acc.getCurrencyDetail().get(0).getCurrency().getCode());
}
}
return display;
}
});
}
public void setHideBalance(boolean b) {
this.hideBalance=b;
}
}
January 2008 February 2008 March 2009
Subscribe to Posts [Atom]