Project

General

Profile

Download (31.8 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.component.TextFieldNFix;
60
import eu.etaxonomy.cdm.vaadin.container.IdUuidName;
61
import eu.etaxonomy.cdm.vaadin.container.LeafNodeTaxonContainer;
62
import eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent;
63
import eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener;
64
import eu.etaxonomy.cdm.vaadin.session.SelectionEvent;
65
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinOperation;
66
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinSessionUtilities;
67
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinUtilities;
68

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

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

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

    
101
    private TreeTable mainTaxaTreeTable, excludedTaxaTreeTable;
102

    
103

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

    
106

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

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

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

    
124

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

    
128
    private boolean isTaxaTableInitialised = false;
129

    
130
    private boolean isFiltertableInitialised = false;
131

    
132

    
133
    private NewTaxonBaseComposite currentNewTaxonBaseComponent;
134
    private ContextMenu taxaTableContextMenu;
135

    
136

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

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

    
151

    
152

    
153

    
154
        init();
155

    
156
        addUIListeners();
157
    }
158

    
159

    
160

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

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

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

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

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

    
198

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

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

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

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

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

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

    
226

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

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

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

    
243
            }
244
        });
245

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

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

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

    
276
    }
277

    
278
    private void initClassificationComboBox() {
279

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

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

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

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

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

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

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

    
320

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

    
324

    
325
        ValueChangeListener selectedListener = new ValueChangeListener() {
326

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

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

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

    
358
        isFiltertableInitialised = true;
359

    
360
    }
361

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

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

    
370

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

    
376

    
377
    private void addUIListeners() {
378

    
379
        searchHorizontalLayout.addLayoutClickListener(new LayoutClickListener() {
380

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

    
389
        addClassificationComboBoxListener();
390
        addTaxaTreeTableListener();
391

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

    
396
    private void addClassificationComboBoxListener() {
397

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

    
400
            private static final long serialVersionUID = 4196786323147791606L;
401

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

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

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

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

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

    
430

    
431
                }
432
            }
433
        });
434
    }
435

    
436
    private void addTaxaTreeTableListener() {
437

    
438
        mainTaxaTreeTable.addValueChangeListener(new ValueChangeListener() {
439

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

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

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

    
471
    private void generateTaxaTreeTableContextMenu(boolean isSynonym) {
472

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

    
476

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

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

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

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

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

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

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

    
501

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

    
505
        setOutOfScopeMenuItem.setSeparatorVisible(true);
506

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

    
510
    }
511

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

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

    
533

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

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

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

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

    
582

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

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

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

    
594
        });
595

    
596
    }
597

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

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

    
607
        });
608
    }
609

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

    
618

    
619

    
620

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

    
629

    
630
    class TaxonTableCheckBoxGenerator implements Table.ColumnGenerator {
631

    
632

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

    
658
        }
659
    }
660

    
661
    class CheckBoxGenerator implements Table.ColumnGenerator {
662

    
663
        private final ValueChangeListener vcListener;
664

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

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

    
689

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

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

    
713
        }
714
    }
715

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

    
723
    }
724

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

    
732
    }
733

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

    
741
    }
742

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

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

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

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

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

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

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

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

    
799
        return mainLayout;
800
    }
801

    
802

    
803

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

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

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

    
830
        return filterVerticalLayout;
831
    }
832

    
833

    
834

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

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

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

    
864
        return searchHorizontalLayout;
865
    }
866

    
867
}
(11-11/12)