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 org.directdemocracyportal.democracy.web.views;
6   
7   import java.util.List;
8   
9   import org.directdemocracyportal.democracy.model.world.Person;
10  import org.directdemocracyportal.democracy.model.world.Vote;
11  import org.directdemocracyportal.democracy.web.ApplicationMessageHolder;
12  import org.directdemocracyportal.democracy.web.ApplicationMessageHolder.MessageConstans;
13  
14  import thinwire.ui.GridBox;
15  import thinwire.ui.Label;
16  import thinwire.ui.Panel;
17  import thinwire.ui.layout.TableLayout;
18  
19  /***
20   * The Class PersonProfilePanel.
21   */
22  public class PersonProfilePanel extends Panel
23  {
24  
25      /***
26       * Instantiates a new person profile panel.
27       *
28       * @param person the person
29       * @param votes the votes
30       */
31      public PersonProfilePanel(Person person, List<Vote> votes) {
32  
33          setLayout(new TableLayout(new double[][] { { 0 }, // Column
34                  // Widths
35                  { 20,0} }, // Row Heights
36                  1, // Margin around edge of container
37                  5)); // Spacing between cells
38  
39  
40          Label informationLabel = new Label(ApplicationMessageHolder
41                  .getMessage(MessageConstans.INFORMATION) + " " + person.getName());
42          informationLabel.setLimit("0,0");
43          getChildren().add(informationLabel);
44  
45          GridBox informationBox = getVotesGridBox(votes);
46          informationBox.setLimit("0,1");
47          getChildren().add(informationBox);
48      }
49  
50      /***
51       * Gets the votes grid box.
52       *
53       * @param votes the votes
54       * @return the votes grid box
55       */
56      private GridBox getVotesGridBox(List<Vote> votes) {
57          GridBox gridBox = new GridBox();
58          gridBox.setVisibleHeader(true);
59  
60          GridBox.Column dateHeader = new GridBox.Column();
61          dateHeader.setName(ApplicationMessageHolder
62                  .getMessage(MessageConstans.DATE));
63          gridBox.getColumns().add(dateHeader);
64  
65          GridBox.Column positionHeader = new GridBox.Column();
66          positionHeader.setName(ApplicationMessageHolder
67                  .getMessage(MessageConstans.VOTE));
68          gridBox.getColumns().add(positionHeader);
69  
70          for (Vote vote: votes) {
71              gridBox.getRows().add(new GridBox.Row(vote.getVoteDate(),vote.getPosition()));
72          }
73  
74          return gridBox;
75      }
76  }