Project

General

Profile

Download (30.2 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
import org.vaadin.peter.contextmenu.ContextMenu;
21
import org.vaadin.peter.contextmenu.ContextMenu.ContextMenuItem;
22
import org.vaadin.peter.contextmenu.ContextMenu.ContextMenuItemClickEvent;
23
import org.vaadin.peter.contextmenu.ContextMenu.ContextMenuItemClickListener;
24

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

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

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

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

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

    
105
    private Object currentClickedTaxonItemId;
106

    
107
    private final boolean taxaTreeTableMultiSelectMode = true;
108

    
109
    private static final String SELECT_CLASSIFICATION = "Select classification ...";
110

    
111

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

    
122
    private static final String PROPERTY_FILTER_ID = "filter";
123
    private static final String PROPERTY_SELECTED_ID = "selected";
124

    
125
    private static final String FILTER_NOT_RESOLVED = "not resolved";
126
    private static final String FILTER_UNPLACED = "unplaced";
127
    private static final String FILTER_UNFINISHED = "unfinished";
128
    private static final String FILTER_UNPUBLISHED = "unpublished";
129

    
130

    
131
    private static final String FILTER_TAXA_INPUT = "Filter Taxa ...";
132
    private static final String IN_VIEW_PREFIX = "in view : ";
133

    
134
    private boolean isTaxaTableInitialised = false;
135

    
136
    private boolean isFiltertableInitialised = false;
137

    
138
    private String selectedTaxaTableMenuItem = null;
139

    
140
    ContextMenu taxaTableContextMenu;
141

    
142
    private List<String> columnIds;
143

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

    
155
        this.listener = new StatusPresenter();
156
        CdmVaadinSessionUtilities.getCurrentCdmDataChangeService().register(this);
157
        addUIListeners();
158

    
159
        initSearchTextField();
160
        initClearSearchButton();
161
        setEnabledAll(false);
162

    
163
        init();
164
    }
165

    
166

    
167

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

    
181
    public void init() {
182
        taxaTreeTable.setSelectable(true);
183
        initClassificationComboBox();
184
    }
185

    
186
    public void setEnabledAll(boolean enabled) {
187
        CdmVaadinUtilities.setEnabled(mainLayout, enabled, Arrays.asList(classificationComboBox));
188
    }
189

    
190

    
191
    public TreeTable getTaxaTreeTable() {
192
        return taxaTreeTable;
193
    }
194

    
195
    public LeafNodeTaxonContainer getTaxonContainer() {
196
        return listener.getCurrentLeafNodeTaxonContainer();
197
    }
198

    
199
    public void clearTaxaTableSelections() {
200
        taxaTreeTable.setValue(null);
201
    }
202

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

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

    
220

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

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

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

    
237
            }
238
        });
239

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

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

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

    
270
    }
