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: PoliticianPage.java 5462 2011-05-10 20:23:49Z 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/PoliticianPage.java $
18  */
19  package com.hack23.cia.web.impl.ui.page.user;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import org.vaadin.navigator7.Navigator.NavigationEvent;
25  import org.vaadin.navigator7.Page;
26  import org.vaadin.navigator7.ParamChangeListener;
27  import org.vaadin.navigator7.uri.Param;
28  
29  import com.hack23.cia.model.internal.application.data.impl.AggregatedBugData;
30  import com.hack23.cia.service.api.DataContainer;
31  import com.vaadin.data.Property;
32  import com.vaadin.data.Property.ValueChangeEvent;
33  import com.vaadin.ui.Alignment;
34  import com.vaadin.ui.GridLayout;
35  import com.vaadin.ui.ListSelect;
36  import com.vaadin.ui.Panel;
37  
38  /**
39   * The Class PoliticianPage.
40   */
41  @Page(uriName = "politician", crawlable = true)
42  @SuppressWarnings("serial")
43  public final class PoliticianPage extends AbstractUserPage implements
44  		Property.ValueChangeListener, ParamChangeListener {
45  
46  	/** The country. */
47  	@Param(pos = 0, required = false)
48  	private String country="";
49  
50  	/** The party. */
51  	@Param(pos = 1, required = false)
52  	private String party="";
53  
54  	/** The id. */
55  	@Param(pos = 2, required = false)
56  	private String id="";
57  
58  	/** The name. */
59  	@Param(pos = 3, required = false)
60  	private String name="";
61  
62  	/** The target select panel. */
63  	private AggregatedBugDataPanel targetSelectPanel = null;
64  
65  	/**
66  	 * Instantiates a new politician page.
67  	 */
68  	public PoliticianPage() {
69  		super();
70  		final GridLayout grid = new GridLayout(10, 8);
71  		grid.setSpacing(true);
72  
73  		final DataContainer<AggregatedBugData, String> dataContainer = getApplicationManager()
74  				.getDataContainer(AggregatedBugData.class);
75  
76  		final List<String> countryNames = new ArrayList<String>();
77  		final List<AggregatedBugData> all = dataContainer.getAll();
78  
79  		final ListSelect targetSelect = new ListSelect(
80  				"Please select target politician", countryNames);
81  		// targetSelect.setValue(newValue)
82  		// ComboBox targetSelect = new ComboBox("Please select target Country",
83  		// countryNames);
84  
85  		// Set the appropriate filtering mode for this example
86  		// targetSelect.setFilteringMode(Filtering.FILTERINGMODE_STARTSWITH);
87  		targetSelect.setImmediate(true);
88  		targetSelect.addListener(this);
89  		grid.addComponent(targetSelect, 0, 0, 9, 0);
90  		grid.setComponentAlignment(targetSelect, Alignment.MIDDLE_CENTER);
91  		targetSelect.setSizeFull();
92  
93  		targetSelectPanel = new AggregatedBugDataPanel(all.iterator().next());
94  		grid.addComponent(targetSelectPanel, 0, 1, 1, 7);
95  		grid.setComponentAlignment(targetSelectPanel, Alignment.MIDDLE_CENTER);
96  		targetSelectPanel.setSizeFull();
97  
98  		final Panel operationalAgentPanel = new Panel(
99  				"Budget/Cost & Operational Statements Panel");
100 		grid.addComponent(operationalAgentPanel, 2, 1, 7, 4);
101 		grid.setComponentAlignment(operationalAgentPanel,
102 				Alignment.MIDDLE_CENTER);
103 		operationalAgentPanel.setSizeFull();
104 
105 		final Panel targetQAPanel = new Panel("Quality Assurance Results");
106 		grid.addComponent(targetQAPanel, 2, 5, 7, 7);
107 		grid.setComponentAlignment(targetQAPanel, Alignment.MIDDLE_CENTER);
108 		targetQAPanel.setSizeFull();
109 
110 		final Panel targetPerformanceIndicatorsPanel = new Panel(
111 				"Performance Indicators ");
112 		grid.addComponent(targetPerformanceIndicatorsPanel, 8, 1, 9, 5);
113 		grid.setComponentAlignment(targetPerformanceIndicatorsPanel,
114 				Alignment.MIDDLE_CENTER);
115 		targetPerformanceIndicatorsPanel.setSizeFull();
116 
117 		final Panel targetOpenDataAccessPanel = new Panel("Data");
118 		grid.addComponent(targetOpenDataAccessPanel, 8, 6, 9, 7);
119 		grid.setComponentAlignment(targetOpenDataAccessPanel,
120 				Alignment.MIDDLE_CENTER);
121 		targetOpenDataAccessPanel.setSizeFull();
122 
123 		grid.setSizeFull();
124 		grid.setMargin(true);
125 		grid.setSpacing(true);
126 		setCompositionRoot(grid);
127 		setHeight(getScreenHeight());
128 
129 	}
130 
131 	/* (non-Javadoc)
132 	 * @see org.vaadin.navigator7.ParamChangeListener#paramChanged(org.vaadin.navigator7.Navigator.NavigationEvent)
133 	 */
134 	@Override
135 	public void paramChanged(final NavigationEvent navigationEvent) {
136 		final DataContainer<AggregatedBugData, String> dataContainer = getApplicationManager()
137 				.getDataContainer(AggregatedBugData.class);
138 		final AggregatedBugData bug = dataContainer.load(country + "/" + party + "/" + id + "/"  + name);
139 
140 		if (bug != null) {
141 			targetSelectPanel.update(bug);
142 		} else {
143 			targetSelectPanel.update(dataContainer.getAll().iterator().next());
144 		}
145 	}
146 
147 	/* (non-Javadoc)
148 	 * @see com.vaadin.data.Property.ValueChangeListener#valueChange(com.vaadin.data.Property.ValueChangeEvent)
149 	 */
150 	@Override
151 	public void valueChange(final ValueChangeEvent event) {
152 		final DataContainer<AggregatedBugData, String> dataContainer = getApplicationManager()
153 				.getDataContainer(AggregatedBugData.class);
154 		final AggregatedBugData countryData = dataContainer.load(event.getProperty()
155 				.toString());
156 
157 		targetSelectPanel.update(countryData);
158 	}
159 
160 	/* (non-Javadoc)
161 	 * @see com.hack23.cia.web.impl.ui.page.common.AbstractPage#getPageTitle()
162 	 */
163 	@Override
164 	public String getPageTitle() {
165 		return "";
166 	}
167 
168 }