Revision 66a8c419
Added by Patrick Plitzner over 7 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/association/TaxonAssociationDetailElement.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.taxeditor.ui.section.occurrence.association; |
11 | 11 |
|
12 |
import java.util.ArrayList; |
|
12 | 13 |
import java.util.Collection; |
13 | 14 |
import java.util.Set; |
14 | 15 |
|
16 |
import org.eclipse.jface.action.MenuManager; |
|
15 | 17 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
16 | 18 |
import org.eclipse.jface.viewers.DoubleClickEvent; |
17 | 19 |
import org.eclipse.jface.viewers.IDoubleClickListener; |
... | ... | |
19 | 21 |
import org.eclipse.jface.viewers.LabelProvider; |
20 | 22 |
import org.eclipse.jface.viewers.ListViewer; |
21 | 23 |
import org.eclipse.swt.SWT; |
24 |
import org.eclipse.swt.widgets.Control; |
|
22 | 25 |
import org.eclipse.swt.widgets.Label; |
26 |
import org.eclipse.swt.widgets.Menu; |
|
27 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
23 | 28 |
|
24 | 29 |
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade; |
25 | 30 |
import eu.etaxonomy.cdm.api.service.IOccurrenceService; |
31 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
26 | 32 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation; |
27 | 33 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
28 | 34 |
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent; |
... | ... | |
56 | 62 |
Collection<SpecimenTypeDesignation> typeDesignations = CdmStore.getService(IOccurrenceService.class).listTypeDesignations(entity.innerDerivedUnit(), null, null, null, null); |
57 | 63 |
Collection<DeterminationEvent> determinationEvents = CdmStore.getService(IOccurrenceService.class).listDeterminationEvents(entity.innerDerivedUnit(), null, null, null, null); |
58 | 64 |
|
65 |
Collection<CdmBase> associations = new ArrayList<>(); |
|
66 |
associations.addAll(associatedTaxa); |
|
67 |
associations.addAll(typeDesignations); |
|
68 |
associations.addAll(determinationEvents); |
|
69 |
|
|
59 | 70 |
if(associatedTaxa.isEmpty() && typeDesignations.isEmpty() && determinationEvents.isEmpty()){ |
60 | 71 |
Label label = formFactory.createLabel(getLayoutComposite(), "No associations"); |
61 | 72 |
label.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1)); |
62 | 73 |
return; |
63 | 74 |
} |
64 |
if(!associatedTaxa.isEmpty()){ |
|
65 |
ListViewer viewer = new ListViewer(getLayoutComposite(), SWT.FULL_SELECTION); |
|
66 |
viewer.getList().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1)); |
|
67 |
viewer.setContentProvider(new ArrayContentProvider()); |
|
68 |
viewer.setLabelProvider(new LabelProvider(){ |
|
69 |
@Override |
|
70 |
public String getText(Object element) { |
|
71 |
return "Associated with "+element.toString(); |
|
72 |
} |
|
73 |
}); |
|
74 |
viewer.setInput(associatedTaxa); |
|
75 |
viewer.addDoubleClickListener(this); |
|
76 |
} |
|
77 |
if(!typeDesignations.isEmpty()){ |
|
78 |
ListViewer viewer = new ListViewer(getLayoutComposite(), SWT.FULL_SELECTION); |
|
79 |
viewer.getList().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 |
SpecimenTypeDesignation typeDesignation = (SpecimenTypeDesignation)element; |
|
85 |
String label = typeDesignation.getTypeStatus()!=null?typeDesignation.getTypeStatus().getLabel()+" of ":"Type of "; |
|
86 |
Set<TaxonNameBase> typifiedNames = typeDesignation.getTypifiedNames(); |
|
87 |
for (TaxonNameBase taxonNameBase : typifiedNames) { |
|
88 |
label += taxonNameBase+", "; |
|
89 |
} |
|
90 |
if(label.endsWith(", ")){ |
|
91 |
label = label.substring(0, label.length()-2); |
|
92 |
} |
|
93 |
return label; |
|
94 |
} |
|
95 |
}); |
|
96 |
viewer.setInput(typeDesignations); |
|
97 |
viewer.addDoubleClickListener(this); |
|
98 |
} |
|
99 |
if(!determinationEvents.isEmpty()){ |
|
100 |
ListViewer viewer = new ListViewer(getLayoutComposite(), SWT.FULL_SELECTION); |
|
101 |
viewer.getList().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1)); |
|
102 |
viewer.setContentProvider(new ArrayContentProvider()); |
|
103 |
viewer.setLabelProvider(new LabelProvider(){ |
|
104 |
@Override |
|
105 |
public String getText(Object element) { |
|
106 |
DeterminationEvent determinationEvent = (DeterminationEvent)element; |
|
107 |
if(determinationEvent.getTaxon()!=null){ |
|
108 |
return "Determined as taxon "+determinationEvent.getTaxon(); |
|
109 |
} |
|
110 |
if(determinationEvent.getTaxonName()!=null){ |
|
111 |
return "Determined as name "+determinationEvent.getTaxonName(); |
|
112 |
} |
|
113 |
return element.toString(); |
|
114 |
} |
|
115 |
}); |
|
116 |
viewer.setInput(determinationEvents); |
|
117 |
viewer.addDoubleClickListener(this); |
|
75 |
if(!associations.isEmpty()){ |
|
76 |
ListViewer viewer = new ListViewer(getLayoutComposite(), SWT.SINGLE); |
|
77 |
viewer.getList().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1)); |
|
78 |
viewer.setContentProvider(new ArrayContentProvider()); |
|
79 |
viewer.setLabelProvider(new LabelProvider(){ |
|
80 |
@Override |
|
81 |
public String getText(Object element) { |
|
82 |
if(element instanceof TaxonBase){ |
|
83 |
return "Associated with "+element.toString(); |
|
84 |
} |
|
85 |
else if(element instanceof DeterminationEvent){ |
|
86 |
DeterminationEvent determinationEvent = (DeterminationEvent)element; |
|
87 |
if(determinationEvent.getTaxon()!=null){ |
|
88 |
return "Determined as taxon "+determinationEvent.getTaxon(); |
|
89 |
} |
|
90 |
if(determinationEvent.getTaxonName()!=null){ |
|
91 |
return "Determined as name "+determinationEvent.getTaxonName(); |
|
92 |
} |
|
93 |
} |
|
94 |
else if(element instanceof SpecimenTypeDesignation){ |
|
95 |
SpecimenTypeDesignation typeDesignation = (SpecimenTypeDesignation)element; |
|
96 |
String label = typeDesignation.getTypeStatus()!=null?typeDesignation.getTypeStatus().getLabel()+" of ":"Type of "; |
|
97 |
Set<TaxonNameBase> typifiedNames = typeDesignation.getTypifiedNames(); |
|
98 |
for (TaxonNameBase taxonNameBase : typifiedNames) { |
|
99 |
label += taxonNameBase+", "; |
|
100 |
} |
|
101 |
if(label.endsWith(", ")){ |
|
102 |
label = label.substring(0, label.length()-2); |
|
103 |
} |
|
104 |
return label; |
|
105 |
} |
|
106 |
return ""; |
|
107 |
} |
|
108 |
}); |
|
109 |
viewer.setInput(associations); |
|
110 |
viewer.addDoubleClickListener(this); |
|
118 | 111 |
} |
119 | 112 |
} |
120 | 113 |
|
Also available in: Unified diff
simplify taxon association section code