Revision f8cdd23e
Added by Patrick Plitzner over 5 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java | ||
---|---|---|
72 | 72 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySession; |
73 | 73 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled; |
74 | 74 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
75 |
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateContentProvider;
|
|
76 |
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
|
|
75 |
import eu.etaxonomy.taxeditor.view.search.derivative.DerivateContentProvider;
|
|
76 |
import eu.etaxonomy.taxeditor.view.search.derivative.DerivateLabelProvider;
|
|
77 | 77 |
import eu.etaxonomy.taxeditor.workbench.part.ICollapsableExpandable; |
78 | 78 |
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart; |
79 | 79 |
|
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/searchFilter/DerivateSearchCompositeController.java | ||
---|---|---|
34 | 34 |
import eu.etaxonomy.taxeditor.store.SearchManager; |
35 | 35 |
import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory; |
36 | 36 |
import eu.etaxonomy.taxeditor.ui.mvc.combo.EnumTermComboController; |
37 |
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
|
|
37 |
import eu.etaxonomy.taxeditor.view.search.derivative.DerivateLabelProvider;
|
|
38 | 38 |
|
39 | 39 |
/** |
40 | 40 |
* Controller class for the {@link DerivateSearchComposite}.<br> |
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/editor/e4/AlignmentEditorE4.java | ||
---|---|---|
55 | 55 |
import eu.etaxonomy.taxeditor.molecular.editor.e4.handler.ToggleLeftRightInsertionHandlerE4; |
56 | 56 |
import eu.etaxonomy.taxeditor.molecular.l10n.Messages; |
57 | 57 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
58 |
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
|
|
58 |
import eu.etaxonomy.taxeditor.view.search.derivative.DerivateLabelProvider;
|
|
59 | 59 |
import info.bioinfweb.commons.swt.SWTUtils; |
60 | 60 |
import info.bioinfweb.libralign.alignmentarea.AlignmentArea; |
61 | 61 |
import info.bioinfweb.libralign.alignmentarea.selection.SelectionModel; |
eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF | ||
---|---|---|
64 | 64 |
eu.etaxonomy.taxeditor.view, |
65 | 65 |
eu.etaxonomy.taxeditor.view.datasource, |
66 | 66 |
eu.etaxonomy.taxeditor.view.datasource.handler, |
67 |
eu.etaxonomy.taxeditor.view.derivateSearch, |
|
68 | 67 |
eu.etaxonomy.taxeditor.view.detail, |
69 | 68 |
eu.etaxonomy.taxeditor.view.e4, |
70 | 69 |
eu.etaxonomy.taxeditor.view.e4.details, |
71 | 70 |
eu.etaxonomy.taxeditor.view.e4.supplementaldata, |
72 |
eu.etaxonomy.taxeditor.view.specimenSearch, |
|
71 |
eu.etaxonomy.taxeditor.view.search.derivative, |
|
72 |
eu.etaxonomy.taxeditor.view.search.specimen, |
|
73 | 73 |
org.eclipse.wb.swt |
74 | 74 |
Require-Bundle: org.eclipse.osgi, |
75 | 75 |
org.eclipse.ui, |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/dna/AbstractSampleDesignationDetailSection.java | ||
---|---|---|
15 | 15 |
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; |
16 | 16 |
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement; |
17 | 17 |
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection; |
18 |
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
|
|
18 |
import eu.etaxonomy.taxeditor.view.search.derivative.DerivateLabelProvider;
|
|
19 | 19 |
|
20 | 20 |
/** |
21 | 21 |
* |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/dna/CurrentSampleDesignationDetailSection.java | ||
---|---|---|
19 | 19 |
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; |
20 | 20 |
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement; |
21 | 21 |
import eu.etaxonomy.taxeditor.ui.section.DefaultCdmBaseComparator; |
22 |
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
|
|
22 |
import eu.etaxonomy.taxeditor.view.search.derivative.DerivateLabelProvider;
|
|
23 | 23 |
|
24 | 24 |
/** |
25 | 25 |
* |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/dna/SampleDesignationHistoryDetailSection.java | ||
---|---|---|
19 | 19 |
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; |
20 | 20 |
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement; |
21 | 21 |
import eu.etaxonomy.taxeditor.ui.section.DefaultCdmBaseComparator; |
22 |
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
|
|
22 |
import eu.etaxonomy.taxeditor.view.search.derivative.DerivateLabelProvider;
|
|
23 | 23 |
|
24 | 24 |
/** |
25 | 25 |
* @author n.hoffmann |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SpecimenProviderSelectionWizardPage.java | ||
---|---|---|
18 | 18 |
|
19 | 19 |
import eu.etaxonomy.cdm.ext.common.ServiceWrapperBase; |
20 | 20 |
import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper; |
21 |
import eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenProviderSelectionController;
|
|
21 |
import eu.etaxonomy.taxeditor.view.search.specimen.SpecimenProviderSelectionController;
|
|
22 | 22 |
|
23 | 23 |
|
24 | 24 |
/** |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SpecimenSearchWizardPage.java | ||
---|---|---|
14 | 14 |
import org.eclipse.swt.widgets.Composite; |
15 | 15 |
|
16 | 16 |
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery; |
17 |
import eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchController;
|
|
17 |
import eu.etaxonomy.taxeditor.view.search.specimen.SpecimenSearchController;
|
|
18 | 18 |
|
19 | 19 |
|
20 | 20 |
/** |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/e4/SpecimenProviderSelectionWizardPageE4.java | ||
---|---|---|
21 | 21 |
import eu.etaxonomy.cdm.ext.common.ServiceWrapperBase; |
22 | 22 |
import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper; |
23 | 23 |
import eu.etaxonomy.taxeditor.view.dataimport.QueryType; |
24 |
import eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenProviderSelectionController;
|
|
24 |
import eu.etaxonomy.taxeditor.view.search.specimen.SpecimenProviderSelectionController;
|
|
25 | 25 |
|
26 | 26 |
|
27 | 27 |
/** |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/e4/SpecimenSearchWizardPageE4.java | ||
---|---|---|
16 | 16 |
import org.eclipse.swt.widgets.Composite; |
17 | 17 |
|
18 | 18 |
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery; |
19 |
import eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchController;
|
|
19 |
import eu.etaxonomy.taxeditor.view.search.specimen.SpecimenSearchController;
|
|
20 | 20 |
|
21 | 21 |
|
22 | 22 |
/** |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/derivateSearch/DerivateContentProvider.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.view.derivateSearch; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Collection; |
|
5 |
import java.util.Collections; |
|
6 |
import java.util.Comparator; |
|
7 |
import java.util.LinkedHashSet; |
|
8 |
import java.util.List; |
|
9 |
import java.util.Set; |
|
10 |
|
|
11 |
import org.eclipse.jface.viewers.ITreeContentProvider; |
|
12 |
import org.eclipse.jface.viewers.TreeNode; |
|
13 |
import org.eclipse.jface.viewers.Viewer; |
|
14 |
|
|
15 |
import eu.etaxonomy.cdm.model.molecular.DnaSample; |
|
16 |
import eu.etaxonomy.cdm.model.molecular.Sequence; |
|
17 |
import eu.etaxonomy.cdm.model.molecular.SingleRead; |
|
18 |
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent; |
|
19 |
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit; |
|
20 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
|
21 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType; |
|
22 |
|
|
23 |
public class DerivateContentProvider implements ITreeContentProvider { |
|
24 |
|
|
25 |
private List<TreeNode> rootNodes; |
|
26 |
|
|
27 |
@Override |
|
28 |
public void dispose() { |
|
29 |
// TODO Auto-generated method stub |
|
30 |
|
|
31 |
} |
|
32 |
|
|
33 |
public List<SpecimenOrObservationBase> getRootElements() { |
|
34 |
List<SpecimenOrObservationBase> elements = new ArrayList<SpecimenOrObservationBase>(); |
|
35 |
|
|
36 |
if(rootNodes != null) { |
|
37 |
for(TreeNode node : rootNodes) { |
|
38 |
elements.add((SpecimenOrObservationBase)node.getValue()); |
|
39 |
} |
|
40 |
} |
|
41 |
return elements; |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public Object[] getElements(Object inputElement) { |
|
50 |
rootNodes = new ArrayList<>(); |
|
51 |
if(inputElement instanceof Collection){ |
|
52 |
for (Object o: (Collection)inputElement) { |
|
53 |
if(o instanceof SpecimenOrObservationBase){ |
|
54 |
SpecimenOrObservationBase<?> rootElement = (SpecimenOrObservationBase<?>)o; |
|
55 |
if(rootElement!=null){ |
|
56 |
rootNodes.add(new TreeNode(rootElement)); |
|
57 |
} |
|
58 |
} |
|
59 |
} |
|
60 |
} |
|
61 |
Collections.sort(rootNodes, new TreeNodeComparator()); |
|
62 |
return rootNodes.toArray(); |
|
63 |
} |
|
64 |
|
|
65 |
@Override |
|
66 |
public Object[] getChildren(Object element) { |
|
67 |
TreeNode currentnode = null; |
|
68 |
Object value = null; |
|
69 |
if(element instanceof TreeNode){ |
|
70 |
currentnode = (TreeNode) element; |
|
71 |
value = ((TreeNode) element).getValue(); |
|
72 |
} |
|
73 |
Set<Object> children = new LinkedHashSet<Object>(); |
|
74 |
if(value instanceof DnaSample && ((DnaSample) value).getRecordBasis()==SpecimenOrObservationType.DnaSample){ |
|
75 |
DnaSample dnaSample = (DnaSample)value; |
|
76 |
Set<Sequence> sequences = dnaSample.getSequences(); |
|
77 |
for (Sequence sequence : sequences) { |
|
78 |
TreeNode node = new TreeNode(sequence); |
|
79 |
node.setParent(currentnode); |
|
80 |
children.add(node); |
|
81 |
} |
|
82 |
} |
|
83 |
else if(value instanceof Sequence){ |
|
84 |
Set<SingleRead> singleReads = ((Sequence) value).getSingleReads(); |
|
85 |
for(SingleRead singleRead:singleReads){ |
|
86 |
TreeNode node = new TreeNode(singleRead); |
|
87 |
node.setParent(currentnode); |
|
88 |
children.add(node); |
|
89 |
} |
|
90 |
return children.toArray(); |
|
91 |
} |
|
92 |
|
|
93 |
if(value instanceof SpecimenOrObservationBase){ |
|
94 |
List<DerivedUnit> derivates = getDerivates((SpecimenOrObservationBase<?>) value); |
|
95 |
for (DerivedUnit derivedUnit:derivates) { |
|
96 |
TreeNode node = new TreeNode(derivedUnit); |
|
97 |
node.setParent(currentnode); |
|
98 |
children.add(node); |
|
99 |
} |
|
100 |
return children.toArray(); |
|
101 |
} |
|
102 |
return null; |
|
103 |
} |
|
104 |
|
|
105 |
@Override |
|
106 |
public Object getParent(Object element) { |
|
107 |
if(element instanceof TreeNode){ |
|
108 |
return ((TreeNode) element).getParent(); |
|
109 |
} |
|
110 |
return null; |
|
111 |
} |
|
112 |
|
|
113 |
@Override |
|
114 |
public boolean hasChildren(Object element) { |
|
115 |
if(element instanceof TreeNode){ |
|
116 |
element = ((TreeNode) element).getValue(); |
|
117 |
} |
|
118 |
|
|
119 |
if(element instanceof DnaSample && ((DnaSample) element).getRecordBasis()==SpecimenOrObservationType.DnaSample){ |
|
120 |
DnaSample dnaSample = (DnaSample)element; |
|
121 |
if(!dnaSample.getSequences().isEmpty()){// || !dnaSample.getAmplifications().isEmpty()){ |
|
122 |
return true; |
|
123 |
} |
|
124 |
} |
|
125 |
else if(element instanceof Sequence){ |
|
126 |
return !((Sequence)element).getSingleReads().isEmpty(); |
|
127 |
} |
|
128 |
|
|
129 |
if(element instanceof SpecimenOrObservationBase){ |
|
130 |
SpecimenOrObservationBase<?> specimenOrObservation = (SpecimenOrObservationBase<?>)element; |
|
131 |
for(DerivationEvent event:specimenOrObservation.getDerivationEvents()){ |
|
132 |
if(!event.getDerivatives().isEmpty()){ |
|
133 |
return true; |
|
134 |
} |
|
135 |
} |
|
136 |
} |
|
137 |
return false; |
|
138 |
} |
|
139 |
|
|
140 |
private List<DerivedUnit> getDerivates(SpecimenOrObservationBase<?> specimenOrObservation){ |
|
141 |
List<DerivedUnit> derivates = new ArrayList<DerivedUnit>(); |
|
142 |
for(DerivationEvent derivationEvent:specimenOrObservation.getDerivationEvents()){ |
|
143 |
derivates.addAll(derivationEvent.getDerivatives()); |
|
144 |
} |
|
145 |
return derivates; |
|
146 |
} |
|
147 |
|
|
148 |
private class TreeNodeComparator implements Comparator<TreeNode>{ |
|
149 |
|
|
150 |
@Override |
|
151 |
public int compare(TreeNode o1, TreeNode o2) { |
|
152 |
if(o1!=null && o2==null){ |
|
153 |
return -1; |
|
154 |
} |
|
155 |
else if(o1==null && o2!=null){ |
|
156 |
return 1; |
|
157 |
} |
|
158 |
else if(o1!=null && o2!=null){ |
|
159 |
SpecimenOrObservationBase<?> specimenOrObservation1 = (SpecimenOrObservationBase<?>) o1.getValue(); |
|
160 |
SpecimenOrObservationBase<?> specimenOrObservation2 = (SpecimenOrObservationBase<?>) o2.getValue(); |
|
161 |
return specimenOrObservation1.getTitleCache().compareTo(specimenOrObservation2.getTitleCache()); |
|
162 |
} |
|
163 |
return 0; |
|
164 |
} |
|
165 |
|
|
166 |
} |
|
167 |
|
|
168 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/derivateSearch/DerivateLabelProvider.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2013 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.view.derivateSearch; |
|
10 |
|
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.Collection; |
|
13 |
import java.util.HashMap; |
|
14 |
import java.util.HashSet; |
|
15 |
import java.util.List; |
|
16 |
import java.util.Map; |
|
17 |
import java.util.Map.Entry; |
|
18 |
import java.util.Set; |
|
19 |
import java.util.UUID; |
|
20 |
|
|
21 |
import org.eclipse.jface.viewers.ColumnLabelProvider; |
|
22 |
import org.eclipse.jface.viewers.TreeNode; |
|
23 |
import org.eclipse.swt.graphics.Image; |
|
24 |
import org.hibernate.LazyInitializationException; |
|
25 |
|
|
26 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
|
27 |
import eu.etaxonomy.cdm.api.service.IOccurrenceService; |
|
28 |
import eu.etaxonomy.cdm.api.service.molecular.ISequenceService; |
|
29 |
import eu.etaxonomy.cdm.common.CdmUtils; |
|
30 |
import eu.etaxonomy.cdm.format.CdmFormatterFactory; |
|
31 |
import eu.etaxonomy.cdm.format.ICdmFormatter.FormatKey; |
|
32 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
33 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
34 |
import eu.etaxonomy.cdm.model.common.DefinedTerm; |
|
35 |
import eu.etaxonomy.cdm.model.common.IdentifiableEntity; |
|
36 |
import eu.etaxonomy.cdm.model.common.Identifier; |
|
37 |
import eu.etaxonomy.cdm.model.molecular.DnaSample; |
|
38 |
import eu.etaxonomy.cdm.model.molecular.Sequence; |
|
39 |
import eu.etaxonomy.cdm.model.molecular.SingleRead; |
|
40 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation; |
|
41 |
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit; |
|
42 |
import eu.etaxonomy.cdm.model.occurrence.FieldUnit; |
|
43 |
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent; |
|
44 |
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen; |
|
45 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
|
46 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType; |
|
47 |
import eu.etaxonomy.cdm.strategy.cache.common.IdentifiableEntityDefaultCacheStrategy; |
|
48 |
import eu.etaxonomy.taxeditor.model.ImageResources; |
|
49 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
50 |
|
|
51 |
/** |
|
52 |
* Label provider for the views to show {@link SpecimenOrObservationBase}s.<br> |
|
53 |
* <br> |
|
54 |
* <b>Note:</b> If you use this label provider you need to assure that you |
|
55 |
* created a {@link ConversationHolder} resp. have an open session because |
|
56 |
* the labels are generated from various fields of the derivate hierarchy which |
|
57 |
* are lazy loaded and could therefore throw a {@link LazyInitializationException}.<br> |
|
58 |
* Use <b>{@link #setConversation(ConversationHolder)}</b> to assign the session to this provider. |
|
59 |
*/ |
|
60 |
public class DerivateLabelProvider extends ColumnLabelProvider { |
|
61 |
|
|
62 |
private static final String NO_SAMPLE_DESIGNATION = "[no sample designation]"; |
|
63 |
|
|
64 |
private static Set<SingleRead> multiLinkSingleReads; |
|
65 |
|
|
66 |
private static Map<DerivedUnit, Collection<SpecimenTypeDesignation>> typeDesignations; |
|
67 |
|
|
68 |
private ConversationHolder conversation; |
|
69 |
|
|
70 |
private static DefinedTerm photoTerm = null; |
|
71 |
private static DefinedTerm drawingTerm = null; |
|
72 |
private static DefinedTerm specimenScanTerm = null; |
|
73 |
private static DefinedTerm detailImageTerm = null; |
|
74 |
private static DefinedTerm sampleDesignationTerm = null; |
|
75 |
|
|
76 |
//FIXME: move static term getters to new singleton utility class |
|
77 |
private static void initializeTerms() { |
|
78 |
List<DefinedTerm> preferredTerms = CdmStore.getTermManager().getPreferredTerms(DefinedTerm.class); |
|
79 |
for (DefinedTerm definedTerm : preferredTerms) { |
|
80 |
if(definedTerm.getUuid().equals(UUID.fromString("c5c59c42-f254-471e-96c6-09f459f7c903"))){ |
|
81 |
photoTerm = definedTerm; |
|
82 |
} |
|
83 |
else if(definedTerm.getUuid().equals(UUID.fromString("669b0409-4aa4-4695-aae4-a95ed27bad4c"))){ |
|
84 |
drawingTerm = definedTerm; |
|
85 |
} |
|
86 |
else if(definedTerm.getUuid().equals(UUID.fromString("acda15be-c0e2-4ea8-8783-b9b0c4ad7f03"))){ |
|
87 |
specimenScanTerm = definedTerm; |
|
88 |
} |
|
89 |
else if(definedTerm.getUuid().equals(UUID.fromString("31eb8d02-bf5d-437c-bcc6-87a626445f34"))){ |
|
90 |
detailImageTerm = definedTerm; |
|
91 |
} |
|
92 |
else if(definedTerm.getUuid().equals(UUID.fromString("fadeba12-1be3-4bc7-9ff5-361b088d86fc"))){ |
|
93 |
sampleDesignationTerm = definedTerm; |
|
94 |
} |
|
95 |
} |
|
96 |
} |
|
97 |
|
|
98 |
public static DefinedTerm getLivingPlantPhotoTerm(){ |
|
99 |
if(photoTerm==null){ |
|
100 |
initializeTerms(); |
|
101 |
} |
|
102 |
return photoTerm; |
|
103 |
} |
|
104 |
|
|
105 |
public static DefinedTerm getArtworkTerm(){ |
|
106 |
if(drawingTerm==null){ |
|
107 |
initializeTerms(); |
|
108 |
} |
|
109 |
return drawingTerm; |
|
110 |
} |
|
111 |
|
|
112 |
public static DefinedTerm getSpecimenScanTerm(){ |
|
113 |
if(specimenScanTerm==null){ |
|
114 |
initializeTerms(); |
|
115 |
} |
|
116 |
return specimenScanTerm; |
|
117 |
} |
|
118 |
|
|
119 |
public static DefinedTerm getDetailImageTerm(){ |
|
120 |
if(detailImageTerm==null){ |
|
121 |
initializeTerms(); |
|
122 |
} |
|
123 |
return detailImageTerm; |
|
124 |
} |
|
125 |
|
|
126 |
public static DefinedTerm getSampleDesignationTerm(){ |
|
127 |
if(sampleDesignationTerm==null){ |
|
128 |
initializeTerms(); |
|
129 |
} |
|
130 |
return sampleDesignationTerm; |
|
131 |
} |
|
132 |
|
|
133 |
|
|
134 |
/** {@inheritDoc} */ |
|
135 |
@Override |
|
136 |
public String getText(Object element) { |
|
137 |
if(element instanceof TreeNode){ |
|
138 |
element = ((TreeNode) element).getValue(); |
|
139 |
} |
|
140 |
String text = null; |
|
141 |
if(element instanceof IdentifiableEntity |
|
142 |
&& ((IdentifiableEntity) element).isProtectedTitleCache()){ |
|
143 |
return ((IdentifiableEntity) element).getTitleCache(); |
|
144 |
} |
|
145 |
|
|
146 |
|
|
147 |
//check if collection code does not exist -> use collection name then |
|
148 |
FormatKey collectionKey = FormatKey.COLLECTION_CODE; |
|
149 |
text = CdmFormatterFactory.format(element,new FormatKey[]{FormatKey.COLLECTION_CODE}); |
|
150 |
if(CdmUtils.isBlank(text)){ |
|
151 |
collectionKey = FormatKey.COLLECTION_NAME; |
|
152 |
} |
|
153 |
|
|
154 |
//Use titlecache for FieldUnits |
|
155 |
if(element instanceof FieldUnit){ |
|
156 |
text = ((FieldUnit) element).getTitleCache(); |
|
157 |
} |
|
158 |
else if(element instanceof MediaSpecimen){ |
|
159 |
text = CdmFormatterFactory.format(element, |
|
160 |
new FormatKey[]{ |
|
161 |
// FormatKey.MEDIA_TITLE_CACHE, FormatKey.SPACE, |
|
162 |
collectionKey, FormatKey.SPACE, |
|
163 |
FormatKey.MOST_SIGNIFICANT_IDENTIFIER, FormatKey.SPACE, |
|
164 |
FormatKey.MEDIA_TITLE, FormatKey.SPACE, |
|
165 |
FormatKey.MEDIA_ARTIST, FormatKey.SPACE, |
|
166 |
}); |
|
167 |
} |
|
168 |
else if (element instanceof DnaSample) { |
|
169 |
text = CdmFormatterFactory.format(element, |
|
170 |
new FormatKey[] { |
|
171 |
collectionKey, FormatKey.SPACE, |
|
172 |
FormatKey.MOST_SIGNIFICANT_IDENTIFIER, FormatKey.SPACE, |
|
173 |
FormatKey.SAMPLE_DESIGNATION, FormatKey.SPACE |
|
174 |
}); |
|
175 |
} |
|
176 |
else if (element instanceof DerivedUnit) { |
|
177 |
text = CdmFormatterFactory.format(element, |
|
178 |
new FormatKey[] { |
|
179 |
collectionKey, FormatKey.SPACE, |
|
180 |
FormatKey.MOST_SIGNIFICANT_IDENTIFIER, FormatKey.SPACE |
|
181 |
}); |
|
182 |
} |
|
183 |
else if (element instanceof Sequence) { |
|
184 |
text = CdmFormatterFactory.format(element, |
|
185 |
new FormatKey[] { |
|
186 |
FormatKey.SEQUENCE_DNA_MARKER, FormatKey.SPACE |
|
187 |
}); |
|
188 |
} |
|
189 |
else if (element instanceof SingleRead) { |
|
190 |
text = CdmFormatterFactory.format(element, |
|
191 |
new FormatKey[] { |
|
192 |
FormatKey.SINGLE_READ_PHEROGRAM_TITLE_CACHE, FormatKey.SPACE, |
|
193 |
FormatKey.AMPLIFICATION_LABEL, FormatKey.SPACE, |
|
194 |
}); |
|
195 |
} |
|
196 |
else if(element instanceof IdentifiableEntity){ |
|
197 |
|
|
198 |
IdentifiableEntity identifiableEntity = (IdentifiableEntity) element; |
|
199 |
if(identifiableEntity.isProtectedTitleCache()){ |
|
200 |
text = identifiableEntity.getTitleCache(); |
|
201 |
} |
|
202 |
} |
|
203 |
if(CdmUtils.isBlank(text) || text.equals(IdentifiableEntityDefaultCacheStrategy.TITLE_CACHE_GENERATION_NOT_IMPLEMENTED)){ |
|
204 |
if(element instanceof CdmBase){ |
|
205 |
text = ((CdmBase) element).getUuid().toString(); |
|
206 |
} |
|
207 |
else{ |
|
208 |
text = element.toString(); |
|
209 |
} |
|
210 |
} |
|
211 |
//remove dot at the end |
|
212 |
if(text.endsWith(".")){ |
|
213 |
text = text.substring(0, text.length()-1); |
|
214 |
} |
|
215 |
return text; |
|
216 |
} |
|
217 |
|
|
218 |
/** {@inheritDoc} */ |
|
219 |
@Override |
|
220 |
public String getToolTipText(Object element) { |
|
221 |
return getDerivateText(element); |
|
222 |
} |
|
223 |
|
|
224 |
/** |
|
225 |
* @param conversation the conversation to set |
|
226 |
*/ |
|
227 |
public void setConversation(ConversationHolder conversation) { |
|
228 |
this.conversation = conversation; |
|
229 |
} |
|
230 |
|
|
231 |
public String getDerivateText(Object element){ |
|
232 |
return getDerivateText(element, conversation); |
|
233 |
} |
|
234 |
|
|
235 |
public static String getDerivateText(Object element, ConversationHolder conversation){ |
|
236 |
//TODO: use list of strings to assemble labels to avoid adding the separator every time and to allow null values |
|
237 |
TreeNode parentNode = null; |
|
238 |
TreeNode node = null; |
|
239 |
Object derivate = element; |
|
240 |
if(element instanceof TreeNode){ |
|
241 |
node = (TreeNode) element; |
|
242 |
parentNode = node.getParent(); |
|
243 |
//unwrap specimen from TreeNode |
|
244 |
derivate = node.getValue(); |
|
245 |
} |
|
246 |
|
|
247 |
if(conversation!=null){ |
|
248 |
conversation.bind(); |
|
249 |
} |
|
250 |
|
|
251 |
final String emptyString = ""; |
|
252 |
final String separator = " "; |
|
253 |
|
|
254 |
String label = emptyString; |
|
255 |
|
|
256 |
//Field Unit |
|
257 |
if(derivate instanceof FieldUnit){ |
|
258 |
FieldUnit fieldUnit = (FieldUnit)derivate; |
|
259 |
if(fieldUnit.getGatheringEvent()!=null){ |
|
260 |
GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent(); |
|
261 |
label += gatheringEvent.getCountry()!=null?gatheringEvent.getCountry().getLabel()+separator:emptyString; |
|
262 |
label += gatheringEvent.getLocality()!=null?gatheringEvent.getLocality().getText()+separator:emptyString; |
|
263 |
label += gatheringEvent.getGatheringDate()!=null?gatheringEvent.getGatheringDate()+separator:emptyString; |
|
264 |
label += gatheringEvent.getCollector()!=null?gatheringEvent.getCollector()+separator:emptyString; |
|
265 |
} |
|
266 |
label += fieldUnit.getFieldNumber()!=null?fieldUnit.getFieldNumber():emptyString; |
|
267 |
} |
|
268 |
//MediaSpecimen |
|
269 |
else if(derivate instanceof MediaSpecimen){ |
|
270 |
MediaSpecimen mediaSpecimen = (MediaSpecimen)derivate; |
|
271 |
if(mediaSpecimen.getMediaSpecimen()!=null){ |
|
272 |
label += mediaSpecimen.getMediaSpecimen().getTitle()!=null?mediaSpecimen.getMediaSpecimen().getTitle().getText()+separator:"[no motif]"; |
|
273 |
label += mediaSpecimen.getMediaSpecimen().getArtist()!=null?mediaSpecimen.getMediaSpecimen().getArtist()+separator:emptyString; |
|
274 |
} |
|
275 |
eu.etaxonomy.cdm.model.occurrence.Collection collection = mediaSpecimen.getCollection(); |
|
276 |
if(collection!=null){ |
|
277 |
label += collection.getName()!=null?collection.getName()+" ":emptyString; |
|
278 |
label += collection.getCode()!=null?"("+collection.getCode()+")"+separator:emptyString; |
|
279 |
} |
|
280 |
label += mediaSpecimen.getAccessionNumber()!=null?mediaSpecimen.getAccessionNumber()+separator:emptyString; |
|
281 |
label += mediaSpecimen.getBarcode()!=null?mediaSpecimen.getBarcode()+separator:emptyString; |
|
282 |
} |
|
283 |
//TissueSample + DnaSample |
|
284 |
else if(derivate instanceof DnaSample){ |
|
285 |
DnaSample dnaSample = (DnaSample)derivate; |
|
286 |
if(((DnaSample) derivate).getRecordBasis()==SpecimenOrObservationType.DnaSample){ |
|
287 |
Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(dnaSample); |
|
288 |
if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){ |
|
289 |
label += currentSampleDesignation.getIdentifier()+separator; |
|
290 |
} |
|
291 |
else{ |
|
292 |
label += NO_SAMPLE_DESIGNATION+separator; |
|
293 |
} |
|
294 |
} |
|
295 |
else if(((DnaSample) derivate).getRecordBasis()==SpecimenOrObservationType.TissueSample){ |
|
296 |
if(dnaSample.getKindOfUnit()!=null){ |
|
297 |
label += dnaSample.getKindOfUnit()+separator; |
|
298 |
} |
|
299 |
Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(dnaSample); |
|
300 |
if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){ |
|
301 |
label += currentSampleDesignation.getIdentifier()+separator; |
|
302 |
} |
|
303 |
else{ |
|
304 |
label += NO_SAMPLE_DESIGNATION+separator; |
|
305 |
} |
|
306 |
} |
|
307 |
|
|
308 |
} |
|
309 |
//DerivedUnit + TissueSample |
|
310 |
else if(derivate instanceof DerivedUnit){ |
|
311 |
DerivedUnit derivedUnit = (DerivedUnit)derivate; |
|
312 |
if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.PreservedSpecimen){ |
|
313 |
//check for type designation |
|
314 |
if(typeDesignations.get(derivedUnit)==null){ |
|
315 |
for (SpecimenTypeDesignation specimenTypeDesignation : derivedUnit.getSpecimenTypeDesignations()) { |
|
316 |
addTypeDesignation(derivedUnit, specimenTypeDesignation); |
|
317 |
} |
|
318 |
} |
|
319 |
//java.util.Collection<FieldUnit> fieldUnits = CdmStore.getService(IOccurrenceService.class).getFieldUnits(derivedUnit.getUuid()); |
|
320 |
//TODO : This is not generic anymore for performance reasons |
|
321 |
Set<SpecimenOrObservationBase> originals = derivedUnit.getOriginals(); |
|
322 |
if(originals!=null && originals.size() ==1) { |
|
323 |
SpecimenOrObservationBase specimen = originals.iterator().next(); |
|
324 |
if(specimen instanceof FieldUnit) { |
|
325 |
FieldUnit fieldUnit = (FieldUnit)specimen; |
|
326 |
GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent(); |
|
327 |
if(gatheringEvent!=null){ |
|
328 |
label += gatheringEvent.getCollector()!=null?gatheringEvent.getCollector()+separator:emptyString; |
|
329 |
} |
|
330 |
label += fieldUnit.getFieldNumber()!=null?fieldUnit.getFieldNumber()+separator:emptyString; |
|
331 |
} |
|
332 |
} |
|
333 |
|
|
334 |
eu.etaxonomy.cdm.model.occurrence.Collection collection = derivedUnit.getCollection(); |
|
335 |
if(collection!=null){ |
|
336 |
label += collection.getCode()!=null?"("+collection.getCode()+")"+separator:emptyString; |
|
337 |
} |
|
338 |
String mostSignificantIdentifier = derivedUnit.getMostSignificantIdentifier(); |
|
339 |
label += mostSignificantIdentifier!=null?mostSignificantIdentifier+separator:emptyString; |
|
340 |
} |
|
341 |
else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){ |
|
342 |
//TissueSample should only be created by using it's own class |
|
343 |
//in future using only one class with different SpecimenOrObservationTypes is desired |
|
344 |
// label += derivedUnit.getKindOfUnit() + NO_SAMPLE_DESIGNATION; |
|
345 |
} |
|
346 |
} |
|
347 |
//Sequence |
|
348 |
else if(derivate instanceof Sequence){ |
|
349 |
Sequence sequence = (Sequence)derivate; |
|
350 |
Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(sequence); |
|
351 |
if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){ |
|
352 |
label += currentSampleDesignation.getIdentifier()+separator; |
|
353 |
} |
|
354 |
else{ |
|
355 |
label += NO_SAMPLE_DESIGNATION+separator; |
|
356 |
} |
|
357 |
label += sequence.getDnaMarker()!=null?sequence.getDnaMarker():emptyString; |
|
358 |
} |
|
359 |
//SingleRead |
|
360 |
else if(derivate instanceof SingleRead){ |
|
361 |
SingleRead singleRead = (SingleRead)derivate; |
|
362 |
if(parentNode!=null && parentNode.getValue() instanceof Sequence){ |
|
363 |
Sequence sequence = (Sequence) parentNode.getValue(); |
|
364 |
Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(sequence); |
|
365 |
if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){ |
|
366 |
label = currentSampleDesignation.getIdentifier()+separator; |
|
367 |
} |
|
368 |
else{ |
|
369 |
label += NO_SAMPLE_DESIGNATION+separator; |
|
370 |
} |
|
371 |
label += singleRead.getPrimer()!=null?singleRead.getPrimer().getLabel()+separator:emptyString; |
|
372 |
if(sequence!=null && sequence.getDnaMarker()!=null){ |
|
373 |
label += sequence.getDnaMarker()+separator; |
|
374 |
} |
|
375 |
if(singleRead.getAmplificationResult()!=null && singleRead.getAmplificationResult().getAmplification()!=null){ |
|
376 |
label += singleRead.getAmplificationResult().getAmplification().getLabelCache()+separator; |
|
377 |
} |
|
378 |
} |
|
379 |
} |
|
380 |
//SOOB |
|
381 |
else if(derivate instanceof SpecimenOrObservationBase){ |
|
382 |
SpecimenOrObservationBase<?> specimen = (SpecimenOrObservationBase<?>) derivate; |
|
383 |
SpecimenOrObservationType type = specimen.getRecordBasis(); |
|
384 |
return specimen.getTitleCache() + (type!=null?" ["+type.toString()+"]":emptyString); |
|
385 |
} |
|
386 |
if(label.isEmpty()){ |
|
387 |
label = derivate.toString(); |
|
388 |
} |
|
389 |
//remove last comma |
|
390 |
else if(label.endsWith(separator)){ |
|
391 |
label = label.substring(0, label.length()-separator.length()); |
|
392 |
} |
|
393 |
return label; |
|
394 |
} |
|
395 |
|
|
396 |
@Override |
|
397 |
public Image getImage(Object element) { |
|
398 |
if(element instanceof TreeNode){ |
|
399 |
element = ((TreeNode) element).getValue(); |
|
400 |
} |
|
401 |
if(element instanceof CdmBase){ |
|
402 |
CdmBase cdmBase = (CdmBase)element; |
|
403 |
boolean hasCharacterData = false; |
|
404 |
if(cdmBase.isInstanceOf(SpecimenOrObservationBase.class)){ |
|
405 |
SpecimenOrObservationBase<?> specimen = HibernateProxyHelper.deproxy(cdmBase, SpecimenOrObservationBase.class); |
|
406 |
if(specimen.hasCharacterData()){ |
|
407 |
hasCharacterData = true; |
|
408 |
} |
|
409 |
} |
|
410 |
if(cdmBase.isInstanceOf(FieldUnit.class)){ |
|
411 |
return hasCharacterData?ImageResources.getImage(ImageResources.FIELD_UNIT_CHARACTER_DATA):ImageResources.getImage(ImageResources.FIELD_UNIT); |
|
412 |
} |
|
413 |
else if(cdmBase.isInstanceOf(DerivedUnit.class)){ |
|
414 |
DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(element, DerivedUnit.class); |
|
415 |
|
|
416 |
if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.FieldUnit){ |
|
417 |
return hasCharacterData?ImageResources.getImage(ImageResources.FIELD_UNIT_CHARACTER_DATA):ImageResources.getImage(ImageResources.FIELD_UNIT); |
|
418 |
} |
|
419 |
else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.DnaSample){ |
|
420 |
return hasCharacterData?ImageResources.getImage(ImageResources.DNA_SAMPLE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.DNA_SAMPLE_DERIVATE); |
|
421 |
} |
|
422 |
else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){ |
|
423 |
return hasCharacterData?ImageResources.getImage(ImageResources.TISSUE_SAMPLE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.TISSUE_SAMPLE_DERIVATE); |
|
424 |
} |
|
425 |
else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.PreservedSpecimen){ |
|
426 |
if(typeDesignations.get(derivedUnit)!=null && !typeDesignations.get(derivedUnit).isEmpty()){ |
|
427 |
return ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE_TYPE); |
|
428 |
} |
|
429 |
return hasCharacterData?ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE); |
|
430 |
} |
|
431 |
else if(derivedUnit.getRecordBasis().isMedia() |
|
432 |
|| derivedUnit.getRecordBasis().isKindOf(SpecimenOrObservationType.Media)){ |
|
433 |
if(derivedUnit.getKindOfUnit()!=null){ |
|
434 |
if(derivedUnit.getKindOfUnit().equals(getArtworkTerm())){ |
|
435 |
return hasCharacterData?ImageResources.getImage(ImageResources.ARTWORK_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.ARTWORK_DERIVATE); |
|
436 |
} |
|
437 |
else if(derivedUnit.getKindOfUnit().equals(getLivingPlantPhotoTerm())){ |
|
438 |
return hasCharacterData?ImageResources.getImage(ImageResources.LIVING_PLANT_PHOTO_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.LIVING_PLANT_PHOTO_DERIVATE); |
|
439 |
} |
|
440 |
else if(derivedUnit.getKindOfUnit().equals(getSpecimenScanTerm())){ |
|
441 |
return hasCharacterData?ImageResources.getImage(ImageResources.SPECIMEN_SCAN_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.SPECIMEN_SCAN_DERIVATE); |
|
442 |
} |
|
443 |
else if(derivedUnit.getKindOfUnit().equals(getDetailImageTerm())){ |
|
444 |
return hasCharacterData?ImageResources.getImage(ImageResources.DETAIL_IMAGE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.DETAIL_IMAGE_DERIVATE); |
|
445 |
} |
|
446 |
} |
|
447 |
} |
|
448 |
} |
|
449 |
else if(cdmBase.isInstanceOf(Sequence.class)){ |
|
450 |
return ImageResources.getImage(ImageResources.SEQUENCE_DERIVATE); |
|
451 |
} |
|
452 |
|
|
453 |
else if(cdmBase.isInstanceOf(SingleRead.class)){ |
|
454 |
if(multiLinkSingleReads!=null && multiLinkSingleReads.contains(element)){ |
|
455 |
return ImageResources.getImage(ImageResources.SINGLE_READ_DERIVATE_MULTILINK); |
|
456 |
} |
|
457 |
else{ |
|
458 |
return ImageResources.getImage(ImageResources.SINGLE_READ_DERIVATE); |
|
459 |
} |
|
460 |
} |
|
461 |
} |
|
462 |
return ImageResources.getImage(ImageResources.DEFAULT_DERIVATIVE); |
|
463 |
} |
|
464 |
|
|
465 |
public static Identifier<DnaSample> getCurrentSampleDesignation(CdmBase entity) { |
|
466 |
if(entity.isInstanceOf(DnaSample.class)){ |
|
467 |
DnaSample dnaSample = HibernateProxyHelper.deproxy(entity, DnaSample.class); |
|
468 |
for (Identifier<DnaSample> identifier : dnaSample.getIdentifiers()) { |
|
469 |
if(identifier.getType()!=null && identifier.getType().equals(DerivateLabelProvider.getSampleDesignationTerm())){ |
|
470 |
//first sample designation is the current |
|
471 |
return identifier; |
|
472 |
} |
|
473 |
} |
|
474 |
} |
|
475 |
else if(entity.isInstanceOf(Sequence.class)){ |
|
476 |
Sequence sequence = HibernateProxyHelper.deproxy(entity, Sequence.class); |
|
477 |
if(sequence.getDnaSample()!=null){ |
|
478 |
return getCurrentSampleDesignation(sequence.getDnaSample()); |
|
479 |
} |
|
480 |
} |
|
481 |
return null; |
|
482 |
} |
|
483 |
|
|
484 |
private static void addTypeDesignation(DerivedUnit derivedUnit, SpecimenTypeDesignation typeDesignation){ |
|
485 |
Collection<SpecimenTypeDesignation> list = typeDesignations.get(derivedUnit); |
|
486 |
if(list==null){ |
|
487 |
list = new ArrayList<SpecimenTypeDesignation>(); |
|
488 |
} |
|
489 |
list.add(typeDesignation); |
|
490 |
typeDesignations.put(derivedUnit, list); |
|
491 |
} |
|
492 |
|
|
493 |
public static Set<SingleRead> getMultiLinkSingleReads() { |
|
494 |
return multiLinkSingleReads; |
|
495 |
} |
|
496 |
|
|
497 |
public void updateLabelCache(Collection<SpecimenOrObservationBase<?>> rootElements) { |
|
498 |
multiLinkSingleReads = new HashSet<SingleRead>(); |
|
499 |
typeDesignations = new HashMap<DerivedUnit, Collection<SpecimenTypeDesignation>>(); |
|
500 |
for(Entry<SingleRead, Collection<Sequence>> entry:CdmStore.getService(ISequenceService.class).getSingleReadSequencesMap().entrySet()){ |
|
501 |
if(entry.getValue().size()>1){ |
|
502 |
multiLinkSingleReads.add(entry.getKey()); |
|
503 |
} |
|
504 |
} |
|
505 |
if(rootElements!=null){ |
|
506 |
Collection<DerivedUnit> derivedUnits = new ArrayList<DerivedUnit>(); |
|
507 |
for (SpecimenOrObservationBase specimenOrObservationBase : rootElements) { |
|
508 |
List<DerivedUnit> childUnits = CdmStore.getService(IOccurrenceService.class).getAllChildDerivatives(specimenOrObservationBase.getUuid()); |
|
509 |
if (childUnits != null){ |
|
510 |
derivedUnits.addAll(childUnits); |
|
511 |
} |
|
512 |
if(specimenOrObservationBase.isInstanceOf(DerivedUnit.class)){ |
|
513 |
specimenOrObservationBase = CdmStore.getService(IOccurrenceService.class).load(specimenOrObservationBase.getUuid()); |
|
514 |
if (specimenOrObservationBase != null){ |
|
515 |
derivedUnits.add(HibernateProxyHelper.deproxy(specimenOrObservationBase, DerivedUnit.class)); |
|
516 |
} |
|
517 |
} |
|
518 |
} |
|
519 |
for (DerivedUnit derivedUnit : derivedUnits) { |
|
520 |
if(!derivedUnit.getSpecimenTypeDesignations().isEmpty()){ |
|
521 |
typeDesignations.put(derivedUnit, derivedUnit.getSpecimenTypeDesignations()); |
|
522 |
} |
|
523 |
} |
|
524 |
} |
|
525 |
} |
|
526 |
|
|
527 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/derivative/DerivateContentProvider.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.view.search.derivative; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Collection; |
|
5 |
import java.util.Collections; |
|
6 |
import java.util.Comparator; |
|
7 |
import java.util.LinkedHashSet; |
|
8 |
import java.util.List; |
|
9 |
import java.util.Set; |
|
10 |
|
|
11 |
import org.eclipse.jface.viewers.ITreeContentProvider; |
|
12 |
import org.eclipse.jface.viewers.TreeNode; |
|
13 |
import org.eclipse.jface.viewers.Viewer; |
|
14 |
|
|
15 |
import eu.etaxonomy.cdm.model.molecular.DnaSample; |
|
16 |
import eu.etaxonomy.cdm.model.molecular.Sequence; |
|
17 |
import eu.etaxonomy.cdm.model.molecular.SingleRead; |
|
18 |
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent; |
|
19 |
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit; |
|
20 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
|
21 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType; |
|
22 |
|
|
23 |
public class DerivateContentProvider implements ITreeContentProvider { |
|
24 |
|
|
25 |
private List<TreeNode> rootNodes; |
|
26 |
|
|
27 |
@Override |
|
28 |
public void dispose() { |
|
29 |
// TODO Auto-generated method stub |
|
30 |
|
|
31 |
} |
|
32 |
|
|
33 |
public List<SpecimenOrObservationBase> getRootElements() { |
|
34 |
List<SpecimenOrObservationBase> elements = new ArrayList<SpecimenOrObservationBase>(); |
|
35 |
|
|
36 |
if(rootNodes != null) { |
|
37 |
for(TreeNode node : rootNodes) { |
|
38 |
elements.add((SpecimenOrObservationBase)node.getValue()); |
|
39 |
} |
|
40 |
} |
|
41 |
return elements; |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public Object[] getElements(Object inputElement) { |
|
50 |
rootNodes = new ArrayList<>(); |
|
51 |
if(inputElement instanceof Collection){ |
|
52 |
for (Object o: (Collection)inputElement) { |
|
53 |
if(o instanceof SpecimenOrObservationBase){ |
|
54 |
SpecimenOrObservationBase<?> rootElement = (SpecimenOrObservationBase<?>)o; |
|
55 |
if(rootElement!=null){ |
|
56 |
rootNodes.add(new TreeNode(rootElement)); |
|
57 |
} |
|
58 |
} |
|
59 |
} |
|
60 |
} |
|
61 |
Collections.sort(rootNodes, new TreeNodeComparator()); |
|
62 |
return rootNodes.toArray(); |
|
63 |
} |
|
64 |
|
|
65 |
@Override |
|
66 |
public Object[] getChildren(Object element) { |
|
67 |
TreeNode currentnode = null; |
|
68 |
Object value = null; |
|
69 |
if(element instanceof TreeNode){ |
|
70 |
currentnode = (TreeNode) element; |
|
71 |
value = ((TreeNode) element).getValue(); |
|
72 |
} |
|
73 |
Set<Object> children = new LinkedHashSet<Object>(); |
|
74 |
if(value instanceof DnaSample && ((DnaSample) value).getRecordBasis()==SpecimenOrObservationType.DnaSample){ |
|
75 |
DnaSample dnaSample = (DnaSample)value; |
|
76 |
Set<Sequence> sequences = dnaSample.getSequences(); |
|
77 |
for (Sequence sequence : sequences) { |
|
78 |
TreeNode node = new TreeNode(sequence); |
|
79 |
node.setParent(currentnode); |
|
80 |
children.add(node); |
|
81 |
} |
|
82 |
} |
|
83 |
else if(value instanceof Sequence){ |
|
84 |
Set<SingleRead> singleReads = ((Sequence) value).getSingleReads(); |
|
85 |
for(SingleRead singleRead:singleReads){ |
|
86 |
TreeNode node = new TreeNode(singleRead); |
|
87 |
node.setParent(currentnode); |
|
88 |
children.add(node); |
|
89 |
} |
|
90 |
return children.toArray(); |
|
91 |
} |
|
92 |
|
|
93 |
if(value instanceof SpecimenOrObservationBase){ |
|
94 |
List<DerivedUnit> derivates = getDerivates((SpecimenOrObservationBase<?>) value); |
|
95 |
for (DerivedUnit derivedUnit:derivates) { |
|
96 |
TreeNode node = new TreeNode(derivedUnit); |
|
97 |
node.setParent(currentnode); |
|
98 |
children.add(node); |
|
99 |
} |
|
100 |
return children.toArray(); |
|
101 |
} |
|
102 |
return null; |
|
103 |
} |
|
104 |
|
|
105 |
@Override |
|
106 |
public Object getParent(Object element) { |
|
107 |
if(element instanceof TreeNode){ |
|
108 |
return ((TreeNode) element).getParent(); |
|
109 |
} |
|
110 |
return null; |
|
111 |
} |
|
112 |
|
|
113 |
@Override |
|
114 |
public boolean hasChildren(Object element) { |
|
115 |
if(element instanceof TreeNode){ |
|
116 |
element = ((TreeNode) element).getValue(); |
|
117 |
} |
|
118 |
|
|
119 |
if(element instanceof DnaSample && ((DnaSample) element).getRecordBasis()==SpecimenOrObservationType.DnaSample){ |
|
120 |
DnaSample dnaSample = (DnaSample)element; |
|
121 |
if(!dnaSample.getSequences().isEmpty()){// || !dnaSample.getAmplifications().isEmpty()){ |
|
122 |
return true; |
|
123 |
} |
|
124 |
} |
|
125 |
else if(element instanceof Sequence){ |
|
126 |
return !((Sequence)element).getSingleReads().isEmpty(); |
|
127 |
} |
|
128 |
|
|
129 |
if(element instanceof SpecimenOrObservationBase){ |
|
130 |
SpecimenOrObservationBase<?> specimenOrObservation = (SpecimenOrObservationBase<?>)element; |
|
131 |
for(DerivationEvent event:specimenOrObservation.getDerivationEvents()){ |
|
132 |
if(!event.getDerivatives().isEmpty()){ |
|
133 |
return true; |
|
134 |
} |
|
135 |
} |
|
136 |
} |
|
137 |
return false; |
|
138 |
} |
|
139 |
|
|
140 |
private List<DerivedUnit> getDerivates(SpecimenOrObservationBase<?> specimenOrObservation){ |
|
141 |
List<DerivedUnit> derivates = new ArrayList<DerivedUnit>(); |
|
142 |
for(DerivationEvent derivationEvent:specimenOrObservation.getDerivationEvents()){ |
|
143 |
derivates.addAll(derivationEvent.getDerivatives()); |
|
144 |
} |
|
145 |
return derivates; |
|
146 |
} |
|
147 |
|
|
148 |
private class TreeNodeComparator implements Comparator<TreeNode>{ |
|
149 |
|
|
150 |
@Override |
|
151 |
public int compare(TreeNode o1, TreeNode o2) { |
|
152 |
if(o1!=null && o2==null){ |
|
153 |
return -1; |
|
154 |
} |
|
155 |
else if(o1==null && o2!=null){ |
|
156 |
return 1; |
|
157 |
} |
|
158 |
else if(o1!=null && o2!=null){ |
|
159 |
SpecimenOrObservationBase<?> specimenOrObservation1 = (SpecimenOrObservationBase<?>) o1.getValue(); |
|
160 |
SpecimenOrObservationBase<?> specimenOrObservation2 = (SpecimenOrObservationBase<?>) o2.getValue(); |
|
161 |
return specimenOrObservation1.getTitleCache().compareTo(specimenOrObservation2.getTitleCache()); |
|
162 |
} |
|
163 |
return 0; |
|
164 |
} |
|
165 |
|
|
166 |
} |
|
167 |
|
|
168 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/derivative/DerivateLabelProvider.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2013 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.view.search.derivative; |
|
10 |
|
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.Collection; |
|
13 |
import java.util.HashMap; |
|
14 |
import java.util.HashSet; |
|
15 |
import java.util.List; |
|
16 |
import java.util.Map; |
|
17 |
import java.util.Map.Entry; |
|
18 |
import java.util.Set; |
|
19 |
import java.util.UUID; |
|
20 |
|
|
21 |
import org.eclipse.jface.viewers.ColumnLabelProvider; |
|
22 |
import org.eclipse.jface.viewers.TreeNode; |
|
23 |
import org.eclipse.swt.graphics.Image; |
|
24 |
import org.hibernate.LazyInitializationException; |
|
25 |
|
|
26 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
|
27 |
import eu.etaxonomy.cdm.api.service.IOccurrenceService; |
|
28 |
import eu.etaxonomy.cdm.api.service.molecular.ISequenceService; |
|
29 |
import eu.etaxonomy.cdm.common.CdmUtils; |
|
30 |
import eu.etaxonomy.cdm.format.CdmFormatterFactory; |
|
31 |
import eu.etaxonomy.cdm.format.ICdmFormatter.FormatKey; |
|
32 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
33 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
34 |
import eu.etaxonomy.cdm.model.common.DefinedTerm; |
|
35 |
import eu.etaxonomy.cdm.model.common.IdentifiableEntity; |
|
36 |
import eu.etaxonomy.cdm.model.common.Identifier; |
|
37 |
import eu.etaxonomy.cdm.model.molecular.DnaSample; |
|
38 |
import eu.etaxonomy.cdm.model.molecular.Sequence; |
|
39 |
import eu.etaxonomy.cdm.model.molecular.SingleRead; |
|
40 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation; |
|
41 |
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit; |
|
42 |
import eu.etaxonomy.cdm.model.occurrence.FieldUnit; |
|
43 |
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent; |
|
44 |
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen; |
|
45 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
|
46 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType; |
|
47 |
import eu.etaxonomy.cdm.strategy.cache.common.IdentifiableEntityDefaultCacheStrategy; |
|
48 |
import eu.etaxonomy.taxeditor.model.ImageResources; |
|
49 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
50 |
|
|
51 |
/** |
|
52 |
* Label provider for the views to show {@link SpecimenOrObservationBase}s.<br> |
|
53 |
* <br> |
|
54 |
* <b>Note:</b> If you use this label provider you need to assure that you |
|
55 |
* created a {@link ConversationHolder} resp. have an open session because |
|
56 |
* the labels are generated from various fields of the derivate hierarchy which |
|
57 |
* are lazy loaded and could therefore throw a {@link LazyInitializationException}.<br> |
|
58 |
* Use <b>{@link #setConversation(ConversationHolder)}</b> to assign the session to this provider. |
|
59 |
*/ |
|
60 |
public class DerivateLabelProvider extends ColumnLabelProvider { |
|
61 |
|
|
62 |
private static final String NO_SAMPLE_DESIGNATION = "[no sample designation]"; |
|
63 |
|
|
64 |
private static Set<SingleRead> multiLinkSingleReads; |
|
65 |
|
|
66 |
private static Map<DerivedUnit, Collection<SpecimenTypeDesignation>> typeDesignations; |
|
67 |
|
|
68 |
private ConversationHolder conversation; |
|
69 |
|
|
70 |
private static DefinedTerm photoTerm = null; |
|
71 |
private static DefinedTerm drawingTerm = null; |
|
72 |
private static DefinedTerm specimenScanTerm = null; |
|
73 |
private static DefinedTerm detailImageTerm = null; |
|
74 |
private static DefinedTerm sampleDesignationTerm = null; |
|
75 |
|
|
76 |
//FIXME: move static term getters to new singleton utility class |
|
77 |
private static void initializeTerms() { |
|
78 |
List<DefinedTerm> preferredTerms = CdmStore.getTermManager().getPreferredTerms(DefinedTerm.class); |
|
79 |
for (DefinedTerm definedTerm : preferredTerms) { |
|
80 |
if(definedTerm.getUuid().equals(UUID.fromString("c5c59c42-f254-471e-96c6-09f459f7c903"))){ |
|
81 |
photoTerm = definedTerm; |
|
82 |
} |
|
83 |
else if(definedTerm.getUuid().equals(UUID.fromString("669b0409-4aa4-4695-aae4-a95ed27bad4c"))){ |
|
84 |
drawingTerm = definedTerm; |
|
85 |
} |
|
86 |
else if(definedTerm.getUuid().equals(UUID.fromString("acda15be-c0e2-4ea8-8783-b9b0c4ad7f03"))){ |
|
87 |
specimenScanTerm = definedTerm; |
|
88 |
} |
|
89 |
else if(definedTerm.getUuid().equals(UUID.fromString("31eb8d02-bf5d-437c-bcc6-87a626445f34"))){ |
|
90 |
detailImageTerm = definedTerm; |
|
91 |
} |
|
92 |
else if(definedTerm.getUuid().equals(UUID.fromString("fadeba12-1be3-4bc7-9ff5-361b088d86fc"))){ |
|
93 |
sampleDesignationTerm = definedTerm; |
|
94 |
} |
|
95 |
} |
|
96 |
} |
|
97 |
|
|
98 |
public static DefinedTerm getLivingPlantPhotoTerm(){ |
|
99 |
if(photoTerm==null){ |
|
100 |
initializeTerms(); |
|
101 |
} |
|
102 |
return photoTerm; |
|
103 |
} |
|
104 |
|
|
105 |
public static DefinedTerm getArtworkTerm(){ |
|
106 |
if(drawingTerm==null){ |
|
107 |
initializeTerms(); |
|
108 |
} |
|
109 |
return drawingTerm; |
|
110 |
} |
|
111 |
|
|
112 |
public static DefinedTerm getSpecimenScanTerm(){ |
|
113 |
if(specimenScanTerm==null){ |
|
114 |
initializeTerms(); |
|
115 |
} |
|
116 |
return specimenScanTerm; |
|
117 |
} |
|
118 |
|
|
119 |
public static DefinedTerm getDetailImageTerm(){ |
|
120 |
if(detailImageTerm==null){ |
|
121 |
initializeTerms(); |
|
122 |
} |
|
123 |
return detailImageTerm; |
|
124 |
} |
|
125 |
|
|
126 |
public static DefinedTerm getSampleDesignationTerm(){ |
|
127 |
if(sampleDesignationTerm==null){ |
|
128 |
initializeTerms(); |
|
129 |
} |
|
130 |
return sampleDesignationTerm; |
|
131 |
} |
|
132 |
|
|
133 |
|
|
134 |
/** {@inheritDoc} */ |
|
135 |
@Override |
|
136 |
public String getText(Object element) { |
|
137 |
if(element instanceof TreeNode){ |
|
138 |
element = ((TreeNode) element).getValue(); |
|
139 |
} |
|
140 |
String text = null; |
|
141 |
if(element instanceof IdentifiableEntity |
|
142 |
&& ((IdentifiableEntity) element).isProtectedTitleCache()){ |
|
143 |
return ((IdentifiableEntity) element).getTitleCache(); |
|
144 |
} |
|
145 |
|
|
146 |
|
|
147 |
//check if collection code does not exist -> use collection name then |
|
148 |
FormatKey collectionKey = FormatKey.COLLECTION_CODE; |
|
149 |
text = CdmFormatterFactory.format(element,new FormatKey[]{FormatKey.COLLECTION_CODE}); |
|
150 |
if(CdmUtils.isBlank(text)){ |
|
151 |
collectionKey = FormatKey.COLLECTION_NAME; |
|
152 |
} |
|
153 |
|
|
154 |
//Use titlecache for FieldUnits |
|
155 |
if(element instanceof FieldUnit){ |
|
156 |
text = ((FieldUnit) element).getTitleCache(); |
|
157 |
} |
|
158 |
else if(element instanceof MediaSpecimen){ |
|
159 |
text = CdmFormatterFactory.format(element, |
|
160 |
new FormatKey[]{ |
|
161 |
// FormatKey.MEDIA_TITLE_CACHE, FormatKey.SPACE, |
|
162 |
collectionKey, FormatKey.SPACE, |
|
163 |
FormatKey.MOST_SIGNIFICANT_IDENTIFIER, FormatKey.SPACE, |
|
164 |
FormatKey.MEDIA_TITLE, FormatKey.SPACE, |
|
165 |
FormatKey.MEDIA_ARTIST, FormatKey.SPACE, |
|
166 |
}); |
|
167 |
} |
|
168 |
else if (element instanceof DnaSample) { |
|
169 |
text = CdmFormatterFactory.format(element, |
|
170 |
new FormatKey[] { |
|
171 |
collectionKey, FormatKey.SPACE, |
|
172 |
FormatKey.MOST_SIGNIFICANT_IDENTIFIER, FormatKey.SPACE, |
|
173 |
FormatKey.SAMPLE_DESIGNATION, FormatKey.SPACE |
|
174 |
}); |
|
175 |
} |
|
176 |
else if (element instanceof DerivedUnit) { |
|
177 |
text = CdmFormatterFactory.format(element, |
|
178 |
new FormatKey[] { |
|
179 |
collectionKey, FormatKey.SPACE, |
|
180 |
FormatKey.MOST_SIGNIFICANT_IDENTIFIER, FormatKey.SPACE |
|
181 |
}); |
|
182 |
} |
|
183 |
else if (element instanceof Sequence) { |
|
184 |
text = CdmFormatterFactory.format(element, |
|
185 |
new FormatKey[] { |
|
186 |
FormatKey.SEQUENCE_DNA_MARKER, FormatKey.SPACE |
|
187 |
}); |
|
188 |
} |
|
189 |
else if (element instanceof SingleRead) { |
|
190 |
text = CdmFormatterFactory.format(element, |
|
191 |
new FormatKey[] { |
|
192 |
FormatKey.SINGLE_READ_PHEROGRAM_TITLE_CACHE, FormatKey.SPACE, |
|
193 |
FormatKey.AMPLIFICATION_LABEL, FormatKey.SPACE, |
|
194 |
}); |
|
195 |
} |
|
196 |
else if(element instanceof IdentifiableEntity){ |
|
197 |
|
|
198 |
IdentifiableEntity identifiableEntity = (IdentifiableEntity) element; |
|
199 |
if(identifiableEntity.isProtectedTitleCache()){ |
|
200 |
text = identifiableEntity.getTitleCache(); |
|
201 |
} |
|
202 |
} |
|
203 |
if(CdmUtils.isBlank(text) || text.equals(IdentifiableEntityDefaultCacheStrategy.TITLE_CACHE_GENERATION_NOT_IMPLEMENTED)){ |
|
204 |
if(element instanceof CdmBase){ |
|
205 |
text = ((CdmBase) element).getUuid().toString(); |
|
206 |
} |
|
207 |
else{ |
|
208 |
text = element.toString(); |
|
209 |
} |
|
210 |
} |
|
211 |
//remove dot at the end |
|
212 |
if(text.endsWith(".")){ |
|
213 |
text = text.substring(0, text.length()-1); |
|
214 |
} |
|
215 |
return text; |
|
216 |
} |
|
217 |
|
|
218 |
/** {@inheritDoc} */ |
|
219 |
@Override |
|
220 |
public String getToolTipText(Object element) { |
|
221 |
return getDerivateText(element); |
|
222 |
} |
|
223 |
|
|
224 |
/** |
|
225 |
* @param conversation the conversation to set |
|
226 |
*/ |
|
227 |
public void setConversation(ConversationHolder conversation) { |
|
228 |
this.conversation = conversation; |
|
229 |
} |
|
230 |
|
|
231 |
public String getDerivateText(Object element){ |
|
232 |
return getDerivateText(element, conversation); |
|
233 |
} |
|
234 |
|
|
235 |
public static String getDerivateText(Object element, ConversationHolder conversation){ |
|
236 |
//TODO: use list of strings to assemble labels to avoid adding the separator every time and to allow null values |
|
237 |
TreeNode parentNode = null; |
|
238 |
TreeNode node = null; |
|
239 |
Object derivate = element; |
|
240 |
if(element instanceof TreeNode){ |
|
241 |
node = (TreeNode) element; |
|
242 |
parentNode = node.getParent(); |
|
243 |
//unwrap specimen from TreeNode |
|
244 |
derivate = node.getValue(); |
|
245 |
} |
|
246 |
|
|
247 |
if(conversation!=null){ |
|
248 |
conversation.bind(); |
|
249 |
} |
|
250 |
|
|
251 |
final String emptyString = ""; |
|
252 |
final String separator = " "; |
|
253 |
|
|
254 |
String label = emptyString; |
|
255 |
|
|
256 |
//Field Unit |
|
257 |
if(derivate instanceof FieldUnit){ |
|
258 |
FieldUnit fieldUnit = (FieldUnit)derivate; |
|
259 |
if(fieldUnit.getGatheringEvent()!=null){ |
|
260 |
GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent(); |
|
261 |
label += gatheringEvent.getCountry()!=null?gatheringEvent.getCountry().getLabel()+separator:emptyString; |
|
262 |
label += gatheringEvent.getLocality()!=null?gatheringEvent.getLocality().getText()+separator:emptyString; |
|
263 |
label += gatheringEvent.getGatheringDate()!=null?gatheringEvent.getGatheringDate()+separator:emptyString; |
|
264 |
label += gatheringEvent.getCollector()!=null?gatheringEvent.getCollector()+separator:emptyString; |
|
265 |
} |
|
266 |
label += fieldUnit.getFieldNumber()!=null?fieldUnit.getFieldNumber():emptyString; |
|
267 |
} |
|
268 |
//MediaSpecimen |
|
269 |
else if(derivate instanceof MediaSpecimen){ |
|
270 |
MediaSpecimen mediaSpecimen = (MediaSpecimen)derivate; |
|
271 |
if(mediaSpecimen.getMediaSpecimen()!=null){ |
|
272 |
label += mediaSpecimen.getMediaSpecimen().getTitle()!=null?mediaSpecimen.getMediaSpecimen().getTitle().getText()+separator:"[no motif]"; |
|
273 |
label += mediaSpecimen.getMediaSpecimen().getArtist()!=null?mediaSpecimen.getMediaSpecimen().getArtist()+separator:emptyString; |
|
274 |
} |
|
275 |
eu.etaxonomy.cdm.model.occurrence.Collection collection = mediaSpecimen.getCollection(); |
|
276 |
if(collection!=null){ |
|
277 |
label += collection.getName()!=null?collection.getName()+" ":emptyString; |
|
278 |
label += collection.getCode()!=null?"("+collection.getCode()+")"+separator:emptyString; |
|
279 |
} |
|
280 |
label += mediaSpecimen.getAccessionNumber()!=null?mediaSpecimen.getAccessionNumber()+separator:emptyString; |
|
281 |
label += mediaSpecimen.getBarcode()!=null?mediaSpecimen.getBarcode()+separator:emptyString; |
|
282 |
} |
|
283 |
//TissueSample + DnaSample |
|
284 |
else if(derivate instanceof DnaSample){ |
|
285 |
DnaSample dnaSample = (DnaSample)derivate; |
|
286 |
if(((DnaSample) derivate).getRecordBasis()==SpecimenOrObservationType.DnaSample){ |
|
287 |
Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(dnaSample); |
|
288 |
if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){ |
|
289 |
label += currentSampleDesignation.getIdentifier()+separator; |
|
290 |
} |
|
291 |
else{ |
|
292 |
label += NO_SAMPLE_DESIGNATION+separator; |
|
293 |
} |
|
294 |
} |
|
295 |
else if(((DnaSample) derivate).getRecordBasis()==SpecimenOrObservationType.TissueSample){ |
|
296 |
if(dnaSample.getKindOfUnit()!=null){ |
|
297 |
label += dnaSample.getKindOfUnit()+separator; |
|
298 |
} |
|
299 |
Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(dnaSample); |
|
300 |
if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){ |
|
301 |
label += currentSampleDesignation.getIdentifier()+separator; |
|
302 |
} |
|
303 |
else{ |
|
304 |
label += NO_SAMPLE_DESIGNATION+separator; |
|
305 |
} |
|
306 |
} |
|
307 |
|
|
308 |
} |
|
309 |
//DerivedUnit + TissueSample |
|
310 |
else if(derivate instanceof DerivedUnit){ |
|
311 |
DerivedUnit derivedUnit = (DerivedUnit)derivate; |
|
312 |
if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.PreservedSpecimen){ |
|
313 |
//check for type designation |
|
314 |
if(typeDesignations.get(derivedUnit)==null){ |
|
315 |
for (SpecimenTypeDesignation specimenTypeDesignation : derivedUnit.getSpecimenTypeDesignations()) { |
|
316 |
addTypeDesignation(derivedUnit, specimenTypeDesignation); |
|
317 |
} |
|
318 |
} |
|
319 |
//java.util.Collection<FieldUnit> fieldUnits = CdmStore.getService(IOccurrenceService.class).getFieldUnits(derivedUnit.getUuid()); |
|
320 |
//TODO : This is not generic anymore for performance reasons |
|
321 |
Set<SpecimenOrObservationBase> originals = derivedUnit.getOriginals(); |
|
322 |
if(originals!=null && originals.size() ==1) { |
|
323 |
SpecimenOrObservationBase specimen = originals.iterator().next(); |
|
324 |
if(specimen instanceof FieldUnit) { |
|
325 |
FieldUnit fieldUnit = (FieldUnit)specimen; |
|
326 |
GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent(); |
|
327 |
if(gatheringEvent!=null){ |
|
328 |
label += gatheringEvent.getCollector()!=null?gatheringEvent.getCollector()+separator:emptyString; |
|
329 |
} |
|
330 |
label += fieldUnit.getFieldNumber()!=null?fieldUnit.getFieldNumber()+separator:emptyString; |
|
331 |
} |
|
332 |
} |
|
333 |
|
|
334 |
eu.etaxonomy.cdm.model.occurrence.Collection collection = derivedUnit.getCollection(); |
|
335 |
if(collection!=null){ |
|
336 |
label += collection.getCode()!=null?"("+collection.getCode()+")"+separator:emptyString; |
|
337 |
} |
|
338 |
String mostSignificantIdentifier = derivedUnit.getMostSignificantIdentifier(); |
|
339 |
label += mostSignificantIdentifier!=null?mostSignificantIdentifier+separator:emptyString; |
|
340 |
} |
|
341 |
else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){ |
|
342 |
//TissueSample should only be created by using it's own class |
|
343 |
//in future using only one class with different SpecimenOrObservationTypes is desired |
|
344 |
// label += derivedUnit.getKindOfUnit() + NO_SAMPLE_DESIGNATION; |
|
345 |
} |
|
346 |
} |
|
347 |
//Sequence |
|
348 |
else if(derivate instanceof Sequence){ |
|
349 |
Sequence sequence = (Sequence)derivate; |
|
350 |
Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(sequence); |
|
351 |
if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){ |
|
352 |
label += currentSampleDesignation.getIdentifier()+separator; |
|
353 |
} |
|
354 |
else{ |
|
355 |
label += NO_SAMPLE_DESIGNATION+separator; |
|
356 |
} |
|
357 |
label += sequence.getDnaMarker()!=null?sequence.getDnaMarker():emptyString; |
|
358 |
} |
|
359 |
//SingleRead |
|
360 |
else if(derivate instanceof SingleRead){ |
|
361 |
SingleRead singleRead = (SingleRead)derivate; |
|
362 |
if(parentNode!=null && parentNode.getValue() instanceof Sequence){ |
|
363 |
Sequence sequence = (Sequence) parentNode.getValue(); |
|
364 |
Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(sequence); |
|
365 |
if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){ |
|
366 |
label = currentSampleDesignation.getIdentifier()+separator; |
|
367 |
} |
|
368 |
else{ |
|
369 |
label += NO_SAMPLE_DESIGNATION+separator; |
|
370 |
} |
|
371 |
label += singleRead.getPrimer()!=null?singleRead.getPrimer().getLabel()+separator:emptyString; |
|
372 |
if(sequence!=null && sequence.getDnaMarker()!=null){ |
|
373 |
label += sequence.getDnaMarker()+separator; |
|
374 |
} |
|
375 |
if(singleRead.getAmplificationResult()!=null && singleRead.getAmplificationResult().getAmplification()!=null){ |
|
376 |
label += singleRead.getAmplificationResult().getAmplification().getLabelCache()+separator; |
|
377 |
} |
|
378 |
} |
|
379 |
} |
|
380 |
//SOOB |
|
381 |
else if(derivate instanceof SpecimenOrObservationBase){ |
|
382 |
SpecimenOrObservationBase<?> specimen = (SpecimenOrObservationBase<?>) derivate; |
|
383 |
SpecimenOrObservationType type = specimen.getRecordBasis(); |
|
384 |
return specimen.getTitleCache() + (type!=null?" ["+type.toString()+"]":emptyString); |
|
385 |
} |
|
386 |
if(label.isEmpty()){ |
|
387 |
label = derivate.toString(); |
|
388 |
} |
|
389 |
//remove last comma |
|
390 |
else if(label.endsWith(separator)){ |
|
391 |
label = label.substring(0, label.length()-separator.length()); |
|
392 |
} |
|
393 |
return label; |
|
394 |
} |
|
395 |
|
|
396 |
@Override |
|
397 |
public Image getImage(Object element) { |
|
398 |
if(element instanceof TreeNode){ |
|
399 |
element = ((TreeNode) element).getValue(); |
|
400 |
} |
|
401 |
if(element instanceof CdmBase){ |
|
402 |
CdmBase cdmBase = (CdmBase)element; |
|
403 |
boolean hasCharacterData = false; |
|
404 |
if(cdmBase.isInstanceOf(SpecimenOrObservationBase.class)){ |
|
405 |
SpecimenOrObservationBase<?> specimen = HibernateProxyHelper.deproxy(cdmBase, SpecimenOrObservationBase.class); |
|
406 |
if(specimen.hasCharacterData()){ |
|
407 |
hasCharacterData = true; |
|
408 |
} |
|
409 |
} |
|
410 |
if(cdmBase.isInstanceOf(FieldUnit.class)){ |
|
411 |
return hasCharacterData?ImageResources.getImage(ImageResources.FIELD_UNIT_CHARACTER_DATA):ImageResources.getImage(ImageResources.FIELD_UNIT); |
|
412 |
} |
|
413 |
else if(cdmBase.isInstanceOf(DerivedUnit.class)){ |
|
414 |
DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(element, DerivedUnit.class); |
|
415 |
|
|
416 |
if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.FieldUnit){ |
|
417 |
return hasCharacterData?ImageResources.getImage(ImageResources.FIELD_UNIT_CHARACTER_DATA):ImageResources.getImage(ImageResources.FIELD_UNIT); |
|
418 |
} |
|
419 |
else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.DnaSample){ |
|
420 |
return hasCharacterData?ImageResources.getImage(ImageResources.DNA_SAMPLE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.DNA_SAMPLE_DERIVATE); |
|
421 |
} |
|
422 |
else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){ |
|
423 |
return hasCharacterData?ImageResources.getImage(ImageResources.TISSUE_SAMPLE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.TISSUE_SAMPLE_DERIVATE); |
|
424 |
} |
|
425 |
else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.PreservedSpecimen){ |
|
426 |
if(typeDesignations.get(derivedUnit)!=null && !typeDesignations.get(derivedUnit).isEmpty()){ |
|
427 |
return ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE_TYPE); |
|
428 |
} |
|
429 |
return hasCharacterData?ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE); |
|
430 |
} |
|
431 |
else if(derivedUnit.getRecordBasis().isMedia() |
|
432 |
|| derivedUnit.getRecordBasis().isKindOf(SpecimenOrObservationType.Media)){ |
|
433 |
if(derivedUnit.getKindOfUnit()!=null){ |
|
434 |
if(derivedUnit.getKindOfUnit().equals(getArtworkTerm())){ |
|
435 |
return hasCharacterData?ImageResources.getImage(ImageResources.ARTWORK_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.ARTWORK_DERIVATE); |
|
436 |
} |
|
437 |
else if(derivedUnit.getKindOfUnit().equals(getLivingPlantPhotoTerm())){ |
|
438 |
return hasCharacterData?ImageResources.getImage(ImageResources.LIVING_PLANT_PHOTO_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.LIVING_PLANT_PHOTO_DERIVATE); |
|
439 |
} |
|
440 |
else if(derivedUnit.getKindOfUnit().equals(getSpecimenScanTerm())){ |
|
441 |
return hasCharacterData?ImageResources.getImage(ImageResources.SPECIMEN_SCAN_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.SPECIMEN_SCAN_DERIVATE); |
|
442 |
} |
|
443 |
else if(derivedUnit.getKindOfUnit().equals(getDetailImageTerm())){ |
|
444 |
return hasCharacterData?ImageResources.getImage(ImageResources.DETAIL_IMAGE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.DETAIL_IMAGE_DERIVATE); |
|
445 |
} |
|
446 |
} |
|
447 |
} |
|
448 |
} |
|
449 |
else if(cdmBase.isInstanceOf(Sequence.class)){ |
|
450 |
return ImageResources.getImage(ImageResources.SEQUENCE_DERIVATE); |
|
451 |
} |
|
452 |
|
|
453 |
else if(cdmBase.isInstanceOf(SingleRead.class)){ |
|
454 |
if(multiLinkSingleReads!=null && multiLinkSingleReads.contains(element)){ |
|
455 |
return ImageResources.getImage(ImageResources.SINGLE_READ_DERIVATE_MULTILINK); |
Also available in: Unified diff
Refactoring