Project

General

Profile

Download (31 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.Set;
15
import java.util.UUID;
16

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

    
23
import com.vaadin.annotations.AutoGenerated;
24
import com.vaadin.data.Item;
25
import com.vaadin.data.Property;
26
import com.vaadin.data.Property.ValueChangeEvent;
27
import com.vaadin.data.Property.ValueChangeListener;
28
import com.vaadin.data.util.IndexedContainer;
29
import com.vaadin.data.util.sqlcontainer.RowId;
30
import com.vaadin.event.FieldEvents;
31
import com.vaadin.event.FieldEvents.TextChangeEvent;
32
import com.vaadin.event.ItemClickEvent;
33
import com.vaadin.event.ItemClickEvent.ItemClickListener;
34
import com.vaadin.event.LayoutEvents.LayoutClickEvent;
35
import com.vaadin.event.LayoutEvents.LayoutClickListener;
36
import com.vaadin.navigator.View;
37
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
38
import com.vaadin.server.FontAwesome;
39
import com.vaadin.ui.Alignment;
40
import com.vaadin.ui.Button;
41
import com.vaadin.ui.Button.ClickEvent;
42
import com.vaadin.ui.CheckBox;
43
import com.vaadin.ui.ComboBox;
44
import com.vaadin.ui.Component;
45
import com.vaadin.ui.CustomComponent;
46
import com.vaadin.ui.GridLayout;
47
import com.vaadin.ui.HorizontalLayout;
48
import com.vaadin.ui.Label;
49
import com.vaadin.ui.Notification;
50
import com.vaadin.ui.Notification.Type;
51
import com.vaadin.ui.Table;
52
import com.vaadin.ui.Table.ColumnHeaderMode;
53
import com.vaadin.ui.Table.TableDragMode;
54
import com.vaadin.ui.TextField;
55
import com.vaadin.ui.TreeTable;
56
import com.vaadin.ui.UI;
57
import com.vaadin.ui.VerticalLayout;
58
import com.vaadin.ui.Window;
59

    
60
import eu.etaxonomy.cdm.vaadin.container.IdUuidName;
61
import eu.etaxonomy.cdm.vaadin.container.LeafNodeTaxonContainer;
62
import eu.etaxonomy.cdm.vaadin.presenter.NewTaxonBasePresenter;
63
import eu.etaxonomy.cdm.vaadin.presenter.StatusPresenter;
64
import eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent;
65
import eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener;
66
import eu.etaxonomy.cdm.vaadin.session.SelectionEvent;
67
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinOperation;
68
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinSessionUtilities;
69
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinUtilities;
70
import eu.etaxonomy.cdm.vaadin.view.IStatusComposite;
71

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

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

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

    
104

    
105
    private final boolean taxaTreeTableMultiSelectMode = true;
106

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

    
109

    
110
    private static final String CREATE_ACC_TAXON = "Create Accepted Taxon";
111
    private static final String CHANGE_TO_ACC_TAXON = "Change to Accepted Taxon";
112
    private static final String REPLACE_ACC_TAXON = "Replace Accepted Taxon";
113
    private static final String CHANGE_TO_SYNONYM = "Change to Synonym";
114
    private static final String CREATE_SYNONYM = "Create Synonym";
115
    private static final String SET_AS_DELETED = "Set as Deleted";
116
    private static final String SET_AS_EXCLUDED = "Set as Excluded";
117
    private static final String SET_AS_UNRESOLVED = "Set as Unresolved";
118
    private static final String SET_AS_OUT_OF_SCOPE = "Set as Out Of Scope";
119

    
120
    private static final String PROPERTY_FILTER_ID = "filter";
121
    private static final String PROPERTY_SELECTED_ID = "selected";
122

    
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

    
133
    private boolean isFiltertableInitialised = false;
134

    
135

    
136

    
137
    ContextMenu taxaTableContextMenu;
138

    
139

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

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

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

    
159
        init();
160
    }
161

    
162

    
163

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

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

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

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

    
194

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

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

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

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

    
214
    private void initTaxaTable() {
215
        taxaTreeTable.setSelectable(true);
216
        taxaTreeTable.setMultiSelect(taxaTreeTableMultiSelectMode);
217
        taxaTreeTable.setImmediate(true);
218
        taxaTreeTable.setDragMode(TableDragMode.ROW);
219

    
220
        taxaTreeTable.setColumnExpandRatio(LeafNodeTaxonContainer.NAME_ID, 1);
221
        taxaTreeTable.setColumnWidth(LeafNodeTaxonContainer.PB_ID, 25);
222

    
223

    
224
        taxaTreeTable.addGeneratedColumn(LeafNodeTaxonContainer.PB_ID, new TaxonTableCheckBoxGenerator());
225

    
226
        taxaTreeTable.setCellStyleGenerator(new Table.CellStyleGenerator() {
227

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

    
240
            }
241
        });
