Project

General

Profile

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

    
12
import java.sql.SQLException;
13
import java.util.ArrayList;
14
import java.util.Arrays;
15
import java.util.List;
16
import java.util.Set;
17
import java.util.UUID;
18

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

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

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

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

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

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

    
105
    private Object currentClickedTaxonItemId;
106

    
107
    private final boolean taxaTreeTableMultiSelectMode = true;
108

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

    
111

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

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

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

    
129

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

    
133
    private boolean isTaxaTableInitialised = false;
134
    private boolean isFiltertableInitialised = false;
135

    
136
    private String selectedTaxaTableMenuItem = null;
137

    
138
    ContextMenu taxaTableContextMenu;
139

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

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

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

    
159
        init();
160
    }
161

    
162

    
163

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

    
177
    public void init() {
178
        taxaTreeTable.setSelectable(true);
179
        initClassificationComboBox();
180
    }
181

    
182
    public void setEnabledAll(boolean enabled) {
183
        CdmVaadinUtilities.setEnabled(mainLayout, enabled, Arrays.asList(classificationComboBox));
184
    }
185

    
186

    
187
    public TreeTable getTaxaTreeTable() {
188
        return taxaTreeTable;
189
    }
190

    
191
    public LeafNodeTaxonContainer getTaxonContainer() {
192
        return listener.getCurrentLeafNodeTaxonContainer();
193
    }
194

    
195
    public void clearTaxaTableSelections() {
196
        taxaTreeTable.setValue(null);
197
    }
198

    
199
    public UUID getSelectedClassificationUuid() {
200
        if(classificationComboBox.getValue() != null) {
201
            return listener.getClassificationContainer().getUuid(classificationComboBox.getValue());
202
        }
203
        return null;
204
    }
205

    
206
    private void initTaxaTable(int classificationId) {
207
        taxaTreeTable.setMultiSelect(taxaTreeTableMultiSelectMode);
208
        taxaTreeTable.setImmediate(false);
209
        taxaTreeTable.setDragMode(TableDragMode.ROW);
210
        if(listener != null) {
211
            List<String> columnIds = new ArrayList<String>();
212
            columnIds.add(LeafNodeTaxonContainer.NAME_ID);
213
            taxaTreeTable.setColumnExpandRatio(LeafNodeTaxonContainer.NAME_ID, 1);
214
            columnIds.add(LeafNodeTaxonContainer.PB_ID);
215
            taxaTreeTable.setColumnWidth(LeafNodeTaxonContainer.PB_ID, 25);
216

    
217
            if(!isTaxaTableInitialised) {
218
                taxaTreeTable.addGeneratedColumn(LeafNodeTaxonContainer.PB_ID, new TaxonTableCheckBoxGenerator());
219
            }
220

    
221
            try {
222
                taxaTreeTable.setContainerDataSource(listener.loadTaxa(classificationId), columnIds);
223
            } catch (SQLException e) {
224
                //TODO : throw up warning dialog
225
                e.printStackTrace();
226
            }
227

    
228

    
229
            taxaTreeTable.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
            taxaTreeTable.setSortContainerPropertyId(LeafNodeTaxonContainer.NAME_ID);
247

    
248
            // NOTE : Not really sure why we need to refresh the container here.
249
            // in the case of 'Table' this is not required
250
            listener.refresh();
251
            updateInViewLabel();
252
            isTaxaTableInitialised = true;
253
        }
254

    
255
        taxaTableContextMenu = new ContextMenu();
256
        taxaTableContextMenu.setAsContextMenuOf(taxaTreeTable);
257
        addTaxaTreeContextMenuItemListener();
258

    
259

    
260
    }
261

    
262
    private void initClassificationComboBox() {
263

    
264
        classificationComboBox.setNewItemsAllowed(false);
265
        classificationComboBox.setNullSelectionAllowed(false);
266
        classificationComboBox.setImmediate(true);
267
        classificationComboBox.setItemCaptionPropertyId(StatusPresenter.C_TCACHE_ID);
268
        classificationComboBox.setInputPrompt(SELECT_CLASSIFICATION);
269
        if(listener != null) {
270
            try {
271
                classificationComboBox.setContainerDataSource(listener.loadClassifications());
272
            } catch (SQLException e) {
273
                //TODO : throw up warning dialog
274
                e.printStackTrace();
275
            }
276
        }
277
    }
