Project

General

Profile

Download (31.7 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2015 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * See LICENSE.TXT at the top of this package for the full license terms.
8
 */
9
package eu.etaxonomy.cdm.vaadin.component.taxon;
10

    
11
import java.sql.SQLException;
12
import java.util.Arrays;
13
import java.util.UUID;
14

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

    
21
import com.vaadin.annotations.AutoGenerated;
22
import com.vaadin.data.Item;
23
import com.vaadin.data.Property;
24
import com.vaadin.data.Property.ValueChangeEvent;
25
import com.vaadin.data.Property.ValueChangeListener;
26
import com.vaadin.data.util.IndexedContainer;
27
import com.vaadin.data.util.sqlcontainer.RowId;
28
import com.vaadin.event.FieldEvents;
29
import com.vaadin.event.FieldEvents.TextChangeEvent;
30
import com.vaadin.event.ItemClickEvent;
31
import com.vaadin.event.ItemClickEvent.ItemClickListener;
32
import com.vaadin.event.LayoutEvents.LayoutClickEvent;
33
import com.vaadin.event.LayoutEvents.LayoutClickListener;
34
import com.vaadin.navigator.View;
35
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
36
import com.vaadin.server.FontAwesome;
37
import com.vaadin.ui.Alignment;
38
import com.vaadin.ui.Button;
39
import com.vaadin.ui.Button.ClickEvent;
40
import com.vaadin.ui.CheckBox;
41
import com.vaadin.ui.ComboBox;
42
import com.vaadin.ui.Component;
43
import com.vaadin.ui.CustomComponent;
44
import com.vaadin.ui.GridLayout;
45
import com.vaadin.ui.HorizontalLayout;
46
import com.vaadin.ui.Label;
47
import com.vaadin.ui.Notification;
48
import com.vaadin.ui.Notification.Type;
49
import com.vaadin.ui.TabSheet;
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.session.CdmChangeEvent;
62
import eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener;
63
import eu.etaxonomy.cdm.vaadin.session.SelectionEvent;
64
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinOperation;
65
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinSessionUtilities;
66
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinUtilities;
67

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

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

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

    
100
    private TreeTable mainTaxaTreeTable, excludedTaxaTreeTable;
101

    
102

    
103
    private static final String SELECT_CLASSIFICATION = "Select classification ...";
104

    
105

    
106
    private static final String CREATE_NEW_TAXON = "Create New Taxon";
107
    private static final String CHANGE_TO_ACC_TAXON = "Change to Accepted Taxon";
108
    private static final String REPLACE_ACC_TAXON = "Replace Accepted Taxon";
109
    private static final String CHANGE_TO_SYNONYM = "Change to Synonym";
110
    private static final String CREATE_SYNONYM = "Create Synonym";
111
    private static final String SET_AS_DELETED = "Set as Deleted";
112
    private static final String SET_AS_EXCLUDED = "Set as Excluded";
113
    private static final String SET_AS_UNRESOLVED = "Set as Unresolved";
114
    private static final String SET_AS_OUT_OF_SCOPE = "Set as Out Of Scope";
115

    
116
    private static final String PROPERTY_FILTER_ID = "filter";
117
    private static final String PROPERTY_SELECTED_ID = "selected";
118

    
119
    private static final String FILTER_UNPLACED = "unplaced";
120
    private static final String FILTER_UNFINISHED = "unfinished";
121
    private static final String FILTER_UNPUBLISHED = "unpublished";
122

    
123

    
124
    private static final String FILTER_TAXA_INPUT = "Filter Taxa ...";
125
    private static final String IN_VIEW_PREFIX = "in view : ";
126

    
127
    private boolean isTaxaTableInitialised = false;
128

    
129
    private boolean isFiltertableInitialised = false;
130

    
131

    
132
    private NewTaxonBaseComposite currentNewTaxonBaseComponent;
133
    private ContextMenu taxaTableContextMenu;
134

    
135

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

    
147
        this.listener = new StatusPresenter();
148
        CdmVaadinSessionUtilities.getCurrentCdmDataChangeService().register(this);
149

    
150

    
151

    
152

    
153
        init();
154

    
155
        addUIListeners();
156
    }
