Project

General

Profile

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

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

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

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

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

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

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

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

    
105
    private Object currentClickedTaxonItemId;
106

    
107
    private final boolean taxaTreeTableMultiSelectMode = true;
108

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

    
111

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

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

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

    
130

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

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

    
137
    private String selectedTaxaTableMenuItem = null;
138

    
139
    ContextMenu taxaTableContextMenu;
140

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

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

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

    
160
        init();
161
    }
162

    
163

    
164

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

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

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

    
187

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

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

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

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

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

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

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

    
229

    
230
            taxaTreeTable.setCellStyleGenerator(new Table.CellStyleGenerator() {
231

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

    
244
                }
245
            });
246

    
247
            taxaTreeTable.setSortContainerPropertyId(LeafNodeTaxonContainer.NAME_ID);
248

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

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

    
260

    
261
    }
262

    
263
    private void initClassificationComboBox() {
264

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

    
280

    
281

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

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

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

    
296

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

    
300

    
301
        ValueChangeListener selectedListener = new ValueChangeListener() {
302

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

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

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

    
334
        isFiltertableInitialised = true;
335

    
336
    }
337

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

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

    
346

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

    
352

    
353
    private void addUIListeners() {
354

    
355
        searchHorizontalLayout.addLayoutClickListener(new LayoutClickListener() {
356

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

    
365
        addClassificationComboBoxListener();
366
        addTaxaTreeTableListener();
367

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

    
372
    private void addClassificationComboBoxListener() {
373

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

    
376
            private static final long serialVersionUID = 4196786323147791606L;
377

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

    
391
    private void addTaxaTreeTableListener() {
392

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

    
409
                }
410
            }
411
        });
412

    
413
        //taxaTreeTable.add
414

    
415

    
416
    }
417

    
418
    private void generateTaxaTreeTableContextMenu(boolean isSynonym) {
419

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

    
423

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

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

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

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

    
438
            changeToSynMenuItem.setSeparatorVisible(true);
439
        }
440

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

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

    
447
        ContextMenuItem setUnresolvedMenuItem = taxaTableContextMenu.addItem(SET_AS_UNRESOLVED);
448
        setUnresolvedMenuItem.setData(SET_AS_UNRESOLVED);
449

    
450

    
451
        ContextMenuItem setOutOfScopeMenuItem = taxaTableContextMenu.addItem(SET_AS_OUT_OF_SCOPE);
452
        setOutOfScopeMenuItem.setData(SET_AS_OUT_OF_SCOPE);
453

    
454
        ContextMenuItem createAccTaxonMenuItem = taxaTableContextMenu.addItem(CREATE_ACC_TAXON);
455
        createAccTaxonMenuItem.setData(CREATE_ACC_TAXON);
456

    
457
    }
