3 * Copyright (C) 2014 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.dna
;
12 import java
.util
.Collection
;
13 import java
.util
.Collections
;
15 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
16 import eu
.etaxonomy
.cdm
.api
.service
.IMediaService
;
17 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
18 import eu
.etaxonomy
.cdm
.model
.molecular
.SingleRead
;
19 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
20 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
21 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
22 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractEntityCollectionSection
;
29 public class SingleReadPherogramCollectionDetailSection
extends AbstractEntityCollectionSection
<SingleRead
, Media
> {
34 * @param parentElement
38 public SingleReadPherogramCollectionDetailSection(CdmFormFactory formFactory
, ConversationHolder conversation
,
39 ICdmFormElement parentElement
, int style
) {
40 super(formFactory
, conversation
, parentElement
, "Read Chromatogram", style
);
46 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getCollection(java.lang.Object)
49 public Collection
<Media
> getCollection(SingleRead entity
) {
50 if(entity
.getPherogram()!=null){
51 return Collections
.singleton(entity
.getPherogram());
53 return Collections
.EMPTY_LIST
;
57 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#createNewElement()
60 public Media
createNewElement() {
61 if(getEntity().getPherogram()==null){
62 return Media
.NewInstance();
68 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#addElement(java.lang.Object)
71 public void addElement(Media element
) {
72 if(getEntity().getPherogram()==null){
73 getEntity().setPherogram(element
);
75 * merge to avoid duplicate key exception
76 * the exception seems to be caused by the two links to the Media object:
77 * - SingleRead->pherogram (used to be not in the cache after saving)
78 * - MediaRepresentationPart->media
79 * Invoking merge() solves this problem
81 CdmStore
.getService(IMediaService
.class).merge(element
);
86 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#removeElement(java.lang.Object)
89 public void removeElement(Media element
) {
90 getEntity().setPherogram(null);
94 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getEmptyString()
97 public String
getEmptyString() {
98 return "No read chromatogram yet";
102 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getTooltipString()
105 protected String
getTooltipString() {
106 return "Add a read chromatogram";