1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2015 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.cdm.vaadin.component;
|
11
|
|
12
|
import java.sql.SQLException;
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.Arrays;
|
15
|
import java.util.List;
|
16
|
import java.util.Set;
|
17
|
import java.util.UUID;
|
18
|
|
19
|
import org.apache.log4j.Logger;
|
20
|
|
21
|
import com.vaadin.annotations.AutoGenerated;
|
22
|
import com.vaadin.data.Item;
|
23
|
import com.vaadin.data.Property;
|
24
|
import com.vaadin.data.Property.ValueChangeEvent;
|
25
|
import com.vaadin.data.Property.ValueChangeListener;
|
26
|
import com.vaadin.data.util.IndexedContainer;
|
27
|
import com.vaadin.data.util.sqlcontainer.RowId;
|
28
|
import com.vaadin.event.Action;
|
29
|
import com.vaadin.event.FieldEvents;
|
30
|
import com.vaadin.event.FieldEvents.TextChangeEvent;
|
31
|
import com.vaadin.event.ItemClickEvent;
|
32
|
import com.vaadin.event.ItemClickEvent.ItemClickListener;
|
33
|
import com.vaadin.event.LayoutEvents.LayoutClickEvent;
|
34
|
import com.vaadin.event.LayoutEvents.LayoutClickListener;
|
35
|
import com.vaadin.navigator.View;
|
36
|
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
|
37
|
import com.vaadin.server.FontAwesome;
|
38
|
import com.vaadin.ui.Alignment;
|
39
|
import com.vaadin.ui.Button;
|
40
|
import com.vaadin.ui.Button.ClickEvent;
|
41
|
import com.vaadin.ui.CheckBox;
|
42
|
import com.vaadin.ui.ComboBox;
|
43
|
import com.vaadin.ui.Component;
|
44
|
import com.vaadin.ui.CustomComponent;
|
45
|
import com.vaadin.ui.GridLayout;
|
46
|
import com.vaadin.ui.HorizontalLayout;
|
47
|
import com.vaadin.ui.Label;
|
48
|
import com.vaadin.ui.Notification;
|
49
|
import com.vaadin.ui.Notification.Type;
|
50
|
import com.vaadin.ui.Table;
|
51
|
import com.vaadin.ui.Table.ColumnHeaderMode;
|
52
|
import com.vaadin.ui.Table.TableDragMode;
|
53
|
import com.vaadin.ui.TextField;
|
54
|
import com.vaadin.ui.TreeTable;
|
55
|
import com.vaadin.ui.UI;
|
56
|
import com.vaadin.ui.VerticalLayout;
|
57
|
import com.vaadin.ui.Window;
|
58
|
|
59
|
import eu.etaxonomy.cdm.vaadin.container.IdUuidName;
|
60
|
import eu.etaxonomy.cdm.vaadin.container.LeafNodeTaxonContainer;
|
61
|
import eu.etaxonomy.cdm.vaadin.presenter.NewTaxonBasePresenter;
|
62
|
import eu.etaxonomy.cdm.vaadin.presenter.StatusPresenter;
|
63
|
import eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent;
|
64
|
import eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener;
|
65
|
import eu.etaxonomy.cdm.vaadin.session.SelectionEvent;
|
66
|
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinSessionUtilities;
|
67
|
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinUtilities;
|
68
|
import eu.etaxonomy.cdm.vaadin.view.IStatusComposite;
|
69
|
|
70
|
/**
|
71
|
* @author cmathew
|
72
|
* @date 11 Mar 2015
|
73
|
*
|
74
|
*/
|
75
|
public class StatusComposite extends CustomComponent implements View, IStatusComposite, ICdmChangeListener {
|
76
|
|
77
|
/*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */
|
78
|
|
79
|
@AutoGenerated
|
80
|
private GridLayout mainLayout;
|
81
|
@AutoGenerated
|
82
|
private Label inViewLabel;
|
83
|
@AutoGenerated
|
84
|
private TreeTable taxaTreeTable;
|
85
|
@AutoGenerated
|
86
|
private HorizontalLayout searchHorizontalLayout;
|
87
|
@AutoGenerated
|
88
|
private Button clearSearchButton;
|
89
|
@AutoGenerated
|
90
|
private TextField searchTextField;
|
91
|
@AutoGenerated
|
92
|
private HorizontalLayout addRemovehorizontalLayout;
|
93
|
@AutoGenerated
|
94
|
private Button removeButton;
|
95
|
@AutoGenerated
|
96
|
private ComboBox addComboBox;
|
97
|
@AutoGenerated
|
98
|
private VerticalLayout filterVerticalLayout;
|
99
|
@AutoGenerated
|
100
|
private Table filterTable;
|
101
|
@AutoGenerated
|
102
|
private Label filterLabel;
|
103
|
@AutoGenerated
|
104
|
private ComboBox classificationComboBox;
|
105
|
private static final Logger logger = Logger.getLogger(StatusComposite.class);
|
106
|
private StatusComponentListener listener;
|
107
|
|
108
|
private Object currentClickedTaxonItemId;
|
109
|
|
110
|
private final boolean taxaTreeTableMultiSelectMode = true;
|
111
|
|
112
|
private static final String SELECT_FILTER = "Select filter ...";
|
113
|
private static final String SELECT_CLASSIFICATION = "Select classification ...";
|
114
|
|
115
|
private static final String ADD_TAXON_SYNONYM_INPUT = "Add ...";
|
116
|
private static final String ADD_TAXON = "New Accepted Taxon";
|
117
|
private static final String ADD_SYNONYM = "New Synonym";
|
118
|
|
119
|
private static final String PROPERTY_FILTER_ID = "filter";
|
120
|
private static final String PROPERTY_SELECTED_ID = "selected";
|
121
|
|
122
|
private static final String FILTER_NOT_RESOLVED = "not resolved";
|
123
|
private static final String FILTER_UNPLACED = "unplaced";
|
124
|
private static final String FILTER_UNFINISHED = "unfinished";
|
125
|
private static final String FILTER_UNPUBLISHED = "unpublished";
|
126
|
|
127
|
|
128
|
private static final String FILTER_TAXA_INPUT = "Filter Taxa ...";
|
129
|
private static final String IN_VIEW_PREFIX = "in view : ";
|
130
|
|
131
|
private boolean isTaxaTableInitialised = false;
|
132
|
private boolean isFiltertableInitialised = false;
|
133
|
|
134
|
/**
|
135
|
* The constructor should first build the main layout, set the
|
136
|
* composition root and then do any custom initialization.
|
137
|
*
|
138
|
* The constructor will not be automatically regenerated by the
|
139
|
* visual editor.
|
140
|
*/
|
141
|
public StatusComposite() {
|
142
|
buildMainLayout();
|
143
|
setCompositionRoot(mainLayout);
|
144
|
|
145
|
this.listener = new StatusPresenter();
|
146
|
CdmVaadinSessionUtilities.getCurrentCdmDataChangeService().register(this);
|
147
|
addUIListeners();
|
148
|
|
149
|
initAddComboBox();
|
150
|
initSearchTextField();
|
151
|
initClearSearchButton();
|
152
|
setEnabledAll(false);
|
153
|
|
154
|
init();
|
155
|
}
|
156
|
|
157
|
|
158
|
|
159
|
public void setClassification(String classification) {
|
160
|
if(classification == null) {
|
161
|
return;
|
162
|
}
|
163
|
Object selectedClassificationId = listener.getClassificationId(classification);
|
164
|
if(selectedClassificationId == null) {
|
165
|
Notification.show("Classification named " + classification + " does not exist.");
|
166
|
} else {
|
167
|
classificationComboBox.setValue(selectedClassificationId);
|
168
|
}
|
169
|
}
|
170
|
|
171
|
public void init() {
|
172
|
taxaTreeTable.setSelectable(true);
|
173
|
initClassificationComboBox();
|
174
|
}
|
175
|
|
176
|
public void setEnabledAll(boolean enabled) {
|
177
|
CdmVaadinUtilities.setEnabled(mainLayout, enabled, Arrays.asList(classificationComboBox));
|
178
|
}
|
179
|
|
180
|
|
181
|
public TreeTable getTaxaTreeTable() {
|
182
|
return taxaTreeTable;
|
183
|
}
|
184
|
|
185
|
public LeafNodeTaxonContainer getTaxonContainer() {
|
186
|
return listener.getCurrentLeafNodeTaxonContainer();
|
187
|
}
|
188
|
|
189
|
public void clearTaxaTableSelections() {
|
190
|
taxaTreeTable.setValue(null);
|
191
|
}
|
192
|
|
193
|
public UUID getSelectedClassificationUuid() {
|
194
|
if(classificationComboBox.getValue() != null) {
|
195
|
return listener.getClassificationContainer().getUuid(classificationComboBox.getValue());
|
196
|
}
|
197
|
return null;
|
198
|
}
|
199
|
|
200
|
private void initTaxaTable(int classificationId) {
|
201
|
taxaTreeTable.setMultiSelect(taxaTreeTableMultiSelectMode);
|
202
|
taxaTreeTable.setImmediate(false);
|
203
|
taxaTreeTable.setDragMode(TableDragMode.ROW);
|
204
|
if(listener != null) {
|
205
|
List<String> columnIds = new ArrayList<String>();
|
206
|
columnIds.add(LeafNodeTaxonContainer.NAME_ID);
|
207
|
taxaTreeTable.setColumnExpandRatio(LeafNodeTaxonContainer.NAME_ID, 1);
|
208
|
columnIds.add(LeafNodeTaxonContainer.PB_ID);
|
209
|
taxaTreeTable.setColumnWidth(LeafNodeTaxonContainer.PB_ID, 25);
|
210
|
|
211
|
if(!isTaxaTableInitialised) {
|
212
|
taxaTreeTable.addGeneratedColumn(LeafNodeTaxonContainer.PB_ID, new TaxonTableCheckBoxGenerator());
|
213
|
}
|
214
|
|
215
|
try {
|
216
|
taxaTreeTable.setContainerDataSource(listener.loadTaxa(classificationId), columnIds);
|
217
|
} catch (SQLException e) {
|
218
|
//TODO : throw up warning dialog
|
219
|
e.printStackTrace();
|
220
|
}
|
221
|
|
222
|
|
223
|
taxaTreeTable.setCellStyleGenerator(new Table.CellStyleGenerator() {
|
224
|
|
225
|
@Override
|
226
|
public String getStyle(Table source, Object itemId, Object propertyId) {
|
227
|
if(source.getItem(itemId) == null) {
|
228
|
return null;
|
229
|
}
|
230
|
if(listener.isSynonym(itemId)) {
|
231
|
// this is a synonym, so we activate the corresponding css class
|
232
|
return "synonym";
|
233
|
} else {
|
234
|
return "taxon";
|
235
|
}
|
236
|
|
237
|
}
|
238
|
});
|
239
|
|
240
|
taxaTreeTable.setSortContainerPropertyId(LeafNodeTaxonContainer.NAME_ID);
|
241
|
|
242
|
// NOTE : Not really sure why we need to refresh the container here.
|
243
|
// in the case of 'Table' this is not required
|
244
|
listener.refresh();
|
245
|
updateInViewLabel();
|
246
|
isTaxaTableInitialised = true;
|
247
|
}
|
248
|
|
249
|
|
250
|
final Action changeAcceptedTaxonToSynonymAction = new Action("Change Accepted Taxon To Synonym");
|
251
|
|
252
|
|
253
|
taxaTreeTable.addActionHandler(new Action.Handler() {
|
254
|
@Override
|
255
|
public Action[] getActions(final Object target, final Object sender) {
|
256
|
return new Action[] { changeAcceptedTaxonToSynonymAction };
|
257
|
}
|
258
|
|
259
|
@Override
|
260
|
public void handleAction(final Action action, final Object sender,
|
261
|
final Object target) {
|
262
|
Notification.show("action for Change Accepted Taxon To Synonym", "Implement me", Type.WARNING_MESSAGE);
|
263
|
}
|
264
|
});
|
265
|
|
266
|
}
|
267
|
|
268
|
private void initClassificationComboBox() {
|
269
|
|
270
|
classificationComboBox.setNewItemsAllowed(false);
|
271
|
classificationComboBox.setNullSelectionAllowed(false);
|
272
|
classificationComboBox.setImmediate(true);
|
273
|
classificationComboBox.setItemCaptionPropertyId(StatusPresenter.C_TCACHE_ID);
|
274
|
classificationComboBox.setInputPrompt(SELECT_CLASSIFICATION);
|
275
|
if(listener != null) {
|
276
|
try {
|
277
|
classificationComboBox.setContainerDataSource(listener.loadClassifications());
|
278
|
} catch (SQLException e) {
|
279
|
//TODO : throw up warning dialog
|
280
|
e.printStackTrace();
|
281
|
}
|
282
|
}
|
283
|
}
|
284
|
|
285
|
|
286
|
|
287
|
private void initFilterTable() {
|
288
|
filterTable.setNullSelectionAllowed(false);
|
289
|
final IndexedContainer container = new IndexedContainer();
|
290
|
container.addContainerProperty("filter", String.class, "");
|
291
|
container.addContainerProperty("selected", Boolean.class, "");
|
292
|
|
293
|
Item item = container.addItem(FILTER_NOT_RESOLVED);
|
294
|
item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_NOT_RESOLVED);
|
295
|
item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
|
296
|
|
297
|
item = container.addItem(FILTER_UNPLACED);
|
298
|
item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_UNPLACED);
|
299
|
item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
|
300
|
|
301
|
item = container.addItem(FILTER_UNFINISHED);
|
302
|
item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_UNFINISHED);
|
303
|
item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
|
304
|
|
305
|
item = container.addItem(FILTER_UNPUBLISHED);
|
306
|
item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_UNPUBLISHED);
|
307
|
item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
|
308
|
|
309
|
|
310
|
filterTable.setContainerDataSource(container);
|
311
|
filterTable.setColumnHeaderMode(ColumnHeaderMode.HIDDEN);
|
312
|
|
313
|
|
314
|
ValueChangeListener selectedListener = new ValueChangeListener() {
|
315
|
|
316
|
private static final long serialVersionUID = -5551250788805117454L;
|
317
|
|
318
|
@Override
|
319
|
public void valueChange(ValueChangeEvent event) {
|
320
|
boolean value = (Boolean) event.getProperty().getValue();
|
321
|
String selectedFilter = (String)filterTable.getItem(((CheckBox)event.getProperty()).getData()).getItemProperty(PROPERTY_FILTER_ID).getValue();
|
322
|
if(selectedFilter != null) {
|
323
|
if(value) {
|
324
|
if(selectedFilter.equals(FILTER_UNPLACED)) {
|
325
|
listener.setUnplacedFilter();
|
326
|
}
|
327
|
if(selectedFilter.equals(FILTER_UNPUBLISHED)) {
|
328
|
listener.setUnpublishedFilter();
|
329
|
}
|
330
|
} else {
|
331
|
if(selectedFilter.equals(FILTER_UNPLACED)) {
|
332
|
listener.removeUnplacedFilter();
|
333
|
}
|
334
|
if(selectedFilter.equals(FILTER_UNPUBLISHED)) {
|
335
|
listener.removeUnpublishedFilter();
|
336
|
}
|
337
|
}
|
338
|
updateInViewLabel();
|
339
|
}
|
340
|
}
|
341
|
};
|
342
|
|
343
|
if(!isFiltertableInitialised) {
|
344
|
filterTable.addGeneratedColumn(PROPERTY_SELECTED_ID, new CheckBoxGenerator(selectedListener));
|
345
|
}
|
346
|
|
347
|
isFiltertableInitialised = true;
|
348
|
|
349
|
}
|
350
|
|
351
|
private void updateInViewLabel() {
|
352
|
inViewLabel.setValue(IN_VIEW_PREFIX + String.valueOf(listener.getCurrentNoOfTaxa()) + " / " + String.valueOf(listener.getTotalNoOfTaxa()) + " taxa");
|
353
|
}
|
354
|
|
355
|
private void initSearchTextField() {
|
356
|
searchTextField.setInputPrompt(FILTER_TAXA_INPUT);
|
357
|
}
|
358
|
|
359
|
|
360
|
private void initAddComboBox() {
|
361
|
addComboBox.setNullSelectionAllowed(false);
|
362
|
addComboBox.setImmediate(true);
|
363
|
addComboBox.addItem(ADD_TAXON_SYNONYM_INPUT);
|
364
|
addComboBox.addItem(ADD_TAXON);
|
365
|
addComboBox.addItem(ADD_SYNONYM);
|
366
|
addComboBox.setValue(ADD_TAXON_SYNONYM_INPUT);
|
367
|
|
368
|
}
|
369
|
|
370
|
private void initClearSearchButton() {
|
371
|
clearSearchButton.setIcon(FontAwesome.REFRESH);
|
372
|
clearSearchButton.setCaption("");
|
373
|
}
|
374
|
|
375
|
|
376
|
private void addUIListeners() {
|
377
|
|
378
|
searchHorizontalLayout.addLayoutClickListener(new LayoutClickListener() {
|
379
|
|
380
|
@Override
|
381
|
public void layoutClick(LayoutClickEvent event) {
|
382
|
if (event.getChildComponent() == searchTextField && searchTextField.getValue().equals(FILTER_TAXA_INPUT)) {
|
383
|
searchTextField.setValue("");
|
384
|
}
|
385
|
}
|
386
|
});
|
387
|
|
388
|
addClassificationComboBoxListener();
|
389
|
addTaxaTreeTableListener();
|
390
|
addAddComboBoxListener();
|
391
|
addRemoveButtonListener();
|
392
|
addSearchTextFieldListener();
|
393
|
addClearSearchButtonListener();
|
394
|
}
|
395
|
|
396
|
private void addClassificationComboBoxListener() {
|
397
|
|
398
|
classificationComboBox.addValueChangeListener(new Property.ValueChangeListener() {
|
399
|
|
400
|
private static final long serialVersionUID = 4196786323147791606L;
|
401
|
|
402
|
@Override
|
403
|
public void valueChange(ValueChangeEvent event) {
|
404
|
if (classificationComboBox.getValue() != null) {
|
405
|
Object selected = classificationComboBox.getValue();
|
406
|
int classificationId = (Integer)((RowId)selected).getId()[0];
|
407
|
initTaxaTable(classificationId);
|
408
|
initFilterTable();
|
409
|
setEnabledAll(true);
|
410
|
}
|
411
|
}
|
412
|
});
|
413
|
}
|
414
|
|
415
|
private void addTaxaTreeTableListener() {
|
416
|
|
417
|
taxaTreeTable.addItemClickListener(new ItemClickListener() {
|
418
|
@Override
|
419
|
public void itemClick(ItemClickEvent event) {
|
420
|
Object itemId = event.getItemId();
|
421
|
if(taxaTreeTable.isSelectable()) {
|
422
|
if(!CdmVaadinUtilities.isSelected(taxaTreeTable, itemId) && !listener.isSynonym(itemId)) {
|
423
|
UUID taxonUuid = listener.getCurrentLeafNodeTaxonContainer().getUuid(itemId);
|
424
|
String taxonName = (String)listener.getCurrentLeafNodeTaxonContainer().getProperty(itemId, LeafNodeTaxonContainer.NAME_ID).getValue();
|
425
|
Object idUuidName = new IdUuidName(itemId, taxonUuid, taxonName);
|
426
|
CdmVaadinSessionUtilities.getCurrentSelectionService()
|
427
|
.fireSelectionEvent(new SelectionEvent(Arrays.asList(idUuidName, getSelectedClassificationUuid()), StatusComposite.class), true);
|
428
|
}
|
429
|
taxaTreeTable.setValue(itemId);
|
430
|
}
|
431
|
}
|
432
|
});
|
433
|
}
|
434
|
|
435
|
private void addAddComboBoxListener() {
|
436
|
addComboBox.addValueChangeListener(new Property.ValueChangeListener() {
|
437
|
|
438
|
private static final long serialVersionUID = -6235423275051269517L;
|
439
|
|
440
|
@Override
|
441
|
public void valueChange(ValueChangeEvent event) {
|
442
|
if (addComboBox.getValue() != null) {
|
443
|
String selected = (String)addComboBox.getValue();
|
444
|
if(!selected.equals(ADD_TAXON_SYNONYM_INPUT)) {
|
445
|
try {
|
446
|
String windowTitle;
|
447
|
|
448
|
Object selectedItemId = null;
|
449
|
IdUuidName accTaxonIdUuid = null;
|
450
|
String accTaxonName = null;
|
451
|
if(selected.equals(ADD_SYNONYM)) {
|
452
|
Set<Object> selectedIds = (Set<Object>)taxaTreeTable.getValue();
|
453
|
// if zero or more than one items (taxa / synonyms) are selected
|
454
|
// throw a warning
|
455
|
if(selectedIds.size() != 1) {
|
456
|
Notification.show("Multiple or No selection", "Please select a single Taxon", Type.WARNING_MESSAGE);
|
457
|
return;
|
458
|
}
|
459
|
selectedItemId = selectedIds.iterator().next();
|
460
|
// if a synonym is selected then throw warning
|
461
|
if(listener.isSynonym(selectedItemId)) {
|
462
|
Notification.show("Synonym selected", "Please choose a Taxon", Type.WARNING_MESSAGE);
|
463
|
return;
|
464
|
}
|
465
|
windowTitle = "Add New Synonym";
|
466
|
accTaxonIdUuid = new IdUuidName(selectedItemId,
|
467
|
listener.getCurrentLeafNodeTaxonContainer().getUuid(selectedItemId),
|
468
|
(String) listener.getCurrentLeafNodeTaxonContainer().getProperty(selectedItemId, LeafNodeTaxonContainer.NAME_ID).getValue());
|
469
|
accTaxonName = (String)listener.getCurrentLeafNodeTaxonContainer().getProperty(selectedItemId, LeafNodeTaxonContainer.NAME_ID).getValue();
|
470
|
} else {
|
471
|
windowTitle = "Add New Taxon";
|
472
|
}
|
473
|
|
474
|
try {
|
475
|
Window dialog = new Window(windowTitle);
|
476
|
dialog.setModal(true);
|
477
|
dialog.setClosable(false);
|
478
|
dialog.setResizable(false);
|
479
|
UI.getCurrent().addWindow(dialog);
|
480
|
Object cId = classificationComboBox.getValue();
|
481
|
UUID classificationUuid = listener.getClassificationContainer().getUuid(cId);
|
482
|
IdUuidName classificationIdUuid = new IdUuidName(classificationComboBox.getValue(),
|
483
|
classificationUuid,
|
484
|
(String) listener.getClassificationContainer().getProperty(cId, StatusPresenter.C_TCACHE_ID).getValue());
|
485
|
NewTaxonBaseComposite newTaxonComponent =
|
486
|
new NewTaxonBaseComposite(dialog,
|
487
|
new NewTaxonBasePresenter(),
|
488
|
accTaxonIdUuid,
|
489
|
accTaxonName,
|
490
|
classificationIdUuid);
|
491
|
dialog.setContent(newTaxonComponent);
|
492
|
} catch (SQLException e) {
|
493
|
// TODO Auto-generated catch block
|
494
|
e.printStackTrace();
|
495
|
}
|
496
|
} finally {
|
497
|
addComboBox.setValue(ADD_TAXON_SYNONYM_INPUT);
|
498
|
}
|
499
|
}
|
500
|
}
|
501
|
}
|
502
|
});
|
503
|
}
|
504
|
|
505
|
private void addSearchTextFieldListener() {
|
506
|
searchTextField.addTextChangeListener(new FieldEvents.TextChangeListener() {
|
507
|
|
508
|
private static final long serialVersionUID = -7376538870420619534L;
|
509
|
|
510
|
@Override
|
511
|
public void textChange(TextChangeEvent event) {
|
512
|
listener.setNameFilter(event.getText());
|
513
|
updateInViewLabel();
|
514
|
}
|
515
|
|
516
|
});
|
517
|
|
518
|
}
|
519
|
|
520
|
private void addClearSearchButtonListener() {
|
521
|
clearSearchButton.addClickListener(new Button.ClickListener() {
|
522
|
|
523
|
@Override
|
524
|
public void buttonClick(ClickEvent event) {
|
525
|
clearDynamicFilters();
|
526
|
updateInViewLabel();
|
527
|
}
|
528
|
|
529
|
});
|
530
|
}
|
531
|
|
532
|
private void clearDynamicFilters() {
|
533
|
listener.removeDynamicFilters();
|
534
|
searchTextField.setValue(FILTER_TAXA_INPUT);
|
535
|
for(Object itemId : filterTable.getItemIds()) {
|
536
|
filterTable.getItem(itemId).getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
|
537
|
}
|
538
|
}
|
539
|
|
540
|
private void addRemoveButtonListener() {
|
541
|
removeButton.addClickListener(new Button.ClickListener() {
|
542
|
@Override
|
543
|
public void buttonClick(ClickEvent event) {
|
544
|
Set<Object> selectedItemIds = (Set)taxaTreeTable.getValue();
|
545
|
if(selectedItemIds.isEmpty()) {
|
546
|
Notification.show("No Taxa / Synonyms selected", "Please select taxa or synonyms to delete", Type.WARNING_MESSAGE);
|
547
|
} else {
|
548
|
Notification.show("Deleting selected Taxa / Synonyms", "Implement me", Type.WARNING_MESSAGE);
|
549
|
}
|
550
|
}
|
551
|
});
|
552
|
}
|
553
|
|
554
|
|
555
|
|
556
|
/* (non-Javadoc)
|
557
|
* @see eu.etaxonomy.cdm.vaadin.view.IStatusComponent#setListener(eu.etaxonomy.cdm.vaadin.view.IStatusComponent.StatusComponentListener)
|
558
|
*/
|
559
|
@Override
|
560
|
public void setListener(StatusComponentListener listener) {
|
561
|
this.listener = listener;
|
562
|
}
|
563
|
|
564
|
|
565
|
class TaxonTableCheckBoxGenerator implements Table.ColumnGenerator {
|
566
|
|
567
|
|
568
|
/**
|
569
|
* Generates the cell containing an open image when boolean is true
|
570
|
*/
|
571
|
@Override
|
572
|
public Component generateCell(Table source, final Object itemId, Object columnId) {
|
573
|
if(source.getItem(itemId) != null) {
|
574
|
Property prop = source.getItem(itemId).getItemProperty(columnId);
|
575
|
if(prop == null) {
|
576
|
return null;
|
577
|
}
|
578
|
CheckBox cb = new CheckBox(null, prop);
|
579
|
ValueChangeListener pbListener = new ValueChangeListener() {
|
580
|
@Override
|
581
|
public void valueChange(ValueChangeEvent event) {
|
582
|
boolean value = (Boolean) event.getProperty().getValue();
|
583
|
listener.updatePublished(value, itemId);
|
584
|
}
|
585
|
};
|
586
|
cb.addValueChangeListener(pbListener);
|
587
|
cb.setData(itemId);
|
588
|
return cb;
|
589
|
} else {
|
590
|
return null;
|
591
|
}
|
592
|
|
593
|
}
|
594
|
}
|
595
|
|
596
|
class CheckBoxGenerator implements Table.ColumnGenerator {
|
597
|
|
598
|
private final ValueChangeListener vcListener;
|
599
|
|
600
|
public CheckBoxGenerator(ValueChangeListener vcListener) {
|
601
|
this.vcListener = vcListener;
|
602
|
}
|
603
|
|
604
|
/**
|
605
|
* Generates the cell containing an open image when boolean is true
|
606
|
*/
|
607
|
@Override
|
608
|
public Component generateCell(Table source, final Object itemId, Object columnId) {
|
609
|
if(source.getItem(itemId) != null) {
|
610
|
Property prop = source.getItem(itemId).getItemProperty(columnId);
|
611
|
if(prop == null) {
|
612
|
return null;
|
613
|
}
|
614
|
CheckBox cb = new CheckBox(null, prop);
|
615
|
cb.addValueChangeListener(vcListener);
|
616
|
cb.setData(itemId);
|
617
|
return cb;
|
618
|
} else {
|
619
|
return null;
|
620
|
}
|
621
|
}
|
622
|
}
|
623
|
|
624
|
|
625
|
/* (non-Javadoc)
|
626
|
* @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onCreate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
|
627
|
*/
|
628
|
@Override
|
629
|
public void onCreate(CdmChangeEvent event) {
|
630
|
if(event.getSourceType().equals(NewTaxonBaseComposite.class)) {
|
631
|
Object itemId = event.getChangedObjects().get(0);
|
632
|
try {
|
633
|
taxaTreeTable.setMultiSelect(false);
|
634
|
if(listener.getCurrentLeafNodeTaxonContainer().isSynonym(itemId)) {
|
635
|
taxaTreeTable.setCollapsed(taxaTreeTable.getValue(), false);
|
636
|
listener.refresh();
|
637
|
taxaTreeTable.setValue(itemId);
|
638
|
} else {
|
639
|
clearDynamicFilters();
|
640
|
listener.setIdFilter(itemId);
|
641
|
taxaTreeTable.setValue(itemId);
|
642
|
}
|
643
|
} finally {
|
644
|
taxaTreeTable.setMultiSelect(taxaTreeTableMultiSelectMode);
|
645
|
}
|
646
|
}
|
647
|
}
|
648
|
|
649
|
/* (non-Javadoc)
|
650
|
* @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onUpdate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
|
651
|
*/
|
652
|
@Override
|
653
|
public void onUpdate(CdmChangeEvent event) {
|
654
|
// TODO Auto-generated method stub
|
655
|
|
656
|
}
|
657
|
|
658
|
/* (non-Javadoc)
|
659
|
* @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onDelete(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
|
660
|
*/
|
661
|
@Override
|
662
|
public void onDelete(CdmChangeEvent event) {
|
663
|
// TODO Auto-generated method stub
|
664
|
|
665
|
}
|
666
|
|
667
|
/* (non-Javadoc)
|
668
|
* @see com.vaadin.navigator.View#enter(com.vaadin.navigator.ViewChangeListener.ViewChangeEvent)
|
669
|
*/
|
670
|
@Override
|
671
|
public void enter(ViewChangeEvent event) {
|
672
|
// TODO Auto-generated method stub
|
673
|
|
674
|
}
|
675
|
|
676
|
@AutoGenerated
|
677
|
private GridLayout buildMainLayout() {
|
678
|
// common part: create layout
|
679
|
mainLayout = new GridLayout();
|
680
|
mainLayout.setImmediate(false);
|
681
|
mainLayout.setWidth("340px");
|
682
|
mainLayout.setHeight("840px");
|
683
|
mainLayout.setMargin(true);
|
684
|
mainLayout.setRows(6);
|
685
|
|
686
|
// top-level component properties
|
687
|
setWidth("340px");
|
688
|
setHeight("840px");
|
689
|
|
690
|
// classificationComboBox
|
691
|
classificationComboBox = new ComboBox();
|
692
|
classificationComboBox.setImmediate(false);
|
693
|
classificationComboBox.setWidth("100.0%");
|
694
|
classificationComboBox.setHeight("-1px");
|
695
|
mainLayout.addComponent(classificationComboBox, 0, 0);
|
696
|
|
697
|
// filterVerticalLayout
|
698
|
filterVerticalLayout = buildFilterVerticalLayout();
|
699
|
mainLayout.addComponent(filterVerticalLayout, 0, 1);
|
700
|
mainLayout.setComponentAlignment(filterVerticalLayout, new Alignment(20));
|
701
|
|
702
|
// addRemovehorizontalLayout
|
703
|
addRemovehorizontalLayout = buildAddRemovehorizontalLayout();
|
704
|
mainLayout.addComponent(addRemovehorizontalLayout, 0, 2);
|
705
|
mainLayout.setComponentAlignment(addRemovehorizontalLayout, new Alignment(48));
|
706
|
|
707
|
// searchHorizontalLayout
|
708
|
searchHorizontalLayout = buildSearchHorizontalLayout();
|
709
|
mainLayout.addComponent(searchHorizontalLayout, 0, 3);
|
710
|
mainLayout.setComponentAlignment(searchHorizontalLayout, new Alignment(48));
|
711
|
|
712
|
// taxaTreeTable
|
713
|
taxaTreeTable = new TreeTable();
|
714
|
taxaTreeTable.setImmediate(false);
|
715
|
taxaTreeTable.setWidth("100.0%");
|
716
|
taxaTreeTable.setHeight("580px");
|
717
|
mainLayout.addComponent(taxaTreeTable, 0, 4);
|
718
|
mainLayout.setComponentAlignment(taxaTreeTable, new Alignment(20));
|
719
|
|
720
|
// inViewLabel
|
721
|
inViewLabel = new Label();
|
722
|
inViewLabel.setImmediate(false);
|
723
|
inViewLabel.setWidth("100.0%");
|
724
|
inViewLabel.setHeight("-1px");
|
725
|
inViewLabel.setValue("in view : ");
|
726
|
mainLayout.addComponent(inViewLabel, 0, 5);
|
727
|
|
728
|
return mainLayout;
|
729
|
}
|
730
|
|
731
|
@AutoGenerated
|
732
|
private VerticalLayout buildFilterVerticalLayout() {
|
733
|
// common part: create layout
|
734
|
filterVerticalLayout = new VerticalLayout();
|
735
|
filterVerticalLayout.setImmediate(false);
|
736
|
filterVerticalLayout.setWidth("100.0%");
|
737
|
filterVerticalLayout.setHeight("-1px");
|
738
|
filterVerticalLayout.setMargin(false);
|
739
|
|
740
|
// filterLabel
|
741
|
filterLabel = new Label();
|
742
|
filterLabel.setImmediate(false);
|
743
|
filterLabel.setWidth("100.0%");
|
744
|
filterLabel.setHeight("-1px");
|
745
|
filterLabel.setValue("Filter by :");
|
746
|
filterVerticalLayout.addComponent(filterLabel);
|
747
|
|
748
|
// filterTable
|
749
|
filterTable = new Table();
|
750
|
filterTable.setImmediate(false);
|
751
|
filterTable.setWidth("100.0%");
|
752
|
filterTable.setHeight("86px");
|
753
|
filterVerticalLayout.addComponent(filterTable);
|
754
|
filterVerticalLayout.setComponentAlignment(filterTable, new Alignment(48));
|
755
|
|
756
|
return filterVerticalLayout;
|
757
|
}
|
758
|
|
759
|
@AutoGenerated
|
760
|
private HorizontalLayout buildAddRemovehorizontalLayout() {
|
761
|
// common part: create layout
|
762
|
addRemovehorizontalLayout = new HorizontalLayout();
|
763
|
addRemovehorizontalLayout.setImmediate(false);
|
764
|
addRemovehorizontalLayout.setWidth("100.0%");
|
765
|
addRemovehorizontalLayout.setHeight("-1px");
|
766
|
addRemovehorizontalLayout.setMargin(false);
|
767
|
addRemovehorizontalLayout.setSpacing(true);
|
768
|
|
769
|
// addComboBox
|
770
|
addComboBox = new ComboBox();
|
771
|
addComboBox.setImmediate(false);
|
772
|
addComboBox.setWidth("100.0%");
|
773
|
addComboBox.setHeight("-1px");
|
774
|
addRemovehorizontalLayout.addComponent(addComboBox);
|
775
|
addRemovehorizontalLayout.setExpandRatio(addComboBox, 3.0f);
|
776
|
|
777
|
// removeButton
|
778
|
removeButton = new Button();
|
779
|
removeButton.setCaption("Remove");
|
780
|
removeButton.setImmediate(true);
|
781
|
removeButton.setWidth("100.0%");
|
782
|
removeButton.setHeight("-1px");
|
783
|
addRemovehorizontalLayout.addComponent(removeButton);
|
784
|
addRemovehorizontalLayout.setExpandRatio(removeButton, 2.0f);
|
785
|
|
786
|
return addRemovehorizontalLayout;
|
787
|
}
|
788
|
|
789
|
@AutoGenerated
|
790
|
private HorizontalLayout buildSearchHorizontalLayout() {
|
791
|
// common part: create layout
|
792
|
searchHorizontalLayout = new HorizontalLayout();
|
793
|
searchHorizontalLayout.setImmediate(false);
|
794
|
searchHorizontalLayout.setWidth("100.0%");
|
795
|
searchHorizontalLayout.setHeight("-1px");
|
796
|
searchHorizontalLayout.setMargin(false);
|
797
|
searchHorizontalLayout.setSpacing(true);
|
798
|
|
799
|
// searchTextField
|
800
|
searchTextField = new TextField();
|
801
|
searchTextField.setImmediate(false);
|
802
|
searchTextField.setWidth("100.0%");
|
803
|
searchTextField.setHeight("-1px");
|
804
|
searchHorizontalLayout.addComponent(searchTextField);
|
805
|
searchHorizontalLayout.setExpandRatio(searchTextField, 4.0f);
|
806
|
searchHorizontalLayout.setComponentAlignment(searchTextField, new Alignment(48));
|
807
|
|
808
|
// clearSearchButton
|
809
|
clearSearchButton = new Button();
|
810
|
clearSearchButton.setCaption("Button");
|
811
|
clearSearchButton.setImmediate(true);
|
812
|
clearSearchButton.setWidth("100.0%");
|
813
|
clearSearchButton.setHeight("-1px");
|
814
|
searchHorizontalLayout.addComponent(clearSearchButton);
|
815
|
searchHorizontalLayout.setExpandRatio(clearSearchButton, 1.0f);
|
816
|
searchHorizontalLayout.setComponentAlignment(clearSearchButton, new Alignment(48));
|
817
|
|
818
|
return searchHorizontalLayout;
|
819
|
}
|
820
|
|
821
|
}
|