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
|
if(source.getItem(itemId) == null) {
|
201
|
return null;
|
202
|
}
|
203
|
Property hasSynProperty = source.getItem(itemId).getItemProperty(LeafNodeTaxonContainer.HAS_SYN_ID);
|
204
|
if(hasSynProperty == null) {
|
205
|
// this is a synonym, so we activate the corresponding css class
|
206
|
return "synonym";
|
207
|
}
|
208
|
return null;
|
209
|
}
|
210
|
});
|
211
|
|
212
|
// NOTE : Not really sure why we need to refresh the container here.
|
213
|
// in the case of 'Table' this is not required
|
214
|
listener.refresh();
|
215
|
updateInViewLabel();
|
216
|
}
|
217
|
|
218
|
|
219
|
final Action changeAcceptedTaxonToSynonymAction = new Action("Change Accepted Taxon To Synonym");
|
220
|
|
221
|
|
222
|
taxaTreeTable.addActionHandler(new Action.Handler() {
|
223
|
@Override
|
224
|
public Action[] getActions(final Object target, final Object sender) {
|
225
|
return new Action[] { changeAcceptedTaxonToSynonymAction };
|
226
|
}
|
227
|
|
228
|
@Override
|
229
|
public void handleAction(final Action action, final Object sender,
|
230
|
final Object target) {
|
231
|
Notification.show("action for Change Accepted Taxon To Synonym", "Implement me", Type.WARNING_MESSAGE);
|
232
|
}
|
233
|
});
|
234
|
|
235
|
}
|
236
|
|
237
|
private void initClassificationComboBox() {
|
238
|
|
239
|
classificationComboBox.setNewItemsAllowed(false);
|
240
|
classificationComboBox.setNullSelectionAllowed(false);
|
241
|
classificationComboBox.setImmediate(true);
|
242
|
classificationComboBox.setItemCaptionPropertyId("titleCache");
|
243
|
classificationComboBox.setInputPrompt(SELECT_CLASSIFICATION);
|
244
|
if(listener != null) {
|
245
|
try {
|
246
|
classificationComboBox.setContainerDataSource(listener.loadClassifications());
|
247
|
} catch (SQLException e) {
|
248
|
//TODO : throw up warning dialog
|
249
|
e.printStackTrace();
|
250
|
}
|
251
|
}
|
252
|
}
|
253
|
|
254
|
|
255
|
|
256
|
private void initFilterTable() {
|
257
|
filterTable.setNullSelectionAllowed(false);
|
258
|
final IndexedContainer container = new IndexedContainer();
|
259
|
container.addContainerProperty("filter", String.class, "");
|
260
|
container.addContainerProperty("selected", Boolean.class, "");
|
261
|
|
262
|
Item item = container.addItem(FILTER_NOT_RESOLVED);
|
263
|
item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_NOT_RESOLVED);
|
264
|
item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
|
265
|
|
266
|
item = container.addItem(FILTER_UNPLACED);
|
267
|
item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_UNPLACED);
|
268
|
item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
|
269
|
|
270
|
item = container.addItem(FILTER_UNFINISHED);
|
271
|
item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_UNFINISHED);
|
272
|
item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
|
273
|
|
274
|
item = container.addItem(FILTER_UNPUBLISHED);
|
275
|
item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_UNPUBLISHED);
|
276
|
item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
|
277
|
|
278
|
|
279
|
filterTable.setContainerDataSource(container);
|
280
|
filterTable.setColumnHeaderMode(ColumnHeaderMode.HIDDEN);
|
281
|
|
282
|
|
283
|
ValueChangeListener selectedListener = new ValueChangeListener() {
|
284
|
|
285
|
private static final long serialVersionUID = -5551250788805117454L;
|
286
|
|
287
|
@Override
|
288
|
public void valueChange(ValueChangeEvent event) {
|
289
|
boolean value = (Boolean) event.getProperty().getValue();
|
290
|
String selectedFilter = (String)filterTable.getItem(((CheckBox)event.getProperty()).getData()).getItemProperty(PROPERTY_FILTER_ID).getValue();
|
291
|
if(selectedFilter != null) {
|
292
|
if(value) {
|
293
|
if(selectedFilter.equals(FILTER_UNPLACED)) {
|
294
|
listener.setUnplacedFilter();
|
295
|
}
|
296
|
if(selectedFilter.equals(FILTER_UNPUBLISHED)) {
|
297
|
listener.setUnpublishedFilter();
|
298
|
}
|
299
|
} else {
|
300
|
if(selectedFilter.equals(FILTER_UNPLACED)) {
|
301
|
listener.removeUnplacedFilter();
|
302
|
}
|
303
|
if(selectedFilter.equals(FILTER_UNPUBLISHED)) {
|
304
|
listener.removeUnpublishedFilter();
|
305
|
}
|
306
|
}
|
307
|
updateInViewLabel();
|
308
|
}
|
309
|
}
|
310
|
|
311
|
|
312
|
};
|
313
|
filterTable.addGeneratedColumn(PROPERTY_SELECTED_ID, new CheckBoxGenerator(selectedListener));
|
314
|
|
315
|
}
|
316
|
|
317
|
private void updateInViewLabel() {
|
318
|
inViewLabel.setValue(IN_VIEW_PREFIX + String.valueOf(listener.getCurrentNoOfTaxa()) + " / " + String.valueOf(listener.getTotalNoOfTaxa()) + " taxa");
|
319
|
}
|
320
|
|
321
|
private void initSearchTextField() {
|
322
|
searchTextField.setInputPrompt(FILTER_TAXA_INPUT);
|
323
|
}
|
324
|
|
325
|
|
326
|
private void initAddComboBox() {
|
327
|
addComboBox.setNullSelectionAllowed(false);
|
328
|
addComboBox.setImmediate(true);
|
329
|
addComboBox.addItem(ADD_TAXON_SYNONYM_INPUT);
|
330
|
addComboBox.addItem(ADD_TAXON);
|
331
|
addComboBox.addItem(ADD_SYNONYM);
|
332
|
addComboBox.setValue(ADD_TAXON_SYNONYM_INPUT);
|
333
|
|
334
|
}
|
335
|
|
336
|
private void initClearSearchButton() {
|
337
|
clearSearchButton.setIcon(FontAwesome.REFRESH);
|
338
|
clearSearchButton.setCaption("");
|
339
|
}
|
340
|
|
341
|
private void addUIListeners() {
|
342
|
|
343
|
searchHorizontalLayout.addLayoutClickListener(new LayoutClickListener() {
|
344
|
|
345
|
@Override
|
346
|
public void layoutClick(LayoutClickEvent event) {
|
347
|
if (event.getChildComponent() == searchTextField && searchTextField.getValue().equals(FILTER_TAXA_INPUT)) {
|
348
|
searchTextField.setValue("");
|
349
|
}
|
350
|
}
|
351
|
});
|
352
|
|
353
|
addClassificationComboBoxListener();
|
354
|
addTaxaTreeTableListener();
|
355
|
addAddComboBoxListener();
|
356
|
addRemoveButtonListener();
|
357
|
addSearchTextFieldListener();
|
358
|
addClearSearchButtonListener();
|
359
|
}
|
360
|
|
361
|
private void addClassificationComboBoxListener() {
|
362
|
|
363
|
classificationComboBox.addValueChangeListener(new Property.ValueChangeListener() {
|
364
|
|
365
|
private static final long serialVersionUID = 4196786323147791606L;
|
366
|
|
367
|
@Override
|
368
|
public void valueChange(ValueChangeEvent event) {
|
369
|
if (classificationComboBox.getValue() != null) {
|
370
|
Object selected = classificationComboBox.getValue();
|
371
|
logger.info("selected : " + selected);
|
372
|
int classificationId = (Integer)((RowId)selected).getId()[0];
|
373
|
initTaxaTable(classificationId);
|
374
|
initFilterTable();
|
375
|
setEnabledAll(true);
|
376
|
}
|
377
|
}
|
378
|
});
|
379
|
}
|
380
|
|
381
|
private void addTaxaTreeTableListener() {
|
382
|
taxaTreeTable.addItemClickListener(new ItemClickListener() {
|
383
|
|
384
|
@Override
|
385
|
public void itemClick(ItemClickEvent event) {
|
386
|
|
387
|
Object itemId = event.getItemId();
|
388
|
if(!listener.isSynonym(itemId)) {
|
389
|
UUID taxonUuid = listener.getCurrentLeafNodeTaxonContainer().getUuid(itemId);
|
390
|
CdmVaadinSessionUtilities.getCurrentSelectionService()
|
391
|
.fireSelectionEvent(new SelectionEvent(Arrays.asList((Object)taxonUuid), StatusComposite.class), true);
|
392
|
}
|
393
|
}
|
394
|
});
|
395
|
|
396
|
}
|
397
|
|
398
|
private void addAddComboBoxListener() {
|
399
|
addComboBox.addValueChangeListener(new Property.ValueChangeListener() {
|
400
|
|
401
|
private static final long serialVersionUID = -6235423275051269517L;
|
402
|
|
403
|
@Override
|
404
|
public void valueChange(ValueChangeEvent event) {
|
405
|
if (addComboBox.getValue() != null) {
|
406
|
String selected = (String)addComboBox.getValue();
|
407
|
if(!selected.equals(ADD_TAXON_SYNONYM_INPUT)) {
|
408
|
try {
|
409
|
String windowTitle;
|
410
|
|
411
|
Object selectedItemId = null;
|
412
|
IdAndUuid accTaxonIdUuid = null;
|
413
|
if(selected.equals(ADD_SYNONYM)) {
|
414
|
Set<Object> selectedIds = (Set<Object>)taxaTreeTable.getValue();
|
415
|
// if zero or more than one items (taxa / synonyms) are selected
|
416
|
// throw a warning
|
417
|
if(selectedIds.size() == 0) {
|
418
|
Notification.show("Multiple or No selection", "Please select a single Taxon", Type.WARNING_MESSAGE);
|
419
|
return;
|
420
|
}
|
421
|
// if a synonym is selected then throw warning
|
422
|
if(listener.isSynonym(selected)) {
|
423
|
Notification.show("Synonym selected", "Please choose a Taxon", Type.WARNING_MESSAGE);
|
424
|
return;
|
425
|
}
|
426
|
windowTitle = "Add New Synonym";
|
427
|
selectedItemId = selectedIds.iterator().next();
|
428
|
accTaxonIdUuid = new IdAndUuid(selectedItemId, listener.getCurrentLeafNodeTaxonContainer().getUuid(selectedItemId));
|
429
|
} else {
|
430
|
windowTitle = "Add New Taxon";
|
431
|
}
|
432
|
|
433
|
try {
|
434
|
Window dialog = new Window(windowTitle);
|
435
|
dialog.setModal(true);
|
436
|
dialog.setClosable(false);
|
437
|
dialog.setResizable(false);
|
438
|
UI.getCurrent().addWindow(dialog);
|
439
|
|
440
|
UUID classificationUuid = listener.getClassificationContainer().getUuid(classificationComboBox.getValue());
|
441
|
IdAndUuid classificationIdUuid = new IdAndUuid(classificationComboBox.getValue(), classificationUuid);
|
442
|
NewTaxonBaseComposite newTaxonComponent =
|
443
|
new NewTaxonBaseComposite(dialog,
|
444
|
new NewTaxonBasePresenter(),
|
445
|
accTaxonIdUuid,
|
446
|
classificationIdUuid);
|
447
|
dialog.setContent(newTaxonComponent);
|
448
|
} catch (SQLException e) {
|
449
|
// TODO Auto-generated catch block
|
450
|
e.printStackTrace();
|
451
|
}
|
452
|
} finally {
|
453
|
addComboBox.setValue(ADD_TAXON_SYNONYM_INPUT);
|
454
|
}
|
455
|
}
|
456
|
}
|
457
|
}
|
458
|
});
|
459
|
}
|
460
|
|
461
|
private void addSearchTextFieldListener() {
|
462
|
searchTextField.addTextChangeListener(new FieldEvents.TextChangeListener() {
|
463
|
|
464
|
private static final long serialVersionUID = -7376538870420619534L;
|
465
|
|
466
|
@Override
|
467
|
public void textChange(TextChangeEvent event) {
|
468
|
listener.setNameFilter(event.getText());
|
469
|
updateInViewLabel();
|
470
|
}
|
471
|
|
472
|
});
|
473
|
|
474
|
}
|
475
|
|
476
|
private void addClearSearchButtonListener() {
|
477
|
clearSearchButton.addClickListener(new Button.ClickListener() {
|
478
|
|
479
|
@Override
|
480
|
public void buttonClick(ClickEvent event) {
|
481
|
listener.removeNameFilter();
|
482
|
searchTextField.setValue(FILTER_TAXA_INPUT);
|
483
|
updateInViewLabel();
|
484
|
}
|
485
|
|
486
|
});
|
487
|
}
|
488
|
|
489
|
private void addRemoveButtonListener() {
|
490
|
removeButton.addClickListener(new Button.ClickListener() {
|
491
|
|
492
|
@Override
|
493
|
public void buttonClick(ClickEvent event) {
|
494
|
Set<Object> selectedItemIds = (Set)taxaTreeTable.getValue();
|
495
|
if(selectedItemIds.isEmpty()) {
|
496
|
Notification.show("No Taxa / Synonyms selected", "Please select taxa or synonyms to delete", Type.WARNING_MESSAGE);
|
497
|
} else {
|
498
|
Notification.show("Deleting selected Taxa / Synonyms", "Implement me", Type.WARNING_MESSAGE);
|
499
|
}
|
500
|
}
|
501
|
|
502
|
});
|
503
|
}
|
504
|
|
505
|
|
506
|
|
507
|
/* (non-Javadoc)
|
508
|
* @see eu.etaxonomy.cdm.vaadin.view.IStatusComponent#setListener(eu.etaxonomy.cdm.vaadin.view.IStatusComponent.StatusComponentListener)
|
509
|
*/
|
510
|
@Override
|
511
|
public void setListener(StatusComponentListener listener) {
|
512
|
this.listener = listener;
|
513
|
}
|
514
|
|
515
|
|
516
|
class TaxonTableCheckBoxGenerator implements Table.ColumnGenerator {
|
517
|
|
518
|
|
519
|
/**
|
520
|
* Generates the cell containing an open image when boolean is true
|
521
|
*/
|
522
|
@Override
|
523
|
public Component generateCell(Table source, final Object itemId, Object columnId) {
|
524
|
if(source.getItem(itemId) != null) {
|
525
|
Property prop = source.getItem(itemId).getItemProperty(columnId);
|
526
|
if(prop == null) {
|
527
|
return null;
|
528
|
}
|
529
|
CheckBox cb = new CheckBox(null, prop);
|
530
|
ValueChangeListener pbListener = new ValueChangeListener() {
|
531
|
@Override
|
532
|
public void valueChange(ValueChangeEvent event) {
|
533
|
boolean value = (Boolean) event.getProperty().getValue();
|
534
|
listener.updatePublished(value, itemId);
|
535
|
}
|
536
|
};
|
537
|
cb.addValueChangeListener(pbListener);
|
538
|
cb.setData(itemId);
|
539
|
return cb;
|
540
|
} else {
|
541
|
return null;
|
542
|
}
|
543
|
|
544
|
}
|
545
|
}
|
546
|
|
547
|
class CheckBoxGenerator implements Table.ColumnGenerator {
|
548
|
|
549
|
private final ValueChangeListener vcListener;
|
550
|
|
551
|
public CheckBoxGenerator(ValueChangeListener vcListener) {
|
552
|
this.vcListener = vcListener;
|
553
|
}
|
554
|
|
555
|
/**
|
556
|
* Generates the cell containing an open image when boolean is true
|
557
|
*/
|
558
|
@Override
|
559
|
public Component generateCell(Table source, final Object itemId, Object columnId) {
|
560
|
if(source.getItem(itemId) != null) {
|
561
|
Property prop = source.getItem(itemId).getItemProperty(columnId);
|
562
|
if(prop == null) {
|
563
|
return null;
|
564
|
}
|
565
|
CheckBox cb = new CheckBox(null, prop);
|
566
|
cb.addValueChangeListener(vcListener);
|
567
|
cb.setData(itemId);
|
568
|
return cb;
|
569
|
} else {
|
570
|
return null;
|
571
|
}
|
572
|
|
573
|
}
|
574
|
}
|
575
|
|
576
|
|
577
|
@AutoGenerated
|
578
|
private GridLayout buildMainLayout() {
|
579
|
// common part: create layout
|
580
|
mainLayout = new GridLayout();
|
581
|
mainLayout.setImmediate(false);
|
582
|
mainLayout.setWidth("340px");
|
583
|
mainLayout.setHeight("840px");
|
584
|
mainLayout.setMargin(true);
|
585
|
mainLayout.setSpacing(true);
|
586
|
mainLayout.setRows(6);
|
587
|
|
588
|
// top-level component properties
|
589
|
setWidth("340px");
|
590
|
setHeight("840px");
|
591
|
|
592
|
// classificationComboBox
|
593
|
classificationComboBox = new ComboBox();
|
594
|
classificationComboBox.setImmediate(false);
|
595
|
classificationComboBox.setWidth("100.0%");
|
596
|
classificationComboBox.setHeight("-1px");
|
597
|
mainLayout.addComponent(classificationComboBox, 0, 0);
|
598
|
|
599
|
// filterVerticalLayout
|
600
|
filterVerticalLayout = buildFilterVerticalLayout();
|
601
|
mainLayout.addComponent(filterVerticalLayout, 0, 1);
|
602
|
mainLayout.setComponentAlignment(filterVerticalLayout, new Alignment(20));
|
603
|
|
604
|
// addRemovehorizontalLayout
|
605
|
addRemovehorizontalLayout = buildAddRemovehorizontalLayout();
|
606
|
mainLayout.addComponent(addRemovehorizontalLayout, 0, 2);
|
607
|
mainLayout.setComponentAlignment(addRemovehorizontalLayout, new Alignment(48));
|
608
|
|
609
|
// searchHorizontalLayout
|
610
|
searchHorizontalLayout = buildSearchHorizontalLayout();
|
611
|
mainLayout.addComponent(searchHorizontalLayout, 0, 3);
|
612
|
mainLayout.setComponentAlignment(searchHorizontalLayout, new Alignment(48));
|
613
|
|
614
|
// taxaTreeTable
|
615
|
taxaTreeTable = new TreeTable();
|
616
|
taxaTreeTable.setImmediate(false);
|
617
|
taxaTreeTable.setWidth("100.0%");
|
618
|
taxaTreeTable.setHeight("534px");
|
619
|
mainLayout.addComponent(taxaTreeTable, 0, 4);
|
620
|
mainLayout.setComponentAlignment(taxaTreeTable, new Alignment(20));
|
621
|
|
622
|
// inViewLabel
|
623
|
inViewLabel = new Label();
|
624
|
inViewLabel.setImmediate(false);
|
625
|
inViewLabel.setWidth("100.0%");
|
626
|
inViewLabel.setHeight("-1px");
|
627
|
inViewLabel.setValue("in view : ");
|
628
|
mainLayout.addComponent(inViewLabel, 0, 5);
|
629
|
|
630
|
return mainLayout;
|
631
|
}
|
632
|
|
633
|
@AutoGenerated
|
634
|
private VerticalLayout buildFilterVerticalLayout() {
|
635
|
// common part: create layout
|
636
|
filterVerticalLayout = new VerticalLayout();
|
637
|
filterVerticalLayout.setImmediate(false);
|
638
|
filterVerticalLayout.setWidth("100.0%");
|
639
|
filterVerticalLayout.setHeight("-1px");
|
640
|
filterVerticalLayout.setMargin(false);
|
641
|
|
642
|
// filterLabel
|
643
|
filterLabel = new Label();
|
644
|
filterLabel.setImmediate(false);
|
645
|
filterLabel.setWidth("100.0%");
|
646
|
filterLabel.setHeight("-1px");
|
647
|
filterLabel.setValue("Filter by :");
|
648
|
filterVerticalLayout.addComponent(filterLabel);
|
649
|
|
650
|
// filterTable
|
651
|
filterTable = new Table();
|
652
|
filterTable.setImmediate(false);
|
653
|
filterTable.setWidth("100.0%");
|
654
|
filterTable.setHeight("86px");
|
655
|
filterVerticalLayout.addComponent(filterTable);
|
656
|
filterVerticalLayout.setComponentAlignment(filterTable, new Alignment(48));
|
657
|
|
658
|
return filterVerticalLayout;
|
659
|
}
|
660
|
|
661
|
@AutoGenerated
|
662
|
private HorizontalLayout buildAddRemovehorizontalLayout() {
|
663
|
// common part: create layout
|
664
|
addRemovehorizontalLayout = new HorizontalLayout();
|
665
|
addRemovehorizontalLayout.setImmediate(false);
|
666
|
addRemovehorizontalLayout.setWidth("100.0%");
|
667
|
addRemovehorizontalLayout.setHeight("-1px");
|
668
|
addRemovehorizontalLayout.setMargin(false);
|
669
|
addRemovehorizontalLayout.setSpacing(true);
|
670
|
|
671
|
// addComboBox
|
672
|
addComboBox = new ComboBox();
|
673
|
addComboBox.setImmediate(false);
|
674
|
addComboBox.setWidth("100.0%");
|
675
|
addComboBox.setHeight("-1px");
|
676
|
addRemovehorizontalLayout.addComponent(addComboBox);
|
677
|
addRemovehorizontalLayout.setExpandRatio(addComboBox, 3.0f);
|
678
|
|
679
|
// removeButton
|
680
|
removeButton = new Button();
|
681
|
removeButton.setCaption("Remove");
|
682
|
removeButton.setImmediate(true);
|
683
|
removeButton.setWidth("100.0%");
|
684
|
removeButton.setHeight("-1px");
|
685
|
addRemovehorizontalLayout.addComponent(removeButton);
|
686
|
addRemovehorizontalLayout.setExpandRatio(removeButton, 2.0f);
|
687
|
|
688
|
return addRemovehorizontalLayout;
|
689
|
}
|
690
|
|
691
|
@AutoGenerated
|
692
|
private HorizontalLayout buildSearchHorizontalLayout() {
|
693
|
// common part: create layout
|
694
|
searchHorizontalLayout = new HorizontalLayout();
|
695
|
searchHorizontalLayout.setImmediate(false);
|
696
|
searchHorizontalLayout.setWidth("100.0%");
|
697
|
searchHorizontalLayout.setHeight("-1px");
|
698
|
searchHorizontalLayout.setMargin(false);
|
699
|
searchHorizontalLayout.setSpacing(true);
|
700
|
|
701
|
// searchTextField
|
702
|
searchTextField = new TextField();
|
703
|
searchTextField.setImmediate(false);
|
704
|
searchTextField.setWidth("100.0%");
|
705
|
searchTextField.setHeight("-1px");
|
706
|
searchHorizontalLayout.addComponent(searchTextField);
|
707
|
searchHorizontalLayout.setExpandRatio(searchTextField, 4.0f);
|
708
|
searchHorizontalLayout.setComponentAlignment(searchTextField, new Alignment(48));
|
709
|
|
710
|
// clearSearchButton
|
711
|
clearSearchButton = new Button();
|
712
|
clearSearchButton.setCaption("Button");
|
713
|
clearSearchButton.setImmediate(true);
|
714
|
clearSearchButton.setWidth("100.0%");
|
715
|
clearSearchButton.setHeight("-1px");
|
716
|
searchHorizontalLayout.addComponent(clearSearchButton);
|
717
|
searchHorizontalLayout.setExpandRatio(clearSearchButton, 1.0f);
|
718
|
searchHorizontalLayout.setComponentAlignment(clearSearchButton, new Alignment(48));
|
719
|
|
720
|
return searchHorizontalLayout;
|
721
|
}
|
722
|
|
723
|
/* (non-Javadoc)
|
724
|
* @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onCreate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
|
725
|
*/
|
726
|
@Override
|
727
|
public void onCreate(CdmChangeEvent event) {
|
728
|
if(event.getSourceType().equals(NewTaxonBaseComposite.class)) {
|
729
|
Object itemId = event.getChangedObjects().get(0);
|
730
|
listener.getCurrentLeafNodeTaxonContainer().removeTaxonFromCache(itemId);
|
731
|
|
732
|
// FIXME : need to figure out how to programmatically select an item in the
|
733
|
// table
|
734
|
|
735
|
listener.getCurrentLeafNodeTaxonContainer().getItem(itemId);
|
736
|
listener.refresh();
|
737
|
taxaTreeTable.select(itemId);
|
738
|
}
|
739
|
|
740
|
}
|
741
|
|
742
|
/* (non-Javadoc)
|
743
|
* @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onUpdate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
|
744
|
*/
|
745
|
@Override
|
746
|
public void onUpdate(CdmChangeEvent event) {
|
747
|
// TODO Auto-generated method stub
|
748
|
|
749
|
}
|
750
|
|
751
|
/* (non-Javadoc)
|
752
|
* @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onDelete(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
|
753
|
*/
|
754
|
@Override
|
755
|
public void onDelete(CdmChangeEvent event) {
|
756
|
// TODO Auto-generated method stub
|
757
|
|
758
|
}
|
759
|
|
760
|
/* (non-Javadoc)
|
761
|
* @see com.vaadin.navigator.View#enter(com.vaadin.navigator.ViewChangeListener.ViewChangeEvent)
|
762
|
*/
|
763
|
@Override
|
764
|
public void enter(ViewChangeEvent event) {
|
765
|
// TODO Auto-generated method stub
|
766
|
|
767
|
}
|
768
|
|
769
|
}
|