278

    
279

    
280

    
281
    private void initFilterTable() {
282
        filterTable.setNullSelectionAllowed(false);
283
        final IndexedContainer container = new IndexedContainer();
284
        container.addContainerProperty("filter", String.class, "");
285
        container.addContainerProperty("selected", Boolean.class, "");
286

    
287
        Item item = container.addItem(FILTER_UNFINISHED);
288
        item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_UNFINISHED);
289
        item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
290

    
291
        item = container.addItem(FILTER_UNPUBLISHED);
292
        item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_UNPUBLISHED);
293
        item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
294

    
295

    
296
        filterTable.setContainerDataSource(container);
297
        filterTable.setColumnHeaderMode(ColumnHeaderMode.HIDDEN);
298

    
299

    
300
        ValueChangeListener selectedListener = new ValueChangeListener() {
301

    
302
            private static final long serialVersionUID = -5551250788805117454L;
303

    
304
            @Override
305
            public void valueChange(ValueChangeEvent event) {
306
                boolean value = (Boolean) event.getProperty().getValue();
307
                String selectedFilter = (String)filterTable.getItem(((CheckBox)event.getProperty()).getData()).getItemProperty(PROPERTY_FILTER_ID).getValue();
308
                if(selectedFilter != null) {
309
                    if(value) {
310
                        if(selectedFilter.equals(FILTER_UNPLACED)) {
311
                            listener.setUnplacedFilter();
312
                        }
313
                        if(selectedFilter.equals(FILTER_UNPUBLISHED)) {
314
                            listener.setUnpublishedFilter();
315
                        }
316
                    } else {
317
                        if(selectedFilter.equals(FILTER_UNPLACED)) {
318
                            listener.removeUnplacedFilter();
319
                        }
320
                        if(selectedFilter.equals(FILTER_UNPUBLISHED)) {
321
                            listener.removeUnpublishedFilter();
322
                        }
323
                    }
324
                    updateInViewLabel();
325
                }
326
            }
327
        };
328

    
329
        if(!isFiltertableInitialised) {
330
            filterTable.addGeneratedColumn(PROPERTY_SELECTED_ID, new CheckBoxGenerator(selectedListener));
331
        }
332

    
333
        isFiltertableInitialised = true;
334

    
335
    }
336

    
337
    private void updateInViewLabel() {
338
        inViewLabel.setValue(IN_VIEW_PREFIX + String.valueOf(listener.getCurrentNoOfTaxa()) + " / " + String.valueOf(listener.getTotalNoOfTaxa()) + " taxa");
339
    }
340

    
341
    private void initSearchTextField() {
342
        searchTextField.setInputPrompt(FILTER_TAXA_INPUT);
343
    }
344

    
345

    
346
    private void initClearSearchButton() {
347
        clearSearchButton.setIcon(FontAwesome.REFRESH);
348
        clearSearchButton.setCaption("");
349
    }
350

    
351

    
352
    private void addUIListeners() {
353

    
354
        searchHorizontalLayout.addLayoutClickListener(new LayoutClickListener() {
355

    
356
            @Override
357
            public void layoutClick(LayoutClickEvent event) {
358
                if (event.getChildComponent() == searchTextField && searchTextField.getValue().equals(FILTER_TAXA_INPUT)) {
359
                    searchTextField.setValue("");
360
                }
361
            }
362
        });
363

    
364
        addClassificationComboBoxListener();
365
        addTaxaTreeTableListener();
366

    
367
        addSearchTextFieldListener();
368
        addClearSearchButtonListener();
369
    }
370

    
371
    private void addClassificationComboBoxListener() {
372

    
373
        classificationComboBox.addValueChangeListener(new Property.ValueChangeListener() {
374

    
375
            private static final long serialVersionUID = 4196786323147791606L;
376

    
377
            @Override
378
            public void valueChange(ValueChangeEvent event) {
379
                if (classificationComboBox.getValue() != null) {
380
                    Object selected = classificationComboBox.getValue();
381
                    int classificationId = (Integer)((RowId)selected).getId()[0];
382
                    initTaxaTable(classificationId);
383
                    initFilterTable();
384
                    setEnabledAll(true);
385
                }
386
            }
387
        });
388
    }
