Project

General

Profile

« Previous | Next » 

Revision fa9bf282

Added by Patrick Plitzner about 8 years ago

list specimen-taxon associations separately in specimen details view

  • remove determination info from derivative label

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/association/TaxonAssociationDetailElement.java
11 11

  
12 12
import java.util.ArrayList;
13 13
import java.util.Collection;
14
import java.util.Set;
15
import java.util.UUID;
14 16

  
15 17
import org.eclipse.core.commands.Command;
16 18
import org.eclipse.core.commands.ExecutionException;
......
24 26
import org.eclipse.jface.viewers.DoubleClickEvent;
25 27
import org.eclipse.jface.viewers.IDoubleClickListener;
26 28
import org.eclipse.jface.viewers.IStructuredSelection;
29
import org.eclipse.jface.viewers.LabelProvider;
27 30
import org.eclipse.jface.viewers.TableViewer;
28 31
import org.eclipse.swt.SWT;
29 32
import org.eclipse.swt.widgets.Label;
......
34 37

  
35 38
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
36 39
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
40
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
41
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
42
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
37 43
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
38 44
import eu.etaxonomy.taxeditor.model.MessagingUtils;
39 45
import eu.etaxonomy.taxeditor.store.CdmStore;
......
49 55
 */
50 56
public class TaxonAssociationDetailElement extends AbstractCdmDetailElement<DerivedUnitFacade> implements IDoubleClickListener{
51 57

  
52
    private TableViewer associationsViewer;
53

  
54 58
    public TaxonAssociationDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
55 59
        super(formFactory, formElement);
56 60
    }
......
61 65

  
62 66
        //TODO add context menu for deleting associations
63 67

  
64
        Collection<TaxonBase<?>> associatedTaxa = CdmStore.getService(IOccurrenceService.class).listAssociatedTaxa(entity.innerDerivedUnit(), null, null, null, null);
68
        Collection<TaxonBase<?>> associatedTaxa = CdmStore.getService(IOccurrenceService.class).listIndividualsAssociationTaxa(entity.innerDerivedUnit(), null, null, null, null);
69
        Collection<SpecimenTypeDesignation> typeDesignations = CdmStore.getService(IOccurrenceService.class).listTypeDesignations(entity.innerDerivedUnit(), null, null, null, null);
70
        Collection<DeterminationEvent> determinationEvents = CdmStore.getService(IOccurrenceService.class).listDeterminationEvents(entity.innerDerivedUnit(), null, null, null, null);
65 71

  
66
        if(!associatedTaxa.isEmpty()){
67
            associationsViewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
68
            associationsViewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
69
            associationsViewer.setContentProvider(new ArrayContentProvider());
70
            associationsViewer.setInput(associatedTaxa);
71
            associationsViewer.addDoubleClickListener(this);
72
        }
