1
2
3
4
5 package com.hack23.cia.web.views.admin;
6
7 import thinwire.ui.Button;
8 import thinwire.ui.GridBox;
9 import thinwire.ui.Label;
10 import thinwire.ui.Panel;
11 import thinwire.ui.TabFolder;
12 import thinwire.ui.TabSheet;
13 import thinwire.ui.TextField;
14 import thinwire.ui.event.ActionEvent;
15 import thinwire.ui.event.ActionListener;
16 import thinwire.ui.layout.TableLayout;
17
18 import com.hack23.cia.model.application.dto.common.UserSessionDTO;
19 import com.hack23.cia.model.application.impl.admin.AgencyActionEvent;
20 import com.hack23.cia.model.application.impl.common.Agency;
21 import com.hack23.cia.web.action.admin.AgencyAction;
22 import com.hack23.cia.web.common.BeanLocator;
23 import com.hack23.cia.web.views.components.gridboxes.LanguagesGridBox;
24 import com.hack23.cia.web.views.components.gridboxes.PortalsGridBox;
25
26 /***
27 * The Class AbstractAdminPanel.
28 */
29 public abstract class AbstractAdminPanel extends Panel {
30
31 /*** The add language action listener. */
32 private final ActionListener addLanguageActionListener = new ActionListener() {
33 @Override
34 public void actionPerformed(final ActionEvent ev) {
35 ((Button) ev.getSource()).setUserObject(new AgencyAction(
36 AgencyActionEvent.Operation.AddLanguage, agency.getId()));
37 BeanLocator.getApplicationActionListener().actionPerformed(ev);
38 }
39 };
40
41 /*** The agency. */
42 private final Agency agency;
43
44 /*** The agency name field. */
45 private final TextField agencyNameField = new TextField();
46
47 /*** The cancel action listener. */
48 private final ActionListener cancelActionListener = new ActionListener() {
49 @Override
50 public void actionPerformed(final ActionEvent ev) {
51 agencyNameField.setText(agency.getName());
52 }
53 };
54
55 /*** The new portal action listener. */
56 private final ActionListener newPortalActionListener = new ActionListener() {
57 @Override
58 public void actionPerformed(final ActionEvent ev) {
59 ((Button) ev.getSource()).setUserObject(new AgencyAction(
60 AgencyActionEvent.Operation.AddPortal, agency.getId()));
61 BeanLocator.getApplicationActionListener().actionPerformed(ev);
62 }
63 };
64
65
66 /*** The ok action listener. */
67 private final ActionListener okActionListener = new ActionListener() {
68 @Override
69 public void actionPerformed(final ActionEvent ev) {
70 agency.setName(agencyNameField.getText());
71 ((Button) ev.getSource()).setUserObject(new AgencyAction(
72 AgencyActionEvent.Operation.UpdateAgency, agency.getId(),agency));
73 BeanLocator.getApplicationActionListener().actionPerformed(ev);
74 }
75 };
76
77 /*** The tab folder. */
78 private final TabFolder tabFolder = new TabFolder();
79
80 /*** The user session dto. */
81 private final UserSessionDTO userSessionDTO;
82
83 /***
84 * Instantiates a new abstract admin panel.
85 *
86 * @param userSessionDTO the user session dto
87 * @param agency the agency
88 */
89 public AbstractAdminPanel(final UserSessionDTO userSessionDTO,final Agency agency) {
90 this.userSessionDTO = userSessionDTO;
91 this.agency = new Agency();
92 this.agency.setId(agency.getId());
93 this.agency.setName(agency.getName());
94 setLayout(new TableLayout(new double[][] { { 0 },
95 { 0 } },
96 1,
97 5));
98
99 final TabSheet gridBoxTabSheet = createAgencyTabSheet(agency);
100
101 tabFolder.getChildren().add(gridBoxTabSheet);
102 getChildren().add(tabFolder);
103 }
104
105 /***
106 * Creates the agency tab sheet.
107 *
108 * @param agency the agency
109 * @return the tab sheet
110 */
111 private TabSheet createAgencyTabSheet(final Agency agency) {
112 final TabSheet tabSheet = new TabSheet();
113 tabSheet.setText(userSessionDTO
114 .getLanguageResource(Agency.LanguageContentKey.CONFIGURE_AGENCY));
115 tabSheet.setLayout(new TableLayout(new double[][] { { 0, 0, 0 },
116
117 { 0, 0, 0, 0 } },
118 10,
119 5));
120
121 final Label nameLabel = new Label(userSessionDTO
122 .getLanguageResource(Agency.LanguageContentKey.NAME));
123 nameLabel.setLimit("0,0");
124 tabSheet.getChildren().add(nameLabel);
125
126 agencyNameField.setLimit("1,0,2,1");
127 agencyNameField.setText(agency.getName());
128 tabSheet.getChildren().add(agencyNameField);
129
130 final Label portalsLabel = new Label(userSessionDTO
131 .getLanguageResource(Agency.LanguageContentKey.PORTALS));
132 portalsLabel.setLimit("0,1");
133 tabSheet.getChildren().add(portalsLabel);
134
135 final GridBox portalGridBox = new PortalsGridBox(userSessionDTO,agency.getPortals());
136 portalGridBox.setLimit("1,1,2,1");
137 tabSheet.getChildren().add(portalGridBox);
138
139 final Button addLanguageButton = new Button(userSessionDTO
140 .getLanguageResource(Agency.LanguageContentKey.ADD_LANGUAGE));
141 addLanguageButton.setLimit("0,2");
142 addLanguageButton.addActionListener(ACTION_CLICK,
143 addLanguageActionListener);
144 tabSheet.getChildren().add(addLanguageButton);
145
146 final GridBox languagesGridBox = new LanguagesGridBox(userSessionDTO,agency);
147 languagesGridBox.setLimit("1,2,2,1");
148 tabSheet.getChildren().add(languagesGridBox);
149
150 final Button newPortalButton = new Button(userSessionDTO
151 .getLanguageResource(Agency.LanguageContentKey.BUTTON_NEW_PORTAL));
152 newPortalButton.setLimit("0,3");
153 newPortalButton
154 .addActionListener(ACTION_CLICK, newPortalActionListener);
155 tabSheet.getChildren().add(newPortalButton);
156
157 final Button cancelButton = new Button(userSessionDTO
158 .getLanguageResource(Agency.LanguageContentKey.BUTTON_CANCEL));
159 cancelButton.setLimit("1,3");
160 cancelButton.addActionListener(ACTION_CLICK, cancelActionListener);
161 tabSheet.getChildren().add(cancelButton);
162
163 final Button okButton = new Button(userSessionDTO
164 .getLanguageResource(Agency.LanguageContentKey.BUTTON_OK));
165 okButton.setLimit("2,3");
166 okButton.addActionListener(ACTION_CLICK, okActionListener);
167 tabSheet.getChildren().add(okButton);
168 return tabSheet;
169 }
170
171
172 /***
173 * Gets the agency.
174 *
175 * @return the agency
176 */
177 public final Agency getAgency() {
178 return agency;
179 }
180
181 /***
182 * Gets the tab folder.
183 *
184 * @return the tab folder
185 */
186 public final TabFolder getTabFolder() {
187 return tabFolder;
188 }
189
190 /***
191 * Gets the user session dto.
192 *
193 * @return the user session dto
194 */
195 public final UserSessionDTO getUserSessionDTO() {
196 return userSessionDTO;
197 }
198
199 }