157

    
158

    
159

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

    
173
    public void init() {
174
        initSearchTextField();
175
        initClearSearchButton();
176
        initTaxaTabSheet();
177
        initClassificationComboBox();
178

    
179
        setEnabledAll(false);
180
        setExpandRatios();
181
    }
182

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

    
191
    public void setEnabledAll(boolean enabled) {
192
        CdmVaadinUtilities.setEnabled(mainLayout, enabled, Arrays.asList(classificationComboBox));
193
        taxaTabSheet.getTab(mainTaxaTreeTable).setEnabled(enabled);
194
        taxaTabSheet.getTab(excludedTaxaTreeTable).setEnabled(enabled);
195
    }
196

    
197

    
198
    public TreeTable getTaxaTreeTable() {
199
        return mainTaxaTreeTable;
200
    }
201

    
202
    public LeafNodeTaxonContainer getTaxonContainer() {
203
        return listener.getCurrentLeafNodeTaxonContainer();
204
    }
205

    
206
    public void clearTaxaTableSelections() {
207
        mainTaxaTreeTable.setValue(null);
208
    }
209

    
210
    public UUID getSelectedClassificationUuid() {
211
        if(classificationComboBox.getValue() != null) {
212
            return listener.getClassificationContainer().getUuid(classificationComboBox.getValue());
213
        }
214
        return null;
215
    }
216

    
217
    private void initMainTaxaTable() {
218
        mainTaxaTreeTable.setSelectable(true);
219
        mainTaxaTreeTable.setImmediate(true);
220
        mainTaxaTreeTable.setDragMode(TableDragMode.ROW);
221

    
222
        mainTaxaTreeTable.setColumnExpandRatio(LeafNodeTaxonContainer.NAME_ID, 1);
223
        mainTaxaTreeTable.setColumnWidth(LeafNodeTaxonContainer.PB_ID, 25);
224

    
225

    
226
        mainTaxaTreeTable.addGeneratedColumn(LeafNodeTaxonContainer.PB_ID, new TaxonTableCheckBoxGenerator());
227

    
228
        mainTaxaTreeTable.setCellStyleGenerator(new Table.CellStyleGenerator() {
229

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

    
242
            }
243
        });
244

    
245
        taxaTableContextMenu = new ContextMenu();
246
        taxaTableContextMenu.setAsContextMenuOf(mainTaxaTreeTable);
247
        addTaxaTreeContextMenuItemListener();
248
        isTaxaTableInitialised = true;
249
    }
250

    
251
    private void refreshTaxaTable(int classificationId) {
252
        if(!isTaxaTableInitialised) {
253
            initMainTaxaTable();
254
        }
255

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

    
275
    }
276

    
277
    private void initClassificationComboBox() {
278

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

    
294
    private void initTaxaTabSheet() {
295
        mainTaxaTreeTable = buildTaxaTreeTable();
296
        mainTaxaTreeTable.setCaption("Main");
297

    
298
        excludedTaxaTreeTable = buildTaxaTreeTable();
299
        excludedTaxaTreeTable.setCaption("Excluded");
300

    
301
        taxaTabSheet.addComponent(mainTaxaTreeTable);
302
        taxaTabSheet.addComponent(excludedTaxaTreeTable);
303
    }
304

    
305
    private void initFilterTable() {
306
        filterTable.setNullSelectionAllowed(false);
307
        final IndexedContainer container = new IndexedContainer();
308
        container.addContainerProperty("filter", String.class, "");
309
        container.addContainerProperty("selected", Boolean.class, "");
310

    
311
        Item item = container.addItem(FILTER_UNFINISHED);
312
        item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_UNFINISHED);
313
        item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
314

    
315
        item = container.addItem(FILTER_UNPUBLISHED);
316
        item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_UNPUBLISHED);
317
        item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
318

    
319

    
320
        filterTable.setContainerDataSource(container);
321
        filterTable.setColumnHeaderMode(ColumnHeaderMode.HIDDEN);
322

    
323

    
324
        ValueChangeListener selectedListener = new ValueChangeListener() {
325

    
326
            private static final long serialVersionUID = -5551250788805117454L;
327

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

    
353
        if(!isFiltertableInitialised) {
354
            filterTable.addGeneratedColumn(PROPERTY_SELECTED_ID, new CheckBoxGenerator(selectedListener));
355
        }
356

    
357
        isFiltertableInitialised = true;
358

    
359
    }
