1
2
3
4
5 package org.directdemocracyportal.democracy.web.views.dialogs;
6
7 import java.util.List;
8
9 import org.directdemocracyportal.democracy.model.world.Country;
10 import org.directdemocracyportal.democracy.web.ApplicationMessageHolder;
11 import org.directdemocracyportal.democracy.web.ApplicationMessageHolder.MessageConstans;
12
13 import thinwire.ui.Button;
14 import thinwire.ui.DropDownGridBox;
15 import thinwire.ui.GridBox;
16 import thinwire.ui.Label;
17 import thinwire.ui.TextField;
18 import thinwire.ui.AlignTextComponent.AlignX;
19 import thinwire.ui.GridBox.Row;
20 import thinwire.ui.event.ActionEvent;
21 import thinwire.ui.event.ActionListener;
22 import thinwire.ui.layout.TableLayout;
23
24 /***
25 * The Class CreatePartyDialog.
26 */
27 public class CreatePartyDialog extends AbstractActionDialog
28 {
29
30 /*** The name field. */
31 private TextField nameField = new TextField();
32
33 /*** The drop down grid box. */
34 private DropDownGridBox dropDownGridBox;
35
36 /*** The error message label. */
37 private Label errorMessageLabel = new Label();
38
39 /*** The create party action listener. */
40 ActionListener createPartyActionListener = new ActionListener() {
41 public void actionPerformed(ActionEvent ev) {
42 dialogResult = DialogResult.Do_Action;
43 setVisible(false);
44 }
45 };
46
47 /*** The cancel action listener. */
48 ActionListener cancelActionListener = new ActionListener() {
49 public void actionPerformed(ActionEvent ev) {
50 dialogResult = DialogResult.Action_Cancelled;
51 setVisible(false);
52 }
53 };
54
55 /*** The countries. */
56 private final List<Country> countries;
57
58 /***
59 * Instantiates a new creates the party dialog.
60 *
61 * @param countries the countries
62 */
63 public CreatePartyDialog(List<Country> countries) {
64 super(ApplicationMessageHolder
65 .getMessage(MessageConstans.CREATE_POLITICAL_PARTY));
66 this.countries = countries;
67 dropDownGridBox = createCountryDropDown();
68 setPosition(200, 200);
69 setSize(350, 160);
70 setLayout(new TableLayout(new double[][] { { 120, 200 },
71
72 { 30, 30, 30, 30 } },
73 10,
74 5));
75 Label nameLabel = new Label(ApplicationMessageHolder
76 .getMessage(MessageConstans.NAME));
77 nameLabel.setLimit("0,0");
78 getChildren().add(nameLabel);
79
80 nameField.setLimit("1,0");
81 getChildren().add(nameField);
82
83 Label countryLabel = new Label(ApplicationMessageHolder
84 .getMessage(MessageConstans.COUNTRY));
85 countryLabel.setLimit("0,1");
86 countryLabel.setAlignX(AlignX.LEFT);
87 getChildren().add(countryLabel);
88
89 dropDownGridBox.setLimit("1,1");
90 getChildren().add(dropDownGridBox);
91
92 errorMessageLabel.setVisible(false);
93 errorMessageLabel.setLimit("0,2,2,1");
94 getChildren().add(errorMessageLabel);
95
96 Button okButton = new Button(ApplicationMessageHolder
97 .getMessage(MessageConstans.BUTTON_OK));
98 okButton.setLimit("0,3");
99 okButton.addActionListener(ACTION_CLICK, createPartyActionListener);
100 getChildren().add(okButton);
101
102 Button cancelButton = new Button(ApplicationMessageHolder
103 .getMessage(MessageConstans.BUTTON_CANCEL));
104 cancelButton.setLimit("1,3");
105 cancelButton.addActionListener(ACTION_CLICK, cancelActionListener);
106 getChildren().add(cancelButton);
107 }
108
109 /***
110 * Creates the country drop down.
111 *
112 * @return the drop down grid box
113 */
114 private DropDownGridBox createCountryDropDown() {
115 DropDownGridBox ddgb = new DropDownGridBox();
116 GridBox gb = ddgb.getComponent();
117
118 GridBox.Column idHeader = new GridBox.Column();
119 idHeader.setName(ApplicationMessageHolder
120 .getMessage(MessageConstans.HEADER_ID));
121 idHeader.setVisible(false);
122 gb.getColumns().add(idHeader);
123
124 gb.getColumns().add(new GridBox.Column(ApplicationMessageHolder
125 .getMessage(MessageConstans.COUNTRY), true));
126
127 for (Country country : countries) {
128 gb.getRows().add(
129 new GridBox.Row(country.getId(), country.getName()));
130 }
131 return ddgb;
132 }
133
134 /***
135 * Gets the country id.
136 *
137 * @return the country id
138 */
139 public Long getCountryId() {
140 Row selectedRow = dropDownGridBox.getComponent().getSelectedRow();
141 return (Long) selectedRow.get(0);
142 }
143
144 /***
145 * Gets the name.
146 *
147 * @return the name
148 */
149 public String getName() {
150 return nameField.getText();
151 }
152 }