1
2
3
4
5
6 package com.hack23.cia.web.views.user;
7
8 import java.util.List;
9
10 import thinwire.ui.Tree;
11 import thinwire.ui.Tree.Item;
12 import thinwire.ui.layout.TableLayout;
13
14 import com.hack23.cia.model.application.dto.common.UserSessionDTO;
15 import com.hack23.cia.model.application.impl.common.Agency;
16 import com.hack23.cia.model.sweden.impl.Ballot;
17 import com.hack23.cia.model.sweden.impl.CommitteeReport;
18 import com.hack23.cia.web.action.user.BallotAction;
19 import com.hack23.cia.web.action.user.CommitteeReportAction;
20 import com.hack23.cia.web.common.BeanLocator;
21
22 /***
23 * The Class CommitteeReportPanel.
24 */
25 public class CommitteeReportPanel extends AbstractParliamentPanel {
26
27 /*** The user session dto. */
28 private final UserSessionDTO userSessionDTO;
29
30 /***
31 * Instantiates a new committee report panel.
32 *
33 * @param userSessionDTO the user session dto
34 * @param commiteeReports the commitee reports
35 */
36 public CommitteeReportPanel(final UserSessionDTO userSessionDTO,final List<CommitteeReport> commiteeReports) {
37 this.userSessionDTO = userSessionDTO;
38 setLayout(new TableLayout(new double[][] { { 0 },
39 { 0 } },
40 1,
41 5));
42
43 final Tree globalPortalTree = createRootTree(commiteeReports);
44 globalPortalTree.setLimit("0,0,1,1");
45 getChildren().add(globalPortalTree);
46 }
47
48 /***
49 * Creates the root tree.
50 *
51 * @param commiteeReports the commitee reports
52 * @return the tree
53 */
54 private Tree createRootTree(final List<CommitteeReport> commiteeReports) {
55 final Tree tree = new Tree();
56 tree.addActionListener(ACTION_CLICK, BeanLocator
57 .getApplicationActionListener());
58 tree.addActionListener(ACTION_DOUBLE_CLICK, BeanLocator
59 .getApplicationActionListener());
60
61 tree.setRootItemVisible(true);
62
63 final Tree.Item root = tree.getRootItem();
64 root.setText(userSessionDTO
65 .getLanguageResource(Agency.LanguageContentKey.LAST_TEN_DECIDED_COMMITEE_REPORTS));
66 root.setExpanded(true);
67
68 if (commiteeReports != null) {
69 for (final CommitteeReport commiteeReport : commiteeReports) {
70 createTree(root, commiteeReport);
71 }
72 }
73 return tree;
74 }
75
76 /***
77 * Creates the tree.
78 *
79 * @param parent the parent
80 * @param ballot the ballot
81 */
82 private void createTree(final Item parent, final Ballot ballot) {
83 if (ballot != null) {
84 final Tree.Item ballotItem = new Tree.Item(ballot.getDescription());
85 ballotItem.setUserObject(new BallotAction(ballot.getId()));
86 parent.getChildren().add(ballotItem);
87 }
88 }
89
90 /***
91 * Creates the tree.
92 *
93 * @param parent the parent
94 * @param commiteeReport the commitee report
95 */
96 private void createTree(final Item parent,
97 final CommitteeReport commiteeReport) {
98 if (commiteeReport != null) {
99 final Tree.Item commiteeReportItem = new Tree.Item(commiteeReport
100 .getName());
101 commiteeReportItem.setUserObject(new CommitteeReportAction(
102 commiteeReport.getId()));
103 parent.getChildren().add(commiteeReportItem);
104
105 if (commiteeReport.getDecisionDate() != null) {
106 final Tree.Item datumItem = new Tree.Item(userSessionDTO
107 .getLanguageResource(Agency.LanguageContentKey.DECISION_DATE)
108 + " " + commiteeReport.getDecisionDate().toString());
109 commiteeReportItem.getChildren().add(datumItem);
110
111 if (commiteeReport.getBallots().size() > 0) {
112 final Tree.Item ballotItem = new Tree.Item(
113 userSessionDTO
114 .getLanguageResource(Agency.LanguageContentKey.BALLOTS));
115 commiteeReportItem.getChildren().add(ballotItem);
116
117 for (final Ballot ballot : commiteeReport.getBallots()) {
118 createTree(ballotItem, ballot);
119 }
120 }
121 }
122 }
123 }
124 }