View Javadoc
1   /******************************************************************************
2    * SpinContactsForm.java - A bean to wrap the Contact Spinner in a form friendly package
3    * 
4    * PicMan - The BuckoSoft Picture Manager in Java
5    * Copyright(c) 2006 - Dick Balaska
6    * 
7    */
8   package com.buckosoft.PicMan.web;
9   
10  import java.util.HashMap;
11  import java.util.List;
12  
13  import com.buckosoft.BSAccount.web.BSAccountUserWebSession;
14  import com.buckosoft.PicMan.business.PicManFacade;
15  import com.buckosoft.PicMan.db.DatabaseFacade;
16  import com.buckosoft.PicMan.domain.Chain;
17  import com.buckosoft.PicMan.domain.Set;
18  
19  /** A bean to wrap the Contact Spinner in a form friendly package
20   * @author Dick Balaska
21   */
22  public class SpinContactsForm {
23  
24  	private	BSAccountUserWebSession	userWebSession;
25  	private	Chain			chain = null;
26  	private	boolean			filtersSaved = false;
27  
28  	private PicManFacade	pmf;
29  	private DatabaseFacade	dbf;
30  	
31  	public void setPicMan(PicManFacade pmf) { this.pmf = pmf; }
32  	public PicManFacade getPicMan() { return(pmf); }
33  
34  	public void setDatabase(DatabaseFacade dbf) { this.dbf = dbf; }
35  	public DatabaseFacade getDatabase() { return(dbf); }
36  
37  	public	BSAccountUserWebSession	getUserWebSession() { return(userWebSession); }
38  	public	void		setUserWebSession(BSAccountUserWebSession us) { userWebSession = us; }
39  
40  	public Chain		getChain() { return(chain); }
41  	public void			setChain(Chain chain) { this.chain = chain; }
42  
43  	public List<Set>	getSets() { return(dbf.getSets()); }
44  	public List<Integer>getSizes() { return(dbf.getSizes()); }
45  	public int			getSizeCount() { return(dbf.getSizeCount()); }
46  	
47  	public List<Chain>	getChains() { return(dbf.getChains()); }
48  
49  	public	String		getSetSizeCheckboxesHtml() {
50  		return(pmf.getSetSizeCheckboxesHtml(chain));
51  	}
52  
53  	public boolean isFiltersSaved() {
54  		return filtersSaved;
55  	}
56  	public void setFiltersSaved(boolean filtersSaved) {
57  		this.filtersSaved = filtersSaved;
58  	}
59  	
60  	/** Get a String of the set names as Javascript
61  	 * @return A string
62  	 */ 
63  	public String getSetNamesAsJavaScript() {
64  		HashMap<String, Boolean>	hasSets = new HashMap<String, Boolean>();
65  		List<Set>		sets = dbf.getSets();
66  		int[]			sizes = dbf.getSizeArray();
67  		StringBuffer	sb = new StringBuffer();
68  		
69  		for (Set set : sets) {
70  			String	setName = set.getName();
71  			for (int sizesIndex=0; sizesIndex<sizes.length; sizesIndex++) {
72  				int	size = sizes[sizesIndex];
73  				if (chain.hasSetSize(setName, size)) {
74  					hasSets.put(setName, new Boolean(true));
75  				}
76  			}
77  		}
78  		sb.append("var i=0;\nvar hSets = new Array();\n");
79  		for (String key : hasSets.keySet()) {
80  			sb.append("hSets[i++] = \"");
81  			sb.append(key);
82  			sb.append("\";\n");
83  		}
84  		
85  		return(sb.toString());
86  	}
87  }