1
|
/**
|
2
|
* Copyright (C) 2014 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.ui.section.occurrence.dna;
|
10
|
|
11
|
import java.util.Collection;
|
12
|
import java.util.Collections;
|
13
|
|
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;
|
22
|
|
23
|
/**
|
24
|
* @author pplitzner
|
25
|
* @date 03.03.2014
|
26
|
*
|
27
|
*/
|
28
|
public class SingleReadPherogramCollectionDetailSection extends AbstractEntityCollectionSection<SingleRead, Media> {
|
29
|
|
30
|
/**
|
31
|
* @param formFactory
|
32
|
* @param conversation
|
33
|
* @param parentElement
|
34
|
* @param title
|
35
|
* @param style
|
36
|
*/
|
37
|
public SingleReadPherogramCollectionDetailSection(CdmFormFactory formFactory, ConversationHolder conversation,
|
38
|
ICdmFormElement parentElement, int style) {
|
39
|
super(formFactory, conversation, parentElement, "Read Chromatogram", style);
|
40
|
}
|
41
|
|
42
|
|
43
|
|
44
|
/* (non-Javadoc)
|
45
|
* @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getCollection(java.lang.Object)
|
46
|
*/
|
47
|
@Override
|
48
|
public Collection<Media> getCollection(SingleRead entity) {
|
49
|
if(entity.getPherogram()!=null){
|
50
|
return Collections.singleton(entity.getPherogram());
|
51
|
}
|
52
|
return Collections.EMPTY_LIST;
|
53
|
}
|
54
|
|
55
|
/* (non-Javadoc)
|
56
|
* @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#createNewElement()
|
57
|
*/
|
58
|
@Override
|
59
|
public Media createNewElement() {
|
60
|
if(getEntity().getPherogram()==null){
|
61
|
return Media.NewInstance();
|
62
|
}
|
63
|
return null;
|
64
|
}
|
65
|
|
66
|
/* (non-Javadoc)
|
67
|
* @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#addElement(java.lang.Object)
|
68
|
*/
|
69
|
@Override
|
70
|
public void addElement(Media element) {
|
71
|
if(getEntity().getPherogram()==null){
|
72
|
getEntity().setPherogram(element);
|
73
|
/*
|
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
|
79
|
*/
|
80
|
CdmStore.getService(IMediaService.class).merge(element);
|
81
|
}
|
82
|
}
|
83
|
|
84
|
/* (non-Javadoc)
|
85
|
* @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#removeElement(java.lang.Object)
|
86
|
*/
|
87
|
@Override
|
88
|
public void removeElement(Media element) {
|
89
|
getEntity().setPherogram(null);
|
90
|
}
|
91
|
|
92
|
/* (non-Javadoc)
|
93
|
* @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getEmptyString()
|
94
|
*/
|
95
|
@Override
|
96
|
public String getEmptyString() {
|
97
|
return "No read chromatogram yet";
|
98
|
}
|
99
|
|
100
|
/* (non-Javadoc)
|
101
|
* @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getTooltipString()
|
102
|
*/
|
103
|
@Override
|
104
|
protected String getTooltipString() {
|
105
|
return "Add a read chromatogram";
|
106
|
}
|
107
|
|
108
|
|
109
|
|
110
|
/**
|
111
|
* {@inheritDoc}
|
112
|
*/
|
113
|
@Override
|
114
|
public Media addExisting() {
|
115
|
return null;
|
116
|
}
|
117
|
|
118
|
|
119
|
|
120
|
/**
|
121
|
* {@inheritDoc}
|
122
|
*/
|
123
|
@Override
|
124
|
public boolean allowAddExisting() {
|
125
|
return false;
|
126
|
}
|
127
|
}
|