360

    
361
    private void updateInViewLabel() {
362
        inViewLabel.setValue(IN_VIEW_PREFIX + String.valueOf(listener.getCurrentNoOfTaxa()) + " / " + String.valueOf(listener.getTotalNoOfTaxa()) + " taxa");
363
    }
364

    
365
    private void initSearchTextField() {
366
        searchTextField.setInputPrompt(FILTER_TAXA_INPUT);
367
    }
368

    
369

    
370
    private void initClearSearchButton() {
371
        clearSearchButton.setIcon(FontAwesome.REFRESH);
372
        clearSearchButton.setCaption("");
373
    }
374

    
375

    
376
    private void addUIListeners() {
377

    
378
        searchHorizontalLayout.addLayoutClickListener(new LayoutClickListener() {
379

    
380
            @Override
381
            public void layoutClick(LayoutClickEvent event) {
382
                if (event.getChildComponent() == searchTextField && searchTextField.getValue().equals(FILTER_TAXA_INPUT)) {
383
                    searchTextField.setValue("");
384
                }
385
            }
386
        });
387

    
388
        addClassificationComboBoxListener();
389
        addTaxaTreeTableListener();
390

    
391
        addSearchTextFieldListener();
392
        addClearSearchButtonListener();
393
    }
394

    
395
    private void addClassificationComboBoxListener() {
396

    
397
        classificationComboBox.addValueChangeListener(new Property.ValueChangeListener() {
398

    
399
            private static final long serialVersionUID = 4196786323147791606L;
400

    
401
            @Override
402
            public void valueChange(ValueChangeEvent event) {
403
                if (classificationComboBox.getValue() != null) {
404
                    Object selected = classificationComboBox.getValue();
405
                    final int classificationId = (Integer)((RowId)selected).getId()[0];
406

    
407
                    setEnabledAll(false);
408
                    filterTable.setReadOnly(true);
409
                    mainTaxaTreeTable.setSelectable(false);
410

    
411
                    CdmVaadinUtilities.exec(new CdmVaadinOperation(100, null) {
412

    
413
                        @Override
414
                        public boolean execute() {
415
                            setProgress("loading taxa");
416
                            return true;
417
                        }
418

    
419
                        @Override
420
                        public void postOpUIUpdate(boolean isOpSuccess) {
421
                            refreshTaxaTable(classificationId);
422
                            initFilterTable();
423
                            setEnabledAll(true);
424
                            filterTable.setReadOnly(false);
425
                            mainTaxaTreeTable.setSelectable(true);
426
                        }
427
                    });
428

    
429

    
430
                }
431
            }
432
        });
433
    }
434

    
435
    private void addTaxaTreeTableListener() {
436

    
437
        mainTaxaTreeTable.addValueChangeListener(new ValueChangeListener() {
438

    
439
            @Override
440
            public void valueChange(ValueChangeEvent event) {
441
                Object itemId = mainTaxaTreeTable.getValue();
442
                Object taxonIun = null;
443
                if(mainTaxaTreeTable.isSelectable() && itemId != null) {
444
                    boolean isSynonym = listener.isSynonym(itemId);
445
                    if(!isSynonym) {
446
                        UUID taxonUuid = listener.getCurrentLeafNodeTaxonContainer().getUuid(itemId);
447
                        String taxonName = (String)listener.getCurrentLeafNodeTaxonContainer().getProperty(itemId, LeafNodeTaxonContainer.NAME_ID).getValue();
448
                        taxonIun = new IdUuidName(itemId, taxonUuid, taxonName);
449

    
450
                    }
451
                    CdmVaadinSessionUtilities.getCurrentSelectionService()
452
                    .fireSelectionEvent(new SelectionEvent(Arrays.asList(taxonIun), StatusComposite.this), true);
453
                }
454
            }
455
        });
456

    
457
        mainTaxaTreeTable.addItemClickListener(new ItemClickListener() {
458
            @Override
459
            public void itemClick(ItemClickEvent event) {
460
                Object itemId = event.getItemId();
461
                if(mainTaxaTreeTable.isSelectable() && itemId != null) {
462
                    boolean isSynonym = listener.isSynonym(itemId);
463
                    mainTaxaTreeTable.setValue(itemId);
464
                    generateTaxaTreeTableContextMenu(isSynonym);
465
                }
466
            }
467
        });
468
    }
