1 package org.paneris.jammyjoes.mvp; 2 3 import java.util.HashMap; 4 import java.util.Map; 5 import java.util.Vector; 6 7 import org.melati.template.ServletTemplateContext; 8 9 public class AffiliateStatsPresenter extends AbstractPresenter implements Presenter { 10 11 private Map _monthMap; 12 private Vector _results; 13 private TimesliceValue _max; 14 private TimesliceFactory _timesliceFactory; 15 private final Selection selection; 16 private final boolean detail; 17 private AffiliateTotals _total; 18 19 public AffiliateStatsPresenter(String name, ServletTemplateContext context, 20 TimesliceFactory timesliceFactory, Selection selection, boolean detail) { 21 this.selection = selection; 22 this.detail = detail; 23 _monthMap = new HashMap(); 24 _results = new Vector(); 25 _timesliceFactory = timesliceFactory; 26 _max = new TimesliceValue(_timesliceFactory.create(null),0); 27 _total = new AffiliateTotals(); 28 context.put(name + "_max", _max); 29 context.put(name + "_results", _results); 30 context.put(name + "_months", _monthMap); 31 context.put(name + "_total", _total); 32 context.put(name + "_sorter", new CollectionSorter()); 33 } 34 35 public Selection createSelection() { 36 return selection; 37 } 38 39 public Command createCommand() { 40 if (detail) { 41 return new CopyIntoContextCommand(_results, _total); 42 } else { 43 return new CollectingCommand(_monthMap, _max, _timesliceFactory, _total); 44 } 45 } 46 47 }