- implemented derivate specific textual representation in DerivateView
authorPatric Plitzner <p.plitzner@bgbm.org>
Tue, 3 Jun 2014 14:35:46 +0000 (14:35 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Tue, 3 Jun 2014 14:35:46 +0000 (14:35 +0000)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/derivateSearch/DerivateLabelProvider.java

index 2745a94d1c7ecaf9341f9d36b456dc231a3248fe..ff919dfca756439b4493a023000b3e91e4d2fe05 100644 (file)
@@ -106,7 +106,7 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
         if(editorInput instanceof DerivateViewEditorInput){
             SpecimenOrObservationBase<?> specimen = ((DerivateViewEditorInput) editorInput).getDerivate();
             SpecimenOrObservationBase<?> rootElement = ((DerivateViewEditorInput) editorInput).getRootElement();
-            setPartName(rootElement.toString());
+            setPartName(DerivateLabelProvider.getDerivateText(rootElement));
             viewer.setSelection(new StructuredSelection(new TreeNode(specimen)));
         }
 
index e59473a89934146c594f87a42886c501c999646f..0ef56d87eedc279a737ad30b8926d8598f77c4bd 100644 (file)
@@ -15,10 +15,14 @@ import org.eclipse.jface.viewers.ColumnLabelProvider;
 import org.eclipse.jface.viewers.TreeNode;
 import org.eclipse.swt.graphics.Image;
 
+import eu.etaxonomy.cdm.model.molecular.DnaSample;
 import eu.etaxonomy.cdm.model.molecular.Sequence;
 import eu.etaxonomy.cdm.model.molecular.SingleRead;
+import eu.etaxonomy.cdm.model.occurrence.Collection;
 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
 import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
+import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
+import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
 import eu.etaxonomy.taxeditor.model.ImageResources;
@@ -42,16 +46,88 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
         return getDerivateText(element);
     }
 
-    private String getDerivateText(Object element){
+    /**
+     *
+     * @param element
+     * @return
+     */
+    public static String getDerivateText(Object element){
+        TreeNode parentNode = null;
         if(element instanceof TreeNode){
+            parentNode = ((TreeNode) element).getParent();
+            //unwrap specimen from TreeNode
             element = ((TreeNode) element).getValue();
         }
-        if(element instanceof SpecimenOrObservationBase){
+
+        String label = "";
+        if(element instanceof FieldUnit){
+            FieldUnit fieldUnit = (FieldUnit)element;
+            GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
+            if(gatheringEvent!=null){
+                label += gatheringEvent.getCountry()!=null?gatheringEvent.getCountry().getLabel()+", ":"";
+                label += gatheringEvent.getLocality()!=null?gatheringEvent.getLocality().getText()+", ":"";
+//                label += gatheringEvent.getGatheringDate()!=null?gatheringEvent.getGatheringDate()+", ":"";
+                label += gatheringEvent.getCollector()!=null?gatheringEvent.getCollector()+", ":"";
+            }
+            label += fieldUnit.getFieldNumber()!=null?fieldUnit.getFieldNumber():"";
+        }
+        else if(element instanceof DerivedUnit){
+            DerivedUnit derivedUnit = (DerivedUnit)element;
+            if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.PreservedSpecimen){
+                if(parentNode!=null && parentNode.getValue() instanceof FieldUnit){
+                    FieldUnit fieldUnit = (FieldUnit) parentNode.getValue();
+                    GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
+                    if(gatheringEvent!=null){
+                        label += gatheringEvent.getCollector()!=null?gatheringEvent.getCollector()+", ":"";
+                    }
+                    label += fieldUnit.getFieldNumber()!=null?fieldUnit.getFieldNumber()+", ":"";
+                }
+                Collection collection = derivedUnit.getCollection();
+                if(collection!=null){
+                    label += collection.getName()!=null?collection.getName()+" ":"";
+                    label += collection.getCode()!=null?"("+collection.getCode()+"), ":"";
+                }
+                label += derivedUnit.getAccessionNumber()!=null?derivedUnit.getAccessionNumber()+", ":"";
+                label += derivedUnit.getBarcode()!=null?derivedUnit.getBarcode():"";
+            }
+            else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){
+
+            }
+        }
+        else if(element instanceof MediaSpecimen){
+            MediaSpecimen mediaSpecimen = (MediaSpecimen)element;
+            //TODO implement
+            label += element.toString();
+        }
+        else if(element instanceof DnaSample
+                || (element instanceof DerivedUnit
+                        && ((SpecimenOrObservationBase<?>) element).getRecordBasis()==SpecimenOrObservationType.DnaSample)){
+            //TODO implement
+            label += element.toString();
+
+        }
+        else if(element instanceof Sequence){
+            Sequence sequence = (Sequence)element;
+            label += "SampleDesignation?"+", ";
+            label += sequence.getDnaMarker()!=null?sequence.getDnaMarker():"";
+        }
+        else if(element instanceof SingleRead){
+            SingleRead singleRead = (SingleRead)element;
+            label += singleRead.getPrimer()!=null?singleRead.getPrimer().getLabel()+", ":"";
+            label += "Marker?";
+        }
+        else if(element instanceof SpecimenOrObservationBase){
             SpecimenOrObservationBase<?> derivate = (SpecimenOrObservationBase<?>) element;
             SpecimenOrObservationType type = derivate.getRecordBasis();
             return derivate.getTitleCache() + (type!=null?" ["+type.toString()+"]":"");
         }
-        return element.toString();
+        if(label.isEmpty()){
+            label = element.toString();
+        }
+        else if(label.endsWith(", ")){
+            label = label.substring(0, label.length()-2);
+        }
+        return label;
     }
 
     /* (non-Javadoc)