1
2
3
4
5 package org.directdemocracyportal.democracy.web.views;
6
7 import java.util.Map;
8
9 import org.directdemocracyportal.democracy.model.core.GroupAgent;
10 import org.directdemocracyportal.democracy.model.core.Resource;
11 import org.directdemocracyportal.democracy.model.core.Role;
12 import org.directdemocracyportal.democracy.model.world.Organisation;
13 import org.directdemocracyportal.democracy.model.world.Person;
14 import org.directdemocracyportal.democracy.model.world.PoliticalParty;
15 import org.directdemocracyportal.democracy.model.world.Resolution;
16 import org.directdemocracyportal.democracy.web.ApplicationMessageHolder;
17 import org.directdemocracyportal.democracy.web.BeanLocator;
18 import org.directdemocracyportal.democracy.web.ApplicationMessageHolder.MessageConstans;
19 import org.directdemocracyportal.democracy.web.action.ShowOrganisationAction;
20 import org.directdemocracyportal.democracy.web.action.ShowPersonAction;
21
22 import thinwire.ui.GridBox;
23 import thinwire.ui.Label;
24 import thinwire.ui.Panel;
25 import thinwire.ui.TabFolder;
26 import thinwire.ui.TabSheet;
27 import thinwire.ui.layout.TableLayout;
28
29 /***
30 * The Class OrganisationOverviewPanel.
31 */
32 public class OrganisationOverviewPanel extends Panel
33 {
34
35 /***
36 * Instantiates a new organisation overview panel.
37 *
38 * @param organisation the organisation
39 */
40 public OrganisationOverviewPanel(Organisation organisation) {
41 setLayout(new TableLayout(new double[][] { { 0 },
42 { 0 } },
43 1,
44 5));
45
46 TabFolder tabFolder = createTabFolder(organisation);
47 tabFolder.setLimit("0,0,1,1");
48 getChildren().add(tabFolder);
49 }
50
51 /***
52 * Creates the tab folder.
53 *
54 * @param organisation the organisation
55 * @return the tab folder
56 */
57 private TabFolder createTabFolder(Organisation organisation) {
58 TabSheet resources = createResourceTabSheet(organisation);
59 TabSheet orgStructure = createOrgStructureTabSheet(organisation);
60 TabSheet members = createMembersTabSheet(organisation);
61 TabSheet partiesInPower = createPartiesInPowerTabSheet(organisation);
62
63 TabFolder tabFolder = new TabFolder();
64 tabFolder.getChildren().add(resources);
65 tabFolder.getChildren().add(orgStructure);
66 tabFolder.getChildren().add(members);
67 tabFolder.getChildren().add(partiesInPower);
68
69 tabFolder.setCurrentIndex(0);
70 return tabFolder;
71 }
72
73 /***
74 * Creates the resource tab sheet.
75 *
76 * @param organisation the organisation
77 * @return the tab sheet
78 */
79 private TabSheet createResourceTabSheet(Organisation organisation) {
80 TabSheet resources = new TabSheet();
81
82 resources.setText(organisation.getName() + ApplicationMessageHolder
83 .getMessage(MessageConstans.DOCUMENT));
84
85 resources.setLayout(new TableLayout(new double[][] { { 0 },
86
87 { 20, 0 } },
88 1,
89 5));
90
91 Label nameLabel = new Label(ApplicationMessageHolder
92 .getMessage(MessageConstans.MEMBERS));
93 nameLabel.setLimit("0,0");
94 resources.getChildren().add(nameLabel);
95
96 GridBox orgBox = getResourceGridBox(organisation);
97 orgBox.setLimit("0,1");
98 resources.getChildren().add(orgBox);
99
100 return resources;
101 }
102
103 /***
104 * Gets the resource grid box.
105 *
106 * @param organisation the organisation
107 * @return the resource grid box
108 */
109 private GridBox getResourceGridBox(Organisation organisation) {
110 GridBox gridBox = new GridBox();
111 gridBox.setVisibleHeader(true);
112
113 GridBox.Column nameHeader = new GridBox.Column();
114 nameHeader.setName(ApplicationMessageHolder
115 .getMessage(MessageConstans.HEADER_NAME));
116 gridBox.getColumns().add(nameHeader);
117
118 GridBox.Column linkHeader = new GridBox.Column();
119 linkHeader.setName(ApplicationMessageHolder
120 .getMessage(MessageConstans.LINK));
121 gridBox.getColumns().add(linkHeader);
122
123 for (Resource resource : organisation.getResources()) {
124 Resolution resolution = (Resolution) resource;
125 gridBox.getRows().add(
126 new GridBox.Row(resolution.getName(),resolution.getHref()));
127 }
128 return gridBox;
129 }
130
131 /***
132 * Creates the members tab sheet.
133 *
134 * @param organisation the organisation
135 * @return the tab sheet
136 */
137 private TabSheet createMembersTabSheet(Organisation organisation) {
138 TabSheet members = new TabSheet();
139
140 members.setText(organisation.getName() + ApplicationMessageHolder
141 .getMessage(MessageConstans.MEMBERS));
142
143 members.setLayout(new TableLayout(new double[][] { { 0 },
144
145 { 20, 0 } },
146 1,
147 5));
148
149 Label nameLabel = new Label(ApplicationMessageHolder
150 .getMessage(MessageConstans.MEMBERS));
151 nameLabel.setLimit("0,0");
152 members.getChildren().add(nameLabel);
153
154 GridBox orgBox = getMemberGridBox(organisation);
155 orgBox.setLimit("0,1");
156 members.getChildren().add(orgBox);
157
158 return members;
159 }
160
161 /***
162 * Gets the member grid box.
163 *
164 * @param organisation the organisation
165 * @return the member grid box
166 */
167 private GridBox getMemberGridBox(Organisation organisation) {
168 GridBox gridBox = new GridBox();
169 gridBox.setVisibleHeader(true);
170 gridBox.addActionListener(ACTION_CLICK, BeanLocator
171 .getApplicationActionListener());
172 gridBox.setVisibleHeader(true);
173
174 GridBox.Column nameHeader = new GridBox.Column();
175 nameHeader.setName(ApplicationMessageHolder
176 .getMessage(MessageConstans.HEADER_NAME));
177 gridBox.getColumns().add(nameHeader);
178
179 GridBox.Column rolesHeader = new GridBox.Column();
180 rolesHeader.setName(ApplicationMessageHolder
181 .getMessage(MessageConstans.ROLES));
182 gridBox.getColumns().add(rolesHeader);
183
184 GridBox.Column partyHeader = new GridBox.Column();
185 partyHeader.setName(ApplicationMessageHolder
186 .getMessage(MessageConstans.POLITICAL_PARTY));
187 gridBox.getColumns().add(partyHeader);
188
189 GridBox.Column voteHeader = new GridBox.Column();
190 voteHeader.setName(ApplicationMessageHolder
191 .getMessage(MessageConstans.VOTE));
192 gridBox.getColumns().add(voteHeader);
193
194 for (Person person : organisation.personsActive()) {
195 Role roleInOrg = person.getRoleInOrg(organisation);
196 PoliticalParty politicalParty = person.getPoliticalParty();
197
198 GridBox.Row row = new GridBox.Row(person.getName(), roleInOrg == null ? ""
199 : roleInOrg.getName(), politicalParty == null ? ""
200 : politicalParty.getName(),person.getResources().size());
201 row.setUserObject(new ShowPersonAction(person.getId()));
202 gridBox.getRows().add(
203 row);
204 }
205 return gridBox;
206 }
207
208 /***
209 * Creates the org structure tab sheet.
210 *
211 * @param organisation the organisation
212 * @return the tab sheet
213 */
214 private TabSheet createOrgStructureTabSheet(Organisation organisation) {
215 TabSheet orgStructure = new TabSheet();
216
217 orgStructure.setText(organisation.getName() + ApplicationMessageHolder
218 .getMessage(MessageConstans.OVERVIEW));
219
220 orgStructure.setLayout(new TableLayout(new double[][] { { 0 },
221
222 { 20, 0 } },
223 1,
224 5));
225
226 Label nameLabel = new Label(ApplicationMessageHolder
227 .getMessage(MessageConstans.ORGANISATIONS));
228 nameLabel.setLimit("0,0");
229 orgStructure.getChildren().add(nameLabel);
230
231 GridBox orgBox = getOrgGridBox(organisation);
232 orgBox.setLimit("0,1");
233 orgStructure.getChildren().add(orgBox);
234
235 return orgStructure;
236 }
237
238 /***
239 * Gets the org grid box.
240 *
241 * @param organisation the organisation
242 * @return the org grid box
243 */
244 private GridBox getOrgGridBox(Organisation organisation) {
245 GridBox gridBox = new GridBox();
246 gridBox.addActionListener(ACTION_CLICK, BeanLocator
247 .getApplicationActionListener());
248 gridBox.setVisibleHeader(true);
249
250 GridBox.Column nameHeader = new GridBox.Column();
251 nameHeader.setName(ApplicationMessageHolder
252 .getMessage(MessageConstans.HEADER_NAME));
253 gridBox.getColumns().add(nameHeader);
254
255 GridBox.Column orgTypeHeader = new GridBox.Column();
256 orgTypeHeader.setName(ApplicationMessageHolder
257 .getMessage(MessageConstans.ORGANISATION_TYPE));
258 gridBox.getColumns().add(orgTypeHeader);
259
260 GridBox.Column numberPeopleHeader = new GridBox.Column();
261 numberPeopleHeader.setName(ApplicationMessageHolder
262 .getMessage(MessageConstans.NUMBER_OF_MEMBERS));
263 gridBox.getColumns().add(numberPeopleHeader);
264
265 for (GroupAgent groupAgent : organisation.getChildren()) {
266 Organisation orgUnit = (Organisation) groupAgent;
267 GridBox.Row row = new GridBox.Row(orgUnit.getName(), orgUnit
268 .getOrganisationType(), orgUnit
269 .getNumberOfMembers());
270 row.setUserObject(new ShowOrganisationAction(orgUnit.getId()));
271 gridBox.getRows().add(
272 row);
273 }
274 return gridBox;
275 }
276
277 /***
278 * Creates the parties in power tab sheet.
279 *
280 * @param organisation the organisation
281 * @return the tab sheet
282 */
283 private TabSheet createPartiesInPowerTabSheet(Organisation organisation) {
284 TabSheet members = new TabSheet();
285
286 members.setText(ApplicationMessageHolder
287 .getMessage(MessageConstans.PARTIES_IN_POWER));
288
289 members.setLayout(new TableLayout(new double[][] { { 0 },
290
291 { 20, 0 } },
292 1,
293 5));
294
295 Label nameLabel = new Label(ApplicationMessageHolder
296 .getMessage(MessageConstans.POLITICAL_PARTIES_IN)
297 + organisation.getName());
298 nameLabel.setLimit("0,0");
299 members.getChildren().add(nameLabel);
300
301 GridBox orgBox = getPartyGridBox(organisation);
302 orgBox.setLimit("0,1");
303 members.getChildren().add(orgBox);
304
305 return members;
306 }
307
308 /***
309 * Gets the party grid box.
310 *
311 * @param organisation the organisation
312 * @return the party grid box
313 */
314 private GridBox getPartyGridBox(Organisation organisation) {
315 GridBox gridBox = new GridBox();
316 gridBox.setVisibleHeader(true);
317
318 GridBox.Column nameHeader = new GridBox.Column();
319 nameHeader.setName(ApplicationMessageHolder
320 .getMessage(MessageConstans.HEADER_NAME));
321 gridBox.getColumns().add(nameHeader);
322
323 GridBox.Column positionerHeader = new GridBox.Column();
324 positionerHeader.setName(ApplicationMessageHolder
325 .getMessage(MessageConstans.NUMBER_OF_ROLES));
326 gridBox.getColumns().add(positionerHeader);
327
328 Map<PoliticalParty, Long> activePoliticalParties = organisation
329 .getActivePoliticalParties();
330 for (PoliticalParty party : activePoliticalParties.keySet()) {
331 gridBox.getRows().add(
332 new GridBox.Row(party.getName(), activePoliticalParties
333 .get(party)));
334 }
335 return gridBox;
336 }
337
338 }