469

    
470
    private void generateTaxaTreeTableContextMenu(boolean isSynonym) {
471

    
472
        taxaTableContextMenu.removeAllItems();
473
        if(isSynonym) {
474

    
475

    
476
            ContextMenuItem changeToAccTaxonMenuItem = taxaTableContextMenu.addItem(CHANGE_TO_ACC_TAXON);
477
            changeToAccTaxonMenuItem.setData(CHANGE_TO_ACC_TAXON);
478

    
479
            ContextMenuItem replaceAccTaxonMenuItem = taxaTableContextMenu.addItem(REPLACE_ACC_TAXON);
480
            replaceAccTaxonMenuItem.setData(REPLACE_ACC_TAXON);
481

    
482
            replaceAccTaxonMenuItem.setSeparatorVisible(true);
483
        } else {
484
            ContextMenuItem createSynMenuItem = taxaTableContextMenu.addItem(CREATE_SYNONYM);
485
            createSynMenuItem.setData(CREATE_SYNONYM);
486

    
487
            ContextMenuItem changeToSynMenuItem = taxaTableContextMenu.addItem(CHANGE_TO_SYNONYM);
488
            changeToSynMenuItem.setData(CHANGE_TO_SYNONYM);
489
        }
490

    
491
        ContextMenuItem setDeletedMenuItem = taxaTableContextMenu.addItem(SET_AS_DELETED);
492
        setDeletedMenuItem.setData(SET_AS_DELETED);
493

    
494
        ContextMenuItem setExcludedMenuItem = taxaTableContextMenu.addItem(SET_AS_EXCLUDED);
495
        setExcludedMenuItem.setData(SET_AS_EXCLUDED);
496

    
497
        ContextMenuItem setUnresolvedMenuItem = taxaTableContextMenu.addItem(SET_AS_UNRESOLVED);
498
        setUnresolvedMenuItem.setData(SET_AS_UNRESOLVED);
499

    
500

    
501
        ContextMenuItem setOutOfScopeMenuItem = taxaTableContextMenu.addItem(SET_AS_OUT_OF_SCOPE);
502
        setOutOfScopeMenuItem.setData(SET_AS_OUT_OF_SCOPE);
503

    
504
        setOutOfScopeMenuItem.setSeparatorVisible(true);
505

    
506
        ContextMenuItem createAccTaxonMenuItem = taxaTableContextMenu.addItem(CREATE_NEW_TAXON);
507
        createAccTaxonMenuItem.setData(CREATE_NEW_TAXON);
508

    
509
    }
510

    
511
    private void addTaxaTreeContextMenuItemListener() {
512
        if(taxaTableContextMenu != null) {
513
            taxaTableContextMenu.addItemClickListener(new ContextMenuItemClickListener() {
514

    
515
                @Override
516
                public void contextMenuItemClicked(ContextMenuItemClickEvent event) {
517
                    Object source = event.getSource();
518
                    if(source instanceof ContextMenuItem) {
519
                        ContextMenuItem menuItem = (ContextMenuItem) source;
520
                        String action = (String)menuItem.getData();
521
                        if(CREATE_NEW_TAXON.equals(action) || CREATE_SYNONYM.equals(action)) {
522
                            showAddTaxonBaseWindow(action);
523
                        } else {
524
                            Notification.show(action + " to be implemented", Type.WARNING_MESSAGE);
525
                        }
526
                    }
527
                }
528
            });
529
        }
530
    }
