Project

General

Profile

Download (31.3 KB) Statistics
| Branch: | Tag: | Revision:
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 void setTaxaTableEnabled(boolean enabled) {
182
//        taxaTreeTable.setEnabled(enabled);
183
//    }
184
//
185
//    public void setTaxaTableSelectable(boolean isTaxaTableSelectable) {
186
//        taxaTreeTable.setSelectable(isTaxaTableSelectable);
187
//    }
188

    
189
    public TreeTable getTaxaTreeTable() {
190
        return taxaTreeTable;
191
    }
192

    
193
    public LeafNodeTaxonContainer getTaxonContainer() {
194
        return listener.getCurrentLeafNodeTaxonContainer();
195
    }
196

    
197
    public void clearTaxaTableSelections() {
198
        taxaTreeTable.setValue(null);
199
    }
200

    
201
    public UUID getSelectedClassificationUuid() {
202
        if(classificationComboBox.getValue() != null) {
203
            return listener.getClassificationContainer().getUuid(classificationComboBox.getValue());
204
        }
205
        return null;
206
    }
207

    
208
    private void initTaxaTable(int classificationId) {
209
        taxaTreeTable.setMultiSelect(taxaTreeTableMultiSelectMode);
210
        taxaTreeTable.setImmediate(false);
211
        taxaTreeTable.setDragMode(TableDragMode.ROW);
212
        if(listener != null) {
213
            List<String> columnIds = new ArrayList<String>();
214
            columnIds.add(LeafNodeTaxonContainer.NAME_ID);
215
            taxaTreeTable.setColumnExpandRatio(LeafNodeTaxonContainer.NAME_ID, 1);
216
            columnIds.add(LeafNodeTaxonContainer.PB_ID);
217
            taxaTreeTable.setColumnWidth(LeafNodeTaxonContainer.PB_ID, 25);
218

    
219
            if(!isTaxaTableInitialised) {
220
                taxaTreeTable.addGeneratedColumn(LeafNodeTaxonContainer.PB_ID, new TaxonTableCheckBoxGenerator());
221
            }
222

    
223
            try {
224
                taxaTreeTable.setContainerDataSource(listener.loadTaxa(classificationId), columnIds);
225
            } catch (SQLException e) {
226
                //TODO : throw up warning dialog
227
                e.printStackTrace();
228
            }
229

    
230

    
231
            taxaTreeTable.setCellStyleGenerator(new Table.CellStyleGenerator() {
232

    
233
                @Override
234
                public String getStyle(Table source, Object itemId, Object propertyId) {
235
                    if(source.getItem(itemId) == null) {
236
                        return null;
237
                    }
238
                    Property hasSynProperty = source.getItem(itemId).getItemProperty(LeafNodeTaxonContainer.HAS_SYN_ID);
239
                    if(hasSynProperty == null) {
240
                        // this is a synonym, so we activate the corresponding css class
241
                        return "synonym";
242
                    }
243
                    return null;
244
                }
245
            });
246

    
247

    
248

    
249
            // NOTE : Not really sure why we need to refresh the container here.
250
            // in the case of 'Table' this is not required
251
            listener.refresh();
252
            updateInViewLabel();
253
            isTaxaTableInitialised = true;
254
        }
255

    
256

    
257
        final Action changeAcceptedTaxonToSynonymAction = new Action("Change Accepted Taxon To Synonym");
258

    
259

    
260
        taxaTreeTable.addActionHandler(new Action.Handler() {
261
            @Override
262
            public Action[] getActions(final Object target, final Object sender) {
263
                return new Action[] { changeAcceptedTaxonToSynonymAction };
264
            }
265

    
266
            @Override
267
            public void handleAction(final Action action, final Object sender,
268
                    final Object target) {
269
                Notification.show("action for Change Accepted Taxon To Synonym", "Implement me", Type.WARNING_MESSAGE);
270
            }
271
        });
272

    
273
    }
274

    
275
    private void initClassificationComboBox() {
276

    
277
        classificationComboBox.setNewItemsAllowed(false);
278
        classificationComboBox.setNullSelectionAllowed(false);
279
        classificationComboBox.setImmediate(true);
280
        classificationComboBox.setItemCaptionPropertyId(StatusPresenter.C_TCACHE_ID);
281
        classificationComboBox.setInputPrompt(SELECT_CLASSIFICATION);
282
        if(listener != null) {
283
            try {
284
                classificationComboBox.setContainerDataSource(listener.loadClassifications());
285
            } catch (SQLException e) {
286
                //TODO : throw up warning dialog
287
                e.printStackTrace();
288
            }
289
        }
290
    }
291

    
292

    
293

    
294
    private void initFilterTable() {
295
        filterTable.setNullSelectionAllowed(false);
296
        final IndexedContainer container = new IndexedContainer();
297
        container.addContainerProperty("filter", String.class, "");
298
        container.addContainerProperty("selected", Boolean.class, "");
299

    
300
        Item item = container.addItem(FILTER_NOT_RESOLVED);
301
        item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_NOT_RESOLVED);
302
        item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
303

    
304
        item = container.addItem(FILTER_UNPLACED);
305
        item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_UNPLACED);
