Project

General

Profile

Download (33.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

    
21
import com.vaadin.annotations.AutoGenerated;
22
import com.vaadin.data.Container.Hierarchical;
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.Action;
30
import com.vaadin.event.FieldEvents;
31
import com.vaadin.event.FieldEvents.TextChangeEvent;
32
import com.vaadin.event.ItemClickEvent;
33
import com.vaadin.event.ItemClickEvent.ItemClickListener;
34
import com.vaadin.event.LayoutEvents.LayoutClickEvent;
35
import com.vaadin.event.LayoutEvents.LayoutClickListener;
36
import com.vaadin.event.Transferable;
37
import com.vaadin.event.dd.DragAndDropEvent;
38
import com.vaadin.event.dd.DropHandler;
39
import com.vaadin.event.dd.acceptcriteria.AcceptAll;
40
import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
41
import com.vaadin.navigator.View;
42
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
43
import com.vaadin.server.FontAwesome;
44
import com.vaadin.ui.AbstractSelect.AbstractSelectTargetDetails;
45
import com.vaadin.ui.Alignment;
46
import com.vaadin.ui.Button;
47
import com.vaadin.ui.Button.ClickEvent;
48
import com.vaadin.ui.CheckBox;
49
import com.vaadin.ui.ComboBox;
50
import com.vaadin.ui.Component;
51
import com.vaadin.ui.CustomComponent;
52
import com.vaadin.ui.GridLayout;
53
import com.vaadin.ui.HorizontalLayout;
54
import com.vaadin.ui.Label;
55
import com.vaadin.ui.Notification;
56
import com.vaadin.ui.Notification.Type;
57
import com.vaadin.ui.Table;
58
import com.vaadin.ui.Table.ColumnHeaderMode;
59
import com.vaadin.ui.Table.TableDragMode;
60
import com.vaadin.ui.TextField;
61
import com.vaadin.ui.TreeTable;
62
import com.vaadin.ui.UI;
63
import com.vaadin.ui.VerticalLayout;
64
import com.vaadin.ui.Window;
65

    
66
import eu.etaxonomy.cdm.vaadin.container.IdUuidName;
67
import eu.etaxonomy.cdm.vaadin.container.LeafNodeTaxonContainer;
68
import eu.etaxonomy.cdm.vaadin.presenter.NewTaxonBasePresenter;
69
import eu.etaxonomy.cdm.vaadin.presenter.StatusPresenter;
70
import eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent;
71
import eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener;
72
import eu.etaxonomy.cdm.vaadin.session.SelectionEvent;
73
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinSessionUtilities;
74
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinUtilities;
75
import eu.etaxonomy.cdm.vaadin.view.IStatusComposite;
76

    
77
/**
78
 * @author cmathew
79
 * @date 11 Mar 2015
80
 *
81
 */
82
public class StatusComposite extends CustomComponent implements View, IStatusComposite, ICdmChangeListener {
83

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

    
86
    @AutoGenerated
87
    private GridLayout mainLayout;
88
    @AutoGenerated
89
    private Label inViewLabel;
90
    @AutoGenerated
91
    private TreeTable taxaTreeTable;
92
    @AutoGenerated
93
    private HorizontalLayout searchHorizontalLayout;
94
    @AutoGenerated
95
    private Button clearSearchButton;
96
    @AutoGenerated
97
    private TextField searchTextField;
98
    @AutoGenerated
99
    private HorizontalLayout addRemovehorizontalLayout;
100
    @AutoGenerated
101
    private Button removeButton;
102
    @AutoGenerated
103
    private ComboBox addComboBox;
104
    @AutoGenerated
105
    private VerticalLayout filterVerticalLayout;
106
    @AutoGenerated
107
    private Table filterTable;
108
    @AutoGenerated
109
    private Label filterLabel;
110
    @AutoGenerated
111
    private ComboBox classificationComboBox;
112
    private static final Logger logger = Logger.getLogger(StatusComposite.class);
113
    private StatusComponentListener listener;
114

    
115
    private Object currentClickedTaxonItemId;
116

    
117
    private final boolean taxaTreeTableMultiSelectMode = true;
118

    
119
    private static final String SELECT_FILTER = "Select filter ...";
120
    private static final String SELECT_CLASSIFICATION = "Select classification ...";
121

    
122
    private static final String ADD_TAXON_SYNONYM_INPUT = "Add ...";
123
    private static final String ADD_TAXON = "New Accepted Taxon";
124
    private static final String ADD_SYNONYM = "New Synonym";
125

    
126
    private static final String PROPERTY_FILTER_ID = "filter";
127
    private static final String PROPERTY_SELECTED_ID = "selected";
128

    
129
    private static final String FILTER_NOT_RESOLVED = "not resolved";
130
    private static final String FILTER_UNPLACED = "unplaced";
131
    private static final String FILTER_UNFINISHED = "unfinished";
132
    private static final String FILTER_UNPUBLISHED = "unpublished";
133

    
134

    
135
    private static final String FILTER_TAXA_INPUT = "Filter Taxa ...";
136
    private static final String IN_VIEW_PREFIX = "in view : ";
137

    
138
    private boolean isTaxaTableInitialised = false;
139
    private boolean isFiltertableInitialised = false;
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
        initAddComboBox();
157
        initSearchTextField();
158
        initClearSearchButton();
159
        setEnabledAll(false);
160

    
161
        init();
162
    }
163

    
164

    
165

    
166

    
167
    public void init() {
168
        taxaTreeTable.setSelectable(true);
169

    
170
        initClassificationComboBox();
171
    }
172

    
173
    public void setEnabledAll(boolean enabled) {
174
        CdmVaadinUtilities.setEnabled(mainLayout, enabled, Arrays.asList(classificationComboBox));
175
    }
176

    
177

    
178
    public void setTaxaTableEnabled(boolean enabled) {
179
        taxaTreeTable.setEnabled(enabled);
180
    }
181

    
182
    public void setTaxaTableSelectable(boolean isTaxaTableSelectable) {
183
        taxaTreeTable.setSelectable(isTaxaTableSelectable);
184
    }
185

    
186
    public void clearTaxaTableSelections() {
187
        taxaTreeTable.setValue(null);
188
    }
189

    
190
    public UUID getSelectedClassificationUuid() {
191
        if(classificationComboBox.getValue() != null) {
192
            return listener.getClassificationContainer().getUuid(classificationComboBox.getValue());
193
        }
194
        return null;
195
    }
196

    
197
    private void initTaxaTable(int classificationId) {
198
        taxaTreeTable.setMultiSelect(taxaTreeTableMultiSelectMode);
199
        taxaTreeTable.setImmediate(false);
200
        taxaTreeTable.setDragMode(TableDragMode.ROW);
201
        if(listener != null) {
202
            List<String> columnIds = new ArrayList<String>();
203
            columnIds.add(LeafNodeTaxonContainer.NAME_ID);
204
            taxaTreeTable.setColumnExpandRatio(LeafNodeTaxonContainer.NAME_ID, 1);
205
            columnIds.add(LeafNodeTaxonContainer.PB_ID);
206
            taxaTreeTable.setColumnWidth(LeafNodeTaxonContainer.PB_ID, 25);
207

    
208
            if(!isTaxaTableInitialised) {
209
                taxaTreeTable.addGeneratedColumn(LeafNodeTaxonContainer.PB_ID, new TaxonTableCheckBoxGenerator());
210
            }
211

    
212
            try {
213
                taxaTreeTable.setContainerDataSource(listener.loadTaxa(classificationId), columnIds);
214
            } catch (SQLException e) {
215
                //TODO : throw up warning dialog
216
                e.printStackTrace();
217
            }
218

    
219

    
220
            taxaTreeTable.setCellStyleGenerator(new Table.CellStyleGenerator() {
221

    
222
                @Override
223
                public String getStyle(Table source, Object itemId, Object propertyId) {
224
                    if(source.getItem(itemId) == null) {
225
                        return null;
226
                    }
227
                    Property hasSynProperty = source.getItem(itemId).getItemProperty(LeafNodeTaxonContainer.HAS_SYN_ID);
228
                    if(hasSynProperty == null) {
229
                        // this is a synonym, so we activate the corresponding css class
230
                        return "synonym";
231
                    }
232
                    return null;
233
                }
234
            });
235

    
236
            taxaTreeTable.setDropHandler(new DropHandler() {
237

    
238
                @Override
239
                public AcceptCriterion getAcceptCriterion() {
240
                    return AcceptAll.get();
241
                }
242

    
243
                @Override
244
                public void drop(DragAndDropEvent event) {
245
                    // Wrapper for the object that is dragged
246
                    Transferable t = event.getTransferable();
247
                    Component source = t.getSourceComponent();
248

    
249
                    // This is the case where the source of the dd is another
250
                    // taxon table not the one in this object
251
                    if (source instanceof TreeTable  && source != taxaTreeTable) {
252
                        TreeTable table = (TreeTable)t.getSourceComponent();
253
                        Hierarchical sourceHierachicalContainer = table.getContainerDataSource();
254

    
255
                        IdUuidName fromTaxonIun, toTaxonIun;
256
                        if(sourceHierachicalContainer instanceof LeafNodeTaxonContainer) {
257
                            LeafNodeTaxonContainer lntc = (LeafNodeTaxonContainer)sourceHierachicalContainer;
258
                            Object sourceItemId = t.getData("itemId");
259
                            String fromName = (String)lntc.getProperty(sourceItemId, LeafNodeTaxonContainer.NAME_ID).getValue();
260

    
261
                            AbstractSelectTargetDetails dropData = ((AbstractSelectTargetDetails) event.getTargetDetails());
262
                            Object targetItemId = dropData.getItemIdOver();
263
                            String toName = (String)listener.getCurrentLeafNodeTaxonContainer().getProperty(targetItemId, LeafNodeTaxonContainer.NAME_ID).getValue();
264

    
265
                            fromTaxonIun = new IdUuidName(sourceItemId,
266
                                    lntc.getUuid(sourceItemId),
267
                                    fromName);
268
                            toTaxonIun = new IdUuidName(targetItemId,
269
                                    listener.getCurrentLeafNodeTaxonContainer().getUuid(targetItemId),
270
                                    toName);
271
                            EditConceptRelationshipComposite.showInDialog(ConceptRelationshipComposite.CREATE_NEW_CR_TITLE,
272
                                    fromTaxonIun,
273
                                    null,
274
                                    toTaxonIun,
275
                                    CdmChangeEvent.Action.Create);
276
                        }
277
                    }
278

    
279

    
280
                }
281
            });
282

    
283
            // NOTE : Not really sure why we need to refresh the container here.
284
            // in the case of 'Table' this is not required
285
            listener.refresh();
286
            updateInViewLabel();
287
            isTaxaTableInitialised = true;
288
        }
289

    
290

    
291
        final Action changeAcceptedTaxonToSynonymAction = new Action("Change Accepted Taxon To Synonym");
292

    
293

    
294
        taxaTreeTable.addActionHandler(new Action.Handler() {
295
            @Override
296
            public Action[] getActions(final Object target, final Object sender) {
297
                return new Action[] { changeAcceptedTaxonToSynonymAction };
298
            }
299

    
300
            @Override
301
            public void handleAction(final Action action, final Object sender,
302
                    final Object target) {
303
                Notification.show("action for Change Accepted Taxon To Synonym", "Implement me", Type.WARNING_MESSAGE);
304
            }
305
        });
306

    
307
    }
308

    
309
    private void initClassificationComboBox() {
310

    
311
        classificationComboBox.setNewItemsAllowed(false);
312
        classificationComboBox.setNullSelectionAllowed(false);
313
        classificationComboBox.setImmediate(true);
314
        classificationComboBox.setItemCaptionPropertyId(StatusPresenter.C_TCACHE_ID);
315
        classificationComboBox.setInputPrompt(SELECT_CLASSIFICATION);
316
        if(listener != null) {
317
            try {
318
                classificationComboBox.setContainerDataSource(listener.loadClassifications());
319
            } catch (SQLException e) {
320
                //TODO : throw up warning dialog
321
                e.printStackTrace();
322
            }
323
        }
324
    }
325

    
326

    
327

    
328
    private void initFilterTable() {
329
        filterTable.setNullSelectionAllowed(false);
330
        final IndexedContainer container = new IndexedContainer();
331
        container.addContainerProperty("filter", String.class, "");
332
        container.addContainerProperty("selected", Boolean.class, "");
333

    
334
        Item item = container.addItem(FILTER_NOT_RESOLVED);
335
        item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_NOT_RESOLVED);
336
        item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
337

    
338
        item = container.addItem(FILTER_UNPLACED);
339
        item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_UNPLACED);
