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: CountryPage.java 5436 2011-04-26 18:25:22Z 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/CountryPage.java $
18  */
19  package com.hack23.cia.web.impl.ui.page.user;
20  
21  import org.vaadin.navigator7.Navigator.NavigationEvent;
22  import org.vaadin.navigator7.Page;
23  import org.vaadin.navigator7.ParamChangeListener;
24  import org.vaadin.navigator7.uri.Param;
25  
26  import com.hack23.cia.model.internal.application.data.impl.AggregatedCountryData;
27  import com.hack23.cia.model.internal.application.data.impl.CountryMetaDataType;
28  import com.hack23.cia.service.api.DataContainer;
29  import com.vaadin.ui.Alignment;
30  import com.vaadin.ui.GridLayout;
31  
32  /**
33   * The Class CountryPage.
34   */
35  @Page(uriName = "country", crawlable = true)
36  @SuppressWarnings("serial")
37  public final class CountryPage extends AbstractUserPage implements ParamChangeListener {
38  
39  	/** The country name. */
40  	@Param(pos = 0, required = true)
41  	String countryName;
42  
43  	/** The country iso. */
44  	@Param(pos = 1, required = true)
45  	String countryIso;
46  
47  	/** The target select panel. */
48  	private AggregatedCountryDataPanel targetSelectPanel = null;
49  
50  	/** The world bank data panel. */
51  	private WorldBankIndicatorCountryPanel worldBankDataPanel=null;
52  
53  	/** The target politicians panel. */
54  	private AggregatedBugsDataPanel targetPoliticiansPanel=null;
55  
56  	/**
57  	 * Instantiates a new country page.
58  	 */
59  	public CountryPage() {
60  		super();
61  	}
62  
63  	/* (non-Javadoc)
64  	 * @see com.hack23.cia.web.impl.ui.page.common.AbstractPage#getPageTitle()
65  	 */
66  	@Override
67  	public String getPageTitle() {
68  		return getUserState().translateFromEnglish("Country overview " + countryName);
69  	}
70  
71  	/* (non-Javadoc)
72  	 * @see org.vaadin.navigator7.ParamChangeListener#paramChanged(org.vaadin.navigator7.Navigator.NavigationEvent)
73  	 */
74  	@Override
75  	public void paramChanged(final NavigationEvent navigationEvent) {
76  		final DataContainer<AggregatedCountryData, String> dataContainer = getApplicationManager()
77  				.getDataContainer(AggregatedCountryData.class);
78  		final AggregatedCountryData country = dataContainer.load(countryName);
79  		final GridLayout grid = new GridLayout(10, 8);
80  
81  		targetSelectPanel = new AggregatedCountryDataPanel();
82  		grid.addComponent(targetSelectPanel, 0, 0, 1, 7);
83  		grid.setComponentAlignment(targetSelectPanel, Alignment.MIDDLE_CENTER);
84  		targetSelectPanel.update(country);
85  		targetSelectPanel.setSizeFull();
86  
87  		if (country.getType().equals(CountryMetaDataType.ITSYOUR_PARLIAMENT)) {
88  			worldBankDataPanel = new WorldBankIndicatorCountryPanel();
89  			grid.addComponent(worldBankDataPanel, 2, 0, 7, 7);
90  			grid.setComponentAlignment(worldBankDataPanel,
91  					Alignment.MIDDLE_CENTER);
92  			worldBankDataPanel.update(country);
93  			worldBankDataPanel.setSizeFull();
94  
95  			targetPoliticiansPanel = new AggregatedBugsDataPanel(
96  					translateFromEnglish("Politicians"));
97  			grid.addComponent(targetPoliticiansPanel, 8, 0, 9, 7);
98  			grid.setComponentAlignment(targetPoliticiansPanel,
99  					Alignment.MIDDLE_CENTER);
100 			targetPoliticiansPanel.update(country);
101 			targetPoliticiansPanel.setSizeFull();
102 		} else {
103 			worldBankDataPanel = new WorldBankIndicatorCountryPanel();
104 			grid.addComponent(worldBankDataPanel, 2, 0, 9, 7);
105 			grid.setComponentAlignment(worldBankDataPanel,
106 					Alignment.MIDDLE_CENTER);
107 			worldBankDataPanel.update(country);
108 			worldBankDataPanel.setSizeFull();
109 		}
110 
111 		grid.setSizeFull();
112 		grid.setMargin(false);
113 		grid.setSpacing(true);
114 		setCompositionRoot(grid);
115 		setHeight(getScreenHeight());
116 	}
117 
118 }