2 * Copyright (C) 2014 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.dna
;
11 import java
.util
.Collection
;
12 import java
.util
.Collections
;
14 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
15 import eu
.etaxonomy
.cdm
.api
.service
.IMediaService
;
16 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
17 import eu
.etaxonomy
.cdm
.model
.molecular
.SingleRead
;
18 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
19 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
20 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
21 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractEntityCollectionSection
;
28 public class SingleReadPherogramCollectionDetailSection
extends AbstractEntityCollectionSection
<SingleRead
, Media
> {
33 * @param parentElement
37 public SingleReadPherogramCollectionDetailSection(CdmFormFactory formFactory
, ConversationHolder conversation
,
38 ICdmFormElement parentElement
, int style
) {
39 super(formFactory
, conversation
, parentElement
, "Read Chromatogram", style
);
45 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getCollection(java.lang.Object)
48 public Collection
<Media
> getCollection(SingleRead entity
) {
49 if(entity
.getPherogram()!=null){
50 return Collections
.singleton(entity
.getPherogram());
52 return Collections
.EMPTY_LIST
;
56 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#createNewElement()
59 public Media
createNewElement() {
60 if(getEntity().getPherogram()==null){
61 return Media
.NewInstance();
67 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#addElement(java.lang.Object)
70 public void addElement(Media element
) {
71 if(getEntity().getPherogram()==null){
72 getEntity().setPherogram(element
);
74 * merge to avoid duplicate key exception
75 * the exception seems to be caused by the two links to the Media object:
76 * - SingleRead->pherogram (used to be not in the cache after saving)
77 * - MediaRepresentationPart->media
78 * Invoking merge() solves this problem
80 CdmStore
.getService(IMediaService
.class).merge(element
);
85 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#removeElement(java.lang.Object)
88 public void removeElement(Media element
) {
89 getEntity().setPherogram(null);
93 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getEmptyString()
96 public String
getEmptyString() {
97 return "No read chromatogram yet";
101 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getTooltipString()
104 protected String
getTooltipString() {
105 return "Add a read chromatogram";