Project

General

Profile

« Previous | Next » 

Revision c0918c7c

Added by Patrick Plitzner about 6 years ago

ref #7095 Refactor RowWrapper

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/DescriptionTreeFormat.java
11 11

  
12 12
import java.util.Comparator;
13 13
import java.util.List;
14
import java.util.Set;
15 14

  
16 15
import ca.odell.glazedlists.TreeList;
17 16
import eu.etaxonomy.cdm.model.description.WorkingSet;
18 17
import eu.etaxonomy.cdm.model.name.Rank;
19 18
import eu.etaxonomy.cdm.model.taxon.Classification;
20
import eu.etaxonomy.cdm.model.taxon.Taxon;
21 19
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
22 20

  
23 21
/**
......
31 29
 public class DescriptionTreeFormat implements TreeList.Format<Object> {
32 30

  
33 31
     private Rank maxRank;
34
     private Classification classification;
35 32

  
36 33
     public DescriptionTreeFormat(WorkingSet workingSet) {
37 34
         this.maxRank = workingSet.getMaxRank();
38
         Set<TaxonNode> taxonSubtreeFilter = workingSet.getTaxonSubtreeFilter();
39
         if(taxonSubtreeFilter!=null && !taxonSubtreeFilter.isEmpty()){
40
             this.classification = taxonSubtreeFilter.iterator().next().getClassification();
41
         }
42 35
     }
43 36

  
44 37
     @Override
45 38
     public void getPath(List path, Object element) {
46 39
         if(element instanceof RowWrapper){
47 40
             //TODO: check for multiple taxon nodes in multiple classifications
48
             Taxon taxon = ((RowWrapper) element).getAssociatedTaxon();
49
             TaxonNode taxonNode = taxon.getTaxonNode(classification);
41
             TaxonNode taxonNode = ((RowWrapper) element).getTaxonNode();
50 42
             addPathRecursive(path, taxonNode);
51 43
         }
52 44
         path.add(element);
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/MatrixRowComparator.java
43 43
        if(o1 instanceof RowWrapper && o2 instanceof RowWrapper){
44 44
            RowWrapper rowWrapper1 = (RowWrapper)o1;
45 45
            RowWrapper rowWrapper2 = (RowWrapper)o2;
46
            TaxonNode node1 = rowWrapper1.getAssociatedTaxon().getTaxonNodes().iterator().next().getParent();
47
            TaxonNode node2 = rowWrapper2.getAssociatedTaxon().getTaxonNodes().iterator().next().getParent();
46
            TaxonNode node1 = rowWrapper1.getTaxonNode().getParent();
47
            TaxonNode node2 = rowWrapper2.getTaxonNode().getParent();
48 48
            if(node1!=null && node2!=null){
49 49
                return comparator.compare(node1, node2);
50 50
            }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/MatrixUtility.java
8 8
*/
9 9
package eu.etaxonomy.taxeditor.editor.workingSet.matrix;
10 10

  
11
import java.util.Set;
12

  
11 13
import eu.etaxonomy.cdm.model.description.Feature;
12 14
import eu.etaxonomy.cdm.model.description.QuantitativeData;
15
import eu.etaxonomy.cdm.model.description.WorkingSet;
16
import eu.etaxonomy.cdm.model.taxon.Classification;
17
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
13 18

  
14 19
/**
15 20
 * Utility class for the character matrix editor
......
50 55
                +" - " //$NON-NLS-1$
51 56
                +(max==null?"?":max.toString()); //$NON-NLS-1$
52 57
    }
58

  
59

  
60
    public static Classification getClassificationForWorkingSet(WorkingSet workingSet){
61
        Set<TaxonNode> taxonSubtreeFilter = workingSet.getTaxonSubtreeFilter();
62
        if(taxonSubtreeFilter!=null && !taxonSubtreeFilter.isEmpty()){
63
            return taxonSubtreeFilter.iterator().next().getClassification();
64
        }
65
        return null;
66
    }
53 67
}
54 68

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/RowWrapper.java
22 22
import eu.etaxonomy.cdm.model.description.QuantitativeData;
23 23
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
24 24
import eu.etaxonomy.cdm.model.description.State;
25
import eu.etaxonomy.cdm.model.description.WorkingSet;
25 26
import eu.etaxonomy.cdm.model.location.NamedArea;
26 27
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
27 28
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
28 29
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
29 30
import eu.etaxonomy.cdm.model.taxon.Taxon;
30 31
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
32
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
31 33
import eu.etaxonomy.taxeditor.model.MessagingUtils;
32 34
import eu.etaxonomy.taxeditor.store.CdmStore;
33 35

  
......
43 45

  
44 46
    private SpecimenDescription description;
45 47

  
46
    private Taxon associatedTaxon;
48
    private TaxonNode taxonNode;
47 49
    private FieldUnit fieldUnit;
48 50
    private String identifier;
49 51
    private NamedArea country;
50 52
    private Map<Feature, DescriptionElementBase> featureToElementMap = new HashMap<>();
51 53

  
52
    public RowWrapper(SpecimenDescription description) {
54
    public RowWrapper(SpecimenDescription description, WorkingSet workingSet) {
53 55
        this.description = description;
54 56

  
55 57
        IOccurrenceService occurrenceService = CdmStore.getService(IOccurrenceService.class);
......
59 61
            Collection<TaxonBase<?>> associatedTaxa = occurrenceService.listAssociatedTaxa(specimen, null, null, null, null);
60 62
            if(associatedTaxa!=null){
61 63
                //FIXME: what about multiple associated taxa
62
                associatedTaxon = (Taxon) associatedTaxa.iterator().next();
64
                taxonNode = ((Taxon) associatedTaxa.iterator().next()).getTaxonNode(MatrixUtility.getClassificationForWorkingSet(workingSet));
63 65
            }
64 66
            Collection<FieldUnit> fieldUnits = occurrenceService.getFieldUnits(specimen.getUuid());
65 67
            if(fieldUnits.size()!=1){
......
101 103
        return description;
102 104
    }
103 105

  
104
    public Taxon getAssociatedTaxon() {
105
        return associatedTaxon;
106
    public TaxonNode getTaxonNode() {
107
        return taxonNode;
106 108
    }
107 109

  
108 110
    public FieldUnit getFieldUnit() {
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/SpecimenColumnPropertyAccessor.java
37 37
            RowWrapper rowWrapper = (RowWrapper)rowObject;
38 38
            switch (columnIndex) {
39 39
            case 0:
40
                return rowWrapper.getAssociatedTaxon();
40
                return rowWrapper.getTaxonNode();
41 41
            case 1:
42 42
                return rowWrapper.getFieldUnit();
43 43
            case 2:

Also available in: Unified diff