531

    
532

    
533
    private void showAddTaxonBaseWindow(String action) {
534
        if (action != null) {
535
            String windowTitle;
536

    
537
            Object selectedItemId = null;
538
            IdUuidName accTaxonIdUuid = null;
539
            String accTaxonName = null;
540
            if(action.equals(CREATE_SYNONYM)) {
541
                selectedItemId = mainTaxaTreeTable.getValue();
542

    
543
                // if a synonym is selected then throw warning
544
                if(listener.isSynonym(selectedItemId)) {
545
                    Notification.show("Synonym selected", "Please choose a Taxon", Type.WARNING_MESSAGE);
546
                    return;
547
                }
548
                windowTitle = "Add New Synonym";
549
                accTaxonIdUuid = new IdUuidName(selectedItemId,
550
                        listener.getCurrentLeafNodeTaxonContainer().getUuid(selectedItemId),
551
                        (String) listener.getCurrentLeafNodeTaxonContainer().getProperty(selectedItemId, LeafNodeTaxonContainer.NAME_ID).getValue());
552
                accTaxonName = (String)listener.getCurrentLeafNodeTaxonContainer().getProperty(selectedItemId, LeafNodeTaxonContainer.NAME_ID).getValue();
553
            } else {
554
                windowTitle = "Add New Taxon";
555
            }
556

    
557
            try {
558
                Window dialog = new Window(windowTitle);
559
                dialog.setModal(true);
560
                dialog.setClosable(false);
561
                dialog.setResizable(false);
562
                UI.getCurrent().addWindow(dialog);
563
                Object cId = classificationComboBox.getValue();
564
                UUID classificationUuid = listener.getClassificationContainer().getUuid(cId);
565
                IdUuidName classificationIdUuid = new IdUuidName(classificationComboBox.getValue(),
566
                        classificationUuid,
567
                        (String) listener.getClassificationContainer().getProperty(cId, StatusPresenter.C_TCACHE_ID).getValue());
568
                 currentNewTaxonBaseComponent = new NewTaxonBaseComposite(dialog,
569
                                new NewTaxonBasePresenter(),
570
                                accTaxonIdUuid,
571
                                accTaxonName,
572
                                classificationIdUuid);
573
                dialog.setContent(currentNewTaxonBaseComponent);
574
            } catch (SQLException e) {
575
                // TODO Auto-generated catch block
576
                e.printStackTrace();
577
            }
578
        }
579
    }
580

    
581

    
582
    private void addSearchTextFieldListener() {
583
        searchTextField.addTextChangeListener(new FieldEvents.TextChangeListener() {
584

    
585
            private static final long serialVersionUID = -7376538870420619534L;
586

    
587
            @Override
588
            public void textChange(TextChangeEvent event) {
589
                listener.setNameFilter(event.getText());
590
                updateInViewLabel();
591
            }
592

    
593
        });
594

    
595
    }
596

    
597
    private void addClearSearchButtonListener() {
598
        clearSearchButton.addClickListener(new Button.ClickListener() {
599

    
600
            @Override
601
            public void buttonClick(ClickEvent event) {
602
                clearDynamicFilters();
603
                updateInViewLabel();
604
            }
605

    
606
        });
607
    }
608

    
609
    private void clearDynamicFilters() {
610
        listener.removeDynamicFilters();
611
        searchTextField.setValue(FILTER_TAXA_INPUT);
612
        for(Object itemId : filterTable.getItemIds()) {
613
            filterTable.getItem(itemId).getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
614
        }
615
    }
616

    
617

    
618

    
619

    
620
    /* (non-Javadoc)
621
     * @see eu.etaxonomy.cdm.vaadin.view.IStatusComponent#setListener(eu.etaxonomy.cdm.vaadin.view.IStatusComponent.StatusComponentListener)
622
     */
623
    @Override
624
    public void setListener(StatusComponentListener listener) {
625
        this.listener = listener;
626
    }
627

    
628

    
629
    class TaxonTableCheckBoxGenerator implements Table.ColumnGenerator {
630

    
631

    
632
        /**
633
         * Generates the cell containing an open image when boolean is true
634
         */
635
        @Override
636
        public Component generateCell(Table source, final Object itemId, Object columnId) {
637
            if(source.getItem(itemId) != null) {
638
                Property prop = source.getItem(itemId).getItemProperty(columnId);
639
                if(prop == null) {
640
                    return null;
641
                }
642
                CheckBox cb = new CheckBox(null, prop);
643
                ValueChangeListener pbListener = new ValueChangeListener() {
644
                    @Override
645
                    public void valueChange(ValueChangeEvent event) {
646
                        boolean value = (Boolean) event.getProperty().getValue();
647
                        listener.updatePublished(value, itemId);
648
                    }
649
                };
650
                cb.addValueChangeListener(pbListener);
651
                cb.setData(itemId);
652
                return cb;
653
            } else {
654
                return null;
655
            }
656

    
657
        }
658
    }
