1
2
3
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 },
38 { 0 } },
39 1,
40 5));
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");
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 },
66
67 { 0 } },
68 1,
69 5));
70
71
72 final BallotGridBox ballotGridBox = new BallotGridBox(userSessionDTO,ballot, ballot.getVotes());
73 ballotGridBox.setLimit("0,0");
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 },
108
109 { 0 } },
110 1,
111 5));
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 },
132
133 { 0 } },
134 1,
135 5));
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 },
155
156 { 0 } },
157 1,
158 5));
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 },
180
181 { 0 } },
182 1,
183 5));
184
185 final TabFolder tabFolder = new TabFolder();
186 tabFolder.setLimit("0,0");
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 },
216
217 { 0 } },
218 1,
219 5));
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 },
239
240 { 0 } },
241 1,
242 5));
243
244 final WebBrowser comp = new WebBrowser();
245 comp.setLimit("0,0");
246 comp.setLocation(ballot.getVoteResultsHref());
247 homePage.getChildren().add(comp);
248 return homePage;
249 }
250
251
252 }