340
        item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
341

    
342
        item = container.addItem(FILTER_UNFINISHED);
343
        item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_UNFINISHED);
344
        item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
345

    
346
        item = container.addItem(FILTER_UNPUBLISHED);
347
        item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_UNPUBLISHED);
348
        item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
349

    
350

    
351
        filterTable.setContainerDataSource(container);
352
        filterTable.setColumnHeaderMode(ColumnHeaderMode.HIDDEN);
353

    
354

    
355
        ValueChangeListener selectedListener = new ValueChangeListener() {
356

    
357
            private static final long serialVersionUID = -5551250788805117454L;
358

    
359
            @Override
360
            public void valueChange(ValueChangeEvent event) {
361
                boolean value = (Boolean) event.getProperty().getValue();
362
                String selectedFilter = (String)filterTable.getItem(((CheckBox)event.getProperty()).getData()).getItemProperty(PROPERTY_FILTER_ID).getValue();
363
                if(selectedFilter != null) {
364
                    if(value) {
365
                        if(selectedFilter.equals(FILTER_UNPLACED)) {
366
                            listener.setUnplacedFilter();
367
                        }
368
                        if(selectedFilter.equals(FILTER_UNPUBLISHED)) {
369
                            listener.setUnpublishedFilter();
370
                        }
371
                    } else {
372
                        if(selectedFilter.equals(FILTER_UNPLACED)) {
373
                            listener.removeUnplacedFilter();
374
                        }
375
                        if(selectedFilter.equals(FILTER_UNPUBLISHED)) {
376
                            listener.removeUnpublishedFilter();
377
                        }
378
                    }
379
                    updateInViewLabel();
380
                }
381
            }
382
        };