659

    
660
    class CheckBoxGenerator implements Table.ColumnGenerator {
661

    
662
        private final ValueChangeListener vcListener;
663

    
664
        public CheckBoxGenerator(ValueChangeListener vcListener) {
665
            this.vcListener = vcListener;
666
        }
667

    
668
        /**
669
         * Generates the cell containing an open image when boolean is true
670
         */
671
        @Override
672
        public Component generateCell(Table source, final Object itemId, Object columnId) {
673
            if(source.getItem(itemId) != null) {
674
                Property prop = source.getItem(itemId).getItemProperty(columnId);
675
                if(prop == null) {
676
                    return null;
677
                }
678
                CheckBox cb = new CheckBox(null, prop);
679
                cb.addValueChangeListener(vcListener);
680
                cb.setData(itemId);
681
                return cb;
682
            } else {
683
                return null;
684
            }
685
        }
686
    }
687

    
688

    
689
    /* (non-Javadoc)
690
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onCreate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
691
     */
692
    @Override
693
    public void onCreate(CdmChangeEvent event) {
694
        if(event.getSource() != null && event.getSource() == currentNewTaxonBaseComponent) {
695
            Object itemId = event.getChangedObjects().get(0);
696
            boolean newTaxon= (Boolean) event.getChangedObjects().get(1);
697

    
698
            if(newTaxon) {
699
                // after creating a new taxon we clear all filters and
700
                // filter in only the newly created taxon and select it
701
                clearDynamicFilters();
702
                listener.setIdFilter(itemId);
703
                mainTaxaTreeTable.setValue(itemId);
704
            } else {
705
                // after creating a new synonym we expand the selected taxon
706
                // and select the newly created synonym
707
                mainTaxaTreeTable.setCollapsed(mainTaxaTreeTable.getValue(), false);
708
                listener.refresh();
709
                mainTaxaTreeTable.setValue(itemId);
710
            }
711

    
712
        }
713
    }
714

    
715
    /* (non-Javadoc)
716
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onUpdate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
717
     */
718
    @Override
719
    public void onUpdate(CdmChangeEvent event) {
720
        // TODO Auto-generated method stub
721

    
722
    }
723

    
724
    /* (non-Javadoc)
725
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onDelete(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
726
     */
727
    @Override
728
    public void onDelete(CdmChangeEvent event) {
729
        // TODO Auto-generated method stub
730

    
731
    }
732

    
733
    /* (non-Javadoc)
734
     * @see com.vaadin.navigator.View#enter(com.vaadin.navigator.ViewChangeListener.ViewChangeEvent)
735
     */
736
    @Override
737
    public void enter(ViewChangeEvent event) {
738
        // TODO Auto-generated method stub
739

    
740
    }
741

    
742
    private TreeTable buildTaxaTreeTable() {
743
        TreeTable taxaTreeTable = new TreeTable();
744
        taxaTreeTable.setImmediate(false);
745
        taxaTreeTable.setWidth("100.0%");
746
        taxaTreeTable.setHeight("100.0%");
747
        return taxaTreeTable;
748
    }
749

    
750
    @AutoGenerated
