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
|
import java.util.Comparator;
|
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.Sequence;
|
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
|
import eu.etaxonomy.taxeditor.ui.section.DefaultCdmBaseComparator;
|
24
|
|
25
|
/**
|
26
|
* @author pplitzner
|
27
|
* @date 03.03.2014
|
28
|
*
|
29
|
*/
|
30
|
public class SequenceContigFileCollectionDetailSection extends AbstractEntityCollectionSection<Sequence, Media> {
|
31
|
|
32
|
/**
|
33
|
* @param formFactory
|
34
|
* @param conversation
|
35
|
* @param parentElement
|
36
|
* @param title
|
37
|
* @param style
|
38
|
*/
|
39
|
public SequenceContigFileCollectionDetailSection(CdmFormFactory formFactory, ConversationHolder conversation,
|
40
|
ICdmFormElement parentElement, int style) {
|
41
|
super(formFactory, conversation, parentElement, "Contig File", style);
|
42
|
}
|
43
|
|
44
|
|
45
|
|
46
|
/* (non-Javadoc)
|
47
|
* @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getCollection(java.lang.Object)
|
48
|
*/
|
49
|
@Override
|
50
|
public Collection<Media> getCollection(Sequence entity) {
|
51
|
if(entity.getContigFile()!=null){
|
52
|
return Collections.singleton(entity.getContigFile());
|
53
|
}
|
54
|
return Collections.EMPTY_LIST;
|
55
|
}
|
56
|
|
57
|
@Override
|
58
|
public Comparator<Media> getComparator() {
|
59
|
return new DefaultCdmBaseComparator<>();
|
60
|
}
|
61
|
|
62
|
/* (non-Javadoc)
|
63
|
* @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#createNewElement()
|
64
|
*/
|
65
|
@Override
|
66
|
public Media createNewElement() {
|
67
|
if(getEntity().getContigFile()==null){
|
68
|
return Media.NewInstance();
|
69
|
}
|
70
|
return null;
|
71
|
}
|
72
|
|
73
|
/* (non-Javadoc)
|
74
|
* @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#addElement(java.lang.Object)
|
75
|
*/
|
76
|
@Override
|
77
|
public void addElement(Media element) {
|
78
|
if(getEntity().getContigFile()==null){
|
79
|
getEntity().setContigFile(element);
|
80
|
/*
|
81
|
* merge to avoid duplicate key exception
|
82
|
* the exception seems to be caused by the two links to the Media object:
|
83
|
* - Sequence->contigFile (used to be not in the cache after saving)
|
84
|
* - MediaRepresentationPart->media
|
85
|
* Invoking merge() solves this problem
|
86
|
*/
|
87
|
CdmStore.getService(IMediaService.class).merge(element);
|
88
|
}
|
89
|
}
|
90
|
|
91
|
/* (non-Javadoc)
|
92
|
* @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#removeElement(java.lang.Object)
|
93
|
*/
|
94
|
@Override
|
95
|
public void removeElement(Media element) {
|
96
|
getEntity().setContigFile(null);
|
97
|
}
|
98
|
|
99
|
/* (non-Javadoc)
|
100
|
* @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getEmptyString()
|
101
|
*/
|
102
|
@Override
|
103
|
public String getEmptyString() {
|
104
|
return "No contig file yet";
|
105
|
}
|
106
|
|
107
|
/* (non-Javadoc)
|
108
|
* @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getTooltipString()
|
109
|
*/
|
110
|
@Override
|
111
|
protected String getTooltipString() {
|
112
|
return "Add a contig file";
|
113
|
}
|
114
|
|
115
|
|
116
|
|
117
|
/**
|
118
|
* {@inheritDoc}
|
119
|
*/
|
120
|
@Override
|
121
|
public Media addExisting() {
|
122
|
return null;
|
123
|
}
|
124
|
|
125
|
|
126
|
|
127
|
/**
|
128
|
* {@inheritDoc}
|
129
|
*/
|
130
|
@Override
|
131
|
public boolean allowAddExisting() {
|
132
|
return false;
|
133
|
}
|
134
|
}
|