383

    
384
        if(!isFiltertableInitialised) {
385
            filterTable.addGeneratedColumn(PROPERTY_SELECTED_ID, new CheckBoxGenerator(selectedListener));
386
        }
387

    
388
        isFiltertableInitialised = true;
389

    
390
    }
391

    
392
    private void updateInViewLabel() {
393
        inViewLabel.setValue(IN_VIEW_PREFIX + String.valueOf(listener.getCurrentNoOfTaxa()) + " / " + String.valueOf(listener.getTotalNoOfTaxa()) + " taxa");
394
    }
395

    
396
    private void initSearchTextField() {
397
        searchTextField.setInputPrompt(FILTER_TAXA_INPUT);
398
    }
399

    
400

    
401
    private void initAddComboBox() {
402
        addComboBox.setNullSelectionAllowed(false);
403
        addComboBox.setImmediate(true);
404
        addComboBox.addItem(ADD_TAXON_SYNONYM_INPUT);
405
        addComboBox.addItem(ADD_TAXON);
406
        addComboBox.addItem(ADD_SYNONYM);
407
        addComboBox.setValue(ADD_TAXON_SYNONYM_INPUT);
408

    
409
    }
410

    
411
    private void initClearSearchButton() {
412
        clearSearchButton.setIcon(FontAwesome.REFRESH);
413
        clearSearchButton.setCaption("");
414
    }
