Project

General

Profile

Download (30.9 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.Arrays;
14
import java.util.UUID;
15

    
16
import org.apache.log4j.Logger;
17
import org.vaadin.peter.contextmenu.ContextMenu;
18
import org.vaadin.peter.contextmenu.ContextMenu.ContextMenuItem;
19
import org.vaadin.peter.contextmenu.ContextMenu.ContextMenuItemClickEvent;
20
import org.vaadin.peter.contextmenu.ContextMenu.ContextMenuItemClickListener;
21

    
22
import com.vaadin.annotations.AutoGenerated;
23
import com.vaadin.data.Item;
24
import com.vaadin.data.Property;
25
import com.vaadin.data.Property.ValueChangeEvent;
26
import com.vaadin.data.Property.ValueChangeListener;
27
import com.vaadin.data.util.IndexedContainer;
28
import com.vaadin.data.util.sqlcontainer.RowId;
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.CdmVaadinOperation;
67
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinSessionUtilities;
68
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinUtilities;
69
import eu.etaxonomy.cdm.vaadin.view.IStatusComposite;
70

    
71
/**
72
 * @author cmathew
73
 * @date 11 Mar 2015
74
 *
75
 */
76
public class StatusComposite extends CustomComponent implements View, IStatusComposite, ICdmChangeListener {
77

    
78
    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */
79

    
80
    @AutoGenerated
81
    private GridLayout mainLayout;
82
    @AutoGenerated
83
    private Label inViewLabel;
84
    @AutoGenerated
85
    private TreeTable taxaTreeTable;
86
    @AutoGenerated
87
    private HorizontalLayout searchHorizontalLayout;
88
    @AutoGenerated
89
    private Button clearSearchButton;
90
    @AutoGenerated
91
    private TextField searchTextField;
92
    @AutoGenerated
93
    private VerticalLayout filterVerticalLayout;
94
    @AutoGenerated
95
    private Table filterTable;
96
    @AutoGenerated
97
    private Label filterLabel;
98
    @AutoGenerated
99
    private ComboBox classificationComboBox;
100
    private static final Logger logger = Logger.getLogger(StatusComposite.class);
101
    private StatusComponentListener listener;
102

    
103

    
104

    
105

    
106
    private static final String SELECT_CLASSIFICATION = "Select classification ...";
107

    
108

    
109
    private static final String CREATE_NEW_TAXON = "Create New Taxon";
110
    private static final String CHANGE_TO_ACC_TAXON = "Change to Accepted Taxon";
111
    private static final String REPLACE_ACC_TAXON = "Replace Accepted Taxon";
112
    private static final String CHANGE_TO_SYNONYM = "Change to Synonym";
113
    private static final String CREATE_SYNONYM = "Create Synonym";
114
    private static final String SET_AS_DELETED = "Set as Deleted";
115
    private static final String SET_AS_EXCLUDED = "Set as Excluded";
116
    private static final String SET_AS_UNRESOLVED = "Set as Unresolved";
117
    private static final String SET_AS_OUT_OF_SCOPE = "Set as Out Of Scope";
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_UNPLACED = "unplaced";
123
    private static final String FILTER_UNFINISHED = "unfinished";
124
    private static final String FILTER_UNPUBLISHED = "unpublished";
125

    
126

    
127
    private static final String FILTER_TAXA_INPUT = "Filter Taxa ...";
128
    private static final String IN_VIEW_PREFIX = "in view : ";
129

    
130
    private boolean isTaxaTableInitialised = false;
131

    
132
    private boolean isFiltertableInitialised = false;
133

    
134

    
135
    private NewTaxonBaseComposite currentNewTaxonBaseComponent;
136
    private ContextMenu taxaTableContextMenu;
137

    
138

    
139
    /**
140
     * The constructor should first build the main layout, set the
141
     * composition root and then do any custom initialization.
142
     *
143
     * The constructor will not be automatically regenerated by the
144
     * visual editor.
145
     */
146
    public StatusComposite() {
147
        buildMainLayout();
148
        setCompositionRoot(mainLayout);
149

    
150
        this.listener = new StatusPresenter();
151
        CdmVaadinSessionUtilities.getCurrentCdmDataChangeService().register(this);
152
        addUIListeners();
153

    
154
        initSearchTextField();
155
        initClearSearchButton();
156
        setEnabledAll(false);
157

    
158
        init();
159
    }
160

    
161

    
162

    
163
    public void setClassification(String classification) {
164
        if(classification == null) {
165
            return;
166
        }
167
        Object selectedClassificationId = listener.getClassificationId(classification);
168
        if(selectedClassificationId == null) {
169
            Notification.show("Classification named " + classification + " does not exist.");
170
        } else {
171
            classificationComboBox.setValue(selectedClassificationId);
172
            classificationComboBox.setReadOnly(true);
173
        }
174
    }
175

    
176
    public void init() {
177
        initClassificationComboBox();
178
        setExpandRatios();
179
    }
180

    
181
    private void setExpandRatios() {
182
        mainLayout.setRowExpandRatio(0, 1);
183
        mainLayout.setRowExpandRatio(1, 5);
184
        mainLayout.setRowExpandRatio(2, 1);
185
        mainLayout.setRowExpandRatio(3, 35);
186
        mainLayout.setRowExpandRatio(4, 1);
187
    }
188

    
189
    public void setEnabledAll(boolean enabled) {
190
        CdmVaadinUtilities.setEnabled(mainLayout, enabled, Arrays.asList(classificationComboBox));
191
    }
192

    
193

    
194
    public TreeTable getTaxaTreeTable() {
195
        return taxaTreeTable;
196
    }
197

    
198
    public LeafNodeTaxonContainer getTaxonContainer() {
199
        return listener.getCurrentLeafNodeTaxonContainer();
200
    }
201

    
202
    public void clearTaxaTableSelections() {
203
        taxaTreeTable.setValue(null);
204
    }
205

    
206
    public UUID getSelectedClassificationUuid() {
207
        if(classificationComboBox.getValue() != null) {
208
            return listener.getClassificationContainer().getUuid(classificationComboBox.getValue());
209
        }
210
        return null;
211
    }
212

    
213
    private void initTaxaTable() {
214
        taxaTreeTable.setSelectable(true);
215
        taxaTreeTable.setImmediate(true);
216
        taxaTreeTable.setDragMode(TableDragMode.ROW);
217

    
218
        taxaTreeTable.setColumnExpandRatio(LeafNodeTaxonContainer.NAME_ID, 1);
219
        taxaTreeTable.setColumnWidth(LeafNodeTaxonContainer.PB_ID, 25);
220

    
221

    
222
        taxaTreeTable.addGeneratedColumn(LeafNodeTaxonContainer.PB_ID, new TaxonTableCheckBoxGenerator());
223

    
224
        taxaTreeTable.setCellStyleGenerator(new Table.CellStyleGenerator() {
225

    
226
            @Override
227
            public String getStyle(Table source, Object itemId, Object propertyId) {
228
                if(source.getItem(itemId) == null) {
229
                    return null;
230
                }
231
                if(listener.isSynonym(itemId)) {
232
                    // this is a synonym, so we activate the corresponding css class
233
                    return "synonym";
234
                } else {
235
                    return "taxon";
236
                }
237

    
238
            }
239
        });
240

    
241
        taxaTableContextMenu = new ContextMenu();
242
        taxaTableContextMenu.setAsContextMenuOf(taxaTreeTable);
243
        addTaxaTreeContextMenuItemListener();
244
        isTaxaTableInitialised = true;
245
    }
246

    
247
    private void refreshTaxaTable(int classificationId) {
248
        if(!isTaxaTableInitialised) {
249
            initTaxaTable();
250
        }
251

    
252
        try {
253
            // Cannot use the setContainerDataSource method which has the column ids as
254
            // second argument, since this method is taken from the Table class and
255
            // hence the container strategy is not set to null, implying that the old
256
            // preorder list is not cleaned up - potential bug in the tree table api ?
257
            taxaTreeTable.setContainerDataSource(listener.loadTaxa(classificationId));
258
            taxaTreeTable.setVisibleColumns(LeafNodeTaxonContainer.NAME_ID, LeafNodeTaxonContainer.PB_ID);
259
        } catch (SQLException e) {
260
            //TODO : throw up warning dialog
261
            e.printStackTrace();
262
        }
263
        // We need to set the sort property id to null and then
264
        // reset it to the name column else the sort is not performed
265
        // since the sort property id has not changed - potential bug
266
        // in the tree table api ?
267
        taxaTreeTable.setSortContainerPropertyId(null);
268
        taxaTreeTable.setSortContainerPropertyId(LeafNodeTaxonContainer.NAME_ID);
269
        updateInViewLabel();
270

    
271
    }
272

    
273
    private void initClassificationComboBox() {
274

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

    
290
    private void initFilterTable() {
291
        filterTable.setNullSelectionAllowed(false);
292
        final IndexedContainer container = new IndexedContainer();
293
        container.addContainerProperty("filter", String.class, "");
294
        container.addContainerProperty("selected", Boolean.class, "");
295

    
296
        Item item = container.addItem(FILTER_UNFINISHED);
297
        item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_UNFINISHED);
298
        item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
299

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

    
304

    
305
        filterTable.setContainerDataSource(container);
306
        filterTable.setColumnHeaderMode(ColumnHeaderMode.HIDDEN);
307

    
308

    
309
        ValueChangeListener selectedListener = new ValueChangeListener() {
310

    
311
            private static final long serialVersionUID = -5551250788805117454L;
312

    
313
            @Override
314
            public void valueChange(ValueChangeEvent event) {
315
                boolean value = (Boolean) event.getProperty().getValue();
316
                String selectedFilter = (String)filterTable.getItem(((CheckBox)event.getProperty()).getData()).getItemProperty(PROPERTY_FILTER_ID).getValue();
317
                if(selectedFilter != null) {
318
                    if(value) {
319
                        if(selectedFilter.equals(FILTER_UNPLACED)) {
320
                            listener.setUnplacedFilter();
321
                        }
322
                        if(selectedFilter.equals(FILTER_UNPUBLISHED)) {
323
                            listener.setUnpublishedFilter();
324
                        }
325
                    } else {
326
                        if(selectedFilter.equals(FILTER_UNPLACED)) {
327
                            listener.removeUnplacedFilter();
328
                        }
329
                        if(selectedFilter.equals(FILTER_UNPUBLISHED)) {
330
                            listener.removeUnpublishedFilter();
331
                        }
332
                    }
333
                    updateInViewLabel();
334
                }
335
            }
336
        };
337

    
338
        if(!isFiltertableInitialised) {
339
            filterTable.addGeneratedColumn(PROPERTY_SELECTED_ID, new CheckBoxGenerator(selectedListener));
340
        }
341

    
342
        isFiltertableInitialised = true;
343

    
344
    }
345

    
346
    private void updateInViewLabel() {
347
        inViewLabel.setValue(IN_VIEW_PREFIX + String.valueOf(listener.getCurrentNoOfTaxa()) + " / " + String.valueOf(listener.getTotalNoOfTaxa()) + " taxa");
348
    }
349

    
350
    private void initSearchTextField() {
351
        searchTextField.setInputPrompt(FILTER_TAXA_INPUT);
352
    }
353

    
354

    
355
    private void initClearSearchButton() {
356
        clearSearchButton.setIcon(FontAwesome.REFRESH);
357
        clearSearchButton.setCaption("");
358
    }
359

    
360

    
361
    private void addUIListeners() {
362

    
363
        searchHorizontalLayout.addLayoutClickListener(new LayoutClickListener() {
364

    
365
            @Override
366
            public void layoutClick(LayoutClickEvent event) {
367
                if (event.getChildComponent() == searchTextField && searchTextField.getValue().equals(FILTER_TAXA_INPUT)) {
368
                    searchTextField.setValue("");
369
                }
370
            }
371
        });
372

    
373
        addClassificationComboBoxListener();
374
        addTaxaTreeTableListener();
375

    
376
        addSearchTextFieldListener();
377
        addClearSearchButtonListener();
378
    }
379

    
380
    private void addClassificationComboBoxListener() {
381

    
382
        classificationComboBox.addValueChangeListener(new Property.ValueChangeListener() {
383

    
384
            private static final long serialVersionUID = 4196786323147791606L;
385

    
386
            @Override
387
            public void valueChange(ValueChangeEvent event) {
388
                if (classificationComboBox.getValue() != null) {
389
                    Object selected = classificationComboBox.getValue();
390
                    final int classificationId = (Integer)((RowId)selected).getId()[0];
391

    
392
                    setEnabledAll(false);
393
                    filterTable.setReadOnly(true);
394
                    taxaTreeTable.setSelectable(false);
395

    
396
                    CdmVaadinUtilities.exec(new CdmVaadinOperation(100, null) {
397

    
398
                        @Override
399
                        public boolean execute() {
400
                            setProgress("loading taxa");
401
                            return true;
402
                        }
403

    
404
                        @Override
405
                        public void postOpUIUpdate(boolean isOpSuccess) {
406
                            refreshTaxaTable(classificationId);
407
                            initFilterTable();
408
                            setEnabledAll(true);
409
                            filterTable.setReadOnly(false);
410
                            taxaTreeTable.setSelectable(true);
411
                        }
412
                    });
413

    
414

    
415
                }
416
            }
417
        });
418
    }
419

    
420
    private void addTaxaTreeTableListener() {
421

    
422
        taxaTreeTable.addValueChangeListener(new ValueChangeListener() {
423

    
424
            @Override
425
            public void valueChange(ValueChangeEvent event) {
426
                Object itemId = taxaTreeTable.getValue();
427
                Object taxonIun = null;
428
                if(taxaTreeTable.isSelectable() && itemId != null) {
429
                    boolean isSynonym = listener.isSynonym(itemId);
430
                    if(!isSynonym) {
431
                        UUID taxonUuid = listener.getCurrentLeafNodeTaxonContainer().getUuid(itemId);
432
                        String taxonName = (String)listener.getCurrentLeafNodeTaxonContainer().getProperty(itemId, LeafNodeTaxonContainer.NAME_ID).getValue();
433
                        taxonIun = new IdUuidName(itemId, taxonUuid, taxonName);
434

    
435
                    }
436
                    CdmVaadinSessionUtilities.getCurrentSelectionService()
437
                    .fireSelectionEvent(new SelectionEvent(Arrays.asList(taxonIun, getSelectedClassificationUuid()), StatusComposite.class), true);
438
                }
439
            }
440
        });
441

    
442
        taxaTreeTable.addItemClickListener(new ItemClickListener() {
443
            @Override
444
            public void itemClick(ItemClickEvent event) {
445
                Object itemId = event.getItemId();
446
                if(taxaTreeTable.isSelectable() && itemId != null) {
447
                    boolean isSynonym = listener.isSynonym(itemId);
448
                    taxaTreeTable.setValue(itemId);
449
                    generateTaxaTreeTableContextMenu(isSynonym);
450
                }
451
            }
452
        });
453
    }
454

    
455
    private void generateTaxaTreeTableContextMenu(boolean isSynonym) {
456

    
457
        taxaTableContextMenu.removeAllItems();
458
        if(isSynonym) {
459

    
460

    
461
            ContextMenuItem changeToAccTaxonMenuItem = taxaTableContextMenu.addItem(CHANGE_TO_ACC_TAXON);
462
            changeToAccTaxonMenuItem.setData(CHANGE_TO_ACC_TAXON);
463

    
464
            ContextMenuItem replaceAccTaxonMenuItem = taxaTableContextMenu.addItem(REPLACE_ACC_TAXON);
465
            replaceAccTaxonMenuItem.setData(REPLACE_ACC_TAXON);
466

    
467
            replaceAccTaxonMenuItem.setSeparatorVisible(true);
468
        } else {
469
            ContextMenuItem createSynMenuItem = taxaTableContextMenu.addItem(CREATE_SYNONYM);
470
            createSynMenuItem.setData(CREATE_SYNONYM);
471

    
472
            ContextMenuItem changeToSynMenuItem = taxaTableContextMenu.addItem(CHANGE_TO_SYNONYM);
473
            changeToSynMenuItem.setData(CHANGE_TO_SYNONYM);
474
        }
475

    
476
        ContextMenuItem setDeletedMenuItem = taxaTableContextMenu.addItem(SET_AS_DELETED);
477
        setDeletedMenuItem.setData(SET_AS_DELETED);
478

    
479
        ContextMenuItem setExcludedMenuItem = taxaTableContextMenu.addItem(SET_AS_EXCLUDED);
480
        setExcludedMenuItem.setData(SET_AS_EXCLUDED);
481

    
482
        ContextMenuItem setUnresolvedMenuItem = taxaTableContextMenu.addItem(SET_AS_UNRESOLVED);
483
        setUnresolvedMenuItem.setData(SET_AS_UNRESOLVED);
484

    
485

    
486
        ContextMenuItem setOutOfScopeMenuItem = taxaTableContextMenu.addItem(SET_AS_OUT_OF_SCOPE);
487
        setOutOfScopeMenuItem.setData(SET_AS_OUT_OF_SCOPE);
488

    
489
        setOutOfScopeMenuItem.setSeparatorVisible(true);
490

    
491
        ContextMenuItem createAccTaxonMenuItem = taxaTableContextMenu.addItem(CREATE_NEW_TAXON);
492
        createAccTaxonMenuItem.setData(CREATE_NEW_TAXON);
493

    
494
    }
495

    
496
    private void addTaxaTreeContextMenuItemListener() {
497
        if(taxaTableContextMenu != null) {
498
            taxaTableContextMenu.addItemClickListener(new ContextMenuItemClickListener() {
499

    
500
                @Override
501
                public void contextMenuItemClicked(ContextMenuItemClickEvent event) {
502
                    Object source = event.getSource();
503
                    if(source instanceof ContextMenuItem) {
504
                        ContextMenuItem menuItem = (ContextMenuItem) source;
505
                        String action = (String)menuItem.getData();
506
                        if(CREATE_NEW_TAXON.equals(action) || CREATE_SYNONYM.equals(action)) {
507
                            showAddTaxonBaseWindow(action);
508
                        } else {
509
                            Notification.show(action + " to be implemented", Type.WARNING_MESSAGE);
510
                        }
511
                    }
512
                }
513
            });
514
        }
515
    }
516

    
517

    
518
    private void showAddTaxonBaseWindow(String action) {
519
        if (action != null) {
520
            String windowTitle;
521

    
522
            Object selectedItemId = null;
523
            IdUuidName accTaxonIdUuid = null;
524
            String accTaxonName = null;
525
            if(action.equals(CREATE_SYNONYM)) {
526
                selectedItemId = taxaTreeTable.getValue();
527

    
528
                // if a synonym is selected then throw warning
529
                if(listener.isSynonym(selectedItemId)) {
530
                    Notification.show("Synonym selected", "Please choose a Taxon", Type.WARNING_MESSAGE);
531
                    return;
532
                }
533
                windowTitle = "Add New Synonym";
534
                accTaxonIdUuid = new IdUuidName(selectedItemId,
535
                        listener.getCurrentLeafNodeTaxonContainer().getUuid(selectedItemId),
536
                        (String) listener.getCurrentLeafNodeTaxonContainer().getProperty(selectedItemId, LeafNodeTaxonContainer.NAME_ID).getValue());
537
                accTaxonName = (String)listener.getCurrentLeafNodeTaxonContainer().getProperty(selectedItemId, LeafNodeTaxonContainer.NAME_ID).getValue();
538
            } else {
539
                windowTitle = "Add New Taxon";
540
            }
541

    
542
            try {
543
                Window dialog = new Window(windowTitle);
544
                dialog.setModal(true);
545
                dialog.setClosable(false);
546
                dialog.setResizable(false);
547
                UI.getCurrent().addWindow(dialog);
548
                Object cId = classificationComboBox.getValue();
549
                UUID classificationUuid = listener.getClassificationContainer().getUuid(cId);
550
                IdUuidName classificationIdUuid = new IdUuidName(classificationComboBox.getValue(),
551
                        classificationUuid,
552
                        (String) listener.getClassificationContainer().getProperty(cId, StatusPresenter.C_TCACHE_ID).getValue());
553
                 currentNewTaxonBaseComponent = new NewTaxonBaseComposite(dialog,
554
                                new NewTaxonBasePresenter(),
555
                                accTaxonIdUuid,
556
                                accTaxonName,
557
                                classificationIdUuid);
558
                dialog.setContent(currentNewTaxonBaseComponent);
559
            } catch (SQLException e) {
560
                // TODO Auto-generated catch block
561
                e.printStackTrace();
562
            }
563
        }
564
    }
565

    
566

    
567
    private void addSearchTextFieldListener() {
568
        searchTextField.addTextChangeListener(new FieldEvents.TextChangeListener() {
569

    
570
            private static final long serialVersionUID = -7376538870420619534L;
571

    
572
            @Override
573
            public void textChange(TextChangeEvent event) {
574
                listener.setNameFilter(event.getText());
575
                updateInViewLabel();
576
            }
577

    
578
        });
579

    
580
    }
581

    
582
    private void addClearSearchButtonListener() {
583
        clearSearchButton.addClickListener(new Button.ClickListener() {
584

    
585
            @Override
586
            public void buttonClick(ClickEvent event) {
587
                clearDynamicFilters();
588
                updateInViewLabel();
589
            }
590

    
591
        });
592
    }
593

    
594
    private void clearDynamicFilters() {
595
        listener.removeDynamicFilters();
596
        searchTextField.setValue(FILTER_TAXA_INPUT);
597
        for(Object itemId : filterTable.getItemIds()) {
598
            filterTable.getItem(itemId).getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
599
        }
600
    }
601

    
602

    
603

    
604

    
605
    /* (non-Javadoc)
606
     * @see eu.etaxonomy.cdm.vaadin.view.IStatusComponent#setListener(eu.etaxonomy.cdm.vaadin.view.IStatusComponent.StatusComponentListener)
607
     */
608
    @Override
609
    public void setListener(StatusComponentListener listener) {
610
        this.listener = listener;
611
    }
612

    
613

    
614
    class TaxonTableCheckBoxGenerator implements Table.ColumnGenerator {
615

    
616

    
617
        /**
618
         * Generates the cell containing an open image when boolean is true
619
         */
620
        @Override
621
        public Component generateCell(Table source, final Object itemId, Object columnId) {
622
            if(source.getItem(itemId) != null) {
623
                Property prop = source.getItem(itemId).getItemProperty(columnId);
624
                if(prop == null) {
625
                    return null;
626
                }
627
                CheckBox cb = new CheckBox(null, prop);
628
                ValueChangeListener pbListener = new ValueChangeListener() {
629
                    @Override
630
                    public void valueChange(ValueChangeEvent event) {
631
                        boolean value = (Boolean) event.getProperty().getValue();
632
                        listener.updatePublished(value, itemId);
633
                    }
634
                };
635
                cb.addValueChangeListener(pbListener);
636
                cb.setData(itemId);
637
                return cb;
638
            } else {
639
                return null;
640
            }
641

    
642
        }
643
    }
644

    
645
    class CheckBoxGenerator implements Table.ColumnGenerator {
646

    
647
        private final ValueChangeListener vcListener;
648

    
649
        public CheckBoxGenerator(ValueChangeListener vcListener) {
650
            this.vcListener = vcListener;
651
        }
652

    
653
        /**
654
         * Generates the cell containing an open image when boolean is true
655
         */
656
        @Override
657
        public Component generateCell(Table source, final Object itemId, Object columnId) {
658
            if(source.getItem(itemId) != null) {
659
                Property prop = source.getItem(itemId).getItemProperty(columnId);
660
                if(prop == null) {
661
                    return null;
662
                }
663
                CheckBox cb = new CheckBox(null, prop);
664
                cb.addValueChangeListener(vcListener);
665
                cb.setData(itemId);
666
                return cb;
667
            } else {
668
                return null;
669
            }
670
        }
671
    }
672

    
673

    
674
    /* (non-Javadoc)
675
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onCreate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
676
     */
677
    @Override
678
    public void onCreate(CdmChangeEvent event) {
679
        if(event.getSource() != null && event.getSource() == currentNewTaxonBaseComponent) {
680
            Object itemId = event.getChangedObjects().get(0);
681
            boolean newTaxon= (Boolean) event.getChangedObjects().get(1);
682

    
683
            if(newTaxon) {
684
                // after creating a new taxon we clear all filters and
685
                // filter in only the newly created taxon and select it
686
                clearDynamicFilters();
687
                listener.setIdFilter(itemId);
688
                taxaTreeTable.setValue(itemId);
689
            } else {
690
                // after creating a new synonym we expand the selected taxon
691
                // and select the newly created synonym
692
                taxaTreeTable.setCollapsed(taxaTreeTable.getValue(), false);
693
                listener.refresh();
694
                taxaTreeTable.setValue(itemId);
695
            }
696

    
697
        }
698
    }
699

    
700
    /* (non-Javadoc)
701
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onUpdate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
702
     */
703
    @Override
704
    public void onUpdate(CdmChangeEvent event) {
705
        // TODO Auto-generated method stub
706

    
707
    }
708

    
709
    /* (non-Javadoc)
710
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onDelete(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
711
     */
712
    @Override
713
    public void onDelete(CdmChangeEvent event) {
714
        // TODO Auto-generated method stub
715

    
716
    }
717

    
718
    /* (non-Javadoc)
719
     * @see com.vaadin.navigator.View#enter(com.vaadin.navigator.ViewChangeListener.ViewChangeEvent)
720
     */
721
    @Override
722
    public void enter(ViewChangeEvent event) {
723
        // TODO Auto-generated method stub
724

    
725
    }
726

    
727
    @AutoGenerated
728
    private GridLayout buildMainLayout() {
729
        // common part: create layout
730
        mainLayout = new GridLayout();
731
        mainLayout.setImmediate(false);
732
        mainLayout.setWidth("340px");
733
        mainLayout.setHeight("100%");
734
        mainLayout.setMargin(true);
735
        mainLayout.setSpacing(true);
736
        mainLayout.setRows(5);
737

    
738
        // top-level component properties
739
        setWidth("340px");
740
        setHeight("100.0%");
741

    
742
        // classificationComboBox
743
        classificationComboBox = new ComboBox();
744
        classificationComboBox.setImmediate(false);
745
        classificationComboBox.setWidth("100.0%");
746
        classificationComboBox.setHeight("100.0%");
747
        mainLayout.addComponent(classificationComboBox, 0, 0);
748

    
749
        // filterVerticalLayout
750
        filterVerticalLayout = buildFilterVerticalLayout();
751
        mainLayout.addComponent(filterVerticalLayout, 0, 1);
752
        mainLayout.setComponentAlignment(filterVerticalLayout, new Alignment(20));
753

    
754
        // searchHorizontalLayout
755
        searchHorizontalLayout = buildSearchHorizontalLayout();
756
        mainLayout.addComponent(searchHorizontalLayout, 0, 2);
757
        mainLayout.setComponentAlignment(searchHorizontalLayout, new Alignment(48));
758

    
759
        // taxaTreeTable
760
        taxaTreeTable = new TreeTable();
761
        taxaTreeTable.setImmediate(false);
762
        taxaTreeTable.setWidth("100.0%");
763
        taxaTreeTable.setHeight("100.0%");
764
        mainLayout.addComponent(taxaTreeTable, 0, 3);
765
        mainLayout.setComponentAlignment(taxaTreeTable, new Alignment(20));
766

    
767
        // inViewLabel
768
        inViewLabel = new Label();
769
        inViewLabel.setImmediate(false);
770
        inViewLabel.setWidth("100.0%");
771
        inViewLabel.setHeight("100.0%");
772
        inViewLabel.setValue("in view : ");
773
        mainLayout.addComponent(inViewLabel, 0, 4);
774

    
775
        return mainLayout;
776
    }
777

    
778

    
779

    
780
    @AutoGenerated
781
    private VerticalLayout buildFilterVerticalLayout() {
782
        // common part: create layout
783
        filterVerticalLayout = new VerticalLayout();
784
        filterVerticalLayout.setImmediate(false);
785
        filterVerticalLayout.setWidth("100.0%");
786
        filterVerticalLayout.setHeight("100.0%");
787
        filterVerticalLayout.setMargin(false);
788

    
789
        // filterLabel
790
        filterLabel = new Label();
791
        filterLabel.setImmediate(false);
792
        filterLabel.setWidth("100.0%");
793
        filterLabel.setHeight("-1px");
794
        filterLabel.setValue("Filter by :");
795
        filterVerticalLayout.addComponent(filterLabel);
796

    
797
        // filterTable
798
        filterTable = new Table();
799
        filterTable.setImmediate(false);
800
        filterTable.setWidth("100.0%");
801
        filterTable.setHeight("100.0%");
802
        filterVerticalLayout.addComponent(filterTable);
803
        filterVerticalLayout.setExpandRatio(filterTable, 1.0f);
804
        filterVerticalLayout.setComponentAlignment(filterTable, new Alignment(48));
805

    
806
        return filterVerticalLayout;
807
    }
808

    
809

    
810

    
811
    @AutoGenerated
812
    private HorizontalLayout buildSearchHorizontalLayout() {
813
        // common part: create layout
814
        searchHorizontalLayout = new HorizontalLayout();
815
        searchHorizontalLayout.setImmediate(false);
816
        searchHorizontalLayout.setWidth("100.0%");
817
        searchHorizontalLayout.setHeight("100.0%");
818
        searchHorizontalLayout.setMargin(false);
819
        searchHorizontalLayout.setSpacing(true);
820

    
821
        // searchTextField
822
        searchTextField = new TextField();
823
        searchTextField.setImmediate(false);
824
        searchTextField.setWidth("100.0%");
825
        searchTextField.setHeight("-1px");
826
        searchHorizontalLayout.addComponent(searchTextField);
827
        searchHorizontalLayout.setExpandRatio(searchTextField, 4.0f);
828
        searchHorizontalLayout.setComponentAlignment(searchTextField, new Alignment(48));
829

    
830
        // clearSearchButton
831
        clearSearchButton = new Button();
832
        clearSearchButton.setCaption("Button");
833
        clearSearchButton.setImmediate(true);
834
        clearSearchButton.setWidth("100.0%");
835
        clearSearchButton.setHeight("-1px");
836
        searchHorizontalLayout.addComponent(clearSearchButton);
837
        searchHorizontalLayout.setExpandRatio(clearSearchButton, 1.0f);
838
        searchHorizontalLayout.setComponentAlignment(clearSearchButton, new Alignment(48));
839

    
840
        return searchHorizontalLayout;
841
    }
842

    
843
}
(8-8/8)