389

    
390
    private void addTaxaTreeTableListener() {
391

    
392
        taxaTreeTable.addItemClickListener(new ItemClickListener() {
393
            @Override
394
            public void itemClick(ItemClickEvent event) {
395
                Object itemId = event.getItemId();
396
                if(taxaTreeTable.isSelectable()) {
397
                    boolean isSynonym = listener.isSynonym(itemId);
398
                    if(!CdmVaadinUtilities.isSelected(taxaTreeTable, itemId) && !isSynonym) {
399
                        UUID taxonUuid = listener.getCurrentLeafNodeTaxonContainer().getUuid(itemId);
400
                        String taxonName = (String)listener.getCurrentLeafNodeTaxonContainer().getProperty(itemId, LeafNodeTaxonContainer.NAME_ID).getValue();
401
                        Object idUuidName = new IdUuidName(itemId, taxonUuid, taxonName);
402
                        CdmVaadinSessionUtilities.getCurrentSelectionService()
403
                        .fireSelectionEvent(new SelectionEvent(Arrays.asList(idUuidName, getSelectedClassificationUuid()), StatusComposite.class), true);
404
                    }
405
                    taxaTreeTable.setValue(Arrays.asList(itemId));
406
                    generateTaxaTreeTableContextMenu(isSynonym);
407

    
408
                }
409
            }
410
        });
411

    
412
        //taxaTreeTable.add
413

    
414

    
415
    }
416

    
417
    private void generateTaxaTreeTableContextMenu(boolean isSynonym) {
418

    
419
        taxaTableContextMenu.removeAllItems();
420
        if(isSynonym) {
421

    
422

    
423
            ContextMenuItem changeToAccTaxonMenuItem = taxaTableContextMenu.addItem(CHANGE_TO_ACC_TAXON);
424
            changeToAccTaxonMenuItem.setData(CHANGE_TO_ACC_TAXON);
425

    
426
            ContextMenuItem replaceAccTaxonMenuItem = taxaTableContextMenu.addItem(REPLACE_ACC_TAXON);
427
            replaceAccTaxonMenuItem.setData(REPLACE_ACC_TAXON);
428

    
429
            replaceAccTaxonMenuItem.setSeparatorVisible(true);
430
        } else {
431
            ContextMenuItem createSynMenuItem = taxaTableContextMenu.addItem(CREATE_SYNONYM);
432
            createSynMenuItem.setData(CREATE_SYNONYM);
433

    
434
            ContextMenuItem changeToSynMenuItem = taxaTableContextMenu.addItem(CHANGE_TO_SYNONYM);
435
            changeToSynMenuItem.setData(CHANGE_TO_SYNONYM);
436

    
437
            changeToSynMenuItem.setSeparatorVisible(true);
438
        }
439

    
440
        ContextMenuItem setDeletedMenuItem = taxaTableContextMenu.addItem(SET_AS_DELETED);
441
        setDeletedMenuItem.setData(SET_AS_DELETED);
442

    
443
        ContextMenuItem setExcludedMenuItem = taxaTableContextMenu.addItem(SET_AS_EXCLUDED);
444
        setExcludedMenuItem.setData(SET_AS_EXCLUDED);
445

    
446
        ContextMenuItem setOutOfScopeMenuItem = taxaTableContextMenu.addItem(SET_AS_OUT_OF_SCOPE);
447
        setOutOfScopeMenuItem.setData(SET_AS_OUT_OF_SCOPE);
448

    
449
        ContextMenuItem createAccTaxonMenuItem = taxaTableContextMenu.addItem(CREATE_ACC_TAXON);
450
        createAccTaxonMenuItem.setData(CREATE_ACC_TAXON);
451

    
452
    }
453

    
454
    private void addTaxaTreeContextMenuItemListener() {
455
        if(taxaTableContextMenu != null) {
456
            taxaTableContextMenu.addItemClickListener(new ContextMenuItemClickListener() {
457

    
458
                @Override
459
                public void contextMenuItemClicked(ContextMenuItemClickEvent event) {
460
                    Object source = event.getSource();
461
                    if(source instanceof ContextMenuItem) {
462
                        ContextMenuItem menuItem = (ContextMenuItem) source;
463
                        String action = (String)menuItem.getData();
464
                        if(CREATE_ACC_TAXON.equals(action) || CREATE_SYNONYM.equals(action)) {
465
                            showAddTaxonBaseWindow(action);
466
                        } else {
467
                            Notification.show(action + " to be implemented", Type.WARNING_MESSAGE);
468
                        }
469
                    }
470
                }
471
            });
472
        }
473
    }
