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.application.OnlinePoliticalParty;
10  import org.directdemocracyportal.democracy.model.world.PoliticalParty;
11  import org.directdemocracyportal.democracy.web.BeanLocator;
12  import org.directdemocracyportal.democracy.web.ImageConstants;
13  import org.directdemocracyportal.democracy.web.action.ShowOnlinePoliticalPartyAction;
14  
15  import thinwire.ui.GridBox;
16  import thinwire.ui.Image;
17  import thinwire.ui.Panel;
18  import thinwire.ui.layout.TableLayout;
19  
20  /***
21   * The Class PoliticalPartiesPanel.
22   */
23  public class PoliticalPartiesPanel extends Panel
24  {
25  
26      /***
27       * Instantiates a new political parties panel.
28       *
29       * @param parties the parties
30       */
31      public PoliticalPartiesPanel(List<OnlinePoliticalParty> parties) {
32          setLayout(new TableLayout(new double[][] { { 0 }, // Column Widths
33                  { 32, 0 } }, // Row Heights
34                  1, // Margin around edge of container
35                  5)); // Spacing between cells
36  
37          Image img = new Image(ImageConstants.POLITICAL_PARTY_BUTTON);
38          img.setSize(ImageConstants.BUTTON_SIZE, ImageConstants.BUTTON_SIZE);
39          img.setLimit("0,0,l,c");
40          getChildren().add(img);
41  
42          GridBox gridBox = new GridBox();
43          gridBox.setVisibleHeader(true);
44          gridBox.setLimit("0,1,1,1");
45  
46          GridBox.Column usernameHeader = new GridBox.Column();
47          usernameHeader.setName("Political Party");
48          gridBox.getColumns().add(usernameHeader);
49  
50          for (PoliticalParty party : parties) {
51              GridBox.Row row = new GridBox.Row(party.getName());
52              row.setUserObject(new ShowOnlinePoliticalPartyAction(party.getId()));
53              gridBox.getRows().add(
54                      row);
55          }
56          gridBox.addActionListener(ACTION_CLICK, BeanLocator
57                  .getApplicationActionListener());
58  
59          getChildren().add(gridBox);
60      }
61  }