271

    
272
    private void initClassificationComboBox() {
273

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

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

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

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

    
303

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

    
307

    
308
        ValueChangeListener selectedListener = new ValueChangeListener() {
309

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

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

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

    
341
        isFiltertableInitialised = true;
342

    
343
    }
344

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

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

    
353

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

    
359

    
360
    private void addUIListeners() {
361

    
362
        searchHorizontalLayout.addLayoutClickListener(new LayoutClickListener() {
363

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

    
372
        addClassificationComboBoxListener();
373
        addTaxaTreeTableListener();
374

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

    
379
    private void addClassificationComboBoxListener() {
380

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

    
383
            private static final long serialVersionUID = 4196786323147791606L;
384

    
385
            @Override
386
            public void valueChange(ValueChangeEvent event) {
387
                if (classificationComboBox.getValue() != null) {
388
                    Object selected = classificationComboBox.getValue();
389
                    int classificationId = (Integer)((RowId)selected).getId()[0];
390
                    refreshTaxaTable(classificationId);
391
                    initFilterTable();
392
                    setEnabledAll(true);
393
                }
394
            }
395
        });
396
    }
397

    
398
    private void addTaxaTreeTableListener() {
399

    
400
        taxaTreeTable.addItemClickListener(new ItemClickListener() {
401
            @Override
402
            public void itemClick(ItemClickEvent event) {
403
                Object itemId = event.getItemId();
404
                if(taxaTreeTable.isSelectable()) {
405
                    boolean isSynonym = listener.isSynonym(itemId);
406
                    if(!CdmVaadinUtilities.isSelected(taxaTreeTable, itemId) && !isSynonym) {
407
                        UUID taxonUuid = listener.getCurrentLeafNodeTaxonContainer().getUuid(itemId);
408
                        String taxonName = (String)listener.getCurrentLeafNodeTaxonContainer().getProperty(itemId, LeafNodeTaxonContainer.NAME_ID).getValue();
409
                        Object idUuidName = new IdUuidName(itemId, taxonUuid, taxonName);
410
                        CdmVaadinSessionUtilities.getCurrentSelectionService()
411
                        .fireSelectionEvent(new SelectionEvent(Arrays.asList(idUuidName, getSelectedClassificationUuid()), StatusComposite.class), true);
412
                    }
413
                    taxaTreeTable.setValue(Arrays.asList(itemId));
414
                    generateTaxaTreeTableContextMenu(isSynonym);
415

    
416
                }
417
            }
418
        });
419

    
420
        //taxaTreeTable.add
421

    
422

    
423
    }
424

    
425
    private void generateTaxaTreeTableContextMenu(boolean isSynonym) {
426

    
427
        taxaTableContextMenu.removeAllItems();
428
        if(isSynonym) {
429

    
430

    
431
            ContextMenuItem changeToAccTaxonMenuItem = taxaTableContextMenu.addItem(CHANGE_TO_ACC_TAXON);
432
            changeToAccTaxonMenuItem.setData(CHANGE_TO_ACC_TAXON);
433

    
434
            ContextMenuItem replaceAccTaxonMenuItem = taxaTableContextMenu.addItem(REPLACE_ACC_TAXON);
435
            replaceAccTaxonMenuItem.setData(REPLACE_ACC_TAXON);
436

    
437
            replaceAccTaxonMenuItem.setSeparatorVisible(true);
438
        } else {
439
            ContextMenuItem createSynMenuItem = taxaTableContextMenu.addItem(CREATE_SYNONYM);
440
            createSynMenuItem.setData(CREATE_SYNONYM);
441

    
442
            ContextMenuItem changeToSynMenuItem = taxaTableContextMenu.addItem(CHANGE_TO_SYNONYM);
443
            changeToSynMenuItem.setData(CHANGE_TO_SYNONYM);
444

    
445
            changeToSynMenuItem.setSeparatorVisible(true);
446
        }
447

    
448
        ContextMenuItem setDeletedMenuItem = taxaTableContextMenu.addItem(SET_AS_DELETED);
449
        setDeletedMenuItem.setData(SET_AS_DELETED);
450

    
451
        ContextMenuItem setExcludedMenuItem = taxaTableContextMenu.addItem(SET_AS_EXCLUDED);
452
        setExcludedMenuItem.setData(SET_AS_EXCLUDED);
453

    
454
        ContextMenuItem setUnresolvedMenuItem = taxaTableContextMenu.addItem(SET_AS_UNRESOLVED);
455
        setUnresolvedMenuItem.setData(SET_AS_UNRESOLVED);
456

    
457

    
458
        ContextMenuItem setOutOfScopeMenuItem = taxaTableContextMenu.addItem(SET_AS_OUT_OF_SCOPE);
459
        setOutOfScopeMenuItem.setData(SET_AS_OUT_OF_SCOPE);
460

    
461
        ContextMenuItem createAccTaxonMenuItem = taxaTableContextMenu.addItem(CREATE_ACC_TAXON);
462
        createAccTaxonMenuItem.setData(CREATE_ACC_TAXON);
463

    
464
    }
465

    
466
    private void addTaxaTreeContextMenuItemListener() {
467
        if(taxaTableContextMenu != null) {
468
            taxaTableContextMenu.addItemClickListener(new ContextMenuItemClickListener() {
469

    
470
                @Override
471
                public void contextMenuItemClicked(ContextMenuItemClickEvent event) {
472
                    Object source = event.getSource();
473
                    if(source instanceof ContextMenuItem) {
474
                        ContextMenuItem menuItem = (ContextMenuItem) source;
475
                        String action = (String)menuItem.getData();
476
                        if(CREATE_ACC_TAXON.equals(action) || CREATE_SYNONYM.equals(action)) {
477
                            showAddTaxonBaseWindow(action);
478
                        } else {
479
                            Notification.show(action + " to be implemented", Type.WARNING_MESSAGE);
480
                        }
481
                    }
482
                }
483
            });
484
        }
485
    }
486

    
487

    
488
    private void showAddTaxonBaseWindow(String action) {
489
        if (action != null) {
490
            String windowTitle;
491

    
492
            Object selectedItemId = null;
493
            IdUuidName accTaxonIdUuid = null;
494
            String accTaxonName = null;
495
            if(action.equals(CREATE_SYNONYM)) {
496
                Set<Object> selectedIds = (Set<Object>)taxaTreeTable.getValue();
497
                // if zero or more than one items (taxa / synonyms) are selected
498
                // throw a warning
499
                if(selectedIds.size() != 1) {
500
                    Notification.show("Multiple or No selection", "Please select a single Taxon", Type.WARNING_MESSAGE);
501
                    return;
502
                }
503
                selectedItemId = selectedIds.iterator().next();
504
                // if a synonym is selected then throw warning
505
                if(listener.isSynonym(selectedItemId)) {
506
                    Notification.show("Synonym selected", "Please choose a Taxon", Type.WARNING_MESSAGE);
507
                    return;
508
                }
509
                windowTitle = "Add New Synonym";
510
                accTaxonIdUuid = new IdUuidName(selectedItemId,
511
                        listener.getCurrentLeafNodeTaxonContainer().getUuid(selectedItemId),
512
                        (String) listener.getCurrentLeafNodeTaxonContainer().getProperty(selectedItemId, LeafNodeTaxonContainer.NAME_ID).getValue());
513
                accTaxonName = (String)listener.getCurrentLeafNodeTaxonContainer().getProperty(selectedItemId, LeafNodeTaxonContainer.NAME_ID).getValue();
514
            } else {
515
                windowTitle = "Add New Taxon";
516
            }
517

    
518
            try {
519
                Window dialog = new Window(windowTitle);
520
                dialog.setModal(true);
521
                dialog.setClosable(false);
522
                dialog.setResizable(false);
523
                UI.getCurrent().addWindow(dialog);
524
                Object cId = classificationComboBox.getValue();
525
                UUID classificationUuid = listener.getClassificationContainer().getUuid(cId);
526
                IdUuidName classificationIdUuid = new IdUuidName(classificationComboBox.getValue(),
527
                        classificationUuid,
528
                        (String) listener.getClassificationContainer().getProperty(cId, StatusPresenter.C_TCACHE_ID).getValue());
529
                NewTaxonBaseComposite newTaxonComponent =
530
                        new NewTaxonBaseComposite(dialog,
531
                                new NewTaxonBasePresenter(),
532
                                accTaxonIdUuid,
533
                                accTaxonName,
534
                                classificationIdUuid);
535
                dialog.setContent(newTaxonComponent);
536
            } catch (SQLException e) {
537
                // TODO Auto-generated catch block
538
                e.printStackTrace();
539
            }
540
        }
541
    }
542

    
543

    
544
    private void addSearchTextFieldListener() {
545
        searchTextField.addTextChangeListener(new FieldEvents.TextChangeListener() {
546

    
547
            private static final long serialVersionUID = -7376538870420619534L;
548

    
549
            @Override
550
            public void textChange(TextChangeEvent event) {
551
                listener.setNameFilter(event.getText());
552
                updateInViewLabel();
553
            }
554

    
555
        });
556

    
557
    }
558

    
559
    private void addClearSearchButtonListener() {
560
        clearSearchButton.addClickListener(new Button.ClickListener() {
561

    
562
            @Override
563
            public void buttonClick(ClickEvent event) {
564
                clearDynamicFilters();
565
                updateInViewLabel();
566
            }
567

    
568
        });
569
    }
570

    
571
    private void clearDynamicFilters() {
572
        listener.removeDynamicFilters();
573
        searchTextField.setValue(FILTER_TAXA_INPUT);
574
        for(Object itemId : filterTable.getItemIds()) {
575
            filterTable.getItem(itemId).getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
576
        }
577
    }
578

    
579

    
580

    
581

    
582
    /* (non-Javadoc)
583
     * @see eu.etaxonomy.cdm.vaadin.view.IStatusComponent#setListener(eu.etaxonomy.cdm.vaadin.view.IStatusComponent.StatusComponentListener)
584
     */
585
    @Override
586
    public void setListener(StatusComponentListener listener) {
587
        this.listener = listener;
588
    }
589

    
590

    
591
    class TaxonTableCheckBoxGenerator implements Table.ColumnGenerator {
592

    
593

    
594
        /**
595
         * Generates the cell containing an open image when boolean is true
596
         */
597
        @Override
598
        public Component generateCell(Table source, final Object itemId, Object columnId) {
599
            if(source.getItem(itemId) != null) {
600
                Property prop = source.getItem(itemId).getItemProperty(columnId);
601
                if(prop == null) {
602
                    return null;
603
                }
604
                CheckBox cb = new CheckBox(null, prop);
605
                ValueChangeListener pbListener = new ValueChangeListener() {
606
                    @Override
607
                    public void valueChange(ValueChangeEvent event) {
608
                        boolean value = (Boolean) event.getProperty().getValue();
609
                        listener.updatePublished(value, itemId);
610
                    }
611
                };
612
                cb.addValueChangeListener(pbListener);
613
                cb.setData(itemId);
614
                return cb;
615
            } else {
616
                return null;
617
            }
618

    
619
        }
620
    }
621

    
622
    class CheckBoxGenerator implements Table.ColumnGenerator {
623

    
624
        private final ValueChangeListener vcListener;
625

    
626
        public CheckBoxGenerator(ValueChangeListener vcListener) {
627
            this.vcListener = vcListener;
628
        }
629

    
630
        /**
631
         * Generates the cell containing an open image when boolean is true
632
         */
633
        @Override
634
        public Component generateCell(Table source, final Object itemId, Object columnId) {
635
            if(source.getItem(itemId) != null) {
636
                Property prop = source.getItem(itemId).getItemProperty(columnId);
637
                if(prop == null) {
638
                    return null;
639
                }
640
                CheckBox cb = new CheckBox(null, prop);
641
                cb.addValueChangeListener(vcListener);
642
                cb.setData(itemId);
643
                return cb;
644
            } else {
645
                return null;
646
            }
647
        }
648
    }
649

    
650

    
651
    /* (non-Javadoc)
652
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onCreate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
653
     */
654
    @Override
655
    public void onCreate(CdmChangeEvent event) {
656
        if(event.getSourceType().equals(NewTaxonBaseComposite.class)) {
657
            Object itemId = event.getChangedObjects().get(0);
658
            try {
659
                taxaTreeTable.setMultiSelect(false);
660
                if(listener.getCurrentLeafNodeTaxonContainer().isSynonym(itemId)) {
661
                    taxaTreeTable.setCollapsed(taxaTreeTable.getValue(), false);
662
                    listener.refresh();
663
                    taxaTreeTable.setValue(itemId);
664
                } else {
665
                    clearDynamicFilters();
666
                    listener.setIdFilter(itemId);
667
                    taxaTreeTable.setValue(itemId);
668
                }
669
            } finally {
670
                taxaTreeTable.setMultiSelect(taxaTreeTableMultiSelectMode);
671
            }
672
        }
673
    }
674

    
675
    /* (non-Javadoc)
676
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onUpdate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
677
     */
678
    @Override
679
    public void onUpdate(CdmChangeEvent event) {
680
        // TODO Auto-generated method stub
681

    
682
    }
683

    
684
    /* (non-Javadoc)
685
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onDelete(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
686
     */
687
    @Override
688
    public void onDelete(CdmChangeEvent event) {
689
        // TODO Auto-generated method stub
690

    
691
    }
692

    
693
    /* (non-Javadoc)
694
     * @see com.vaadin.navigator.View#enter(com.vaadin.navigator.ViewChangeListener.ViewChangeEvent)
695
     */
696
    @Override
697
    public void enter(ViewChangeEvent event) {
698
        // TODO Auto-generated method stub
699

    
700
    }
701

    
702
    @AutoGenerated
703
    private GridLayout buildMainLayout() {
704
        // common part: create layout
705
        mainLayout = new GridLayout();
706
        mainLayout.setImmediate(false);
707
        mainLayout.setWidth("340px");
708
        mainLayout.setHeight("840px");
709
        mainLayout.setMargin(true);
710
        mainLayout.setRows(6);
711

    
712
        // top-level component properties
713
        setWidth("340px");
714
        setHeight("840px");
715

    
716
        // classificationComboBox
717
        classificationComboBox = new ComboBox();
718
        classificationComboBox.setImmediate(false);
719
        classificationComboBox.setWidth("100.0%");
720
        classificationComboBox.setHeight("-1px");
721
        mainLayout.addComponent(classificationComboBox, 0, 0);
722

    
723
        // filterVerticalLayout
724
        filterVerticalLayout = buildFilterVerticalLayout();
725
        mainLayout.addComponent(filterVerticalLayout, 0, 1);
726
        mainLayout.setComponentAlignment(filterVerticalLayout, new Alignment(20));
727

    
728
        // searchHorizontalLayout
729
        searchHorizontalLayout = buildSearchHorizontalLayout();
730
        mainLayout.addComponent(searchHorizontalLayout, 0, 3);
731
        mainLayout.setComponentAlignment(searchHorizontalLayout, new Alignment(48));
732

    
733
        // taxaTreeTable
734
        taxaTreeTable = new TreeTable();
735
        taxaTreeTable.setImmediate(false);
736
        taxaTreeTable.setWidth("100.0%");
737
        taxaTreeTable.setHeight("614px");
738
        mainLayout.addComponent(taxaTreeTable, 0, 4);
739
        mainLayout.setComponentAlignment(taxaTreeTable, new Alignment(20));
740

    
741
        // inViewLabel
742
        inViewLabel = new Label();
743
        inViewLabel.setImmediate(false);
744
        inViewLabel.setWidth("100.0%");
745
        inViewLabel.setHeight("-1px");
746
        inViewLabel.setValue("in view : ");
747
        mainLayout.addComponent(inViewLabel, 0, 5);
748

    
749
        return mainLayout;
750
    }
751

    
752

    
753

    
754
    @AutoGenerated
755
    private VerticalLayout buildFilterVerticalLayout() {
756
        // common part: create layout
757
        filterVerticalLayout = new VerticalLayout();
758
        filterVerticalLayout.setImmediate(false);
759
        filterVerticalLayout.setWidth("100.0%");
760
        filterVerticalLayout.setHeight("-1px");
761
        filterVerticalLayout.setMargin(false);
762

    
763
        // filterLabel
764
        filterLabel = new Label();
765
        filterLabel.setImmediate(false);
766
        filterLabel.setWidth("100.0%");
767
        filterLabel.setHeight("-1px");
768
        filterLabel.setValue("Filter by :");
769
        filterVerticalLayout.addComponent(filterLabel);
770

    
771
        // filterTable
772
        filterTable = new Table();
773
        filterTable.setImmediate(false);
774
        filterTable.setWidth("100.0%");
775
        filterTable.setHeight("74px");
776
        filterVerticalLayout.addComponent(filterTable);
777
        filterVerticalLayout.setComponentAlignment(filterTable, new Alignment(48));
778

    
779
        return filterVerticalLayout;
780
    }
781

    
782

    
783

    
784
    @AutoGenerated
785
    private HorizontalLayout buildSearchHorizontalLayout() {
786
        // common part: create layout
787
        searchHorizontalLayout = new HorizontalLayout();
788
        searchHorizontalLayout.setImmediate(false);
789
        searchHorizontalLayout.setWidth("100.0%");
790
        searchHorizontalLayout.setHeight("-1px");
791
        searchHorizontalLayout.setMargin(false);
792
        searchHorizontalLayout.setSpacing(true);
793

    
794
        // searchTextField
795
        searchTextField = new TextField();
796
        searchTextField.setImmediate(false);
797
        searchTextField.setWidth("100.0%");
798
        searchTextField.setHeight("-1px");
799
        searchHorizontalLayout.addComponent(searchTextField);
800
        searchHorizontalLayout.setExpandRatio(searchTextField, 4.0f);
801
        searchHorizontalLayout.setComponentAlignment(searchTextField, new Alignment(48));
802

    
803
        // clearSearchButton
804
        clearSearchButton = new Button();
805
        clearSearchButton.setCaption("Button");
806
        clearSearchButton.setImmediate(true);
807
        clearSearchButton.setWidth("100.0%");
808
        clearSearchButton.setHeight("-1px");
809
        searchHorizontalLayout.addComponent(clearSearchButton);
810
        searchHorizontalLayout.setExpandRatio(clearSearchButton, 1.0f);
811
        searchHorizontalLayout.setComponentAlignment(clearSearchButton, new Alignment(48));
812

    
813
        return searchHorizontalLayout;
814
    }
815

    
816
}
(8-8/8)