474

    
475

    
476
    private void showAddTaxonBaseWindow(String action) {
477
        if (action != null) {
478
            String windowTitle;
479

    
480
            Object selectedItemId = null;
481
            IdUuidName accTaxonIdUuid = null;
482
            String accTaxonName = null;
483
            if(action.equals(CREATE_SYNONYM)) {
484
                Set<Object> selectedIds = (Set<Object>)taxaTreeTable.getValue();
485
                // if zero or more than one items (taxa / synonyms) are selected
486
                // throw a warning
487
                if(selectedIds.size() != 1) {
488
                    Notification.show("Multiple or No selection", "Please select a single Taxon", Type.WARNING_MESSAGE);
489
                    return;
490
                }
491
                selectedItemId = selectedIds.iterator().next();
492
                // if a synonym is selected then throw warning
493
                if(listener.isSynonym(selectedItemId)) {
494
                    Notification.show("Synonym selected", "Please choose a Taxon", Type.WARNING_MESSAGE);
495
                    return;
496
                }
497
                windowTitle = "Add New Synonym";
498
                accTaxonIdUuid = new IdUuidName(selectedItemId,
499
                        listener.getCurrentLeafNodeTaxonContainer().getUuid(selectedItemId),
500
                        (String) listener.getCurrentLeafNodeTaxonContainer().getProperty(selectedItemId, LeafNodeTaxonContainer.NAME_ID).getValue());
501
                accTaxonName = (String)listener.getCurrentLeafNodeTaxonContainer().getProperty(selectedItemId, LeafNodeTaxonContainer.NAME_ID).getValue();
502
            } else {
503
                windowTitle = "Add New Taxon";
504
            }
505

    
506
            try {
507
                Window dialog = new Window(windowTitle);
508
                dialog.setModal(true);
509
                dialog.setClosable(false);
510
                dialog.setResizable(false);
511
                UI.getCurrent().addWindow(dialog);
512
                Object cId = classificationComboBox.getValue();
513
                UUID classificationUuid = listener.getClassificationContainer().getUuid(cId);
514
                IdUuidName classificationIdUuid = new IdUuidName(classificationComboBox.getValue(),
515
                        classificationUuid,
516
                        (String) listener.getClassificationContainer().getProperty(cId, StatusPresenter.C_TCACHE_ID).getValue());
517
                NewTaxonBaseComposite newTaxonComponent =
518
                        new NewTaxonBaseComposite(dialog,
519
                                new NewTaxonBasePresenter(),
520
                                accTaxonIdUuid,
521
                                accTaxonName,
522
                                classificationIdUuid);
523
                dialog.setContent(newTaxonComponent);
524
            } catch (SQLException e) {
525
                // TODO Auto-generated catch block
526
                e.printStackTrace();
527
            }
528
        }
529
    }
530

    
531

    
532
    private void addSearchTextFieldListener() {
533
        searchTextField.addTextChangeListener(new FieldEvents.TextChangeListener() {
534

    
535
            private static final long serialVersionUID = -7376538870420619534L;
536

    
537
            @Override
538
            public void textChange(TextChangeEvent event) {
539
                listener.setNameFilter(event.getText());
540
                updateInViewLabel();
541
            }
542

    
543
        });
544

    
545
    }
546

    
547
    private void addClearSearchButtonListener() {
548
        clearSearchButton.addClickListener(new Button.ClickListener() {
549

    
550
            @Override
551
            public void buttonClick(ClickEvent event) {
552
                clearDynamicFilters();
553
                updateInViewLabel();
554
            }
555

    
556
        });
557
    }
558

    
559
    private void clearDynamicFilters() {
560
        listener.removeDynamicFilters();
561
        searchTextField.setValue(FILTER_TAXA_INPUT);
562
        for(Object itemId : filterTable.getItemIds()) {
563
            filterTable.getItem(itemId).getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
564
        }
565
    }
566

    
567

    
568

    
569

    
570
    /* (non-Javadoc)
571
     * @see eu.etaxonomy.cdm.vaadin.view.IStatusComponent#setListener(eu.etaxonomy.cdm.vaadin.view.IStatusComponent.StatusComponentListener)
572
     */