306
        item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
307

    
308
        item = container.addItem(FILTER_UNFINISHED);
309
        item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_UNFINISHED);
310
        item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
311

    
312
        item = container.addItem(FILTER_UNPUBLISHED);
313
        item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_UNPUBLISHED);
314
        item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
315

    
316

    
317
        filterTable.setContainerDataSource(container);
318
        filterTable.setColumnHeaderMode(ColumnHeaderMode.HIDDEN);
319

    
320

    
321
        ValueChangeListener selectedListener = new ValueChangeListener() {
322

    
323
            private static final long serialVersionUID = -5551250788805117454L;
324

    
325
            @Override
326
            public void valueChange(ValueChangeEvent event) {
327
                boolean value = (Boolean) event.getProperty().getValue();
328
                String selectedFilter = (String)filterTable.getItem(((CheckBox)event.getProperty()).getData()).getItemProperty(PROPERTY_FILTER_ID).getValue();
329
                if(selectedFilter != null) {
330
                    if(value) {
331
                        if(selectedFilter.equals(FILTER_UNPLACED)) {
332
                            listener.setUnplacedFilter();
333
                        }
334
                        if(selectedFilter.equals(FILTER_UNPUBLISHED)) {
335
                            listener.setUnpublishedFilter();
336
                        }
337
                    } else {
338
                        if(selectedFilter.equals(FILTER_UNPLACED)) {
339
                            listener.removeUnplacedFilter();
340
                        }
341
                        if(selectedFilter.equals(FILTER_UNPUBLISHED)) {
342
                            listener.removeUnpublishedFilter();
343
                        }
344
                    }
345
                    updateInViewLabel();
346
                }
347
            }
348
        };
349

    
350
        if(!isFiltertableInitialised) {
351
            filterTable.addGeneratedColumn(PROPERTY_SELECTED_ID, new CheckBoxGenerator(selectedListener));
352
        }
353

    
354
        isFiltertableInitialised = true;
355

    
356
    }
357

    
358
    private void updateInViewLabel() {
359
        inViewLabel.setValue(IN_VIEW_PREFIX + String.valueOf(listener.getCurrentNoOfTaxa()) + " / " + String.valueOf(listener.getTotalNoOfTaxa()) + " taxa");
360
    }
361

    
362
    private void initSearchTextField() {
363
        searchTextField.setInputPrompt(FILTER_TAXA_INPUT);
364
    }
365

    
366

    
367
    private void initAddComboBox() {
368
        addComboBox.setNullSelectionAllowed(false);
369
        addComboBox.setImmediate(true);
370
        addComboBox.addItem(ADD_TAXON_SYNONYM_INPUT);
371
        addComboBox.addItem(ADD_TAXON);
372
        addComboBox.addItem(ADD_SYNONYM);
373
        addComboBox.setValue(ADD_TAXON_SYNONYM_INPUT);
374

    
375
    }
376

    
377
    private void initClearSearchButton() {
378
        clearSearchButton.setIcon(FontAwesome.REFRESH);
379
        clearSearchButton.setCaption("");
380
    }
381

    
382

    
383
    private void addUIListeners() {
384

    
385
        searchHorizontalLayout.addLayoutClickListener(new LayoutClickListener() {
386

    
387
            @Override
388
            public void layoutClick(LayoutClickEvent event) {
389
                if (event.getChildComponent() == searchTextField && searchTextField.getValue().equals(FILTER_TAXA_INPUT)) {
390
                    searchTextField.setValue("");
391
                }
392
            }
393
        });
394

    
395
        addClassificationComboBoxListener();
396
        addTaxaTreeTableListener();
397
        addAddComboBoxListener();
398
        addRemoveButtonListener();
399
        addSearchTextFieldListener();
400
        addClearSearchButtonListener();
401
    }
