Revision 60e38397
Added by Fabian Reimeier over 6 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionTableView.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2017 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
1 | 9 |
package eu.etaxonomy.cdm.vaadin.view.distributionStatus; |
2 | 10 |
|
3 |
import java.sql.SQLException; |
|
4 |
import java.util.ArrayList; |
|
5 |
import java.util.Arrays; |
|
6 |
import java.util.List; |
|
7 |
import java.util.UUID; |
|
8 |
|
|
9 |
import com.vaadin.data.Item; |
|
10 |
import com.vaadin.data.Property; |
|
11 |
import com.vaadin.data.Property.ValueChangeEvent; |
|
12 |
import com.vaadin.data.Property.ValueChangeListener; |
|
13 |
import com.vaadin.event.ItemClickEvent; |
|
14 |
import com.vaadin.event.ItemClickEvent.ItemClickListener; |
|
15 | 11 |
import com.vaadin.navigator.View; |
16 |
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; |
|
17 |
import com.vaadin.ui.AbsoluteLayout; |
|
18 |
import com.vaadin.ui.Button; |
|
19 |
import com.vaadin.ui.Button.ClickEvent; |
|
20 |
import com.vaadin.ui.Button.ClickListener; |
|
21 |
import com.vaadin.ui.CustomComponent; |
|
22 |
import com.vaadin.ui.ListSelect; |
|
23 |
import com.vaadin.ui.Notification; |
|
24 |
import com.vaadin.ui.Notification.Type; |
|
25 |
import com.vaadin.ui.Table; |
|
26 |
import com.vaadin.ui.UI; |
|
27 |
import com.vaadin.ui.VerticalLayout; |
|
28 |
import com.vaadin.ui.Window; |
|
29 |
|
|
30 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
31 |
import eu.etaxonomy.cdm.model.common.Language; |
|
32 |
import eu.etaxonomy.cdm.model.common.Representation; |
|
33 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
|
34 |
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm; |
|
35 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
36 |
import eu.etaxonomy.cdm.vaadin.component.DetailWindow; |
|
37 |
import eu.etaxonomy.cdm.vaadin.component.HorizontalToolbar; |
|
38 |
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer; |
|
39 |
import eu.etaxonomy.cdm.vaadin.container.PresenceAbsenceTermContainer; |
|
40 |
import eu.etaxonomy.cdm.vaadin.util.CdmQueryFactory; |
|
41 |
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper; |
|
42 |
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil; |
|
43 |
import eu.etaxonomy.cdm.vaadin.util.TermCacher; |
|
44 |
|
|
45 |
public class DistributionTableView extends CustomComponent implements View{ |
|
46 | 12 |
|
47 |
private static final long serialVersionUID = 1L; |
|
48 |
private HorizontalToolbar toolbar; |
|
49 |
private Table table; |
|
13 |
import eu.etaxonomy.vaadin.mvp.ApplicationView; |
|
50 | 14 |
|
51 |
private DistributionTablePresenter listener; |
|
15 |
/** |
|
16 |
* @author freimeier |
|
17 |
* @since 18.10.2017 |
|
18 |
* |
|
19 |
*/ |
|
20 |
public interface DistributionTableView extends ApplicationView<DistributionTablePresenter>, View { |
|
52 | 21 |
|
53 |
private CdmSQLContainer container; |
|
54 |
private DistributionSettingsConfigWindow distributionSettingConfigWindow; |
|
22 |
/** |
|
23 |
* Updates Distribution Table. |
|
24 |
*/ |
|
25 |
public void update(); |
|
55 | 26 |
|
56 | 27 |
/** |
57 |
* The constructor should first build the main layout, set the |
|
58 |
* composition root and then do any custom initialization. |
|
59 |
* |
|
60 |
* The constructor will not be automatically regenerated by the |
|
61 |
* visual editor. |
|
28 |
* Opens the setting window to change available distribution status. |
|
62 | 29 |
*/ |
63 |
public DistributionTableView() { |
|
64 |
AbsoluteLayout mainLayout = initLayout(); |
|
65 |
setCompositionRoot(mainLayout); |
|
66 |
createEditClickListener(); |
|
67 |
|
|
68 |
} |
|
69 |
|
|
70 |
private AbsoluteLayout initLayout() { |
|
71 |
AbsoluteLayout mainLayout = new AbsoluteLayout(); |
|
72 |
mainLayout.setImmediate(false); |
|
73 |
mainLayout.setWidth("100%"); |
|
74 |
mainLayout.setHeight("100%"); |
|
75 |
|
|
76 |
setWidth("100.0%"); |
|
77 |
setHeight("100.0%"); |
|
78 |
|
|
79 |
//Horizontal Toolbar |
|
80 |
toolbar = new HorizontalToolbar(); |
|
81 |
mainLayout.addComponent(toolbar, "top:0.0px;right:0.0px;"); |
|
82 |
|
|
83 |
// table + formatting |
|
84 |
table = new Table(){ |
|
85 |
private static final long serialVersionUID = -5148756917468804385L; |
|
86 |
|
|
87 |
@Override |
|
88 |
protected String formatPropertyValue(Object rowId, Object colId, Property<?> property) { |
|
89 |
String formattedValue = null; |
|
90 |
PresenceAbsenceTerm presenceAbsenceTerm = null; |
|
91 |
Object value = property.getValue(); |
|
92 |
if(value instanceof String){ |
|
93 |
presenceAbsenceTerm = TermCacher.getInstance().getPresenceAbsenceTerm((String) value); |
|
94 |
} |
|
95 |
if(presenceAbsenceTerm!=null){ |
|
96 |
Representation representation = presenceAbsenceTerm.getRepresentation(Language.DEFAULT()); |
|
97 |
if(representation!=null){ |
|
98 |
if(DistributionEditorUtil.isAbbreviatedLabels()){ |
|
99 |
formattedValue = representation.getAbbreviatedLabel(); |
|
100 |
} |
|
101 |
else{ |
|
102 |
formattedValue = representation.getLabel(); |
|
103 |
} |
|
104 |
} |
|
105 |
if(formattedValue==null){ |
|
106 |
formattedValue = presenceAbsenceTerm.getTitleCache(); |
|
107 |
} |
|
108 |
return formattedValue; |
|
109 |
} |
|
110 |
return super.formatPropertyValue(rowId, colId, property); |
|
111 |
} |
|
112 |
}; |
|
113 |
table.setImmediate(false); |
|
114 |
table.setWidth("100.0%"); |
|
115 |
table.setHeight("100.0%"); |
|
116 |
|
|
117 |
table.setColumnReorderingAllowed(true); |
|
118 |
table.setSortEnabled(false); |
|
119 |
|
|
120 |
table.setColumnCollapsingAllowed(true); |
|
121 |
table.setSelectable(true); |
|
122 |
table.setPageLength(20); |
|
123 |
table.setFooterVisible(true); |
|
124 |
table.setCacheRate(20); |
|
125 |
|
|
126 |
table.addItemClickListener(new ItemClickListener() { |
|
127 |
private static final long serialVersionUID = 2743935539139014771L; |
|
128 |
@Override |
|
129 |
public void itemClick(ItemClickEvent event) { |
|
130 |
if(!(event.getPropertyId().toString().equalsIgnoreCase(CdmQueryFactory.TAXON_COLUMN)) && !(event.getPropertyId().toString().equalsIgnoreCase(CdmQueryFactory.RANK_COLUMN))){ |
|
131 |
final Item item = event.getItem(); |
|
132 |
Property<?> itemProperty = item.getItemProperty("uuid"); |
|
133 |
UUID uuid = UUID.fromString(itemProperty.getValue().toString()); |
|
134 |
final Taxon taxon = HibernateProxyHelper.deproxy(CdmSpringContextHelper.getTaxonService().load(uuid), Taxon.class); |
|
135 |
final String areaID = (String) event.getPropertyId(); |
|
136 |
PresenceAbsenceTerm presenceAbsenceTerm = null; |
|
137 |
Object statusValue = item.getItemProperty(areaID).getValue(); |
|
138 |
if(statusValue instanceof String){ |
|
139 |
presenceAbsenceTerm = TermCacher.getInstance().getPresenceAbsenceTerm((String) statusValue); |
|
140 |
} |
|
141 |
//popup window |
|
142 |
final Window popup = new Window("Choose distribution status"); |
|
143 |
final ListSelect termSelect = new ListSelect(); |
|
144 |
termSelect.setSizeFull(); |
|
145 |
termSelect.setContainerDataSource(PresenceAbsenceTermContainer.getInstance()); |
|
146 |
termSelect.setNullSelectionAllowed(presenceAbsenceTerm!=null); |
|
147 |
if(presenceAbsenceTerm!=null){ |
|
148 |
termSelect.setNullSelectionItemId("[no status]"); |
|
149 |
} |
|
150 |
termSelect.setValue(presenceAbsenceTerm); |
|
151 |
termSelect.addValueChangeListener(new ValueChangeListener() { |
|
152 |
|
|
153 |
private static final long serialVersionUID = 1883728509174752769L; |
|
154 |
|
|
155 |
@Override |
|
156 |
public void valueChange(ValueChangeEvent event) { |
|
157 |
System.out.println(event); |
|
158 |
Object distributionStatus = event.getProperty().getValue(); |
|
159 |
listener.updateDistributionField(areaID, distributionStatus, taxon); |
|
160 |
container.refresh(); |
|
161 |
popup.close(); |
|
162 |
} |
|
163 |
}); |
|
164 |
VerticalLayout layout = new VerticalLayout(termSelect); |
|
165 |
popup.setContent(layout); |
|
166 |
popup.setModal(true); |
|
167 |
popup.center(); |
|
168 |
UI.getCurrent().addWindow(popup); |
|
169 |
} |
|
170 |
} |
|
171 |
}); |
|
172 |
|
|
173 |
|
|
174 |
mainLayout.addComponent(table, "top:75px;right:0.0px;"); |
|
175 |
return mainLayout; |
|
176 |
} |
|
177 |
|
|
178 |
public void addListener(DistributionTablePresenter listener) { |
|
179 |
this.listener = listener; |
|
180 |
} |
|
181 |
|
|
182 |
|
|
183 |
@Override |
|
184 |
public void enter(ViewChangeEvent event) { |
|
185 |
update(); |
|
186 |
} |
|
187 |
|
|
188 |
public void update(){ |
|
189 |
try { |
|
190 |
container = listener.getSQLContainer(); |
|
191 |
} catch (SQLException e) { |
|
192 |
DistributionEditorUtil.showSqlError(e); |
|
193 |
return; |
|
194 |
} |
|
195 |
if(container==null){ |
|
196 |
return; |
|
197 |
} |
|
30 |
public void openSettings(); |
|
198 | 31 |
|
199 |
table.setContainerDataSource(container); |
|
200 |
|
|
201 |
List<String> columnHeaders = new ArrayList<>(Arrays.asList(table.getColumnHeaders())); |
|
202 |
columnHeaders.remove(CdmQueryFactory.DTYPE_COLUMN); |
|
203 |
columnHeaders.remove(CdmQueryFactory.ID_COLUMN); |
|
204 |
columnHeaders.remove(CdmQueryFactory.UUID_COLUMN); |
|
205 |
columnHeaders.remove(CdmQueryFactory.CLASSIFICATION_COLUMN); |
|
206 |
|
|
207 |
List<String> columnList = new ArrayList<String>(columnHeaders); |
|
208 |
|
|
209 |
String[] string = new String[columnList.size()]; |
|
210 |
|
|
211 |
table.setVisibleColumns(columnList.toArray()); |
|
212 |
table.setColumnHeaders(columnList.toArray(string)); |
|
213 |
table.setColumnFooter(CdmQueryFactory.TAXON_COLUMN, "Total amount of Taxa displayed: " + container.size()); |
|
214 |
|
|
215 |
|
|
216 |
} |
|
217 |
|
|
218 |
private void createEditClickListener(){ |
|
219 |
Button detailButton = toolbar.getDetailButton(); |
|
220 |
detailButton.setCaption("Detail View"); |
|
221 |
detailButton.addClickListener(new ClickListener() { |
|
222 |
|
|
223 |
private static final long serialVersionUID = 1479133195403139547L; |
|
224 |
|
|
225 |
@Override |
|
226 |
public void buttonClick(ClickEvent event) { |
|
227 |
Object selectedItemId = DistributionTableView.this.table.getValue(); |
|
228 |
if(selectedItemId!=null){ |
|
229 |
final UUID uuid = UUID.fromString(table.getItem(selectedItemId).getItemProperty("uuid").getValue().toString()); |
|
230 |
Taxon taxon = HibernateProxyHelper.deproxy(CdmSpringContextHelper.getTaxonService().load(uuid), Taxon.class); |
|
231 |
List<DescriptionElementBase> listDescriptions = listener.listDescriptionElementsForTaxon(taxon, null); |
|
232 |
DetailWindow detailWindow = new DetailWindow(taxon, listDescriptions); |
|
233 |
Window window = detailWindow.createWindow(); |
|
234 |
window.center(); |
|
235 |
getUI().addWindow(window); |
|
236 |
} |
|
237 |
else{ |
|
238 |
Notification.show("Please select a taxon", Type.HUMANIZED_MESSAGE); |
|
239 |
} |
|
240 |
} |
|
241 |
}); |
|
242 |
|
|
243 |
Button distributionSettingsButton = toolbar.getDistributionSettingsButton(); |
|
244 |
distributionSettingsButton.addClickListener(new ClickListener() { |
|
245 |
|
|
246 |
private static final long serialVersionUID = -8695281619014251132L; |
|
247 |
|
|
248 |
@Override |
|
249 |
public void buttonClick(ClickEvent event) { |
|
250 |
openDistributionSettings(); |
|
251 |
} |
|
252 |
}); |
|
253 |
|
|
254 |
Button settingsButton = toolbar.getSettingsButton(); |
|
255 |
settingsButton.addClickListener(new ClickListener() { |
|
256 |
|
|
257 |
private static final long serialVersionUID = -147703680580181544L; |
|
258 |
|
|
259 |
@Override |
|
260 |
public void buttonClick(ClickEvent event) { |
|
261 |
openSettings(); |
|
262 |
} |
|
263 |
}); |
|
264 |
} |
|
265 |
|
|
266 |
public void openSettings() { |
|
267 |
SettingsConfigWindow cw = new SettingsConfigWindow(this); |
|
268 |
Window window = cw.createWindow(); |
|
269 |
getUI().addWindow(window); |
|
270 |
} |
|
271 |
|
|
272 |
public void openDistributionSettings() { |
|
273 |
if(distributionSettingConfigWindow==null){ |
|
274 |
distributionSettingConfigWindow = new DistributionSettingsConfigWindow(this); |
|
275 |
} |
|
276 |
Window window = distributionSettingConfigWindow.createWindow(); |
|
277 |
getUI().addWindow(window); |
|
278 |
} |
|
32 |
/** |
|
33 |
* Opens the distribution-setting window to change available areas and chose classification. |
|
34 |
*/ |
|
35 |
public void openDistributionSettings(); |
|
279 | 36 |
|
280 |
} |
|
37 |
} |
Also available in: Unified diff
Fixed #6802 and switched to mvp