573
    @Override
574
    public void setListener(StatusComponentListener listener) {
575
        this.listener = listener;
576
    }
577

    
578

    
579
    class TaxonTableCheckBoxGenerator implements Table.ColumnGenerator {
580

    
581

    
582
        /**
583
         * Generates the cell containing an open image when boolean is true
584
         */
585
        @Override
586
        public Component generateCell(Table source, final Object itemId, Object columnId) {
587
            if(source.getItem(itemId) != null) {
588
                Property prop = source.getItem(itemId).getItemProperty(columnId);
589
                if(prop == null) {
590
                    return null;
591
                }
592
                CheckBox cb = new CheckBox(null, prop);
593
                ValueChangeListener pbListener = new ValueChangeListener() {
594
                    @Override
595
                    public void valueChange(ValueChangeEvent event) {
596
                        boolean value = (Boolean) event.getProperty().getValue();
597
                        listener.updatePublished(value, itemId);
598
                    }
599
                };
600
                cb.addValueChangeListener(pbListener);
601
                cb.setData(itemId);
602
                return cb;
603
            } else {
604
                return null;
605
            }
606

    
607
        }
608
    }
609

    
610
    class CheckBoxGenerator implements Table.ColumnGenerator {
611

    
612
        private final ValueChangeListener vcListener;
613

    
614
        public CheckBoxGenerator(ValueChangeListener vcListener) {
615
            this.vcListener = vcListener;
616
        }
617

    
618
        /**
619
         * Generates the cell containing an open image when boolean is true
620
         */
621
        @Override
622
        public Component generateCell(Table source, final Object itemId, Object columnId) {
623
            if(source.getItem(itemId) != null) {
624
                Property prop = source.getItem(itemId).getItemProperty(columnId);
625
                if(prop == null) {
626
                    return null;
627
                }
628
                CheckBox cb = new CheckBox(null, prop);
629
                cb.addValueChangeListener(vcListener);
630
                cb.setData(itemId);
631
                return cb;
632
            } else {
633
                return null;
634
            }
635
        }
636
    }
637

    
638

    
639
    /* (non-Javadoc)
640
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onCreate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
641
     */
642
    @Override
643
    public void onCreate(CdmChangeEvent event) {
644
        if(event.getSourceType().equals(NewTaxonBaseComposite.class)) {
645
            Object itemId = event.getChangedObjects().get(0);
646
            try {
647
                taxaTreeTable.setMultiSelect(false);
648
                if(listener.getCurrentLeafNodeTaxonContainer().isSynonym(itemId)) {
649
                    taxaTreeTable.setCollapsed(taxaTreeTable.getValue(), false);
650
                    listener.refresh();
651
                    taxaTreeTable.setValue(itemId);
652
                } else {
653
                    clearDynamicFilters();
654
                    listener.setIdFilter(itemId);
655
                    taxaTreeTable.setValue(itemId);
656
                }
657
            } finally {
658
                taxaTreeTable.setMultiSelect(taxaTreeTableMultiSelectMode);
659
            }
660
        }
661
    }
662

    
663
    /* (non-Javadoc)
664
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onUpdate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
665
     */
666
    @Override
667
    public void onUpdate(CdmChangeEvent event) {
668
        // TODO Auto-generated method stub
669

    
670
    }
671

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

    
679
    }
680

    
681
    /* (non-Javadoc)
682
     * @see com.vaadin.navigator.View#enter(com.vaadin.navigator.ViewChangeListener.ViewChangeEvent)
683
     */
684
    @Override
685
    public void enter(ViewChangeEvent event) {
686
        // TODO Auto-generated method stub
687

    
688
    }
689

    
690
    @AutoGenerated
