View Javadoc

1   /*
2    * Copyright 2010 James Pether Sörling
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   *	$Id: AggregatedBugsDataPanel.java 5582 2012-01-04 20:03:13Z pether $
17   *  $HeadURL: https://cia.svn.sourceforge.net/svnroot/cia/trunk/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/page/user/AggregatedBugsDataPanel.java $
18  */
19  package com.hack23.cia.web.impl.ui.page.user;
20  
21  import java.util.HashMap;
22  import java.util.List;
23  import java.util.Map;
24  
25  import com.hack23.cia.model.internal.application.data.impl.AggregatedBugData;
26  import com.hack23.cia.model.internal.application.data.impl.AggregatedCountryData;
27  import com.hack23.cia.model.internal.application.data.impl.BugMetaDataType;
28  import com.hack23.cia.service.api.DataContainer;
29  import com.hack23.cia.web.impl.ui.page.common.panel.AbstractPanel;
30  import com.vaadin.data.Item;
31  import com.vaadin.ui.Tree;
32  import com.vaadin.ui.VerticalLayout;
33  
34  /**
35   * The Class AggregatedBugsDataPanel.
36   */
37  public final class AggregatedBugsDataPanel extends AbstractPanel {
38  
39  	/** The content. */
40  	private VerticalLayout content = null;
41  
42  	/** The Constant serialVersionUID. */
43  	private static final long serialVersionUID = 1L;
44  
45  	/** The data container. */
46  	final DataContainer<AggregatedBugData, String> dataContainer;
47  
48  	/**
49  	 * Instantiates a new aggregated bugs data panel.
50  	 *
51  	 * @param string
52  	 *            the string
53  	 */
54  	public AggregatedBugsDataPanel(final String string) {
55  		super();
56  		setCaption(string);
57  
58  		dataContainer = getApplicationManager().getDataContainer(AggregatedBugData.class);
59  	}
60  
61  	/**
62  	 * Update.
63  	 *
64  	 * @param country
65  	 *            the country
66  	 */
67  	public void update(final AggregatedCountryData country) {
68  		content =new VerticalLayout();
69  		setContent(content);
70  		content.setHeight(null);
71  		content.setWidth("100%");
72  		//content.setSizeFull();
73  		content.setSpacing(true);
74  		content.setMargin(true);
75  
76  		final List<AggregatedBugData> all = dataContainer.getAll();
77  		final Tree tree = new Tree(translateFromEnglish("Politicians"));
78  		final Map<String,Item> partyMap= new HashMap<String, Item>();
79  
80  		final String nationalItemString = translateFromEnglish("National");
81  		tree.addItem(nationalItemString);
82  
83  		for (final AggregatedBugData politician: all) {
84  			if (politician.getCountry().equals(country.getCountry().getName())) {
85  
86  				tree.addItem(politician.getName());
87  
88  				Item partyItem = partyMap.get(politician.getParty());
89  				if (partyItem==null) {
90  					partyItem = tree.addItem(politician.getParty());
91  					partyMap.put(politician.getParty(),partyItem);
92  
93  					if (politician.getType().equals(BugMetaDataType.SWEDISH_POLITICIAN)){
94  						tree.setParent(politician.getParty(), nationalItemString);
95  					} 
96  				}
97  
98  				tree.setParent(politician.getName(), politician.getParty());
99  			}
100 		}
101 
102 		content.addComponent(tree);
103 		tree.setSizeFull();
104 		setSizeFull();
105 	}
106 
107 }