402

    
403
    private void addClassificationComboBoxListener() {
404

    
405
        classificationComboBox.addValueChangeListener(new Property.ValueChangeListener() {
406

    
407
            private static final long serialVersionUID = 4196786323147791606L;
408

    
409
            @Override
410
            public void valueChange(ValueChangeEvent event) {
411
                if (classificationComboBox.getValue() != null) {
412
                    Object selected = classificationComboBox.getValue();
413
                    int classificationId = (Integer)((RowId)selected).getId()[0];
414
                    initTaxaTable(classificationId);
415
                    initFilterTable();
416
                    setEnabledAll(true);
417
                }
418
            }
419
        });
420
    }
421

    
422
    private void addTaxaTreeTableListener() {
423

    
424
        taxaTreeTable.addItemClickListener(new ItemClickListener() {
425
            @Override
426
            public void itemClick(ItemClickEvent event) {
427
                Object itemId = event.getItemId();
428
                if(taxaTreeTable.isSelectable()) {
429
                    if(!listener.isSynonym(itemId)) {
430
                        UUID taxonUuid = listener.getCurrentLeafNodeTaxonContainer().getUuid(itemId);
431
                        String taxonName = (String)listener.getCurrentLeafNodeTaxonContainer().getProperty(itemId, LeafNodeTaxonContainer.NAME_ID).getValue();
432
                        Object idUuidName = new IdUuidName(itemId, taxonUuid, taxonName);
433
                        CdmVaadinSessionUtilities.getCurrentSelectionService()
434
                        .fireSelectionEvent(new SelectionEvent(Arrays.asList(idUuidName, getSelectedClassificationUuid()), StatusComposite.class), true);
435
                    }
436
                    taxaTreeTable.setValue(itemId);
437
                }
438
            }
439
        });
440
    }
441

    
442
    private void addAddComboBoxListener() {
443
        addComboBox.addValueChangeListener(new Property.ValueChangeListener() {
444

    
445
            private static final long serialVersionUID = -6235423275051269517L;
446

    
447
            @Override
448
            public void valueChange(ValueChangeEvent event) {
449
                if (addComboBox.getValue() != null) {
450
                    String selected = (String)addComboBox.getValue();
451
                    if(!selected.equals(ADD_TAXON_SYNONYM_INPUT)) {
452
                        try {
453
                            String windowTitle;
454

    
455
                            Object selectedItemId = null;
456
                            IdUuidName accTaxonIdUuid = null;
457
                            String accTaxonName = null;
458
                            if(selected.equals(ADD_SYNONYM)) {
459
                                Set<Object> selectedIds = (Set<Object>)taxaTreeTable.getValue();
460
                                // if zero or more than one items (taxa / synonyms) are selected
461
                                // throw a warning
462
                                if(selectedIds.size() != 1) {
463
                                    Notification.show("Multiple or No selection", "Please select a single Taxon", Type.WARNING_MESSAGE);
464
                                    return;
465
                                }
466
                                selectedItemId = selectedIds.iterator().next();
467
                                // if a synonym is selected then throw warning
468
                                if(listener.isSynonym(selectedItemId)) {
469
                                    Notification.show("Synonym selected", "Please choose a Taxon", Type.WARNING_MESSAGE);
470
                                    return;
471
                                }
472
                                windowTitle = "Add New Synonym";
473
                                accTaxonIdUuid = new IdUuidName(selectedItemId,
474
                                        listener.getCurrentLeafNodeTaxonContainer().getUuid(selectedItemId),
475
                                        (String) listener.getCurrentLeafNodeTaxonContainer().getProperty(selectedItemId, LeafNodeTaxonContainer.NAME_ID).getValue());
476
                                accTaxonName = (String)listener.getCurrentLeafNodeTaxonContainer().getProperty(selectedItemId, LeafNodeTaxonContainer.NAME_ID).getValue();
477
                            } else {
478
                                windowTitle = "Add New Taxon";
479
                            }
480

    
481
                            try {
482
                                Window dialog = new Window(windowTitle);
483
                                dialog.setModal(true);
484
                                dialog.setClosable(false);
485
                                dialog.setResizable(false);
486
                                UI.getCurrent().addWindow(dialog);
487
                                Object cId = classificationComboBox.getValue();
488
                                UUID classificationUuid = listener.getClassificationContainer().getUuid(cId);
489
                                IdUuidName classificationIdUuid = new IdUuidName(classificationComboBox.getValue(),
490
                                        classificationUuid,
491
                                        (String) listener.getClassificationContainer().getProperty(cId, StatusPresenter.C_TCACHE_ID).getValue());
492
                                NewTaxonBaseComposite newTaxonComponent =
493
                                        new NewTaxonBaseComposite(dialog,
494
                                                new NewTaxonBasePresenter(),
495
                                                accTaxonIdUuid,
496
                                                accTaxonName,
497
                                                classificationIdUuid);
498
                                dialog.setContent(newTaxonComponent);
499
                            } catch (SQLException e) {
500
                                // TODO Auto-generated catch block
501
                                e.printStackTrace();
502
                            }
503
                        } finally {
504
                            addComboBox.setValue(ADD_TAXON_SYNONYM_INPUT);
505
                        }
506
                    }
507
                }
508
            }
509
        });
510
    }
