View Javadoc

1   /*
2   Copyright 2010 James Pether Sörling Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 
3   	$Id
4   */
5   package com.hack23.cia.web.views.user;
6   
7   import thinwire.ui.TabFolder;
8   import thinwire.ui.TabSheet;
9   import thinwire.ui.WebBrowser;
10  import thinwire.ui.layout.TableLayout;
11  
12  import com.hack23.cia.model.application.dto.common.UserSessionDTO;
13  import com.hack23.cia.model.application.impl.common.Agency;
14  import com.hack23.cia.model.application.impl.common.ParliamentChart;
15  import com.hack23.cia.model.sweden.impl.Ballot;
16  import com.hack23.cia.web.common.ImageConstants;
17  import com.hack23.cia.web.views.components.gridboxes.BallotGridBox;
18  import com.hack23.cia.web.views.components.panels.ImagePanel;
19  
20  /***
21   * The Class BallotPanel.
22   */
23  public class BallotPanel extends AbstractParliamentOperationPanel {
24  
25      /*** The user session dto. */
26      private final UserSessionDTO userSessionDTO;
27  
28  	/***
29  	 * Instantiates a new ballot panel.
30  	 *
31  	 * @param userSessionDTO the user session dto
32  	 * @param ballot the ballot
33  	 */
34      public BallotPanel(final UserSessionDTO userSessionDTO, final Ballot ballot) {        
35  		super(userSessionDTO);
36      	this.userSessionDTO = userSessionDTO;
37          setLayout(new TableLayout(new double[][] { { 0 }, // Column Widths
38                  { 0 } }, // Row Heights
39                  1, // Margin around edge of container
40                  5)); // Spacing between cells
41  
42          final TabFolder tabFolder = createTabFolder(ballot);
43          
44          tabFolder.getChildren().add(
45                  createTabFolderCharts(ballot));
46          
47          tabFolder.getChildren().add(
48                  createTabFolderCitizenOperation());
49          tabFolder.setLimit("0,0,1,1"); //$NON-NLS-1$
50          getChildren().add(tabFolder);
51      }
52  
53      /***
54       * Creates the tab ballot.
55       *
56       * @param ballot the ballot
57       * @return the tab sheet
58       */
59      private TabSheet createTabBallot(final Ballot ballot) {
60          final TabSheet homePage = new TabSheet();
61  
62          homePage.setText(ballot.getDescription());
63          homePage.setImage(ImageConstants.BALLOT_IMAGE_SMALL);
64  
65          homePage.setLayout(new TableLayout(new double[][] { { 0 }, // Column
66                  // Widths
67                  { 0 } }, // Row Heights
68                  1, // Margin around edge of container
69                  5)); // Spacing between cells
70  
71          
72          final BallotGridBox ballotGridBox = new BallotGridBox(userSessionDTO,ballot, ballot.getVotes());
73          ballotGridBox.setLimit("0,0"); //$NON-NLS-1$
74          homePage.getChildren().add(ballotGridBox);
75          return homePage;
76      }
77  
78  	/***
79  	 * Creates the tab folder.
80  	 *
81  	 * @param ballot the ballot
82  	 * @return the tab folder
83  	 */
84      private TabFolder createTabFolder(final Ballot ballot) {
85          final TabFolder tabFolder = new TabFolder();
86          tabFolder.getChildren().add(createTabBallot(ballot));
87          
88          if (ballot.getVoteResultsHref() != null) {
89              final TabSheet homePageTab = createTabHomePage(ballot);
90              tabFolder.getChildren().add(homePageTab);
91          }
92          return tabFolder;
93      }
94  	
95  	/***
96  	 * Creates the tab folder chart outcome.
97  	 *
98  	 * @param ballot the ballot
99  	 * @return the tab sheet
100 	 */
101 	private TabSheet createTabFolderChartOutcome(
102 			final Ballot ballot) {
103 		final TabSheet tabSheet = new TabSheet();
104 
105         tabSheet.setText(userSessionDTO
106                 .getLanguageResource(Agency.LanguageContentKey.OUTCOME));
107         tabSheet.setLayout(new TableLayout(new double[][] { { 0 }, // Column
108                 // Widths
109                 { 0 } }, // Row Heights
110                 1, // Margin around edge of container
111                 5)); // Spacing between cells
112         final ImagePanel imagePanel = new ImagePanel(ParliamentChart.getFileName(ParliamentChart.Outcome, ballot, userSessionDTO.getUserSession().getLanguage()));
113         imagePanel.setLimit("0,0");
114         tabSheet.getChildren().add(imagePanel);
115         
116         return tabSheet;
117 	}
118 
119 	/***
120 	 * Creates the tab folder chart political party behavior.
121 	 *
122 	 * @param ballot the ballot
123 	 * @return the tab sheet
124 	 */
125 	private TabSheet createTabFolderChartPoliticalPartyBehavior(
126 			final Ballot ballot) {
127 		final TabSheet tabSheet = new TabSheet();
128 
129         tabSheet.setText(userSessionDTO
130                 .getLanguageResource(Agency.LanguageContentKey.POLITICAL_PARTY_BEHAVIOR));
131         tabSheet.setLayout(new TableLayout(new double[][] { { 0 }, // Column
132                 // Widths
133                 { 0 } }, // Row Heights
134                 1, // Margin around edge of container
135                 5)); // Spacing between cells
136         final ImagePanel imagePanel = new ImagePanel(ParliamentChart.getFileName(ParliamentChart.PoliticalPartyBehavior, ballot, userSessionDTO.getUserSession().getLanguage()));
137         imagePanel.setLimit("0,0");
138         tabSheet.getChildren().add(imagePanel);
139         
140         return tabSheet;
141 	}
142 
143 	/***
144 	 * Creates the tab folder chart proffessional behavior.
145 	 *
146 	 * @param ballot the ballot
147 	 * @return the tab sheet
148 	 */
149 	private TabSheet createTabFolderChartProffessionalBehavior(final Ballot ballot) {
150 		final TabSheet tabSheet = new TabSheet();
151 
152         tabSheet.setText(userSessionDTO
153                 .getLanguageResource(Agency.LanguageContentKey.PROFFESSIONAL_BEHAVIOR));
154         tabSheet.setLayout(new TableLayout(new double[][] { { 0 }, // Column
155                 // Widths
156                 { 0 } }, // Row Heights
157                 1, // Margin around edge of container
158                 5)); // Spacing between cells
159         final ImagePanel imagePanel = new ImagePanel(ParliamentChart.getFileName(ParliamentChart.ProffessionalBehavior, ballot, userSessionDTO.getUserSession().getLanguage()));
160         imagePanel.setLimit("0,0");
161         tabSheet.getChildren().add(imagePanel);
162         
163         return tabSheet;
164 	}
165 
166 
167 	/***
168 	 * Creates the tab folder charts.
169 	 *
170 	 * @param ballot the ballot
171 	 * @return the tab sheet
172 	 */
173     private TabSheet createTabFolderCharts(final Ballot ballot) {
174      	  final TabSheet tabSheet = new TabSheet();
175 
176           tabSheet.setText(userSessionDTO
177                   .getLanguageResource(Agency.LanguageContentKey.CHARTS));
178           tabSheet.setImage(ImageConstants.CHART_IMAGE_SMALL);
179           tabSheet.setLayout(new TableLayout(new double[][] { { 0 }, // Column
180                   // Widths
181                   { 0 } }, // Row Heights
182                   1, // Margin around edge of container
183                   5)); // Spacing between cells
184 
185           final TabFolder tabFolder = new TabFolder();
186           tabFolder.setLimit("0,0"); //$NON-NLS-1$
187 
188           tabFolder.getChildren().add(
189                   createTabFolderChartSummary(ballot));
190           tabFolder.getChildren().add(
191                   createTabFolderChartOutcome(ballot));
192           tabFolder.getChildren().add(
193                   createTabFolderChartPoliticalPartyBehavior(ballot));
194           tabFolder.getChildren().add(
195                   createTabFolderChartProffessionalBehavior(ballot));
196           
197           tabFolder.setCurrentIndex(0);
198           tabSheet.getChildren().add(tabFolder);
199           return tabSheet;
200 	}
201 
202     
203     /***
204      * Creates the tab folder chart summary.
205      *
206      * @param ballot the ballot
207      * @return the tab sheet
208      */
209 	private TabSheet createTabFolderChartSummary(
210 			final Ballot ballot) {
211 		final TabSheet tabSheet = new TabSheet();
212 
213         tabSheet.setText(userSessionDTO
214                 .getLanguageResource(Agency.LanguageContentKey.SUMMARY));
215         tabSheet.setLayout(new TableLayout(new double[][] { { 0 }, // Column
216                 // Widths
217                 { 0 } }, // Row Heights
218                 1, // Margin around edge of container
219                 5)); // Spacing between cells
220         final ImagePanel imagePanel = new ImagePanel(ParliamentChart.getFileName(ParliamentChart.Summary, ballot, userSessionDTO.getUserSession().getLanguage()));
221         imagePanel.setLimit("0,0");
222         tabSheet.getChildren().add(imagePanel);
223         
224         return tabSheet;
225 	}
226     
227     /***
228      * Creates the tab home page.
229      *
230      * @param ballot the ballot
231      * @return the tab sheet
232      */
233     private TabSheet createTabHomePage(final Ballot ballot) {
234         final TabSheet homePage = new TabSheet();
235 
236         homePage.setText(ballot.getDescription());
237 
238         homePage.setLayout(new TableLayout(new double[][] { { 0 }, // Column
239                 // Widths
240                 { 0 } }, // Row Heights
241                 1, // Margin around edge of container
242                 5)); // Spacing between cells
243 
244         final WebBrowser comp = new WebBrowser();
245         comp.setLimit("0,0"); //$NON-NLS-1$
246         comp.setLocation(ballot.getVoteResultsHref());
247         homePage.getChildren().add(comp);
248         return homePage;
249     }
250 
251     
252 }