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.CommitteeReport;
16  import com.hack23.cia.web.common.ImageConstants;
17  import com.hack23.cia.web.views.components.panels.ImagePanel;
18  
19  /***
20   * The Class CommitteeReportSummaryPanel.
21   */
22  public class CommitteeReportSummaryPanel extends AbstractParliamentOperationPanel {
23  
24      /*** The user session dto. */
25      private final UserSessionDTO userSessionDTO;
26  
27  	/***
28  	 * Instantiates a new committee report summary panel.
29  	 *
30  	 * @param userSessionDTO the user session dto
31  	 * @param commiteeReport the commitee report
32  	 */
33      public CommitteeReportSummaryPanel(final UserSessionDTO userSessionDTO, final CommitteeReport commiteeReport) {
34          super(userSessionDTO);
35  		this.userSessionDTO = userSessionDTO;
36          setLayout(new TableLayout(new double[][] { { 0 }, // Column Widths
37                  { 0 } }, // Row Heights
38                  1, // Margin around edge of container
39                  5)); // Spacing between cells
40  
41          final TabFolder tabFolder = createTabFolder(commiteeReport);
42          
43          tabFolder.getChildren().add(
44                  createTabFolderCharts(commiteeReport));
45          tabFolder.getChildren().add(
46                  createTabFolderCitizenOperation());
47          
48          tabFolder.setLimit("0,0,1,1"); //$NON-NLS-1$
49          getChildren().add(tabFolder);
50      }
51  
52      /***
53       * Creates the tab folder.
54       *
55       * @param commiteeReport the commitee report
56       * @return the tab folder
57       */
58      private TabFolder createTabFolder(final CommitteeReport commiteeReport) {
59          final TabFolder tabFolder = new TabFolder();
60  
61          if (commiteeReport.getHref() != null) {
62              final TabSheet homePageTab = createTabHomePage(commiteeReport);
63              tabFolder.getChildren().add(homePageTab);
64          }
65          return tabFolder;
66      }
67  
68  	/***
69  	 * Creates the tab folder chart outcome.
70  	 *
71  	 * @param commiteeReport the commitee report
72  	 * @return the tab sheet
73  	 */
74  	private TabSheet createTabFolderChartOutcome(
75  			final CommitteeReport commiteeReport) {
76  		final TabSheet tabSheet = new TabSheet();
77  
78          tabSheet.setText(userSessionDTO
79                  .getLanguageResource(Agency.LanguageContentKey.OUTCOME));
80          tabSheet.setLayout(new TableLayout(new double[][] { { 0 }, // Column
81                  // Widths
82                  { 0 } }, // Row Heights
83                  1, // Margin around edge of container
84                  5)); // Spacing between cells
85          final ImagePanel imagePanel = new ImagePanel(ParliamentChart.getFileName(ParliamentChart.Outcome, commiteeReport, userSessionDTO.getUserSession().getLanguage()));
86          imagePanel.setLimit("0,0");
87          tabSheet.getChildren().add(imagePanel);
88          
89          return tabSheet;
90  	}
91  	
92  	/***
93  	 * Creates the tab folder chart political party behavior.
94  	 *
95  	 * @param commiteeReport the commitee report
96  	 * @return the tab sheet
97  	 */
98  	private TabSheet createTabFolderChartPoliticalPartyBehavior(
99  			final CommitteeReport commiteeReport) {
100 		final TabSheet tabSheet = new TabSheet();
101 
102         tabSheet.setText(userSessionDTO
103                 .getLanguageResource(Agency.LanguageContentKey.POLITICAL_PARTY_BEHAVIOR));
104         tabSheet.setLayout(new TableLayout(new double[][] { { 0 }, // Column
105                 // Widths
106                 { 0 } }, // Row Heights
107                 1, // Margin around edge of container
108                 5)); // Spacing between cells
109         final ImagePanel imagePanel = new ImagePanel(ParliamentChart.getFileName(ParliamentChart.PoliticalPartyBehavior, commiteeReport, userSessionDTO.getUserSession().getLanguage()));
110         imagePanel.setLimit("0,0");
111         tabSheet.getChildren().add(imagePanel);
112         
113         return tabSheet;
114 	}
115 
116 	/***
117 	 * Creates the tab folder chart proffessional behavior.
118 	 *
119 	 * @param commiteeReport the commitee report
120 	 * @return the tab sheet
121 	 */
122 	private TabSheet createTabFolderChartProffessionalBehavior(final CommitteeReport commiteeReport) {
123 		final TabSheet tabSheet = new TabSheet();
124 
125         tabSheet.setText(userSessionDTO
126                 .getLanguageResource(Agency.LanguageContentKey.PROFFESSIONAL_BEHAVIOR));
127         tabSheet.setLayout(new TableLayout(new double[][] { { 0 }, // Column
128                 // Widths
129                 { 0 } }, // Row Heights
130                 1, // Margin around edge of container
131                 5)); // Spacing between cells
132         final ImagePanel imagePanel = new ImagePanel(ParliamentChart.getFileName(ParliamentChart.ProffessionalBehavior, commiteeReport, userSessionDTO.getUserSession().getLanguage()));
133         imagePanel.setLimit("0,0");
134         tabSheet.getChildren().add(imagePanel);
135         
136         return tabSheet;
137 	}
138 
139 	/***
140 	 * Creates the tab folder charts.
141 	 *
142 	 * @param commiteeReport the commitee report
143 	 * @return the tab sheet
144 	 */
145     private TabSheet createTabFolderCharts(final CommitteeReport commiteeReport) {
146      	  final TabSheet tabSheet = new TabSheet();
147 
148           tabSheet.setText(userSessionDTO
149                   .getLanguageResource(Agency.LanguageContentKey.CHARTS));
150           tabSheet.setImage(ImageConstants.CHART_IMAGE_SMALL);
151           tabSheet.setLayout(new TableLayout(new double[][] { { 0 }, // Column
152                   // Widths
153                   { 0 } }, // Row Heights
154                   1, // Margin around edge of container
155                   5)); // Spacing between cells
156 
157           final TabFolder tabFolder = new TabFolder();
158           tabFolder.setLimit("0,0"); //$NON-NLS-1$
159 
160           tabFolder.getChildren().add(
161                   createTabFolderChartSummary(commiteeReport));
162           tabFolder.getChildren().add(
163                   createTabFolderChartOutcome(commiteeReport));
164           tabFolder.getChildren().add(
165                   createTabFolderChartPoliticalPartyBehavior(commiteeReport));
166           tabFolder.getChildren().add(
167                   createTabFolderChartProffessionalBehavior(commiteeReport));
168        
169           
170           tabFolder.setCurrentIndex(0);
171           tabSheet.getChildren().add(tabFolder);
172           return tabSheet;
173 	}
174 
175 
176 	/***
177 	 * Creates the tab folder chart summary.
178 	 *
179 	 * @param commiteeReport the commitee report
180 	 * @return the tab sheet
181 	 */
182 	private TabSheet createTabFolderChartSummary(
183 			final CommitteeReport commiteeReport) {
184 		final TabSheet tabSheet = new TabSheet();
185 
186         tabSheet.setText(userSessionDTO
187                 .getLanguageResource(Agency.LanguageContentKey.SUMMARY));
188         tabSheet.setLayout(new TableLayout(new double[][] { { 0 }, // Column
189                 // Widths
190                 { 0 } }, // Row Heights
191                 1, // Margin around edge of container
192                 5)); // Spacing between cells
193         final ImagePanel imagePanel = new ImagePanel(ParliamentChart.getFileName(ParliamentChart.Summary, commiteeReport, userSessionDTO.getUserSession().getLanguage()));
194         imagePanel.setLimit("0,0");
195         tabSheet.getChildren().add(imagePanel);
196         
197         return tabSheet;
198 	}
199 
200     /***
201      * Creates the tab home page.
202      *
203      * @param commiteeReport the commitee report
204      * @return the tab sheet
205      */
206     private TabSheet createTabHomePage(final CommitteeReport commiteeReport) {
207         final TabSheet homePage = new TabSheet();
208 
209         homePage.setText(commiteeReport.getName());
210 
211         homePage.setLayout(new TableLayout(new double[][] { { 0 }, // Column
212                 // Widths
213                 { 0 } }, // Row Heights
214                 1, // Margin around edge of container
215                 5)); // Spacing between cells
216 
217         final WebBrowser comp = new WebBrowser();
218         comp.setLimit("0,0"); //$NON-NLS-1$
219         comp.setLocation(commiteeReport.getHref());
220         homePage.getChildren().add(comp);
221         return homePage;
222     }
223 
224 }