Project

General

Profile

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

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

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

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

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

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

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

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

    
104
    private TreeTable mainTaxaTreeTable, excludedTaxaTreeTable;
105

    
106

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

    
109

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

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

    
123
    private static final String FILTER_UNPLACED = "unplaced";
124
    private static final String FILTER_UNFINISHED = "unfinished";
125
    private static final String FILTER_UNPUBLISHED = "unpublished";
126

    
127

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

    
131
    private boolean isTaxaTableInitialised = false;
132

    
133
    private boolean isFiltertableInitialised = false;
134

    
135

    
136
    private NewTaxonBaseComposite currentNewTaxonBaseComponent;
137
    private ContextMenu taxaTableContextMenu;
138

    
139

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

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

    
154

    
155

    
156

    
157
        init();
158

    
159
        addUIListeners();
160
    }
161

    
162

    
163

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

    
177
    public void init() {
178
        initSearchTextField();
179
        initClearSearchButton();
180
        initTaxaTabSheet();
181
        initClassificationComboBox();
182

    
183
        setEnabledAll(false);
184
        setExpandRatios();
185
    }
186

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

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

    
201

    
202
    public TreeTable getTaxaTreeTable() {
203
        return mainTaxaTreeTable;
204
    }
205

    
206
    public LeafNodeTaxonContainer getTaxonContainer() {
207
        return listener.getCurrentLeafNodeTaxonContainer();
208
    }
209

    
210
    public void clearTaxaTableSelections() {
211
        mainTaxaTreeTable.setValue(null);
212
    }
213

    
214
    public UUID getSelectedClassificationUuid() {
215
        if(classificationComboBox.getValue() != null) {
216
            return listener.getClassificationContainer().getUuid(classificationComboBox.getValue());
217
        }
218
        return null;
219
    }
220

    
221
    private void initMainTaxaTable() {
222
        mainTaxaTreeTable.setSelectable(true);
223
        mainTaxaTreeTable.setImmediate(true);
224
        mainTaxaTreeTable.setDragMode(TableDragMode.ROW);
225

    
226
        mainTaxaTreeTable.setColumnExpandRatio(LeafNodeTaxonContainer.NAME_ID, 1);
227
        mainTaxaTreeTable.setColumnWidth(LeafNodeTaxonContainer.PB_ID, 25);
228

    
229

    
230
        mainTaxaTreeTable.addGeneratedColumn(LeafNodeTaxonContainer.PB_ID, new TaxonTableCheckBoxGenerator());
231

    
232
        mainTaxaTreeTable.setCellStyleGenerator(new Table.CellStyleGenerator() {
233

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

    
246
            }
247
        });
248

    
249
        taxaTableContextMenu = new ContextMenu();
250
        taxaTableContextMenu.setAsContextMenuOf(mainTaxaTreeTable);
251
        addTaxaTreeContextMenuItemListener();
252
        isTaxaTableInitialised = true;
253
    }
254

    
255
    private void refreshTaxaTable(int classificationId) {
256
        if(!isTaxaTableInitialised) {
257
            initMainTaxaTable();
258
        }
259

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

    
279
    }
280

    
281
    private void initClassificationComboBox() {
282

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

    
298
    private void initTaxaTabSheet() {
299
        mainTaxaTreeTable = buildTaxaTreeTable();
300
        mainTaxaTreeTable.setCaption("Main");
301

    
302
        excludedTaxaTreeTable = buildTaxaTreeTable();
303
        excludedTaxaTreeTable.setCaption("Excluded");
304

    
305
        taxaTabSheet.addComponent(mainTaxaTreeTable);
306
        taxaTabSheet.addComponent(excludedTaxaTreeTable);
307
    }
308

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

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

    
319
        item = container.addItem(FILTER_UNPUBLISHED);
320
        item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_UNPUBLISHED);
321
        item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
322

    
323

    
324
        filterTable.setContainerDataSource(container);
325
        filterTable.setColumnHeaderMode(ColumnHeaderMode.HIDDEN);