242

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

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

    
254
        try {
255
            // Cannot use the setContainerDataSource method which has the column ids as
256
            // second argument, since this method is taken from the Table class and
257
            // hence the container strategy is not set to null, implying that the old
258
            // preorder list is not cleaned up - potential bug in the tree table api ?
259
            taxaTreeTable.setContainerDataSource(listener.loadTaxa(classificationId));
260
            taxaTreeTable.setVisibleColumns(LeafNodeTaxonContainer.NAME_ID, LeafNodeTaxonContainer.PB_ID);
261
        } catch (SQLException e) {
262
            //TODO : throw up warning dialog
263
            e.printStackTrace();
264
        }
265
        // We need to set the sort property id to null and then
266
        // reset it to the name column else the sort is not performed
267
        // since the sort property id has not changed - potential bug
268
        // in the tree table api ?
269
        taxaTreeTable.setSortContainerPropertyId(null);
270
        taxaTreeTable.setSortContainerPropertyId(LeafNodeTaxonContainer.NAME_ID);
271
        updateInViewLabel();
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
    private void initFilterTable() {
293
        filterTable.setNullSelectionAllowed(false);
294
        final IndexedContainer container = new IndexedContainer();
295
        container.addContainerProperty("filter", String.class, "");
296
        container.addContainerProperty("selected", Boolean.class, "");
297

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

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

    
306

    
307
        filterTable.setContainerDataSource(container);
308
        filterTable.setColumnHeaderMode(ColumnHeaderMode.HIDDEN);
309

    
310

    
311
        ValueChangeListener selectedListener = new ValueChangeListener() {
312

    
313
            private static final long serialVersionUID = -5551250788805117454L;
314

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

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

    
344
        isFiltertableInitialised = true;
345

    
346
    }
347

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

    
352
    private void initSearchTextField() {
353
        searchTextField.setInputPrompt(FILTER_TAXA_INPUT);
354
    }
355

    
356

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

    
362

    
363
    private void addUIListeners() {
364

    
365
        searchHorizontalLayout.addLayoutClickListener(new LayoutClickListener() {
366

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

    
375
        addClassificationComboBoxListener();
376
        addTaxaTreeTableListener();
377

    
378
        addSearchTextFieldListener();
379
        addClearSearchButtonListener();
380
    }
381

    
382
    private void addClassificationComboBoxListener() {
383

    
384
        classificationComboBox.addValueChangeListener(new Property.ValueChangeListener() {
385

    
386
            private static final long serialVersionUID = 4196786323147791606L;
387

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

    
394
                    setEnabledAll(false);
395
                    filterTable.setReadOnly(true);
396
                    taxaTreeTable.setSelectable(false);
397

    
398
                    CdmVaadinUtilities.exec(new CdmVaadinOperation(100, null) {
399

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

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

    
416

    
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
                    boolean isSynonym = listener.isSynonym(itemId);
430
                    if(!CdmVaadinUtilities.isSelected(taxaTreeTable, itemId) && !isSynonym) {
431
                        UUID taxonUuid = listener.getCurrentLeafNodeTaxonContainer().getUuid(itemId);
432
                        String taxonName = (String)listener.getCurrentLeafNodeTaxonContainer().getProperty(itemId, LeafNodeTaxonContainer.NAME_ID).getValue();
433
                        Object idUuidName = new IdUuidName(itemId, taxonUuid, taxonName);
434
                        CdmVaadinSessionUtilities.getCurrentSelectionService()
435
                        .fireSelectionEvent(new SelectionEvent(Arrays.asList(idUuidName, getSelectedClassificationUuid()), StatusComposite.class), true);
436
                    }
437
                    taxaTreeTable.setValue(Arrays.asList(itemId));
438
                    generateTaxaTreeTableContextMenu(isSynonym);
439

    
440
                }
441
            }
442
        });
443

    
444
        //taxaTreeTable.add
445

    
446

    
447
    }
448

    
449
    private void generateTaxaTreeTableContextMenu(boolean isSynonym) {
450

    
451
        taxaTableContextMenu.removeAllItems();
452
        if(isSynonym) {
453

    
454

    
455
            ContextMenuItem changeToAccTaxonMenuItem = taxaTableContextMenu.addItem(CHANGE_TO_ACC_TAXON);
456
            changeToAccTaxonMenuItem.setData(CHANGE_TO_ACC_TAXON);
457

    
458
            ContextMenuItem replaceAccTaxonMenuItem = taxaTableContextMenu.addItem(REPLACE_ACC_TAXON);
459
            replaceAccTaxonMenuItem.setData(REPLACE_ACC_TAXON);
460

    
461
            replaceAccTaxonMenuItem.setSeparatorVisible(true);
462
        } else {
463
            ContextMenuItem createSynMenuItem = taxaTableContextMenu.addItem(CREATE_SYNONYM);
464
            createSynMenuItem.setData(CREATE_SYNONYM);
465

    
466
            ContextMenuItem changeToSynMenuItem = taxaTableContextMenu.addItem(CHANGE_TO_SYNONYM);
467
            changeToSynMenuItem.setData(CHANGE_TO_SYNONYM);
468

    
469
            changeToSynMenuItem.setSeparatorVisible(true);
470
        }
471

    
472
        ContextMenuItem setDeletedMenuItem = taxaTableContextMenu.addItem(SET_AS_DELETED);
473
        setDeletedMenuItem.setData(SET_AS_DELETED);
474

    
475
        ContextMenuItem setExcludedMenuItem = taxaTableContextMenu.addItem(SET_AS_EXCLUDED);
476
        setExcludedMenuItem.setData(SET_AS_EXCLUDED);
477

    
478
        ContextMenuItem setUnresolvedMenuItem = taxaTableContextMenu.addItem(SET_AS_UNRESOLVED);
479
        setUnresolvedMenuItem.setData(SET_AS_UNRESOLVED);
480

    
481

    
482
        ContextMenuItem setOutOfScopeMenuItem = taxaTableContextMenu.addItem(SET_AS_OUT_OF_SCOPE);
483
        setOutOfScopeMenuItem.setData(SET_AS_OUT_OF_SCOPE);
484

    
485
        ContextMenuItem createAccTaxonMenuItem = taxaTableContextMenu.addItem(CREATE_ACC_TAXON);
486
        createAccTaxonMenuItem.setData(CREATE_ACC_TAXON);
487

    
488
    }
489

    
490
    private void addTaxaTreeContextMenuItemListener() {
491
        if(taxaTableContextMenu != null) {
492
            taxaTableContextMenu.addItemClickListener(new ContextMenuItemClickListener() {
493

    
494
                @Override
495
                public void contextMenuItemClicked(ContextMenuItemClickEvent event) {
496
                    Object source = event.getSource();
497
                    if(source instanceof ContextMenuItem) {
498
                        ContextMenuItem menuItem = (ContextMenuItem) source;
499
                        String action = (String)menuItem.getData();
500
                        if(CREATE_ACC_TAXON.equals(action) || CREATE_SYNONYM.equals(action)) {
501
                            showAddTaxonBaseWindow(action);
502
                        } else {
503
                            Notification.show(action + " to be implemented", Type.WARNING_MESSAGE);
504
                        }
505
                    }
506
                }
507
            });
508
        }
509
    }
510

    
511

    
512
    private void showAddTaxonBaseWindow(String action) {
513
        if (action != null) {
514
            String windowTitle;
515

    
516
            Object selectedItemId = null;
517
            IdUuidName accTaxonIdUuid = null;
518
            String accTaxonName = null;
519
            if(action.equals(CREATE_SYNONYM)) {
520
                Set<Object> selectedIds = (Set<Object>)taxaTreeTable.getValue();
521
                // if zero or more than one items (taxa / synonyms) are selected
522
                // throw a warning
523
                if(selectedIds.size() != 1) {
524
                    Notification.show("Multiple or No selection", "Please select a single Taxon", Type.WARNING_MESSAGE);
525
                    return;
526
                }
527
                selectedItemId = selectedIds.iterator().next();
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
                NewTaxonBaseComposite newTaxonComponent =
554
                        new NewTaxonBaseComposite(dialog,
555
                                new NewTaxonBasePresenter(),
556
                                accTaxonIdUuid,
557
                                accTaxonName,
558
                                classificationIdUuid);
559
                dialog.setContent(newTaxonComponent);
560
            } catch (SQLException e) {
561
                // TODO Auto-generated catch block
562
                e.printStackTrace();
563
            }
564
        }
565
    }
566

    
567

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

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

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

    
579
        });
580

    
581
    }
