Project

General

Profile

« Previous | Next » 

Revision 8de0560f

Added by Patrick Plitzner over 4 years ago

ref #7086, #7095 Add descriptions to WS initially in matrix editor

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/WorkingSetEditor.java
46 46

  
47 47
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
48 48
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
49
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
50 49
import eu.etaxonomy.cdm.api.service.ITermService;
51 50
import eu.etaxonomy.cdm.api.service.IWorkingSetService;
52
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
53 51
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
54 52
import eu.etaxonomy.cdm.model.description.FeatureTree;
55
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
56 53
import eu.etaxonomy.cdm.model.description.WorkingSet;
57 54
import eu.etaxonomy.cdm.model.location.NamedArea;
58 55
import eu.etaxonomy.cdm.model.name.Rank;
59
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
60 56
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
61
import eu.etaxonomy.cdm.model.taxon.Taxon;
62 57
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
63 58
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
64 59
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
......
225 220
                if(taxonTreeNode instanceof TaxonNode){
226 221
                    TaxonNode taxonNode = (TaxonNode)taxonTreeNode;
227 222
                    workingSet.addTaxonSubtree(taxonNode);
228
                    if(taxonNode.getTaxon()!=null){
229
                        Taxon taxon = HibernateProxyHelper.deproxy(taxonNode.getTaxon(), Taxon.class);
230
                        Collection<SpecimenOrObservationBase> specimens = CdmStore.getService(IOccurrenceService.class).listByAssociatedTaxon(SpecimenOrObservationBase.class, null, taxon, null, null, null, null, null);
231
                        for (SpecimenOrObservationBase specimen : specimens) {
232
                            Set<SpecimenDescription> specimenDescriptions = specimen.getSpecimenDescriptions();
233
                            for (SpecimenDescription specimenDescription : specimenDescriptions) {
234
                                workingSet.addDescription(specimenDescription);
235
                            }
236
                        }
237
                    }
238 223
                }
239 224
            }
240 225
        }
241 226
        FeatureTree characters = composite.getCharacters();
242
        //save characters because they can be modified in this editor
243
        characters.getDistinctFeatures().forEach(character->CdmStore.getService(ITermService.class).merge(character,true));
227
        if(characters!=null){
228
            //save characters because they can be modified in this editor
229
            characters.getDistinctFeatures().forEach(character->CdmStore.getService(ITermService.class).merge(character,true));
230
        }
244 231

  
245 232

  
246 233
        DefinedTermBase rankMaxSelection = composite.getRankMax().getSelection();
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/DescriptionSelectionDialog.java
10 10

  
11 11
import java.util.ArrayList;
12 12
import java.util.Collection;
13
import java.util.HashSet;
14
import java.util.List;
13 15
import java.util.Set;
14 16

  
15 17
import org.eclipse.jface.dialogs.Dialog;
......
28 30
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
29 31
import eu.etaxonomy.cdm.model.description.WorkingSet;
30 32
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
31
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
32 33
import eu.etaxonomy.cdm.model.taxon.Taxon;
33 34
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
34 35
import eu.etaxonomy.taxeditor.model.ImageResources;
......
60 61
        list.setLabelProvider(new DescriptionLabelProvider());
61 62

  
62 63
        //gather descriptions
63
        Collection<DescriptionBase> descriptions = new ArrayList<>();
64 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
                    }
65
        Set<SpecimenDescription> specimenDescriptions = new HashSet<>();
66
        for (TaxonNode node : taxonNodes) {
67
            specimenDescriptions.addAll(addDescriptionsRecursively(node));
68
        }
69
        list.setInput(specimenDescriptions);
70
        return composite;
71
    }
72

  
73
    private Set<SpecimenDescription> addDescriptionsRecursively(TaxonNode node){
74
        Set<SpecimenDescription> descriptions = new HashSet<>();
75
        if(node.getTaxon()!=null){
76
            Taxon taxon = HibernateProxyHelper.deproxy(node.getTaxon(), Taxon.class);
77
            Collection<SpecimenOrObservationBase> specimens = CdmStore.getService(IOccurrenceService.class).listByAssociatedTaxon(SpecimenOrObservationBase.class, null, taxon, null, null, null, null, null);
78
            for (SpecimenOrObservationBase specimen : specimens) {
79
                Set<SpecimenDescription> specimenDescriptions = specimen.getSpecimenDescriptions();
80
                for (SpecimenDescription specimenDescription : specimenDescriptions) {
81
                    descriptions.add(specimenDescription);
78 82
                }
79 83
            }
80 84
        }
81
        list.setInput(descriptions);
82

  
83
        return composite;
85
        List<TaxonNode> childNodes = node.getChildNodes();
86
        for (TaxonNode childNode : childNodes) {
87
            descriptions.addAll(addDescriptionsRecursively(childNode));
88
        }
89
        return descriptions;
84 90
    }
85 91

  
86 92
    /**

Also available in: Unified diff