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   
6   package com.hack23.cia.web.views.user;
7   
8   import java.util.List;
9   
10  import thinwire.ui.GridBox;
11  import thinwire.ui.TabFolder;
12  import thinwire.ui.TabSheet;
13  import thinwire.ui.WebBrowser;
14  import thinwire.ui.layout.TableLayout;
15  
16  import com.hack23.cia.model.application.dto.common.UserSessionDTO;
17  import com.hack23.cia.model.application.impl.common.Agency;
18  import com.hack23.cia.model.application.impl.common.Language;
19  import com.hack23.cia.model.application.impl.common.ParliamentChart;
20  import com.hack23.cia.model.application.impl.common.UserSession;
21  import com.hack23.cia.model.sweden.impl.ParliamentMember;
22  import com.hack23.cia.model.sweden.impl.ParliamentMemberVoteCompareResult;
23  import com.hack23.cia.model.sweden.impl.RegisterInformation;
24  import com.hack23.cia.model.sweden.impl.Vote;
25  import com.hack23.cia.web.common.ImageConstants;
26  import com.hack23.cia.web.views.components.gridboxes.ParliamentMemberVoteCompareResultGridBox;
27  import com.hack23.cia.web.views.components.gridboxes.RegisterInformationGridbox;
28  import com.hack23.cia.web.views.components.gridboxes.VoteGridBox;
29  import com.hack23.cia.web.views.components.panels.ImagePanel;
30  
31  /***
32   * The Class ParliamentMemberSummaryPanel.
33   */
34  public class ParliamentMemberSummaryPanel extends AbstractParliamentOperationPanel {
35  
36      /*** The user session dto. */
37      private final UserSessionDTO userSessionDTO;
38      
39      
40      /***
41       * Instantiates a new parliament member summary panel.
42       *
43       * @param userSessionDTO the user session dto
44       * @param parliamentMember the parliament member
45       * @param votes the votes
46       * @param friendList the friend list
47       * @param enemyList the enemy list
48       * @param partyFriendList the party friend list
49       * @param partyEnemyList the party enemy list
50       * @param registerInformation the register information
51       */
52      public ParliamentMemberSummaryPanel(final UserSessionDTO userSessionDTO,
53              final ParliamentMember parliamentMember, final List<Vote> votes,
54              final List<ParliamentMemberVoteCompareResult> friendList,
55              final List<ParliamentMemberVoteCompareResult> enemyList,
56              final List<ParliamentMemberVoteCompareResult> partyFriendList,
57              final List<ParliamentMemberVoteCompareResult> partyEnemyList,
58              final RegisterInformation registerInformation) {
59          super(userSessionDTO);
60          this.userSessionDTO = userSessionDTO;
61          setLayout(new TableLayout(new double[][] { { 0 }, // Column Widths
62                  { 0 } }, // Row Heights
63                  1, // Margin around edge of container
64                  5)); // Spacing between cells
65  
66          final TabFolder tabFolder = new TabFolder();
67          tabFolder.setLimit("0,0,1,1"); //$NON-NLS-1$
68  
69          tabFolder.getChildren().add(
70                  createInformationTabSheet(userSessionDTO.getUserSession(), parliamentMember,
71                          registerInformation, votes));
72          tabFolder.getChildren().add(
73                  createTabFolderCharts(parliamentMember));
74          tabFolder.getChildren().add(
75                  createTabFolderFriendsAndEnemies(friendList, enemyList,
76                          partyFriendList, partyEnemyList));
77          tabFolder.getChildren().add(
78                  createTabFolderCitizenOperation());
79       
80          tabFolder.setCurrentIndex(0);
81          getChildren().add(tabFolder);
82  
83      }
84  
85      /***
86       * Creates the information tab sheet.
87       *
88       * @param userSession the user session
89       * @param parliamentMember the parliament member
90       * @param registerInformation the register information
91       * @param votes the votes
92       * @return the tab sheet
93       */
94      private TabSheet createInformationTabSheet(final UserSession userSession,
95              final ParliamentMember parliamentMember,
96              final RegisterInformation registerInformation,
97              final List<Vote> votes) {
98          final TabSheet informationTabSheet = new TabSheet();
99  
100         informationTabSheet.setText(userSessionDTO
101                 .getLanguageResource(Agency.LanguageContentKey.INFORMATION) + ":" + parliamentMember.getName());
102         informationTabSheet.setLayout(new TableLayout(new double[][] { { 0 }, // Column
103                 // Widths
104                 { 0 } }, // Row Heights
105                 1, // Margin around edge of container
106                 5)); // Spacing between cells
107 
108         final TabFolder tabFolder = new TabFolder();
109         tabFolder.setLimit("0,0"); //$NON-NLS-1$
110 
111         if (parliamentMember.getHref() != null) {
112             final TabSheet homePageTab = createTabHomePage(userSession,
113                     parliamentMember);
114             tabFolder.getChildren().add(homePageTab);
115         }
116 
117         if (parliamentMember.getWikiHref() != null) {
118             final TabSheet wikiPageTab = createTabWikiPage(parliamentMember,
119                     userSession);
120             tabFolder.getChildren().add(wikiPageTab);
121         }
122 
123         final TabSheet otherLoyaltiesTab = createTabSheetOtherLoyalties(registerInformation);
124         tabFolder.getChildren().add(otherLoyaltiesTab);
125 
126         final TabSheet votesTabSheet = createVoteTabSheet(votes);
127         tabFolder.getChildren().add(votesTabSheet);
128 
129         tabFolder.setCurrentIndex(0);
130         informationTabSheet.getChildren().add(tabFolder);
131         return informationTabSheet;
132     }
133 
134 
135 	/***
136 	 * Creates the tab folder chart outcome.
137 	 *
138 	 * @param parliamentMember the parliament member
139 	 * @return the tab sheet
140 	 */
141 	private TabSheet createTabFolderChartOutcome(
142 			final ParliamentMember parliamentMember) {
143 		final TabSheet tabSheet = new TabSheet();
144 
145         tabSheet.setText(userSessionDTO
146                 .getLanguageResource(Agency.LanguageContentKey.OUTCOME));
147         tabSheet.setLayout(new TableLayout(new double[][] { { 0 }, // Column
148                 // Widths
149                 { 0 } }, // Row Heights
150                 1, // Margin around edge of container
151                 5)); // Spacing between cells
152         final ImagePanel imagePanel = new ImagePanel(ParliamentChart.getFileName(ParliamentChart.Outcome, parliamentMember, userSessionDTO.getUserSession().getLanguage()));
153         imagePanel.setLimit("0,0");
154         tabSheet.getChildren().add(imagePanel);
155         
156         return tabSheet;
157 	}
158 
159 	/***
160 	 * Creates the tab folder chart political party behavior.
161 	 *
162 	 * @param parliamentMember the parliament member
163 	 * @return the tab sheet
164 	 */
165 	private TabSheet createTabFolderChartPoliticalPartyBehavior(
166 			final ParliamentMember parliamentMember) {
167 		final TabSheet tabSheet = new TabSheet();
168 
169         tabSheet.setText(userSessionDTO
170                 .getLanguageResource(Agency.LanguageContentKey.POLITICAL_PARTY_BEHAVIOR));
171         tabSheet.setLayout(new TableLayout(new double[][] { { 0 }, // Column
172                 // Widths
173                 { 0 } }, // Row Heights
174                 1, // Margin around edge of container
175                 5)); // Spacing between cells
176         final ImagePanel imagePanel = new ImagePanel(ParliamentChart.getFileName(ParliamentChart.PoliticalPartyBehavior, parliamentMember, userSessionDTO.getUserSession().getLanguage()));
177         imagePanel.setLimit("0,0");
178         tabSheet.getChildren().add(imagePanel);
179         
180         return tabSheet;
181 	}
182 
183 	/***
184 	 * Creates the tab folder chart proffessional behavior.
185 	 *
186 	 * @param parliamentMember the parliament member
187 	 * @return the tab sheet
188 	 */
189 	private TabSheet createTabFolderChartProffessionalBehavior(final
190 			ParliamentMember parliamentMember) {
191 		final TabSheet tabSheet = new TabSheet();
192 
193         tabSheet.setText(userSessionDTO
194                 .getLanguageResource(Agency.LanguageContentKey.PROFFESSIONAL_BEHAVIOR));
195         tabSheet.setLayout(new TableLayout(new double[][] { { 0 }, // Column
196                 // Widths
197                 { 0 } }, // Row Heights
198                 1, // Margin around edge of container
199                 5)); // Spacing between cells
200         final ImagePanel imagePanel = new ImagePanel(ParliamentChart.getFileName(ParliamentChart.ProffessionalBehavior, parliamentMember, userSessionDTO.getUserSession().getLanguage()));
201         imagePanel.setLimit("0,0");
202         tabSheet.getChildren().add(imagePanel);
203         
204         return tabSheet;
205 	}
206 
207 	/***
208 	 * Creates the tab folder charts.
209 	 *
210 	 * @param parliamentMember the parliament member
211 	 * @return the tab sheet
212 	 */
213     private TabSheet createTabFolderCharts(final ParliamentMember parliamentMember) {
214     	  final TabSheet tabSheet = new TabSheet();
215 
216           tabSheet.setText(userSessionDTO
217                   .getLanguageResource(Agency.LanguageContentKey.CHARTS));
218           tabSheet.setImage(ImageConstants.CHART_IMAGE_SMALL);
219           tabSheet.setLayout(new TableLayout(new double[][] { { 0 }, // Column
220                   // Widths
221                   { 0 } }, // Row Heights
222                   1, // Margin around edge of container
223                   5)); // Spacing between cells
224 
225           final TabFolder tabFolder = new TabFolder();
226           tabFolder.setLimit("0,0"); //$NON-NLS-1$
227 
228           tabFolder.getChildren().add(
229                   createTabFolderChartSummary(parliamentMember));
230           tabFolder.getChildren().add(
231                   createTabFolderChartOutcome(parliamentMember));
232           tabFolder.getChildren().add(
233                   createTabFolderChartPoliticalPartyBehavior(parliamentMember));
234           tabFolder.getChildren().add(
235                   createTabFolderChartProffessionalBehavior(parliamentMember));
236           
237           tabFolder.setCurrentIndex(0);
238           tabSheet.getChildren().add(tabFolder);
239           return tabSheet;
240    }
241 
242 	/***
243 	 * Creates the tab folder chart summary.
244 	 *
245 	 * @param parliamentMember the parliament member
246 	 * @return the tab sheet
247 	 */
248 	private TabSheet createTabFolderChartSummary(
249 			final ParliamentMember parliamentMember) {
250 		final TabSheet tabSheet = new TabSheet();
251 
252         tabSheet.setText(userSessionDTO
253                 .getLanguageResource(Agency.LanguageContentKey.SUMMARY));
254         tabSheet.setLayout(new TableLayout(new double[][] { { 0 }, // Column
255                 // Widths
256                 { 0 } }, // Row Heights
257                 1, // Margin around edge of container
258                 5)); // Spacing between cells
259         final ImagePanel imagePanel = new ImagePanel(ParliamentChart.getFileName(ParliamentChart.Summary, parliamentMember, userSessionDTO.getUserSession().getLanguage()));
260         imagePanel.setLimit("0,0");
261         tabSheet.getChildren().add(imagePanel);
262         
263         return tabSheet;
264 	}
265 
266  
267 
268 	/***
269 	 * Creates the tab folder friends and enemies.
270 	 *
271 	 * @param friendList the friend list
272 	 * @param enemyList the enemy list
273 	 * @param partyFriendList the party friend list
274 	 * @param partyEnemyList the party enemy list
275 	 * @return the tab sheet
276 	 */
277     private TabSheet createTabFolderFriendsAndEnemies(
278             final List<ParliamentMemberVoteCompareResult> friendList,
279             final List<ParliamentMemberVoteCompareResult> enemyList,
280             final List<ParliamentMemberVoteCompareResult> partyFriendList,
281             final List<ParliamentMemberVoteCompareResult> partyEnemyList) {
282 
283         final TabSheet friendsAndEnemiesTabSheet = new TabSheet();
284 
285         friendsAndEnemiesTabSheet.setText(userSessionDTO
286                 .getLanguageResource(Agency.LanguageContentKey.FRIENDS_AND_ENEMIES));
287         friendsAndEnemiesTabSheet.setLayout(new TableLayout(new double[][] {
288                 { 0 }, // Column
289                 // Widths
290                 { 0 } }, // Row Heights
291                 1, // Margin around edge of container
292                 5)); // Spacing between cells
293 
294         final TabFolder tabFolder = new TabFolder();
295 
296         final TabSheet friendsTab = createTabSheetRelations(userSessionDTO
297                 .getLanguageResource(Agency.LanguageContentKey.TOP_BEST_FRIENDS), friendList);
298         tabFolder.getChildren().add(friendsTab);
299 
300         final TabSheet enenmyTab = createTabSheetRelations(userSessionDTO
301                 .getLanguageResource(Agency.LanguageContentKey.TOP_WORST_ENEMIES), enemyList);
302         tabFolder.getChildren().add(enenmyTab);
303 
304         final TabSheet friendsPartyTab = createTabSheetRelations(
305                 userSessionDTO
306                         .getLanguageResource(Agency.LanguageContentKey.TOP_BEST_FRIENDS)
307                         + " " + userSessionDTO //$NON-NLS-1$
308                                 .getLanguageResource(Agency.LanguageContentKey.INSIDE_PARTY),
309                 partyFriendList);
310         tabFolder.getChildren().add(friendsPartyTab);
311 
312         final TabSheet enenmyPartyTab = createTabSheetRelations(
313                 userSessionDTO
314                         .getLanguageResource(Agency.LanguageContentKey.TOP_WORST_ENEMIES)
315                         + " " + userSessionDTO //$NON-NLS-1$
316                                 .getLanguageResource(Agency.LanguageContentKey.INSIDE_PARTY),
317                 partyEnemyList);
318         tabFolder.getChildren().add(enenmyPartyTab);
319 
320         friendsAndEnemiesTabSheet.getChildren().add(tabFolder);
321 
322         return friendsAndEnemiesTabSheet;
323     }
324 
325 
326     /***
327      * Creates the tab home page.
328      *
329      * @param userSession the user session
330      * @param parliamentMember the parliament member
331      * @return the tab sheet
332      */
333     private TabSheet createTabHomePage(final UserSession userSession,
334             final ParliamentMember parliamentMember) {
335         final TabSheet homePage = new TabSheet();
336 
337         homePage.setText(userSessionDTO
338                 .getLanguageResource(Agency.LanguageContentKey.RIKSDAG_INFORMATION));
339         homePage.setImage(ImageConstants.POLITICAL_PARTY_ICON_SMALL);
340 
341         homePage.setLayout(new TableLayout(new double[][] { { 0 }, // Column
342                 // Widths
343                 { 0 } }, // Row Heights
344                 1, // Margin around edge of container
345                 5)); // Spacing between cells
346 
347         final WebBrowser comp = new WebBrowser();
348         comp.setLimit("0,0"); //$NON-NLS-1$
349 
350         if (Language.SWEDISH_LANGUAGE_CODE.equalsIgnoreCase(userSession
351                 .getLanguage().getShortCode())) {
352             comp.setLocation(parliamentMember.getHref());
353         } else {
354             comp.setLocation(parliamentMember.getInternationalHref());
355         }
356         homePage.getChildren().add(comp);
357         return homePage;
358     }
359 
360     /***
361      * Creates the tab sheet other loyalties.
362      *
363      * @param registerInformation the register information
364      * @return the tab sheet
365      */
366     private TabSheet createTabSheetOtherLoyalties(
367             final RegisterInformation registerInformation) {
368         final TabSheet votesTabShett = new TabSheet();
369 
370         votesTabShett.setText(userSessionDTO
371                 .getLanguageResource(Agency.LanguageContentKey.OTHER_LOYALTIES));
372 
373         votesTabShett.setLayout(new TableLayout(new double[][] { { 0 }, // Column
374                 // Widths
375                 { 0 } }, // Row Heights
376                 1, // Margin around edge of container
377                 5)); // Spacing between cells
378 
379         final GridBox registerInformationBox = new RegisterInformationGridbox(userSessionDTO,
380                 registerInformation);
381         registerInformationBox.setLimit("0,0"); //$NON-NLS-1$
382         votesTabShett.getChildren().add(registerInformationBox);
383 
384         return votesTabShett;
385     }
386 
387     /***
388      * Creates the tab sheet relations.
389      *
390      * @param title the title
391      * @param enemyList the enemy list
392      * @return the tab sheet
393      */
394     private TabSheet createTabSheetRelations(final String title,
395             final List<ParliamentMemberVoteCompareResult> enemyList) {
396         final TabSheet members = new TabSheet();
397 
398         members.setText(title);
399         members.setImage(ImageConstants.POLITICAL_PARTY_ICON_SMALL);
400 
401         members.setLayout(new TableLayout(new double[][] { { 0 }, // Column
402                 // Widths
403                 { 0 } }, // Row Heights
404                 1, // Margin around edge of container
405                 5)); // Spacing between cells
406 
407         final GridBox orgBox = new ParliamentMemberVoteCompareResultGridBox(userSessionDTO,enemyList);
408         orgBox.setLimit("0,0"); //$NON-NLS-1$
409         members.getChildren().add(orgBox);
410 
411         return members;
412     }
413 
414     /***
415      * Creates the tab wiki page.
416      *
417      * @param parliamentMember the parliament member
418      * @param userSession the user session
419      * @return the tab sheet
420      */
421     private TabSheet createTabWikiPage(final ParliamentMember parliamentMember,
422             final UserSession userSession) {
423         final TabSheet wikiPage = new TabSheet();
424 
425         wikiPage.setText(userSessionDTO
426                 .getLanguageResource(Agency.LanguageContentKey.WIKI));
427         wikiPage.setImage(ImageConstants.POLITICAL_PARTY_ICON_SMALL);
428 
429         wikiPage.setLayout(new TableLayout(new double[][] { { 0 }, // Column
430                 // Widths
431                 { 0 } }, // Row Heights
432                 1, // Margin around edge of container
433                 5)); // Spacing between cells
434 
435         final WebBrowser comp = new WebBrowser();
436         comp.setLimit("0,0"); //$NON-NLS-1$
437 
438         if (Language.SWEDISH_LANGUAGE_CODE.equalsIgnoreCase(userSession
439                 .getLanguage().getShortCode())) {
440             comp.setLocation(parliamentMember.getWikiHref());
441         } else {
442             comp.setLocation(parliamentMember.getEnglishWikiHref());
443         }
444         wikiPage.getChildren().add(comp);
445         return wikiPage;
446     }
447 
448     /***
449      * Creates the vote tab sheet.
450      *
451      * @param votes the votes
452      * @return the tab sheet
453      */
454     private TabSheet createVoteTabSheet(final List<Vote> votes) {
455         final TabSheet votesTabShett = new TabSheet();
456 
457         votesTabShett.setText(userSessionDTO
458                 .getLanguageResource(Agency.LanguageContentKey.VOTES));
459 
460         votesTabShett.setLayout(new TableLayout(new double[][] { { 0 }, // Column
461                 // Widths
462                 { 0 } }, // Row Heights
463                 1, // Margin around edge of container
464                 5)); // Spacing between cells
465 
466         final GridBox votesBox = new VoteGridBox(userSessionDTO,votes);
467         votesBox.setLimit("0,0"); //$NON-NLS-1$
468         votesTabShett.getChildren().add(votesBox);
469 
470         return votesTabShett;
471     }
472 
473 }