511

    
512
    private void addSearchTextFieldListener() {
513
        searchTextField.addTextChangeListener(new FieldEvents.TextChangeListener() {
514

    
515
            private static final long serialVersionUID = -7376538870420619534L;
516

    
517
            @Override
518
            public void textChange(TextChangeEvent event) {
519
                listener.setNameFilter(event.getText());
520
                updateInViewLabel();
521
            }
522

    
523
        });
524

    
525
    }
526

    
527
    private void addClearSearchButtonListener() {
528
        clearSearchButton.addClickListener(new Button.ClickListener() {
529

    
530
            @Override
531
            public void buttonClick(ClickEvent event) {
532
                clearDynamicFilters();
533
                updateInViewLabel();
534
            }
535

    
536
        });
537
    }
538

    
539
    private void clearDynamicFilters() {
540
        listener.removeDynamicFilters();
541
        searchTextField.setValue(FILTER_TAXA_INPUT);
542
        for(Object itemId : filterTable.getItemIds()) {
543
            filterTable.getItem(itemId).getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
544
        }
545
    }
546

    
547
    private void addRemoveButtonListener() {
548
        removeButton.addClickListener(new Button.ClickListener() {
549
            @Override
550
            public void buttonClick(ClickEvent event) {
551
                Set<Object> selectedItemIds = (Set)taxaTreeTable.getValue();
552
                if(selectedItemIds.isEmpty()) {
553
                    Notification.show("No Taxa / Synonyms selected", "Please select taxa or synonyms to delete", Type.WARNING_MESSAGE);
554
                } else {
555
                    Notification.show("Deleting selected Taxa / Synonyms", "Implement me", Type.WARNING_MESSAGE);
556
                }
557
            }
558
        });
559
    }
560

    
561

    
562

    
563
    /* (non-Javadoc)
564
     * @see eu.etaxonomy.cdm.vaadin.view.IStatusComponent#setListener(eu.etaxonomy.cdm.vaadin.view.IStatusComponent.StatusComponentListener)
565
     */
566
    @Override
567
    public void setListener(StatusComponentListener listener) {
568
        this.listener = listener;
569
    }
570

    
571

    
572
    class TaxonTableCheckBoxGenerator implements Table.ColumnGenerator {
573

    
574

    
575
        /**
576
         * Generates the cell containing an open image when boolean is true
577
         */
578
        @Override
579
        public Component generateCell(Table source, final Object itemId, Object columnId) {
580
            if(source.getItem(itemId) != null) {
581
                Property prop = source.getItem(itemId).getItemProperty(columnId);
582
                if(prop == null) {
583
                    return null;
584
                }
585
                CheckBox cb = new CheckBox(null, prop);
586
                ValueChangeListener pbListener = new ValueChangeListener() {
587
                    @Override
588
                    public void valueChange(ValueChangeEvent event) {
589
                        boolean value = (Boolean) event.getProperty().getValue();
590
                        listener.updatePublished(value, itemId);
591
                    }
592
                };
593
                cb.addValueChangeListener(pbListener);
594
                cb.setData(itemId);
595
                return cb;
596
            } else {
597
                return null;
598
            }
599

    
600
        }
601
    }
