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.Government;
10  import org.directdemocracyportal.democracy.web.ApplicationMessageHolder;
11  import org.directdemocracyportal.democracy.web.BeanLocator;
12  import org.directdemocracyportal.democracy.web.ImageConstants;
13  import org.directdemocracyportal.democracy.web.ApplicationMessageHolder.MessageConstans;
14  import org.directdemocracyportal.democracy.web.action.ShowGovernmentAction;
15  
16  import thinwire.ui.GridBox;
17  import thinwire.ui.Image;
18  import thinwire.ui.Panel;
19  import thinwire.ui.layout.TableLayout;
20  
21  /***
22   * The Class GovernmentsPanel.
23   */
24  public class GovernmentsPanel extends Panel
25  {
26  
27      /***
28       * Instantiates a new governments panel.
29       *
30       * @param governments the governments
31       */
32      public GovernmentsPanel(List<Government> governments) {
33          setLayout(new TableLayout(new double[][] { { 0 }, // Column Widths
34                  { ImageConstants.BUTTON_SIZE, 0 } }, // Row Heights
35                  1, // Margin around edge of container
36                  5)); // Spacing between cells
37  
38          Image img = new Image(ImageConstants.GOVERNMENT_BUTTON);
39          img.setSize(ImageConstants.BUTTON_SIZE, ImageConstants.BUTTON_SIZE);
40          img.setLimit("0,0,l,c");
41          getChildren().add(img);
42  
43          GridBox gridBox = new GridBox();
44          gridBox.setVisibleHeader(true);
45          gridBox.setLimit("0,1,1,1");
46  
47          GridBox.Column nameHeader = new GridBox.Column();
48          nameHeader.setName(ApplicationMessageHolder
49                  .getMessage(MessageConstans.HEADER_NAME));
50          gridBox.getColumns().add(nameHeader);
51  
52          GridBox.Column typeHeader = new GridBox.Column();
53          typeHeader.setName(ApplicationMessageHolder
54                  .getMessage(MessageConstans.TYPE));
55          gridBox.getColumns().add(typeHeader);
56  
57          GridBox.Column headofStateHeader = new GridBox.Column();
58          headofStateHeader.setName(ApplicationMessageHolder
59                  .getMessage(MessageConstans.HEAD_OF_STATE));
60          gridBox.getColumns().add(headofStateHeader);
61  
62          for (Government government : governments) {
63              GridBox.Row row = new GridBox.Row(government.getName(),
64                      government.getGovernmentType(), government
65                              .getHeadofState().getName());
66              row.setUserObject(new ShowGovernmentAction(government.getId()));
67              gridBox.getRows().add(row);
68          }
69          gridBox.addActionListener(ACTION_CLICK, BeanLocator
70                  .getApplicationActionListener());
71  
72          getChildren().add(gridBox);
73      }
74  }