73
        else{
72
        if(associatedTaxa.isEmpty() && typeDesignations.isEmpty() && determinationEvents.isEmpty()){
74 73
            Label label = formFactory.createLabel(getLayoutComposite(), "No associations");
75 74
            label.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
75
            return;
76
        }
77
        if(!associatedTaxa.isEmpty()){
78
            TableViewer viewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
79
            viewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
80
            viewer.setContentProvider(new ArrayContentProvider());
81
            viewer.setLabelProvider(new LabelProvider(){
82
                @Override
83
                public String getText(Object element) {
84
                    return "Associated with "+element.toString();
85
                }
86
            });
87
            viewer.setInput(associatedTaxa);
88
            viewer.addDoubleClickListener(this);
89
        }
90
        if(!typeDesignations.isEmpty()){
91
            TableViewer viewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
92
            viewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
93
            viewer.setContentProvider(new ArrayContentProvider());
94
            viewer.setLabelProvider(new LabelProvider(){
95
                @Override
96
                public String getText(Object element) {
97
                    SpecimenTypeDesignation typeDesignation = (SpecimenTypeDesignation)element;
98
                    String label = typeDesignation.getTypeStatus().getLabel()+" of ";
99
                        Set<TaxonNameBase> typifiedNames = typeDesignation.getTypifiedNames();
100
                        for (TaxonNameBase taxonNameBase : typifiedNames) {
101
                            label += taxonNameBase+", ";
102
                        }
103
                        if(label.endsWith(", ")){
104
                            label = label.substring(0, label.length()-2);
105
                        }
106
                    return label;
107
                }
108
            });
109
            viewer.setInput(typeDesignations);
110
            viewer.addDoubleClickListener(this);
111
        }
112
        if(!determinationEvents.isEmpty()){
113
            TableViewer viewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
114
            viewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
115
            viewer.setContentProvider(new ArrayContentProvider());
116
            viewer.setLabelProvider(new LabelProvider(){
117
                @Override
118
                public String getText(Object element) {
119
                    DeterminationEvent determinationEvent = (DeterminationEvent)element;
120
                    if(determinationEvent.getTaxon()!=null){
121
                        return "Determined as taxon "+determinationEvent.getTaxon();
122
                    }
123
                    if(determinationEvent.getTaxonName()!=null){
124
                        return "Determined as name "+determinationEvent.getTaxonName();
125
                    }
126
                    return element.toString();
127
                }
128
            });
129
            viewer.setInput(determinationEvents);
130
            viewer.addDoubleClickListener(this);
76 131
        }
77

  
78 132
    }
79 133

  
80 134
    /** {@inheritDoc} */
......
87 141
    public void doubleClick(DoubleClickEvent event) {
88 142
        if(event.getSelection() instanceof IStructuredSelection){
89 143
            Object firstElement = ((IStructuredSelection) event.getSelection()).getFirstElement();
144
            UUID taxonToOpenUuid = null;
90 145
            if(firstElement instanceof TaxonBase<?>){
91
                TaxonBase<?> taxonBase = (TaxonBase<?>)firstElement;
146
                taxonToOpenUuid = ((TaxonBase<?>)firstElement).getUuid();
147
            }
148
            else if(firstElement instanceof SpecimenTypeDesignation){
149
                //TODO how to open an editor for all typed names?
150
            }
151
            else if(firstElement instanceof DeterminationEvent){
152
                if(((DeterminationEvent) firstElement).getTaxon()!=null){
153
                    taxonToOpenUuid = ((DeterminationEvent) firstElement).getTaxon().getUuid();
154
                }
155
                else if(((DeterminationEvent) firstElement).getTaxonName()!=null){
156
                    //TODO how to open editor for taxon name
157
                }
158
            }
159
            if(taxonToOpenUuid!=null){
92 160
                String commandId = "eu.etaxonomy.taxeditor.editor.openTaxonEditor";
93 161

  
94 162

  
......
106 174
                } catch (NotDefinedException e1) {
107 175
                    MessagingUtils.error(this.getClass(), "Command not defined", e1);
108 176
                }
109
                Parameterization params = new Parameterization(iparam, (taxonBase).getUuid().toString());
177
                Parameterization params = new Parameterization(iparam, taxonToOpenUuid.toString());
110 178
                parameters.add(params);
111 179

  
112 180
                //build the parameterized command
......
128 196
            }
129 197
        }
130 198
    }
131

  
132 199
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/derivateSearch/DerivateLabelProvider.java
35 35
import eu.etaxonomy.cdm.model.molecular.Sequence;
36 36
import eu.etaxonomy.cdm.model.molecular.SingleRead;
37 37
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
38
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
39 38
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
40
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
41 39
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
42 40
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
43 41
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
......
61 59

  
62 60
    private static Set<SingleRead> multiLinkSingleReads;
63 61

  
64
    private static Map<DerivedUnit, List<DeterminationEvent>> determinationEvents;
65

  
66 62
    private static Map<DerivedUnit, List<SpecimenTypeDesignation>> typeDesignations;
67 63

  
68 64
    private ConversationHolder conversation;
