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
|
*/
|
9
|
package eu.etaxonomy.cdm.vaadin.view.distributionStatus;
|
10
|
|
11
|
import java.util.Collection;
|
12
|
import java.util.List;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.springframework.beans.factory.annotation.Autowired;
|
16
|
import org.springframework.security.core.GrantedAuthority;
|
17
|
import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer;
|
18
|
|
19
|
import com.vaadin.data.fieldgroup.FieldGroup.CommitEvent;
|
20
|
import com.vaadin.data.fieldgroup.FieldGroup.CommitException;
|
21
|
import com.vaadin.data.fieldgroup.FieldGroup.CommitHandler;
|
22
|
import com.vaadin.data.util.converter.Converter;
|
23
|
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
|
24
|
import com.vaadin.spring.annotation.SpringView;
|
25
|
import com.vaadin.spring.annotation.ViewScope;
|
26
|
import com.vaadin.ui.AbsoluteLayout;
|
27
|
import com.vaadin.ui.AbstractSelect.ItemCaptionMode;
|
28
|
import com.vaadin.ui.Button;
|
29
|
import com.vaadin.ui.Grid;
|
30
|
import com.vaadin.ui.Grid.Column;
|
31
|
import com.vaadin.ui.Grid.FooterCell;
|
32
|
import com.vaadin.ui.Grid.FooterRow;
|
33
|
import com.vaadin.ui.NativeSelect;
|
34
|
import com.vaadin.ui.Notification;
|
35
|
import com.vaadin.ui.Notification.Type;
|
36
|
import com.vaadin.ui.Table;
|
37
|
import com.vaadin.ui.UI;
|
38
|
import com.vaadin.ui.Window;
|
39
|
|
40
|
import eu.etaxonomy.cdm.model.common.Language;
|
41
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
42
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
43
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
44
|
import eu.etaxonomy.cdm.vaadin.component.DetailWindow;
|
45
|
import eu.etaxonomy.cdm.vaadin.component.DistributionToolbar;
|
46
|
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
|
47
|
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
|
48
|
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
|
49
|
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
|
50
|
import eu.etaxonomy.cdm.vaadin.util.DistributionStatusQuery;
|
51
|
import eu.etaxonomy.cdm.vaadin.util.converter.PresenceAbsenceTermUuidObjectConverter;
|
52
|
import eu.etaxonomy.cdm.vaadin.util.converter.PresenceAbsenceTermUuidTitleStringConverter;
|
53
|
import eu.etaxonomy.cdm.vaadin.view.AbstractPageView;
|
54
|
|
55
|
/**
|
56
|
* @author freimeier
|
57
|
* @since 18.10.2017
|
58
|
*
|
59
|
*/
|
60
|
@ViewScope
|
61
|
@SpringView(name=DistributionTableViewBean.NAME)
|
62
|
public class DistributionTableViewBean
|
63
|
extends AbstractPageView<DistributionTablePresenter>
|
64
|
implements IDistributionTableView, AccessRestrictedView {
|
65
|
|
66
|
private static final long serialVersionUID = 1L;
|
67
|
public static final String NAME = "distGrid";
|
68
|
|
69
|
@Autowired
|
70
|
private DistributionToolbar toolbar;
|
71
|
|
72
|
private Table table;
|
73
|
private Grid grid;
|
74
|
private FooterRow footerRow;
|
75
|
|
76
|
private CdmSQLContainer container;
|
77
|
private LazyQueryContainer gridcontainer;
|
78
|
private AreaAndTaxonSettingsConfigWindow areaAndTaxonConfigWindow;;
|
79
|
private DistributionStatusSettingsConfigWindow distributionStatusConfigWindow;
|
80
|
|
81
|
public DistributionTableViewBean() {
|
82
|
super();
|
83
|
}
|
84
|
|
85
|
private AbsoluteLayout initLayout() {
|
86
|
AbsoluteLayout mainLayout = new AbsoluteLayout();
|
87
|
mainLayout.setImmediate(false);
|
88
|
mainLayout.setWidth("100%");
|
89
|
mainLayout.setHeight("100%");
|
90
|
|
91
|
setWidth("100.0%");
|
92
|
setHeight("100.0%");
|
93
|
|
94
|
//Horizontal Toolbar
|
95
|
mainLayout.addComponent(toolbar, "top:0.0px;right:0.0px;");
|
96
|
|
97
|
// // table + formatting
|
98
|
// table = new Table(){
|
99
|
// private static final long serialVersionUID = -5148756917468804385L;
|
100
|
//
|
101
|
// @Override
|
102
|
// protected String formatPropertyValue(Object rowId, Object colId, Property<?> property) {
|
103
|
// String formattedValue = null;
|
104
|
// PresenceAbsenceTerm presenceAbsenceTerm = null;
|
105
|
// Object value = property.getValue();
|
106
|
// if(value instanceof String){
|
107
|
// presenceAbsenceTerm = TermCacher.getInstance().getPresenceAbsenceTerm((String) value);
|
108
|
// }
|
109
|
// if(presenceAbsenceTerm != null){
|
110
|
// Representation representation = presenceAbsenceTerm.getRepresentation(Language.DEFAULT());
|
111
|
// if(representation!=null){
|
112
|
// if(DistributionEditorUtil.isAbbreviatedLabels()){
|
113
|
// formattedValue = representation.getAbbreviatedLabel();
|
114
|
// }
|
115
|
// else{
|
116
|
// formattedValue = representation.getLabel();
|
117
|
// }
|
118
|
// }
|
119
|
// if(formattedValue==null){
|
120
|
// formattedValue = presenceAbsenceTerm.getTitleCache();
|
121
|
// }
|
122
|
// return formattedValue;
|
123
|
// }
|
124
|
// return super.formatPropertyValue(rowId, colId, property);
|
125
|
// }
|
126
|
// };
|
127
|
// table.setImmediate(false);
|
128
|
// table.setWidth("100.0%");
|
129
|
// table.setHeight("100.0%");
|
130
|
//
|
131
|
// table.setColumnReorderingAllowed(true);
|
132
|
// table.setSortEnabled(false);
|
133
|
//
|
134
|
// table.setColumnCollapsingAllowed(true);
|
135
|
// table.setSelectable(true);
|
136
|
// table.setPageLength(20);
|
137
|
// table.setFooterVisible(true);
|
138
|
// table.setCacheRate(20);
|
139
|
//
|
140
|
// table.addItemClickListener(event -> {
|
141
|
// if(!(event.getPropertyId().toString().equalsIgnoreCase(CdmQueryFactory.TAXON_COLUMN))
|
142
|
// && !(event.getPropertyId().toString().equalsIgnoreCase(CdmQueryFactory.RANK_COLUMN))
|
143
|
// // TODO: HACK FOR RL 2017, REMOVE AS SOON AS POSSIBLE
|
144
|
// && !(event.getPropertyId().toString().equalsIgnoreCase("DE"))
|
145
|
// && !(event.getPropertyId().toString().equalsIgnoreCase("Deutschland"))){
|
146
|
// final Item item = event.getItem();
|
147
|
// Property<?> itemProperty = item.getItemProperty("uuid");
|
148
|
// UUID uuid = UUID.fromString(itemProperty.getValue().toString());
|
149
|
// final Taxon taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService()
|
150
|
// .load(uuid,Arrays.asList("descriptions.descriptionElements","name.taxonBases","updatedBy")), Taxon.class);
|
151
|
// final String areaID = (String)event.getPropertyId();
|
152
|
// PresenceAbsenceTerm presenceAbsenceTerm = null;
|
153
|
// Object statusValue = item.getItemProperty(areaID).getValue();
|
154
|
// if(statusValue instanceof String){
|
155
|
// presenceAbsenceTerm = TermCacher.getInstance().getPresenceAbsenceTerm((String) statusValue);
|
156
|
// }
|
157
|
// //popup window
|
158
|
// final Window popup = new Window("Choose distribution status");
|
159
|
// final ListSelect termSelect = new ListSelect();
|
160
|
// termSelect.setSizeFull();
|
161
|
// termSelect.setContainerDataSource(getPresenter().getPresenceAbsenceTermContainer());
|
162
|
// termSelect.setNullSelectionAllowed(presenceAbsenceTerm != null);
|
163
|
// if(presenceAbsenceTerm != null){
|
164
|
// termSelect.setNullSelectionItemId("[no status]");
|
165
|
// }else{
|
166
|
// logger.debug("No distribution status exists yet for area");
|
167
|
// }
|
168
|
// termSelect.setValue(presenceAbsenceTerm);
|
169
|
// termSelect.addValueChangeListener(valueChangeEvent -> {
|
170
|
// Object distributionStatus = valueChangeEvent.getProperty().getValue();
|
171
|
// getPresenter().updateDistributionField(areaID, distributionStatus, taxon);
|
172
|
// container.refresh();
|
173
|
// popup.close();
|
174
|
// });
|
175
|
// VerticalLayout layout = new VerticalLayout(termSelect);
|
176
|
// popup.setContent(layout);
|
177
|
// popup.setModal(true);
|
178
|
// popup.center();
|
179
|
// UI.getCurrent().addWindow(popup);
|
180
|
// }
|
181
|
// });
|
182
|
//
|
183
|
// mainLayout.addComponent(table, "top:75px;right:10.0px;left:10.0px;");
|
184
|
|
185
|
grid = new Grid();
|
186
|
grid.setSizeFull();
|
187
|
grid.setEditorEnabled(true);
|
188
|
grid.setFooterVisible(true);
|
189
|
mainLayout.addComponent(grid, "top:75px;right:10.0px;left:10.0px;");
|
190
|
|
191
|
return mainLayout;
|
192
|
}
|
193
|
|
194
|
/**
|
195
|
* {@inheritDoc}
|
196
|
*/
|
197
|
@Override
|
198
|
public void enter(ViewChangeEvent event) {
|
199
|
update();
|
200
|
}
|
201
|
|
202
|
/**
|
203
|
* {@inheritDoc}
|
204
|
*/
|
205
|
@Override
|
206
|
public void update(){
|
207
|
// try {
|
208
|
// container = getPresenter().getSQLContainer();
|
209
|
// } catch (SQLException e) {
|
210
|
// DistributionEditorUtil.showSqlError(e);
|
211
|
// return;
|
212
|
// }
|
213
|
// if(container==null){
|
214
|
// return;
|
215
|
// }
|
216
|
|
217
|
// table.setContainerDataSource(container);
|
218
|
//
|
219
|
// List<String> columnHeaders = new ArrayList<>(Arrays.asList(table.getColumnHeaders()));
|
220
|
// columnHeaders.remove(CdmQueryFactory.DTYPE_COLUMN);
|
221
|
// columnHeaders.remove(CdmQueryFactory.ID_COLUMN);
|
222
|
// columnHeaders.remove(CdmQueryFactory.UUID_COLUMN);
|
223
|
// columnHeaders.remove(CdmQueryFactory.CLASSIFICATION_COLUMN);
|
224
|
// columnHeaders.sort(new Comparator<String>() {
|
225
|
// @Override
|
226
|
// public int compare(String o1, String o2) {
|
227
|
// if(o1.equals(CdmQueryFactory.TAXON_COLUMN) || o2.equals(CdmQueryFactory.TAXON_COLUMN)) {
|
228
|
// return o1.equals(CdmQueryFactory.TAXON_COLUMN) ? -1 : 1;
|
229
|
// }
|
230
|
// if(o1.equals(CdmQueryFactory.RANK_COLUMN) || o2.equals(CdmQueryFactory.RANK_COLUMN)) {
|
231
|
// return o1.equals(CdmQueryFactory.RANK_COLUMN) ? -1 : 1;
|
232
|
// }
|
233
|
//
|
234
|
// // TODO: HACK FOR RL 2017, REMOVE AS SOON AS POSSIBLE
|
235
|
// if(o1.equals("DE") || o1.equals("Deutschland")
|
236
|
// || o2.equals("DE") || o2.equals("Deutschland")) {
|
237
|
// return (o1.equals("DE") || o1.equals("Deutschland")) ? -1 : 1;
|
238
|
// }
|
239
|
//
|
240
|
// return o1.compareTo(o2);
|
241
|
// }
|
242
|
// });
|
243
|
//
|
244
|
// List<String> columnList = new ArrayList<>(columnHeaders);
|
245
|
//
|
246
|
// String[] string = new String[columnList.size()];
|
247
|
//
|
248
|
// table.setVisibleColumns(columnList.toArray());
|
249
|
// table.setColumnHeaders(columnList.toArray(string));
|
250
|
// table.setColumnFooter(CdmQueryFactory.TAXON_COLUMN, "Total amount of Taxa displayed: " + container.size());
|
251
|
|
252
|
gridcontainer = getPresenter().getAreaDistributionStatusContainer();
|
253
|
if(gridcontainer==null){
|
254
|
return;
|
255
|
}
|
256
|
|
257
|
if(footerRow != null) {
|
258
|
grid.removeFooterRow(footerRow);
|
259
|
}
|
260
|
grid.removeAllColumns();
|
261
|
|
262
|
grid.setContainerDataSource(gridcontainer);
|
263
|
|
264
|
Column uuidColumn = grid.getColumn(DistributionStatusQuery.UUID_COLUMN);
|
265
|
uuidColumn.setEditable(false);
|
266
|
uuidColumn.setHidden(true);
|
267
|
Column taxonColumn = grid.getColumn(DistributionStatusQuery.TAXON_COLUMN);
|
268
|
taxonColumn.setEditable(false);
|
269
|
taxonColumn.setHeaderCaption("Taxon");
|
270
|
taxonColumn.setLastFrozenColumn();
|
271
|
|
272
|
Converter<String, UUID> displayConverter = new PresenceAbsenceTermUuidTitleStringConverter();
|
273
|
Converter<Object, UUID> editorConverter = new PresenceAbsenceTermUuidObjectConverter();
|
274
|
for(Column c : grid.getColumns()) {
|
275
|
if(c.isEditable()) {
|
276
|
NamedArea namedArea = (NamedArea) CdmSpringContextHelper.getTermService().load((UUID.fromString(c.getHeaderCaption())));
|
277
|
String caption = DistributionEditorUtil.isAbbreviatedLabels() ?
|
278
|
namedArea.getRepresentation(Language.DEFAULT()).getAbbreviatedLabel() : namedArea.getTitleCache();
|
279
|
c.setHeaderCaption(caption);
|
280
|
c.setConverter(displayConverter);
|
281
|
|
282
|
NativeSelect termSelect = new NativeSelect();
|
283
|
termSelect.setSizeFull();
|
284
|
termSelect.setContainerDataSource(getPresenter().getPresenceAbsenceTermContainer());
|
285
|
termSelect.setItemCaptionMode(ItemCaptionMode.PROPERTY);
|
286
|
termSelect.setItemCaptionPropertyId("titleCache");
|
287
|
termSelect.setConverter(editorConverter);
|
288
|
termSelect.setImmediate(true);
|
289
|
c.setEditorField(termSelect);
|
290
|
}
|
291
|
}
|
292
|
grid.getEditorFieldGroup().addCommitHandler(new CommitHandler() {
|
293
|
private static final long serialVersionUID = 7515807188410712420L;
|
294
|
|
295
|
@Override
|
296
|
public void preCommit(CommitEvent commitEvent) throws CommitException {
|
297
|
|
298
|
}
|
299
|
|
300
|
@Override
|
301
|
public void postCommit(CommitEvent commitEvent) throws CommitException {
|
302
|
gridcontainer.commit();
|
303
|
}
|
304
|
});
|
305
|
|
306
|
footerRow = grid.appendFooterRow();
|
307
|
Object[] cells = grid.getColumns().stream().map(c -> c.getPropertyId()).toArray(Object[]::new);
|
308
|
if(cells.length == 0) {
|
309
|
return;
|
310
|
}
|
311
|
FooterCell footerCell = null;
|
312
|
if(cells.length > 1) {
|
313
|
footerCell = footerRow.join(cells);
|
314
|
}else {
|
315
|
footerCell = footerRow.getCell(cells[0]);
|
316
|
}
|
317
|
footerCell.setText("Total amount of Taxa displayed: " + gridcontainer.size());
|
318
|
}
|
319
|
|
320
|
private void createEditClickListener(){
|
321
|
//details
|
322
|
Button detailButton = toolbar.getDetailButton();
|
323
|
detailButton.setCaption("Taxon Details");
|
324
|
detailButton.addClickListener(event -> {
|
325
|
// Object selectedItemId = DistributionTableViewBean.this.table.getValue();
|
326
|
Object selectedItemId = DistributionTableViewBean.this.grid.getSelectedRow();
|
327
|
if(selectedItemId!=null){
|
328
|
// final UUID uuid = UUID.fromString(table.getContainerDataSource().getItem(selectedItemId).getItemProperty("uuid").getValue().toString());
|
329
|
final UUID uuid = (UUID) selectedItemId;
|
330
|
// Taxon taxon = HibernateProxyHelper.deproxy(CdmSpringContextHelper.getTaxonService().load(uuid), Taxon.class);
|
331
|
Taxon taxon = (Taxon) CdmSpringContextHelper.getTaxonService().load(uuid);
|
332
|
List<DescriptionElementBase> listDescriptions = getPresenter().listDescriptionElementsForTaxon(taxon, null);
|
333
|
DetailWindow detailWindow = new DetailWindow(taxon, listDescriptions);
|
334
|
Window window = detailWindow.createWindow();
|
335
|
window.center();
|
336
|
getUI().addWindow(window);
|
337
|
}
|
338
|
else{
|
339
|
Notification.show("Please select a taxon", Type.HUMANIZED_MESSAGE);
|
340
|
}
|
341
|
}
|
342
|
);
|
343
|
|
344
|
//area and taxon
|
345
|
Button areaAndTaxonSettingsButton = toolbar.getDistributionSettingsButton();
|
346
|
areaAndTaxonSettingsButton.addClickListener(event -> openAreaAndTaxonSettings());
|
347
|
|
348
|
//distr status
|
349
|
Button distrStatusButton = toolbar.getSettingsButton();
|
350
|
distrStatusButton.addClickListener(event -> openStatusSettings());
|
351
|
}
|
352
|
|
353
|
/**
|
354
|
* {@inheritDoc}
|
355
|
*/
|
356
|
@Override
|
357
|
public void openStatusSettings() {
|
358
|
if(distributionStatusConfigWindow==null){
|
359
|
distributionStatusConfigWindow = new DistributionStatusSettingsConfigWindow(this);
|
360
|
}
|
361
|
Window window = distributionStatusConfigWindow.createWindow("Status");
|
362
|
window.setWidth("25%");
|
363
|
window.setHeight("60%");
|
364
|
UI.getCurrent().addWindow(window);
|
365
|
}
|
366
|
|
367
|
/**
|
368
|
* {@inheritDoc}
|
369
|
*/
|
370
|
@Override
|
371
|
public void openAreaAndTaxonSettings() {
|
372
|
if(areaAndTaxonConfigWindow==null){
|
373
|
areaAndTaxonConfigWindow = new AreaAndTaxonSettingsConfigWindow(this);
|
374
|
}
|
375
|
Window window = areaAndTaxonConfigWindow.createWindow("Areas and Taxa");
|
376
|
UI.getCurrent().addWindow(window);
|
377
|
}
|
378
|
|
379
|
/**
|
380
|
* {@inheritDoc}
|
381
|
*/
|
382
|
@Override
|
383
|
public boolean allowAnonymousAccess() {
|
384
|
// TODO Auto-generated method stub
|
385
|
return false;
|
386
|
}
|
387
|
|
388
|
/**
|
389
|
* {@inheritDoc}
|
390
|
*/
|
391
|
@Override
|
392
|
public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
|
393
|
// TODO Auto-generated method stub
|
394
|
return null;
|
395
|
}
|
396
|
|
397
|
/**
|
398
|
* {@inheritDoc}
|
399
|
*/
|
400
|
@Override
|
401
|
protected String getHeaderText() {
|
402
|
// TODO Auto-generated method stub
|
403
|
return null;
|
404
|
}
|
405
|
|
406
|
/**
|
407
|
* {@inheritDoc}
|
408
|
*/
|
409
|
@Override
|
410
|
protected String getSubHeaderText() {
|
411
|
// TODO Auto-generated method stub
|
412
|
return null;
|
413
|
}
|
414
|
|
415
|
/**
|
416
|
* {@inheritDoc}
|
417
|
*/
|
418
|
@Override
|
419
|
protected void initContent() {
|
420
|
// initialize layout
|
421
|
AbsoluteLayout mainLayout = initLayout();
|
422
|
setCompositionRoot(mainLayout);
|
423
|
// add click listener on DistributionToolbar-buttons
|
424
|
createEditClickListener();
|
425
|
}
|
426
|
}
|