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.application.Portal;
10 import org.directdemocracyportal.democracy.model.world.OrganisationType;
11 import org.directdemocracyportal.democracy.web.ApplicationMessageHolder;
12 import org.directdemocracyportal.democracy.web.ImageConstants;
13 import org.directdemocracyportal.democracy.web.ApplicationMessageHolder.MessageConstans;
14
15 import thinwire.ui.Button;
16 import thinwire.ui.DropDownGridBox;
17 import thinwire.ui.GridBox;
18 import thinwire.ui.Label;
19 import thinwire.ui.TextField;
20 import thinwire.ui.AlignTextComponent.AlignX;
21 import thinwire.ui.GridBox.Row;
22 import thinwire.ui.event.ActionEvent;
23 import thinwire.ui.event.ActionListener;
24 import thinwire.ui.layout.TableLayout;
25
26 /***
27 * The Class RegisterUserDialog.
28 */
29 public class RegisterUserDialog extends AbstractActionDialog
30 {
31
32 /*** The name field. */
33 private TextField nameField = new TextField();
34
35 /*** The email field. */
36 private TextField emailField = new TextField();
37
38 /*** The username field. */
39 private TextField usernameField = new TextField();
40
41 /*** The password field. */
42 private TextField passwordField = new TextField();
43
44 /*** The drop down grid box. */
45 private DropDownGridBox dropDownGridBox;
46
47 /*** The error message box. */
48 private ErrorMessageBox errorMessageBox = new ErrorMessageBox();
49
50 /*** The register user action listener. */
51 ActionListener registerUserActionListener = new ActionListener() {
52 public void actionPerformed(ActionEvent ev) {
53 dialogResult = DialogResult.Do_Action;
54 setVisible(false);
55 }
56 };
57
58 /*** The cancel action listener. */
59 ActionListener cancelActionListener = new ActionListener() {
60 public void actionPerformed(ActionEvent ev) {
61 dialogResult = DialogResult.Action_Cancelled;
62 setVisible(false);
63 }
64 };
65
66 /*** The portals. */
67 private final List<Portal> portals;
68
69 /***
70 * Instantiates a new register user dialog.
71 *
72 * @param portals the portals
73 */
74 public RegisterUserDialog(List<Portal> portals) {
75 super(ApplicationMessageHolder.getMessage(MessageConstans.REGISTER_USER));
76 this.portals = portals;
77 dropDownGridBox = createCountryDropDown();
78 setPosition(200, 200);
79 setSize(350, 280);
80 setLayout(new TableLayout(new double[][] { { 120, 200 },
81
82 { 30, 30, 30, 30, 30, 30, 30 } },
83 10,
84 5));
85 Label nameLabel = new Label(ApplicationMessageHolder
86 .getMessage(MessageConstans.NAME));
87 nameLabel.setLimit("0,0");
88 nameLabel.setAlignX(AlignX.LEFT);
89 getChildren().add(nameLabel);
90
91 nameField.setLimit("1,0");
92 getChildren().add(nameField);
93
94 Label emailLabel = new Label(ApplicationMessageHolder
95 .getMessage(MessageConstans.EMAIL));
96 emailLabel.setLimit("0,1");
97 emailLabel.setAlignX(AlignX.LEFT);
98 getChildren().add(emailLabel);
99
100 emailField.setLimit("1,1");
101 getChildren().add(emailField);
102
103 Label usernameLabel = new Label(ApplicationMessageHolder
104 .getMessage(MessageConstans.USERNAME));
105 usernameLabel.setLimit("0,2");
106 usernameLabel.setAlignX(AlignX.LEFT);
107 getChildren().add(usernameLabel);
108
109 usernameField.setLimit("1,2");
110 getChildren().add(usernameField);
111
112 Label passwordLabel = new Label(ApplicationMessageHolder
113 .getMessage(MessageConstans.PASSWORD));
114 passwordLabel.setLimit("0,3");
115 passwordLabel.setAlignX(AlignX.LEFT);
116 getChildren().add(passwordLabel);
117
118 passwordField.setLimit("1,3");
119 passwordField.setInputHidden(true);
120 getChildren().add(passwordField);
121
122 Label countryLabel = new Label(ApplicationMessageHolder
123 .getMessage(MessageConstans.LOCATION));
124 countryLabel.setLimit("0,4");
125 countryLabel.setAlignX(AlignX.LEFT);
126 getChildren().add(countryLabel);
127
128 dropDownGridBox.setLimit("1,4");
129 getChildren().add(dropDownGridBox);
130
131 errorMessageBox.setLimit("0,5,2,1");
132 getChildren().add(errorMessageBox);
133
134 Button okButton = new Button(ApplicationMessageHolder
135 .getMessage(MessageConstans.BUTTON_OK));
136 okButton.setImage(ImageConstants.BUTTON_OK_ICON);
137 okButton.setLimit("0,6");
138 okButton.addActionListener(ACTION_CLICK, registerUserActionListener);
139 getChildren().add(okButton);
140
141 Button cancelButton = new Button(ApplicationMessageHolder
142 .getMessage(MessageConstans.BUTTON_CANCEL));
143 cancelButton.setImage(ImageConstants.BUTTON_CANCEL_ICON);
144 cancelButton.setLimit("1,6");
145 cancelButton.addActionListener(ACTION_CLICK, cancelActionListener);
146 getChildren().add(cancelButton);
147 }
148
149 /***
150 * Creates the country drop down.
151 *
152 * @return the drop down grid box
153 */
154 private DropDownGridBox createCountryDropDown() {
155 DropDownGridBox ddgb = new DropDownGridBox();
156 GridBox gb = ddgb.getComponent();
157
158 gb.getColumns().add(new GridBox.Column(ApplicationMessageHolder
159 .getMessage(MessageConstans.LOCATION), true));
160
161 for (Portal portal : portals) {
162 if (portal.getOrganisationType().equals(OrganisationType.Local)) {
163 GridBox.Row row = new GridBox.Row(portal.getRegion().getName());
164 row.setUserObject(portal.getId());
165 gb.getRows().add(row);
166 }
167 }
168 return ddgb;
169 }
170
171 /***
172 * Gets the name.
173 *
174 * @return the name
175 */
176 public String getName() {
177 return nameField.getText();
178 }
179
180 /***
181 * Gets the email.
182 *
183 * @return the email
184 */
185 public String getEmail() {
186 return emailField.getText();
187 }
188
189 /***
190 * Gets the username.
191 *
192 * @return the username
193 */
194 public String getUsername() {
195 return usernameField.getText();
196 }
197
198 /***
199 * Gets the password.
200 *
201 * @return the password
202 */
203 public String getPassword() {
204 return passwordField.getText();
205 }
206
207 /***
208 * Gets the portal id.
209 *
210 * @return the portal id
211 */
212 public Long getPortalId() {
213 Row selectedRow = dropDownGridBox.getComponent().getSelectedRow();
214 return (Long) selectedRow.getUserObject();
215 }
216
217 /***
218 * Sets the error message.
219 *
220 * @param message the new error message
221 */
222 public void setErrorMessage(String message) {
223 errorMessageBox.displayErrorMessage(message);
224 }
225 }