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