326

    
327

    
328
        ValueChangeListener selectedListener = new ValueChangeListener() {
329

    
330
            private static final long serialVersionUID = -5551250788805117454L;
331

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

    
357
        if(!isFiltertableInitialised) {
358
            filterTable.addGeneratedColumn(PROPERTY_SELECTED_ID, new CheckBoxGenerator(selectedListener));
359
        }
360

    
361
        isFiltertableInitialised = true;
362

    
363
    }
364

    
365
    private void updateInViewLabel() {
366
        inViewLabel.setValue(IN_VIEW_PREFIX + String.valueOf(listener.getCurrentNoOfTaxa()) + " / " + String.valueOf(listener.getTotalNoOfTaxa()) + " taxa");
367
    }
368

    
369
    private void initSearchTextField() {
370
        searchTextField.setInputPrompt(FILTER_TAXA_INPUT);
371
    }
372

    
373

    
374
    private void initClearSearchButton() {
375
        clearSearchButton.setIcon(FontAwesome.REFRESH);
376
        clearSearchButton.setCaption("");
377
    }
378

    
379

    
380
    private void addUIListeners() {
381

    
382
        searchHorizontalLayout.addLayoutClickListener(new LayoutClickListener() {
383

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

    
392
        addClassificationComboBoxListener();
393
        addTaxaTreeTableListener();
394

    
395
        addSearchTextFieldListener();
396
        addClearSearchButtonListener();
397
    }
398

    
399
    private void addClassificationComboBoxListener() {
400

    
401
        classificationComboBox.addValueChangeListener(new Property.ValueChangeListener() {
402

    
403
            private static final long serialVersionUID = 4196786323147791606L;
404

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

    
411
                    setEnabledAll(false);
412
                    filterTable.setReadOnly(true);
413
                    mainTaxaTreeTable.setSelectable(false);
414

    
415
                    CdmVaadinUtilities.exec(new CdmVaadinOperation(100, null) {
416

    
417
                        @Override
418
                        public boolean execute() {
419
                            setProgress("loading taxa");
420
                            return true;
421
                        }
422

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

    
433

    
434
                }
435
            }
436
        });
437
    }
438

    
439
    private void addTaxaTreeTableListener() {
440

    
441
        mainTaxaTreeTable.addValueChangeListener(new ValueChangeListener() {
442

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

    
454
                    }
455
                    CdmVaadinSessionUtilities.getCurrentSelectionService()
456
                    .fireSelectionEvent(new SelectionEvent(Arrays.asList(taxonIun), StatusComposite.this), true);
457
                }
458
            }
459
        });
460

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

    
474
    private void generateTaxaTreeTableContextMenu(boolean isSynonym) {
475

    
476
        taxaTableContextMenu.removeAllItems();
477
        if(isSynonym) {
478

    
479

    
480
            ContextMenuItem changeToAccTaxonMenuItem = taxaTableContextMenu.addItem(CHANGE_TO_ACC_TAXON);
481
            changeToAccTaxonMenuItem.setData(CHANGE_TO_ACC_TAXON);
482

    
483
            ContextMenuItem replaceAccTaxonMenuItem = taxaTableContextMenu.addItem(REPLACE_ACC_TAXON);
484
            replaceAccTaxonMenuItem.setData(REPLACE_ACC_TAXON);
485

    
486
            replaceAccTaxonMenuItem.setSeparatorVisible(true);
487
        } else {
488
            ContextMenuItem createSynMenuItem = taxaTableContextMenu.addItem(CREATE_SYNONYM);
489
            createSynMenuItem.setData(CREATE_SYNONYM);
490

    
491
            ContextMenuItem changeToSynMenuItem = taxaTableContextMenu.addItem(CHANGE_TO_SYNONYM);
492
            changeToSynMenuItem.setData(CHANGE_TO_SYNONYM);
493
        }
494

    
495
        ContextMenuItem setDeletedMenuItem = taxaTableContextMenu.addItem(SET_AS_DELETED);
496
        setDeletedMenuItem.setData(SET_AS_DELETED);
497

    
498
        ContextMenuItem setExcludedMenuItem = taxaTableContextMenu.addItem(SET_AS_EXCLUDED);
499
        setExcludedMenuItem.setData(SET_AS_EXCLUDED);
500

    
501
        ContextMenuItem setUnresolvedMenuItem = taxaTableContextMenu.addItem(SET_AS_UNRESOLVED);
502
        setUnresolvedMenuItem.setData(SET_AS_UNRESOLVED);
503

    
504

    
505
        ContextMenuItem setOutOfScopeMenuItem = taxaTableContextMenu.addItem(SET_AS_OUT_OF_SCOPE);
506
        setOutOfScopeMenuItem.setData(SET_AS_OUT_OF_SCOPE);
507

    
508
        setOutOfScopeMenuItem.setSeparatorVisible(true);
509

    
510
        ContextMenuItem createAccTaxonMenuItem = taxaTableContextMenu.addItem(CREATE_NEW_TAXON);
511
        createAccTaxonMenuItem.setData(CREATE_NEW_TAXON);
512

    
513
    }