602

    
603
    class CheckBoxGenerator implements Table.ColumnGenerator {
604

    
605
        private final ValueChangeListener vcListener;
606

    
607
        public CheckBoxGenerator(ValueChangeListener vcListener) {
608
            this.vcListener = vcListener;
609
        }
610

    
611
        /**
612
         * Generates the cell containing an open image when boolean is true
613
         */
614
        @Override
615
        public Component generateCell(Table source, final Object itemId, Object columnId) {
616
            if(source.getItem(itemId) != null) {
617
                Property prop = source.getItem(itemId).getItemProperty(columnId);
618
                if(prop == null) {
619
                    return null;
620
                }
621
                CheckBox cb = new CheckBox(null, prop);
622
                cb.addValueChangeListener(vcListener);
623
                cb.setData(itemId);
624
                return cb;
625
            } else {
626
                return null;
627
            }
628
        }
629
    }
630

    
631

    
632
    /* (non-Javadoc)
633
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onCreate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
634
     */
635
    @Override
636
    public void onCreate(CdmChangeEvent event) {
637
        if(event.getSourceType().equals(NewTaxonBaseComposite.class)) {
638
            Object itemId = event.getChangedObjects().get(0);
639
            try {
640
                taxaTreeTable.setMultiSelect(false);
641
                if(listener.getCurrentLeafNodeTaxonContainer().isSynonym(itemId)) {
642
                    taxaTreeTable.setCollapsed(taxaTreeTable.getValue(), false);
643
                    listener.refresh();
644
                    taxaTreeTable.setValue(itemId);
645
                } else {
646
                    clearDynamicFilters();
647
                    listener.setIdFilter(itemId);
648
                    taxaTreeTable.setValue(itemId);
649
                }
650
            } finally {
651
                taxaTreeTable.setMultiSelect(taxaTreeTableMultiSelectMode);
652
            }
653
        }
654
    }
655

    
656
    /* (non-Javadoc)
657
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onUpdate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
658
     */
659
    @Override
660
    public void onUpdate(CdmChangeEvent event) {
661
        // TODO Auto-generated method stub
662

    
663
    }
664

    
665
    /* (non-Javadoc)
666
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onDelete(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
667
     */
668
    @Override
669
    public void onDelete(CdmChangeEvent event) {
670
        // TODO Auto-generated method stub
671

    
672
    }
673

    
674
    /* (non-Javadoc)
675
     * @see com.vaadin.navigator.View#enter(com.vaadin.navigator.ViewChangeListener.ViewChangeEvent)
676
     */
677
    @Override
678
    public void enter(ViewChangeEvent event) {
679
        // TODO Auto-generated method stub
680

    
681
    }
682

    
683
    @AutoGenerated
684
    private GridLayout buildMainLayout() {
685
        // common part: create layout
686
        mainLayout = new GridLayout();
687
        mainLayout.setImmediate(false);
688
        mainLayout.setWidth("340px");
689
        mainLayout.setHeight("840px");
690
        mainLayout.setMargin(true);
691
        mainLayout.setRows(6);
692

    
693
        // top-level component properties
694
        setWidth("340px");
695
        setHeight("840px");
696

    
697
        // classificationComboBox
698
        classificationComboBox = new ComboBox();
699
        classificationComboBox.setImmediate(false);
700
        classificationComboBox.setWidth("100.0%");
701
        classificationComboBox.setHeight("-1px");
702
        mainLayout.addComponent(classificationComboBox, 0, 0);
703

    
704
        // filterVerticalLayout
705
        filterVerticalLayout = buildFilterVerticalLayout();
706
        mainLayout.addComponent(filterVerticalLayout, 0, 1);
707
        mainLayout.setComponentAlignment(filterVerticalLayout, new Alignment(20));
708

    
709
        // addRemovehorizontalLayout
710
        addRemovehorizontalLayout = buildAddRemovehorizontalLayout();
711
        mainLayout.addComponent(addRemovehorizontalLayout, 0, 2);
712
        mainLayout.setComponentAlignment(addRemovehorizontalLayout, new Alignment(48));
713

    
714
        // searchHorizontalLayout
715
        searchHorizontalLayout = buildSearchHorizontalLayout();
716
        mainLayout.addComponent(searchHorizontalLayout, 0, 3);
717
        mainLayout.setComponentAlignment(searchHorizontalLayout, new Alignment(48));
718

    
719
        // taxaTreeTable
720
        taxaTreeTable = new TreeTable();
721
        taxaTreeTable.setImmediate(false);
722
        taxaTreeTable.setWidth("100.0%");
723
        taxaTreeTable.setHeight("580px");
724
        mainLayout.addComponent(taxaTreeTable, 0, 4);
725
        mainLayout.setComponentAlignment(taxaTreeTable, new Alignment(20));
726

    
727
        // inViewLabel
728
        inViewLabel = new Label();
729
        inViewLabel.setImmediate(false);
730
        inViewLabel.setWidth("100.0%");
731
        inViewLabel.setHeight("-1px");
732
        inViewLabel.setValue("in view : ");
733
        mainLayout.addComponent(inViewLabel, 0, 5);
734

    
735
        return mainLayout;
736
    }