751
    private GridLayout buildMainLayout() {
752
        // common part: create layout
753
        mainLayout = new GridLayout();
754
        mainLayout.setImmediate(false);
755
        mainLayout.setWidth("340px");
756
        mainLayout.setHeight("100%");
757
        mainLayout.setMargin(true);
758
        mainLayout.setSpacing(true);
759
        mainLayout.setRows(5);
760

    
761
        // top-level component properties
762
        setWidth("340px");
763
        setHeight("100.0%");
764

    
765
        // classificationComboBox
766
        classificationComboBox = new ComboBox();
767
        classificationComboBox.setImmediate(false);
768
        classificationComboBox.setWidth("100.0%");
769
        classificationComboBox.setHeight("100.0%");
770
        mainLayout.addComponent(classificationComboBox, 0, 0);
771

    
772
        // filterVerticalLayout
773
        filterVerticalLayout = buildFilterVerticalLayout();
774
        mainLayout.addComponent(filterVerticalLayout, 0, 1);
775
        mainLayout.setComponentAlignment(filterVerticalLayout, new Alignment(20));
776

    
777
        // searchHorizontalLayout
778
        searchHorizontalLayout = buildSearchHorizontalLayout();
779
        mainLayout.addComponent(searchHorizontalLayout, 0, 2);
780
        mainLayout.setComponentAlignment(searchHorizontalLayout, new Alignment(48));
781

    
782
        // taxaTabSheet
783
        taxaTabSheet = new TabSheet();
784
        taxaTabSheet.setImmediate(false);
785
        taxaTabSheet.setWidth("100.0%");
786
        taxaTabSheet.setHeight("100.0%");
787
        mainLayout.addComponent(taxaTabSheet, 0, 3);
788
        mainLayout.setComponentAlignment(taxaTabSheet, new Alignment(20));
789

    
790
        // inViewLabel
791
        inViewLabel = new Label();
792
        inViewLabel.setImmediate(false);
793
        inViewLabel.setWidth("100.0%");
794
        inViewLabel.setHeight("100.0%");
795
        inViewLabel.setValue("in view : ");
796
        mainLayout.addComponent(inViewLabel, 0, 4);
797

    
798
        return mainLayout;
799
    }
800

    
801

    
802

    
803
    @AutoGenerated
804
    private VerticalLayout buildFilterVerticalLayout() {
805
        // common part: create layout
806
        filterVerticalLayout = new VerticalLayout();
807
        filterVerticalLayout.setImmediate(false);
808
        filterVerticalLayout.setWidth("100.0%");
809
        filterVerticalLayout.setHeight("100.0%");
810
        filterVerticalLayout.setMargin(false);
811

    
812
        // filterLabel
813
        filterLabel = new Label();
814
        filterLabel.setImmediate(false);
815
        filterLabel.setWidth("100.0%");
816
        filterLabel.setHeight("-1px");
817
        filterLabel.setValue("Filter by :");
818
        filterVerticalLayout.addComponent(filterLabel);
819

    
820
        // filterTable
821
        filterTable = new Table();
822
        filterTable.setImmediate(false);
823
        filterTable.setWidth("100.0%");
824
        filterTable.setHeight("100.0%");
825
        filterVerticalLayout.addComponent(filterTable);
826
        filterVerticalLayout.setExpandRatio(filterTable, 1.0f);
827
        filterVerticalLayout.setComponentAlignment(filterTable, new Alignment(48));
828

    
829
        return filterVerticalLayout;
830
    }
831

    
832

    
833

    
834
    @AutoGenerated
835
    private HorizontalLayout buildSearchHorizontalLayout() {
836
        // common part: create layout
837
        searchHorizontalLayout = new HorizontalLayout();
838
        searchHorizontalLayout.setImmediate(false);
839
        searchHorizontalLayout.setWidth("100.0%");
840
        searchHorizontalLayout.setHeight("-1px");
841
        searchHorizontalLayout.setMargin(false);
842
        searchHorizontalLayout.setSpacing(true);
843

    
844
        // searchTextField
845
        searchTextField = new TextField();
846
        searchTextField.setImmediate(false);
847
        searchTextField.setWidth("100.0%");
848
        searchTextField.setHeight("-1px");
849
        searchHorizontalLayout.addComponent(searchTextField);
850
        searchHorizontalLayout.setExpandRatio(searchTextField, 4.0f);
851
        searchHorizontalLayout.setComponentAlignment(searchTextField, new Alignment(48));
852

    
853
        // clearSearchButton
854
        clearSearchButton = new Button();
855
        clearSearchButton.setCaption("Button");
856
        clearSearchButton.setImmediate(true);
857
        clearSearchButton.setWidth("100.0%");
858
        clearSearchButton.setHeight("-1px");
859
        searchHorizontalLayout.addComponent(clearSearchButton);
860
        searchHorizontalLayout.setExpandRatio(clearSearchButton, 1.0f);
861
        searchHorizontalLayout.setComponentAlignment(clearSearchButton, new Alignment(48));
862

    
863
        return searchHorizontalLayout;
864
    }
865

    
866
}
(11-11/12)