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.components.gridboxes;
6   
7   import java.util.List;
8   
9   import thinwire.ui.GridBox;
10  
11  import com.hack23.cia.model.application.dto.common.UserSessionDTO;
12  import com.hack23.cia.model.application.impl.common.Agency;
13  import com.hack23.cia.model.sweden.impl.Ballot;
14  import com.hack23.cia.model.sweden.impl.Vote;
15  import com.hack23.cia.model.sweden.impl.Vote.Position;
16  import com.hack23.cia.web.action.user.ParliamentMemberAction;
17  import com.hack23.cia.web.common.BeanLocator;
18  
19  /***
20   * The Class BallotGridBox.
21   */
22  public class BallotGridBox extends GridBox {
23  
24      /***
25       * Instantiates a new ballot grid box.
26       *
27       * @param userSessionDTO the user session dto
28       * @param ballot the ballot
29       * @param votes the votes
30       */
31      public BallotGridBox(final UserSessionDTO userSessionDTO,final Ballot ballot, final List<Vote> votes) {
32          super();
33  
34          this.setVisibleHeader(true);
35          this.addActionListener(ACTION_CLICK, BeanLocator
36                  .getApplicationActionListener());
37  
38          final GridBox.Column nameHeader = new GridBox.Column();
39          nameHeader.setName(userSessionDTO
40                  .getLanguageResource(Agency.LanguageContentKey.NAME));
41          this.getColumns().add(nameHeader);
42  
43          final GridBox.Column partyHeader = new GridBox.Column();
44          partyHeader.setName(userSessionDTO
45                  .getLanguageResource(Agency.LanguageContentKey.PARTY));
46          this.getColumns().add(partyHeader);
47  
48          final GridBox.Column votePostionHeader = new GridBox.Column();
49          votePostionHeader.setName(userSessionDTO
50                  .getLanguageResource(Agency.LanguageContentKey.VOTE_POSITION));
51          this.getColumns().add(votePostionHeader);
52  
53          final GridBox.Column winningStatusHeader = new GridBox.Column();
54          winningStatusHeader.setName(userSessionDTO
55                  .getLanguageResource(Agency.LanguageContentKey.WINNING_STATUS));
56          this.getColumns().add(winningStatusHeader);
57  
58          final GridBox.Column partyStatusHeader = new GridBox.Column();
59          partyStatusHeader.setName(userSessionDTO
60                  .getLanguageResource(Agency.LanguageContentKey.PARTY_STATUS));
61          this.getColumns().add(partyStatusHeader);
62  
63          final GridBox.Column winningSideInPartyHeader = new GridBox.Column();
64          winningSideInPartyHeader.setName(userSessionDTO
65                  .getLanguageResource(Agency.LanguageContentKey.WINNING_SIDE_IN_PARTY));
66          this.getColumns().add(winningSideInPartyHeader);
67  
68          final GridBox.Column winningSideHeader = new GridBox.Column();
69          winningSideHeader.setName(userSessionDTO
70                  .getLanguageResource(Agency.LanguageContentKey.WINNING_SIDE));
71          this.getColumns().add(winningSideHeader);
72  
73          for (final Vote vote : votes) {
74  
75              String wonOrLost = null;
76              String rebelOrLoyal = null;
77  
78              if (vote.getPosition().equals(Position.Absent)
79                      || vote.getPosition().equals(Position.Neutral)) {
80                  wonOrLost = "--"; //$NON-NLS-1$
81                  rebelOrLoyal = "--"; //$NON-NLS-1$
82              } else {
83                  if (vote.isWinning()) {
84                      wonOrLost = userSessionDTO
85                              .getLanguageResource(Agency.LanguageContentKey.WON);
86                  } else {
87                      wonOrLost = userSessionDTO
88                              .getLanguageResource(Agency.LanguageContentKey.LOST);
89                  }
90  
91                  if (vote.isRebel()) {
92                      rebelOrLoyal = userSessionDTO
93                              .getLanguageResource(Agency.LanguageContentKey.PARTY_REBEL);
94                  } else {
95                      rebelOrLoyal = userSessionDTO
96                              .getLanguageResource(Agency.LanguageContentKey.PARTY_LOYAL);
97                  }
98              }
99  
100             final GridBox.Row row = new GridBox.Row(vote.getParliamentMember()
101                     .getName(), vote.getParliamentMember().getParty(),
102                     userSessionDTO.getLanguageResource(vote.getPosition()), wonOrLost, rebelOrLoyal,
103                     userSessionDTO.getLanguageResource(ballot.getPartyBallotResult(
104                                     vote.getParliamentMember().getParty())
105                             .getWinningPosition()),
106                     userSessionDTO.getLanguageResource(ballot.getBallotResult()
107                             .getWinningPosition()));
108             row.setUserObject(new ParliamentMemberAction(vote
109                     .getParliamentMember().getId()));
110             this.getRows().add(row);
111         }
112     }
113 
114 }