......
238 234
                        addTypeDesignation(derivedUnit, specimenTypeDesignation);
239 235
                    }
240 236
                }
241
                //check for determination events
242
                if(determinationEvents.get(derivedUnit)==null){
243
                    for (DeterminationEvent determinationEvent : CdmStore.getService(IOccurrenceService.class).listDeterminationEvents(derivedUnit, null, null, null, null)) {
244
                        addDeterminationEvent(derivedUnit, determinationEvent);
245
                    }
246
                }
247 237
                //java.util.Collection<FieldUnit> fieldUnits = CdmStore.getService(IOccurrenceService.class).getFieldUnits(derivedUnit.getUuid());
248 238
                //TODO : This is not generic anymore for performance reasons
249 239
                Set<SpecimenOrObservationBase> originals = derivedUnit.getOriginals();
......
265 255
                }
266 256
                String mostSignificantIdentifier = derivedUnit.getMostSignificantIdentifier();
267 257
                label += mostSignificantIdentifier!=null?mostSignificantIdentifier+separator:emptyString;
268
                //type designation extension
269
                List<SpecimenTypeDesignation> typeDesignationList = typeDesignations.get(derivedUnit);
270
                if(typeDesignationList!=null){
271
                    for (SpecimenTypeDesignation specimenTypeDesignation : typeDesignationList) {
272
                        label += "("+specimenTypeDesignation.getTypeStatus()+" of ";
273
                        for (TaxonNameBase taxonNameBase : specimenTypeDesignation.getTypifiedNames()) {
274
                            label += taxonNameBase+separator;
275
                        }
276
                        if(label.endsWith(separator)){
277
                            label = label.substring(0, label.length()-separator.length());
278
                        }
279
                        label += ")";
280
                    }
281
                }
282
                //determination event extension
283
                List<DeterminationEvent> determinationEventList = determinationEvents.get(derivedUnit);
284
                if(determinationEventList!=null){
285
                    for (DeterminationEvent determinationEvent : determinationEventList) {
286
                        label += "(";
287
                        if(determinationEvent.getTaxon()!=null){
288
                            label += "Determined as "+determinationEvent.getTaxon();
289
                        }
290

  
291
                        if(label.endsWith(separator)){
292
                            label = label.substring(0, label.length()-separator.length());
293
                        }
294
                        label += ")";
295
                    }
296
                }
297 258
            }
298 259
            else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){
299 260
                //TissueSample should only be created by using it's own class
......
369 330
            }
370 331
            else if(cdmBase.isInstanceOf(DerivedUnit.class)){
371 332
                DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(element, DerivedUnit.class);
333

  
334
                boolean isType = false;
335
                //type designation extension
336
                if(typeDesignations.get(derivedUnit)!=null){
337
                    isType = true;
338
                }
372 339
                if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.FieldUnit){
373 340
                    return hasCharacterData?ImageResources.getImage(ImageResources.FIELD_UNIT_CHARACTER_DATA):ImageResources.getImage(ImageResources.FIELD_UNIT);
374 341
                }
......
445 412
            }
446 413
        }
447 414
        DerivateLabelProvider.typeDesignations = new HashMap<DerivedUnit, List<SpecimenTypeDesignation>>();
448
        DerivateLabelProvider.determinationEvents = new HashMap<DerivedUnit, List<DeterminationEvent>>();
449
    }
450

  
451
    private static void addDeterminationEvent(DerivedUnit derivedUnit, DeterminationEvent determinationEvent){
452
        List<DeterminationEvent> list = determinationEvents.get(derivedUnit);
453
        if(list==null){
454
            list = new ArrayList<DeterminationEvent>();
455
        }
456
        list.add(determinationEvent);
457
        determinationEvents.put(derivedUnit, list);
458 415
    }
459 416

  
460 417
    private static void addTypeDesignation(DerivedUnit derivedUnit, SpecimenTypeDesignation typeDesignation){

Also available in: Unified diff