458

    
459
    private void addTaxaTreeContextMenuItemListener() {
460
        if(taxaTableContextMenu != null) {
461
            taxaTableContextMenu.addItemClickListener(new ContextMenuItemClickListener() {
462

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

    
480

    
481
    private void showAddTaxonBaseWindow(String action) {
482
        if (action != null) {
483
            String windowTitle;
484

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

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

    
536

    
537
    private void addSearchTextFieldListener() {
538
        searchTextField.addTextChangeListener(new FieldEvents.TextChangeListener() {
539

    
540
            private static final long serialVersionUID = -7376538870420619534L;
541

    
542
            @Override
543
            public void textChange(TextChangeEvent event) {
544
                listener.setNameFilter(event.getText());
545
                updateInViewLabel();
546
            }
547

    
548
        });
549

    
550
    }
551

    
552
    private void addClearSearchButtonListener() {
553
        clearSearchButton.addClickListener(new Button.ClickListener() {
554

    
555
            @Override
556
            public void buttonClick(ClickEvent event) {
557
                clearDynamicFilters();
558
                updateInViewLabel();
559
            }
560

    
561
        });
562
    }
563

    
564
    private void clearDynamicFilters() {
565
        listener.removeDynamicFilters();
566
        searchTextField.setValue(FILTER_TAXA_INPUT);
567
        for(Object itemId : filterTable.getItemIds()) {
568
            filterTable.getItem(itemId).getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
569
        }
570
    }
571

    
572

    
573

    
574

    
575
    /* (non-Javadoc)
576
     * @see eu.etaxonomy.cdm.vaadin.view.IStatusComponent#setListener(eu.etaxonomy.cdm.vaadin.view.IStatusComponent.StatusComponentListener)
577
     */
578
    @Override
579
    public void setListener(StatusComponentListener listener) {
580
        this.listener = listener;
581
    }
582

    
583

    
584
    class TaxonTableCheckBoxGenerator implements Table.ColumnGenerator {
585

    
586

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

    
612
        }
613
    }
614

    
615
    class CheckBoxGenerator implements Table.ColumnGenerator {
616

    
617
        private final ValueChangeListener vcListener;
618

    
619
        public CheckBoxGenerator(ValueChangeListener vcListener) {
620
            this.vcListener = vcListener;
621
        }
622

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

    
643

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

    
668
    /* (non-Javadoc)
669
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onUpdate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
670
     */
671
    @Override
672
    public void onUpdate(CdmChangeEvent event) {
673
        // TODO Auto-generated method stub
674

    
675
    }
676

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

    
684
    }
685

    
686
    /* (non-Javadoc)
687
     * @see com.vaadin.navigator.View#enter(com.vaadin.navigator.ViewChangeListener.ViewChangeEvent)
688
     */
689
    @Override
690
    public void enter(ViewChangeEvent event) {
691
        // TODO Auto-generated method stub
692

    
693
    }
694

    
695
    @AutoGenerated
696
    private GridLayout buildMainLayout() {
697
        // common part: create layout
698
        mainLayout = new GridLayout();
699
        mainLayout.setImmediate(false);
700
        mainLayout.setWidth("340px");
701
        mainLayout.setHeight("840px");
702
        mainLayout.setMargin(true);
703
        mainLayout.setRows(6);
704

    
705
        // top-level component properties
706
        setWidth("340px");
707
        setHeight("840px");
708

    
709
        // classificationComboBox
710
        classificationComboBox = new ComboBox();
711
        classificationComboBox.setImmediate(false);
712
        classificationComboBox.setWidth("100.0%");
713
        classificationComboBox.setHeight("-1px");
714
        mainLayout.addComponent(classificationComboBox, 0, 0);
715

    
716
        // filterVerticalLayout
717
        filterVerticalLayout = buildFilterVerticalLayout();
718
        mainLayout.addComponent(filterVerticalLayout, 0, 1);
719
        mainLayout.setComponentAlignment(filterVerticalLayout, new Alignment(20));
720

    
721
        // searchHorizontalLayout
722
        searchHorizontalLayout = buildSearchHorizontalLayout();
723
        mainLayout.addComponent(searchHorizontalLayout, 0, 3);
724
        mainLayout.setComponentAlignment(searchHorizontalLayout, new Alignment(48));
725

    
726
        // taxaTreeTable
727
        taxaTreeTable = new TreeTable();
728
        taxaTreeTable.setImmediate(false);
729
        taxaTreeTable.setWidth("100.0%");
730
        taxaTreeTable.setHeight("614px");
731
        mainLayout.addComponent(taxaTreeTable, 0, 4);
732
        mainLayout.setComponentAlignment(taxaTreeTable, new Alignment(20));
733

    
734
        // inViewLabel
735
        inViewLabel = new Label();
736
        inViewLabel.setImmediate(false);
737
        inViewLabel.setWidth("100.0%");
738
        inViewLabel.setHeight("-1px");
739
        inViewLabel.setValue("in view : ");
740
        mainLayout.addComponent(inViewLabel, 0, 5);
741

    
742
        return mainLayout;
743
    }
744

    
745

    
746

    
747
    @AutoGenerated
748
    private VerticalLayout buildFilterVerticalLayout() {
749
        // common part: create layout
750
        filterVerticalLayout = new VerticalLayout();
751
        filterVerticalLayout.setImmediate(false);
752
        filterVerticalLayout.setWidth("100.0%");
753
        filterVerticalLayout.setHeight("-1px");
754
        filterVerticalLayout.setMargin(false);
755

    
756
        // filterLabel
757
        filterLabel = new Label();
758
        filterLabel.setImmediate(false);
759
        filterLabel.setWidth("100.0%");
760
        filterLabel.setHeight("-1px");
761
        filterLabel.setValue("Filter by :");
762
        filterVerticalLayout.addComponent(filterLabel);
763

    
764
        // filterTable
765
        filterTable = new Table();
766
        filterTable.setImmediate(false);
767
        filterTable.setWidth("100.0%");
768
        filterTable.setHeight("74px");
769
        filterVerticalLayout.addComponent(filterTable);
770
        filterVerticalLayout.setComponentAlignment(filterTable, new Alignment(48));
771

    
772
        return filterVerticalLayout;
773
    }
774

    
775

    
776

    
777
    @AutoGenerated
778
    private HorizontalLayout buildSearchHorizontalLayout() {
779
        // common part: create layout
780
        searchHorizontalLayout = new HorizontalLayout();
781
        searchHorizontalLayout.setImmediate(false);
782
        searchHorizontalLayout.setWidth("100.0%");
783
        searchHorizontalLayout.setHeight("-1px");
784
        searchHorizontalLayout.setMargin(false);
785
        searchHorizontalLayout.setSpacing(true);
786

    
787
        // searchTextField
788
        searchTextField = new TextField();
789
        searchTextField.setImmediate(false);
790
        searchTextField.setWidth("100.0%");
791
        searchTextField.setHeight("-1px");
792
        searchHorizontalLayout.addComponent(searchTextField);
793
        searchHorizontalLayout.setExpandRatio(searchTextField, 4.0f);
794
        searchHorizontalLayout.setComponentAlignment(searchTextField, new Alignment(48));
795

    
796
        // clearSearchButton
797
        clearSearchButton = new Button();
798
        clearSearchButton.setCaption("Button");
799
        clearSearchButton.setImmediate(true);
800
        clearSearchButton.setWidth("100.0%");
801
        clearSearchButton.setHeight("-1px");
802
        searchHorizontalLayout.addComponent(clearSearchButton);
803
        searchHorizontalLayout.setExpandRatio(clearSearchButton, 1.0f);
804
        searchHorizontalLayout.setComponentAlignment(clearSearchButton, new Alignment(48));
805

    
806
        return searchHorizontalLayout;
807
    }
808

    
809
}
(8-8/8)