415

    
416

    
417
    private void addUIListeners() {
418

    
419
        searchHorizontalLayout.addLayoutClickListener(new LayoutClickListener() {
420

    
421
            @Override
422
            public void layoutClick(LayoutClickEvent event) {
423
                if (event.getChildComponent() == searchTextField && searchTextField.getValue().equals(FILTER_TAXA_INPUT)) {
424
                    searchTextField.setValue("");
425
                }
426
            }
427
        });
428

    
429
        addClassificationComboBoxListener();
430
        addTaxaTreeTableListener();
431
        addAddComboBoxListener();
432
        addRemoveButtonListener();
433
        addSearchTextFieldListener();
434
        addClearSearchButtonListener();
435
    }
436

    
437
    private void addClassificationComboBoxListener() {
438

    
439
        classificationComboBox.addValueChangeListener(new Property.ValueChangeListener() {
440

    
441
            private static final long serialVersionUID = 4196786323147791606L;
442

    
443
            @Override
444
            public void valueChange(ValueChangeEvent event) {
445
                if (classificationComboBox.getValue() != null) {
446
                    Object selected = classificationComboBox.getValue();
447
                    logger.info("selected : " + selected);
448
                    int classificationId = (Integer)((RowId)selected).getId()[0];
449
                    initTaxaTable(classificationId);
450
                    initFilterTable();
451
                    setEnabledAll(true);
452
                }
453
            }
454
        });
455
    }