737

    
738
    @AutoGenerated
739
    private VerticalLayout buildFilterVerticalLayout() {
740
        // common part: create layout
741
        filterVerticalLayout = new VerticalLayout();
742
        filterVerticalLayout.setImmediate(false);
743
        filterVerticalLayout.setWidth("100.0%");
744
        filterVerticalLayout.setHeight("-1px");
745
        filterVerticalLayout.setMargin(false);
746

    
747
        // filterLabel
748
        filterLabel = new Label();
749
        filterLabel.setImmediate(false);
750
        filterLabel.setWidth("100.0%");
751
        filterLabel.setHeight("-1px");
752
        filterLabel.setValue("Filter by :");
753
        filterVerticalLayout.addComponent(filterLabel);
754

    
755
        // filterTable
756
        filterTable = new Table();
757
        filterTable.setImmediate(false);
758
        filterTable.setWidth("100.0%");
759
        filterTable.setHeight("86px");
760
        filterVerticalLayout.addComponent(filterTable);
761
        filterVerticalLayout.setComponentAlignment(filterTable, new Alignment(48));
762

    
763
        return filterVerticalLayout;
764
    }
765

    
766
    @AutoGenerated
767
    private HorizontalLayout buildAddRemovehorizontalLayout() {
768
        // common part: create layout
769
        addRemovehorizontalLayout = new HorizontalLayout();
770
        addRemovehorizontalLayout.setImmediate(false);
771
        addRemovehorizontalLayout.setWidth("100.0%");
772
        addRemovehorizontalLayout.setHeight("-1px");
773
        addRemovehorizontalLayout.setMargin(false);
774
        addRemovehorizontalLayout.setSpacing(true);
775

    
776
        // addComboBox
777
        addComboBox = new ComboBox();
778
        addComboBox.setImmediate(false);
779
        addComboBox.setWidth("100.0%");
780
        addComboBox.setHeight("-1px");
781
        addRemovehorizontalLayout.addComponent(addComboBox);
782
        addRemovehorizontalLayout.setExpandRatio(addComboBox, 3.0f);
783

    
784
        // removeButton
785
        removeButton = new Button();
786
        removeButton.setCaption("Remove");
787
        removeButton.setImmediate(true);
788
        removeButton.setWidth("100.0%");
789
        removeButton.setHeight("-1px");
790
        addRemovehorizontalLayout.addComponent(removeButton);
791
        addRemovehorizontalLayout.setExpandRatio(removeButton, 2.0f);
792

    
793
        return addRemovehorizontalLayout;
794
    }
795

    
796
    @AutoGenerated
797
    private HorizontalLayout buildSearchHorizontalLayout() {
798
        // common part: create layout
799
        searchHorizontalLayout = new HorizontalLayout();
800
        searchHorizontalLayout.setImmediate(false);
801
        searchHorizontalLayout.setWidth("100.0%");
802
        searchHorizontalLayout.setHeight("-1px");
803
        searchHorizontalLayout.setMargin(false);
804
        searchHorizontalLayout.setSpacing(true);
805

    
806
        // searchTextField
807
        searchTextField = new TextField();
808
        searchTextField.setImmediate(false);
809
        searchTextField.setWidth("100.0%");
810
        searchTextField.setHeight("-1px");
811
        searchHorizontalLayout.addComponent(searchTextField);
812
        searchHorizontalLayout.setExpandRatio(searchTextField, 4.0f);
813
        searchHorizontalLayout.setComponentAlignment(searchTextField, new Alignment(48));
814

    
815
        // clearSearchButton
816
        clearSearchButton = new Button();
817
        clearSearchButton.setCaption("Button");
818
        clearSearchButton.setImmediate(true);
819
        clearSearchButton.setWidth("100.0%");
820
        clearSearchButton.setHeight("-1px");
821
        searchHorizontalLayout.addComponent(clearSearchButton);
822
        searchHorizontalLayout.setExpandRatio(clearSearchButton, 1.0f);
823
        searchHorizontalLayout.setComponentAlignment(clearSearchButton, new Alignment(48));
824

    
825
        return searchHorizontalLayout;
826
    }
827

    
828
}
(6-6/6)