691
    private GridLayout buildMainLayout() {
692
        // common part: create layout
693
        mainLayout = new GridLayout();
694
        mainLayout.setImmediate(false);
695
        mainLayout.setWidth("340px");
696
        mainLayout.setHeight("840px");
697
        mainLayout.setMargin(true);
698
        mainLayout.setRows(6);
699

    
700
        // top-level component properties
701
        setWidth("340px");
702
        setHeight("840px");
703

    
704
        // classificationComboBox
705
        classificationComboBox = new ComboBox();
706
        classificationComboBox.setImmediate(false);
707
        classificationComboBox.setWidth("100.0%");
708
        classificationComboBox.setHeight("-1px");
709
        mainLayout.addComponent(classificationComboBox, 0, 0);
710

    
711
        // filterVerticalLayout
712
        filterVerticalLayout = buildFilterVerticalLayout();
713
        mainLayout.addComponent(filterVerticalLayout, 0, 1);
714
        mainLayout.setComponentAlignment(filterVerticalLayout, new Alignment(20));
715

    
716
        // searchHorizontalLayout
717
        searchHorizontalLayout = buildSearchHorizontalLayout();
718
        mainLayout.addComponent(searchHorizontalLayout, 0, 3);
719
        mainLayout.setComponentAlignment(searchHorizontalLayout, new Alignment(48));
720

    
721
        // taxaTreeTable
722
        taxaTreeTable = new TreeTable();
723
        taxaTreeTable.setImmediate(false);
724
        taxaTreeTable.setWidth("100.0%");
725
        taxaTreeTable.setHeight("614px");
726
        mainLayout.addComponent(taxaTreeTable, 0, 4);
727
        mainLayout.setComponentAlignment(taxaTreeTable, new Alignment(20));
728

    
729
        // inViewLabel
730
        inViewLabel = new Label();
731
        inViewLabel.setImmediate(false);
732
        inViewLabel.setWidth("100.0%");
733
        inViewLabel.setHeight("-1px");
734
        inViewLabel.setValue("in view : ");
735
        mainLayout.addComponent(inViewLabel, 0, 5);
736

    
737
        return mainLayout;
738
    }
739

    
740

    
741

    
742
    @AutoGenerated
743
    private VerticalLayout buildFilterVerticalLayout() {
744
        // common part: create layout
745
        filterVerticalLayout = new VerticalLayout();
746
        filterVerticalLayout.setImmediate(false);
747
        filterVerticalLayout.setWidth("100.0%");
748
        filterVerticalLayout.setHeight("-1px");
749
        filterVerticalLayout.setMargin(false);
750

    
751
        // filterLabel
752
        filterLabel = new Label();
753
        filterLabel.setImmediate(false);
754
        filterLabel.setWidth("100.0%");
755
        filterLabel.setHeight("-1px");
756
        filterLabel.setValue("Filter by :");
757
        filterVerticalLayout.addComponent(filterLabel);
758

    
759
        // filterTable
760
        filterTable = new Table();
761
        filterTable.setImmediate(false);
762
        filterTable.setWidth("100.0%");
763
        filterTable.setHeight("74px");
764
        filterVerticalLayout.addComponent(filterTable);
765
        filterVerticalLayout.setComponentAlignment(filterTable, new Alignment(48));
766

    
767
        return filterVerticalLayout;
768
    }
769

    
770

    
771

    
772
    @AutoGenerated
773
    private HorizontalLayout buildSearchHorizontalLayout() {
774
        // common part: create layout
775
        searchHorizontalLayout = new HorizontalLayout();
776
        searchHorizontalLayout.setImmediate(false);
777
        searchHorizontalLayout.setWidth("100.0%");
778
        searchHorizontalLayout.setHeight("-1px");
779
        searchHorizontalLayout.setMargin(false);
780
        searchHorizontalLayout.setSpacing(true);
781

    
782
        // searchTextField
783
        searchTextField = new TextField();
784
        searchTextField.setImmediate(false);
785
        searchTextField.setWidth("100.0%");
786
        searchTextField.setHeight("-1px");
787
        searchHorizontalLayout.addComponent(searchTextField);
788
        searchHorizontalLayout.setExpandRatio(searchTextField, 4.0f);
789
        searchHorizontalLayout.setComponentAlignment(searchTextField, new Alignment(48));
790

    
791
        // clearSearchButton
792
        clearSearchButton = new Button();
793
        clearSearchButton.setCaption("Button");
794
        clearSearchButton.setImmediate(true);
795
        clearSearchButton.setWidth("100.0%");
796
        clearSearchButton.setHeight("-1px");
797
        searchHorizontalLayout.addComponent(clearSearchButton);
798
        searchHorizontalLayout.setExpandRatio(clearSearchButton, 1.0f);
799
        searchHorizontalLayout.setComponentAlignment(clearSearchButton, new Alignment(48));
800

    
801
        return searchHorizontalLayout;
802
    }
803

    
804
}
(8-8/8)