Merge branch 'release/4.3.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / occurrence / dna / SingleReadPherogramCollectionDetailSection.java
1 // $Id$
2 /**
3 * Copyright (C) 2014 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10 package eu.etaxonomy.taxeditor.ui.section.occurrence.dna;
11
12 import java.util.Collection;
13 import java.util.Collections;
14
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;
23
24 /**
25 * @author pplitzner
26 * @date 03.03.2014
27 *
28 */
29 public class SingleReadPherogramCollectionDetailSection extends AbstractEntityCollectionSection<SingleRead, Media> {
30
31 /**
32 * @param formFactory
33 * @param conversation
34 * @param parentElement
35 * @param title
36 * @param style
37 */
38 public SingleReadPherogramCollectionDetailSection(CdmFormFactory formFactory, ConversationHolder conversation,
39 ICdmFormElement parentElement, int style) {
40 super(formFactory, conversation, parentElement, "Read Chromatogram", style);
41 }
42
43
44
45 /* (non-Javadoc)
46 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getCollection(java.lang.Object)
47 */
48 @Override
49 public Collection<Media> getCollection(SingleRead entity) {
50 if(entity.getPherogram()!=null){
51 return Collections.singleton(entity.getPherogram());
52 }
53 return Collections.EMPTY_LIST;
54 }
55
56 /* (non-Javadoc)
57 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#createNewElement()
58 */
59 @Override
60 public Media createNewElement() {
61 if(getEntity().getPherogram()==null){
62 return Media.NewInstance();
63 }
64 return null;
65 }
66
67 /* (non-Javadoc)
68 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#addElement(java.lang.Object)
69 */
70 @Override
71 public void addElement(Media element) {
72 if(getEntity().getPherogram()==null){
73 getEntity().setPherogram(element);
74 /*
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
80 */
81 CdmStore.getService(IMediaService.class).merge(element);
82 }
83 }
84
85 /* (non-Javadoc)
86 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#removeElement(java.lang.Object)
87 */
88 @Override
89 public void removeElement(Media element) {
90 getEntity().setPherogram(null);
91 }
92
93 /* (non-Javadoc)
94 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getEmptyString()
95 */
96 @Override
97 public String getEmptyString() {
98 return "No read chromatogram yet";
99 }
100
101 /* (non-Javadoc)
102 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getTooltipString()
103 */
104 @Override
105 protected String getTooltipString() {
106 return "Add a read chromatogram";
107 }
108 }