Project

General

Profile

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

    
11
import java.util.ArrayList;
12
import java.util.Collection;
13
import java.util.Set;
14

    
15
import org.eclipse.jface.dialogs.Dialog;
16
import org.eclipse.jface.viewers.ArrayContentProvider;
17
import org.eclipse.jface.viewers.IStructuredSelection;
18
import org.eclipse.jface.viewers.LabelProvider;
19
import org.eclipse.jface.viewers.TableViewer;
20
import org.eclipse.swt.graphics.Image;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Control;
23
import org.eclipse.swt.widgets.Shell;
24

    
25
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
26
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
27
import eu.etaxonomy.cdm.model.description.DescriptionBase;
28
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
29
import eu.etaxonomy.cdm.model.description.WorkingSet;
30
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
31
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
32
import eu.etaxonomy.cdm.model.taxon.Taxon;
33
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
34
import eu.etaxonomy.taxeditor.model.ImageResources;
35
import eu.etaxonomy.taxeditor.store.CdmStore;
36

    
37
/**
38
 * @author pplitzner
39
 * @since Jan 3, 2018
40
 *
41
 */
42
public class DescriptionSelectionDialog extends Dialog {
43

    
44
    private TableViewer list;
45

    
46
    private WorkingSet workingSet;
47

    
48
    Collection<DescriptionBase> selectedDescriptions = new ArrayList<>();
49

    
50
    protected DescriptionSelectionDialog(Shell parentShell, WorkingSet workingSet) {
51
        super(parentShell);
52
        this.workingSet = workingSet;
53
    }
54

    
55
    @Override
56
    protected Control createDialogArea(Composite parent) {
57
        Composite composite = (Composite) super.createDialogArea(parent);
58
        list = new TableViewer(composite);
59
        list.setContentProvider(new ArrayContentProvider());
60
        list.setLabelProvider(new DescriptionLabelProvider());
61

    
62
        //gather descriptions
63
        Collection<DescriptionBase> descriptions = new ArrayList<>();
64
        Set<TaxonNode> taxonNodes = workingSet.getTaxonSubtreeFilter();
65
        for (ITaxonTreeNode taxonTreeNode : taxonNodes) {
66
            if(taxonTreeNode instanceof TaxonNode){
67
                TaxonNode taxonNode = (TaxonNode)taxonTreeNode;
68
                workingSet.addTaxonSubtree(taxonNode);
69
                if(taxonNode.getTaxon()!=null){
70
                    Taxon taxon = HibernateProxyHelper.deproxy(taxonNode.getTaxon(), Taxon.class);
71
                    Collection<SpecimenOrObservationBase> specimens = CdmStore.getService(IOccurrenceService.class).listByAssociatedTaxon(SpecimenOrObservationBase.class, null, taxon, null, null, null, null, null);
72
                    for (SpecimenOrObservationBase specimen : specimens) {
73
                        Set<SpecimenDescription> specimenDescriptions = specimen.getSpecimenDescriptions();
74
                        for (SpecimenDescription specimenDescription : specimenDescriptions) {
75
                            descriptions.add(specimenDescription);
76
                        }
77
                    }
78
                }
79
            }
80
        }
81
        list.setInput(descriptions);
82

    
83
        return composite;
84
    }
85

    
86
    /**
87
     * {@inheritDoc}
88
     */
89
    @Override
90
    protected void okPressed() {
91
        selectedDescriptions = ((IStructuredSelection)list.getSelection()).toList();
92
        super.okPressed();
93
    }
94
    public Collection<DescriptionBase> getDescriptions(){
95
        return selectedDescriptions;
96
    }
97

    
98
    private class DescriptionLabelProvider extends LabelProvider{
99
        /**
100
         * {@inheritDoc}
101
         */
102
        @Override
103
        public Image getImage(Object element) {
104
            if(workingSet.getDescriptions().contains(element)){
105
                return ImageResources.getImage(ImageResources.SYNCED);
106
            }
107
            return null;
108
        }
109
    }
110
}
(3-3/5)