582

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

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

    
592
        });
593
    }
594

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

    
603

    
604

    
605

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

    
614

    
615
    class TaxonTableCheckBoxGenerator implements Table.ColumnGenerator {
616

    
617

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

    
643
        }
644
    }
645

    
646
    class CheckBoxGenerator implements Table.ColumnGenerator {
647

    
648
        private final ValueChangeListener vcListener;
649

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

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

    
674

    
675
    /* (non-Javadoc)
676
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onCreate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
677
     */
678
    @Override
679
    public void onCreate(CdmChangeEvent event) {
680
        if(event.getSourceType().equals(NewTaxonBaseComposite.class)) {
681
            Object itemId = event.getChangedObjects().get(0);
682
            try {
683
                taxaTreeTable.setMultiSelect(false);
684
                if(listener.getCurrentLeafNodeTaxonContainer().isSynonym(itemId)) {
685
                    taxaTreeTable.setCollapsed(taxaTreeTable.getValue(), false);
686
                    listener.refresh();
687
                    taxaTreeTable.setValue(itemId);
688
                } else {
689
                    clearDynamicFilters();
690
                    listener.setIdFilter(itemId);
691
                    taxaTreeTable.setValue(itemId);
692
                }
693
            } finally {
694
                taxaTreeTable.setMultiSelect(taxaTreeTableMultiSelectMode);
695
            }
696
        }
697
    }
698

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

    
706
    }
707

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

    
715
    }
716

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

    
724
    }
725

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

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

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

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

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

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

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

    
774
        return mainLayout;
775
    }
776

    
777

    
778

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

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

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

    
805
        return filterVerticalLayout;
806
    }
807

    
808

    
809

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

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

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

    
839
        return searchHorizontalLayout;
840
    }
841

    
842
}
(8-8/8)