514

    
515
    private void addTaxaTreeContextMenuItemListener() {
516
        if(taxaTableContextMenu != null) {
517
            taxaTableContextMenu.addItemClickListener(new ContextMenuItemClickListener() {
518

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

    
536

    
537
    private void showAddTaxonBaseWindow(String action) {
538
        if (action != null) {
539
            String windowTitle;
540

    
541
            Object selectedItemId = null;
542
            IdUuidName accTaxonIdUuid = null;
543
            String accTaxonName = null;
544
            if(action.equals(CREATE_SYNONYM)) {
545
                selectedItemId = mainTaxaTreeTable.getValue();
546

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

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

    
585

    
586
    private void addSearchTextFieldListener() {
587
        searchTextField.addTextChangeListener(new FieldEvents.TextChangeListener() {
588

    
589
            private static final long serialVersionUID = -7376538870420619534L;
590

    
591
            @Override
592
            public void textChange(TextChangeEvent event) {
593
                listener.setNameFilter(event.getText());
594
                updateInViewLabel();
595
            }
596

    
597
        });
598

    
599
    }
600

    
601
    private void addClearSearchButtonListener() {
602
        clearSearchButton.addClickListener(new Button.ClickListener() {
603

    
604
            @Override
605
            public void buttonClick(ClickEvent event) {
606
                clearDynamicFilters();
607
                updateInViewLabel();
608
            }
609

    
610
        });
611
    }
612

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

    
621

    
622

    
623

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

    
632

    
633
    class TaxonTableCheckBoxGenerator implements Table.ColumnGenerator {
634

    
635

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

    
661
        }
662
    }
663

    
664
    class CheckBoxGenerator implements Table.ColumnGenerator {
665

    
666
        private final ValueChangeListener vcListener;
667

    
668
        public CheckBoxGenerator(ValueChangeListener vcListener) {
669
            this.vcListener = vcListener;
670
        }
671

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

    
692

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

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

    
716
        }
717
    }
718

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

    
726
    }
727

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

    
735
    }
736

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

    
744
    }
745

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

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

    
765
        // top-level component properties
766
        setWidth("340px");
767
        setHeight("100.0%");
768

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

    
776
        // filterVerticalLayout
777
        filterVerticalLayout = buildFilterVerticalLayout();
778
        mainLayout.addComponent(filterVerticalLayout, 0, 1);
779
        mainLayout.setComponentAlignment(filterVerticalLayout, new Alignment(20));
780

    
781
        // searchHorizontalLayout
782
        searchHorizontalLayout = buildSearchHorizontalLayout();
783
        mainLayout.addComponent(searchHorizontalLayout, 0, 2);
784
        mainLayout.setComponentAlignment(searchHorizontalLayout, new Alignment(48));
785

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

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

    
802
        return mainLayout;
803
    }
804

    
805

    
806

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

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

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

    
833
        return filterVerticalLayout;
834
    }
835

    
836

    
837

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

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

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

    
867
        return searchHorizontalLayout;
868
    }
869

    
870
}
(7-7/7)