456

    
457
    private void addTaxaTreeTableListener() {
458
        taxaTreeTable.addItemClickListener(new ItemClickListener() {
459
            @Override
460
            public void itemClick(ItemClickEvent event) {
461
                Object itemId = event.getItemId();
462
                if(taxaTreeTable.isSelectable()) {
463
                    if(!listener.isSynonym(itemId)) {
464
                        UUID taxonUuid = listener.getCurrentLeafNodeTaxonContainer().getUuid(itemId);
465
                        String taxonName = (String)listener.getCurrentLeafNodeTaxonContainer().getProperty(itemId, LeafNodeTaxonContainer.NAME_ID).getValue();
466
                        Object idUuidName = new IdUuidName(itemId, taxonUuid, taxonName);
467
                        CdmVaadinSessionUtilities.getCurrentSelectionService()
468
                        .fireSelectionEvent(new SelectionEvent(Arrays.asList(idUuidName, getSelectedClassificationUuid()), StatusComposite.class), true);
469
                    }
470
                    taxaTreeTable.setValue(itemId);
471
                }
472
            }
473
        });
474
    }
475

    
476
    private void addAddComboBoxListener() {
477
        addComboBox.addValueChangeListener(new Property.ValueChangeListener() {
478

    
479
            private static final long serialVersionUID = -6235423275051269517L;
480

    
481
            @Override
482
            public void valueChange(ValueChangeEvent event) {
483
                if (addComboBox.getValue() != null) {
484
                    String selected = (String)addComboBox.getValue();
485
                    if(!selected.equals(ADD_TAXON_SYNONYM_INPUT)) {
486
                        try {
487
                            String windowTitle;
488

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

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

    
546
    private void addSearchTextFieldListener() {
547
        searchTextField.addTextChangeListener(new FieldEvents.TextChangeListener() {
548

    
549
            private static final long serialVersionUID = -7376538870420619534L;
550

    
551
            @Override
552
            public void textChange(TextChangeEvent event) {
553
                listener.setNameFilter(event.getText());
554
                updateInViewLabel();
555
            }
556

    
557
        });
558

    
559
    }
560

    
561
    private void addClearSearchButtonListener() {
562
        clearSearchButton.addClickListener(new Button.ClickListener() {
563

    
564
            @Override
565
            public void buttonClick(ClickEvent event) {
566
                clearDynamicFilters();
567
                updateInViewLabel();
568
            }
569

    
570
        });
571
    }
572

    
573
    private void clearDynamicFilters() {
574
        listener.removeDynamicFilters();
575
        searchTextField.setValue(FILTER_TAXA_INPUT);
576
        for(Object itemId : filterTable.getItemIds()) {
577
            filterTable.getItem(itemId).getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
578
        }
579
    }
580

    
581
    private void addRemoveButtonListener() {
582
        removeButton.addClickListener(new Button.ClickListener() {
583
            @Override
584
            public void buttonClick(ClickEvent event) {
585
                Set<Object> selectedItemIds = (Set)taxaTreeTable.getValue();
586
                if(selectedItemIds.isEmpty()) {
587
                    Notification.show("No Taxa / Synonyms selected", "Please select taxa or synonyms to delete", Type.WARNING_MESSAGE);
588
                } else {
589
                    Notification.show("Deleting selected Taxa / Synonyms", "Implement me", Type.WARNING_MESSAGE);
590
                }
591
            }
592
        });
593
    }
594

    
595

    
596

    
597
    /* (non-Javadoc)
598
     * @see eu.etaxonomy.cdm.vaadin.view.IStatusComponent#setListener(eu.etaxonomy.cdm.vaadin.view.IStatusComponent.StatusComponentListener)
599
     */
600
    @Override
601
    public void setListener(StatusComponentListener listener) {
602
        this.listener = listener;
603
    }
604

    
605

    
606
    class TaxonTableCheckBoxGenerator implements Table.ColumnGenerator {
607

    
608

    
609
        /**
610
         * Generates the cell containing an open image when boolean is true
611
         */
612
        @Override
613
        public Component generateCell(Table source, final Object itemId, Object columnId) {
614
            if(source.getItem(itemId) != null) {
615
                Property prop = source.getItem(itemId).getItemProperty(columnId);
616
                if(prop == null) {
617
                    return null;
618
                }
619
                CheckBox cb = new CheckBox(null, prop);
620
                ValueChangeListener pbListener = new ValueChangeListener() {
621
                    @Override
622
                    public void valueChange(ValueChangeEvent event) {
623
                        boolean value = (Boolean) event.getProperty().getValue();
624
                        listener.updatePublished(value, itemId);
625
                    }
626
                };
627
                cb.addValueChangeListener(pbListener);
628
                cb.setData(itemId);
629
                return cb;
630
            } else {
631
                return null;
632
            }
633

    
634
        }
635
    }
636

    
637
    class CheckBoxGenerator implements Table.ColumnGenerator {
638

    
639
        private final ValueChangeListener vcListener;
640

    
641
        public CheckBoxGenerator(ValueChangeListener vcListener) {
642
            this.vcListener = vcListener;
643
        }
644

    
645
        /**
646
         * Generates the cell containing an open image when boolean is true
647
         */
648
        @Override
649
        public Component generateCell(Table source, final Object itemId, Object columnId) {
650
            if(source.getItem(itemId) != null) {
651
                Property prop = source.getItem(itemId).getItemProperty(columnId);
652
                if(prop == null) {
653
                    return null;
654
                }
655
                CheckBox cb = new CheckBox(null, prop);
656
                cb.addValueChangeListener(vcListener);
657
                cb.setData(itemId);
658
                return cb;
659
            } else {
660
                return null;
661
            }
662
        }
663
    }
664

    
665

    
666
    /* (non-Javadoc)
667
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onCreate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
668
     */
669
    @Override
670
    public void onCreate(CdmChangeEvent event) {
671
        if(event.getSourceType().equals(NewTaxonBaseComposite.class)) {
672
            Object itemId = event.getChangedObjects().get(0);
673
            try {
674
                taxaTreeTable.setMultiSelect(false);
675
                if(listener.getCurrentLeafNodeTaxonContainer().isSynonym(itemId)) {
676
                    taxaTreeTable.setCollapsed(taxaTreeTable.getValue(), false);
677
                    listener.refresh();
678
                    taxaTreeTable.setValue(itemId);
679
                } else {
680
                    clearDynamicFilters();
681
                    listener.setIdFilter(itemId);
682
                    taxaTreeTable.setValue(itemId);
683
                }
684
            } finally {
685
                taxaTreeTable.setMultiSelect(taxaTreeTableMultiSelectMode);
686
            }
687
        }
688
    }
689

    
690
    /* (non-Javadoc)
691
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onUpdate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
692
     */
693
    @Override
694
    public void onUpdate(CdmChangeEvent event) {
695
        // TODO Auto-generated method stub
696

    
697
    }
698

    
699
    /* (non-Javadoc)
700
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onDelete(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
701
     */
702
    @Override
703
    public void onDelete(CdmChangeEvent event) {
704
        // TODO Auto-generated method stub
705

    
706
    }
707

    
708
    /* (non-Javadoc)
709
     * @see com.vaadin.navigator.View#enter(com.vaadin.navigator.ViewChangeListener.ViewChangeEvent)
710
     */
711
    @Override
712
    public void enter(ViewChangeEvent event) {
713
        // TODO Auto-generated method stub
714

    
715
    }
716

    
717
    @AutoGenerated
718
    private GridLayout buildMainLayout() {
719
        // common part: create layout
720
        mainLayout = new GridLayout();
721
        mainLayout.setImmediate(false);
722
        mainLayout.setWidth("340px");
723
        mainLayout.setHeight("840px");
724
        mainLayout.setMargin(true);
725
        mainLayout.setRows(6);
726

    
727
        // top-level component properties
728
        setWidth("340px");
729
        setHeight("840px");
730

    
731
        // classificationComboBox
732
        classificationComboBox = new ComboBox();
733
        classificationComboBox.setImmediate(false);
734
        classificationComboBox.setWidth("100.0%");
735
        classificationComboBox.setHeight("-1px");
736
        mainLayout.addComponent(classificationComboBox, 0, 0);
737

    
738
        // filterVerticalLayout
739
        filterVerticalLayout = buildFilterVerticalLayout();
740
        mainLayout.addComponent(filterVerticalLayout, 0, 1);
741
        mainLayout.setComponentAlignment(filterVerticalLayout, new Alignment(20));
742

    
743
        // addRemovehorizontalLayout
744
        addRemovehorizontalLayout = buildAddRemovehorizontalLayout();
745
        mainLayout.addComponent(addRemovehorizontalLayout, 0, 2);
746
        mainLayout.setComponentAlignment(addRemovehorizontalLayout, new Alignment(48));
747

    
748
        // searchHorizontalLayout
749
        searchHorizontalLayout = buildSearchHorizontalLayout();
750
        mainLayout.addComponent(searchHorizontalLayout, 0, 3);
751
        mainLayout.setComponentAlignment(searchHorizontalLayout, new Alignment(48));
752

    
753
        // taxaTreeTable
754
        taxaTreeTable = new TreeTable();
755
        taxaTreeTable.setImmediate(false);
756
        taxaTreeTable.setWidth("100.0%");
757
        taxaTreeTable.setHeight("580px");
758
        mainLayout.addComponent(taxaTreeTable, 0, 4);
759
        mainLayout.setComponentAlignment(taxaTreeTable, new Alignment(20));
760

    
761
        // inViewLabel
762
        inViewLabel = new Label();
763
        inViewLabel.setImmediate(false);
764
        inViewLabel.setWidth("100.0%");
765
        inViewLabel.setHeight("-1px");
766
        inViewLabel.setValue("in view : ");
767
        mainLayout.addComponent(inViewLabel, 0, 5);
768

    
769
        return mainLayout;
770
    }
771

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

    
781
        // filterLabel
782
        filterLabel = new Label();
783
        filterLabel.setImmediate(false);
784
        filterLabel.setWidth("100.0%");
785
        filterLabel.setHeight("-1px");
786
        filterLabel.setValue("Filter by :");
787
        filterVerticalLayout.addComponent(filterLabel);
788

    
789
        // filterTable
790
        filterTable = new Table();
791
        filterTable.setImmediate(false);
792
        filterTable.setWidth("100.0%");
793
        filterTable.setHeight("86px");
794
        filterVerticalLayout.addComponent(filterTable);
795
        filterVerticalLayout.setComponentAlignment(filterTable, new Alignment(48));
796

    
797
        return filterVerticalLayout;
798
    }
799

    
800
    @AutoGenerated
801
    private HorizontalLayout buildAddRemovehorizontalLayout() {
802
        // common part: create layout
803
        addRemovehorizontalLayout = new HorizontalLayout();
804
        addRemovehorizontalLayout.setImmediate(false);
805
        addRemovehorizontalLayout.setWidth("100.0%");
806
        addRemovehorizontalLayout.setHeight("-1px");
807
        addRemovehorizontalLayout.setMargin(false);
808
        addRemovehorizontalLayout.setSpacing(true);
809

    
810
        // addComboBox
811
        addComboBox = new ComboBox();
812
        addComboBox.setImmediate(false);
813
        addComboBox.setWidth("100.0%");
814
        addComboBox.setHeight("-1px");
815
        addRemovehorizontalLayout.addComponent(addComboBox);
816
        addRemovehorizontalLayout.setExpandRatio(addComboBox, 3.0f);
817

    
818
        // removeButton
819
        removeButton = new Button();
820
        removeButton.setCaption("Remove");
821
        removeButton.setImmediate(true);
822
        removeButton.setWidth("100.0%");
823
        removeButton.setHeight("-1px");
824
        addRemovehorizontalLayout.addComponent(removeButton);
825
        addRemovehorizontalLayout.setExpandRatio(removeButton, 2.0f);
826

    
827
        return addRemovehorizontalLayout;
828
    }
829

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

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

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

    
859
        return searchHorizontalLayout;
860
    }
861

    
862
}
(6-6/6)