1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.hack23.cia.web.impl.ui.page.user;
20
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.GregorianCalendar;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28
29 import org.vaadin.vaadinvisualizations.AnnotatedTimeLine;
30 import org.vaadin.vaadinvisualizations.AnnotatedTimeLineEntry;
31
32 import com.google.api.translate.Language;
33 import com.hack23.cia.model.internal.application.data.impl.OperationalStatementData;
34 import com.hack23.cia.service.api.Translator;
35 import com.hack23.cia.web.impl.ui.common.ApplicationUserStateHolder;
36 import com.hack23.cia.web.impl.ui.page.common.panel.AbstractPanel;
37 import com.vaadin.data.Property;
38 import com.vaadin.data.Property.ValueChangeEvent;
39 import com.vaadin.ui.NativeSelect;
40 import com.vaadin.ui.VerticalSplitPanel;
41
42
43
44
45 public final class SwedishBudgetResultPanel extends AbstractPanel implements
46 Property.ValueChangeListener {
47
48
49 private static final long serialVersionUID = 1L;
50
51
52 private final VerticalSplitPanel vert = new VerticalSplitPanel();
53
54
55 private AnnotatedTimeLine timeline;
56
57
58 private final Collection<List<OperationalStatementData>> operationStatementsCollection;
59
60
61 private final Map<String, String> languageToSwedishMap = new HashMap<String, String>();
62
63
64 private final Translator translator;
65
66
67 private final Language language;
68
69
70
71
72 public SwedishBudgetResultPanel() {
73 super();
74 translator = getApplicationManager().getTranslator();
75 language = getUserState().getGoogleApiLanguage();
76 setCaption(translateFromEnglish("Budget/Cost & Operational Statements"));
77
78 vert.setSplitPosition(30, VerticalSplitPanel.UNITS_PIXELS);
79 operationStatementsCollection = ApplicationUserStateHolder
80 .getUserState().getApplicationManager()
81 .getOperationalStatementDAO().getList();
82
83 final NativeSelect governmentAuthoritySelectBox = new NativeSelect(
84 translateFromEnglish("Please select a Government Authority"));
85
86 final List<String> names = new ArrayList<String>();
87 for (final List<OperationalStatementData> opList : operationStatementsCollection) {
88 final String swedishName = opList.get(0).getName();
89 final String englishName = translator.translateFromSwedish(
90 swedishName, language);
91
92 languageToSwedishMap.put(englishName, swedishName);
93
94 names.add(englishName);
95
96 }
97
98 Collections.sort(names);
99 for (final String name : names) {
100 governmentAuthoritySelectBox.addItem(name);
101 }
102
103 final List<OperationalStatementData> selectedOpStatements = operationStatementsCollection
104 .iterator().next();
105
106 governmentAuthoritySelectBox.setNullSelectionAllowed(false);
107 governmentAuthoritySelectBox.setValue(selectedOpStatements.get(0)
108 .getName());
109 governmentAuthoritySelectBox.setImmediate(true);
110 governmentAuthoritySelectBox.addListener(this);
111 vert.addComponent(governmentAuthoritySelectBox);
112
113 timeline = createAnnotatedTimeLine(selectedOpStatements);
114 vert.addComponent(timeline);
115 timeline.setSizeFull();
116 setContent(vert);
117 vert.setSizeFull();
118 }
119
120
121
122
123
124
125
126
127 private AnnotatedTimeLine createAnnotatedTimeLine(
128 final List<OperationalStatementData> selectedOpStatements) {
129 final AnnotatedTimeLine atl = new AnnotatedTimeLine();
130 atl.setOption("displayAnnotations", true);
131 atl.setOption("wmode", "window");
132 atl.setOption("width", "100%");
133 atl.setOption("height", "100%");
134
135 atl.addLineLabel(translator.translateFromSwedish(selectedOpStatements
136 .get(0).getName(), language)
137 + ", 1997-jan -- 2009-dec");
138
139 for (final OperationalStatementData operationalStatement : selectedOpStatements) {
140 try {
141 final ArrayList<AnnotatedTimeLineEntry> timeLineEntries = new ArrayList<AnnotatedTimeLineEntry>();
142 timeLineEntries.add(new AnnotatedTimeLineEntry(
143 operationalStatement.getStateSubsidyResult()
144 .doubleValue(), "", ""));
145 atl.add(new GregorianCalendar(operationalStatement.getYear(),
146 operationalStatement.getMonth().intValue(), 1),
147 timeLineEntries);
148
149 } catch (final Exception e) {
150 LOGGER.warn("Add msg", e);
151 }
152 }
153
154 return atl;
155 }
156
157
158
159
160
161
162
163
164
165
166 private List<OperationalStatementData> findByName(
167 final Collection<List<OperationalStatementData>> operationStatementsCollection2,
168 final String property) {
169
170 for (final List<OperationalStatementData> stmt : operationStatementsCollection2) {
171 if (stmt.iterator().next().getName().equals(property)) {
172 return stmt;
173 }
174 }
175 return null;
176 }
177
178
179
180
181
182
183
184
185 @Override
186 public void valueChange(final ValueChangeEvent event) {
187 if (event != null) {
188 vert.removeComponent(timeline);
189 timeline = createAnnotatedTimeLine(findByName(
190 operationStatementsCollection,
191 languageToSwedishMap.get(event.getProperty().toString())));
192 vert.addComponent(timeline);
193 timeline.setSizeFull();
194 }
195 }
196
197 }