1
|
/**
|
2
|
* Copyright (C) 2013 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.media;
|
10
|
|
11
|
import org.joda.time.DateTime;
|
12
|
|
13
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
14
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
15
|
import eu.etaxonomy.cdm.model.common.DefinedTerm;
|
16
|
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
|
17
|
import eu.etaxonomy.cdm.model.common.Language;
|
18
|
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
|
19
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
20
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
21
|
import eu.etaxonomy.cdm.model.common.VocabularyEnum;
|
22
|
import eu.etaxonomy.cdm.model.media.Media;
|
23
|
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
24
|
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
|
25
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
26
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
27
|
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
|
28
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
29
|
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
|
30
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
31
|
import eu.etaxonomy.taxeditor.ui.element.LanguageStringWithLabelElement;
|
32
|
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
|
33
|
import eu.etaxonomy.taxeditor.ui.mvc.element.DateElement;
|
34
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
35
|
import eu.etaxonomy.taxeditor.ui.section.media.ITogglableMediaElement;
|
36
|
import eu.etaxonomy.taxeditor.ui.section.media.MediaDetailElement;
|
37
|
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
|
38
|
|
39
|
/**
|
40
|
* @author pplitzner
|
41
|
* @date 16.12.2013
|
42
|
*
|
43
|
*/
|
44
|
public class MediaSpecimenGeneralDetailElement extends AbstractCdmDetailElement<MediaSpecimen> implements ITogglableMediaElement{
|
45
|
|
46
|
private final TermVocabulary mediaSpecimenVocabulary = CdmStore.getService(IVocabularyService.class).find(VocabularyEnum.MediaSpecimenKindOfUnit.getUuid());
|
47
|
|
48
|
private TermComboElement<DefinedTerm> comboKindOfUnit;
|
49
|
private LanguageStringWithLabelElement textTitleLanguageString;
|
50
|
private EntitySelectionElement<AgentBase> selectionArtist;
|
51
|
private DateElement date;
|
52
|
private LanguageStringWithLabelElement textMethodLanguageString;
|
53
|
private EntitySelectionElement<Collection> selection_collection;
|
54
|
private TextWithLabelElement text_accessionNumber;
|
55
|
private EntitySelectionElement<Reference> selection_publishedIn;
|
56
|
private CheckboxElement checkIsPublish;
|
57
|
|
58
|
private MediaDetailElement mediaDetailElement;
|
59
|
/**
|
60
|
* @param formFactory
|
61
|
* @param formElement
|
62
|
*/
|
63
|
public MediaSpecimenGeneralDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
|
64
|
super(formFactory, formElement);
|
65
|
}
|
66
|
|
67
|
@Override
|
68
|
protected void createControls(ICdmFormElement formElement, MediaSpecimen entity, int style) {
|
69
|
Media media = entity.getMediaSpecimen();
|
70
|
if(media==null){
|
71
|
formFactory.createLabel(formElement, "No media attached to this MediaSpecimen!");
|
72
|
}
|
73
|
else{
|
74
|
comboKindOfUnit = formFactory.createDefinedTermComboElement(mediaSpecimenVocabulary, formElement, "Kind of Media", entity.getKindOfUnit(), style);
|
75
|
textTitleLanguageString = formFactory.createLanguageStringWithLabelElement(formElement, "Motif", media.getTitle(), style);
|
76
|
selectionArtist = formFactory.createSelectionElement(AgentBase.class, //getConversationHolder(),
|
77
|
formElement, "Prepared by", media.getArtist(), EntitySelectionElement.ALL, style);
|
78
|
TimePeriod mediaCreated = entity.getMediaSpecimen().getMediaCreated();
|
79
|
|
80
|
date = formFactory.createDateElement(formElement, "Preparation Date", mediaCreated, style, true);
|
81
|
textMethodLanguageString = formFactory.createLanguageStringWithLabelElement(formElement, "Method", media.getDescription(Language.getDefaultLanguage()), style);
|
82
|
selection_collection = formFactory.createSelectionElement(Collection.class,// getConversationHolder(),
|
83
|
formElement, "Collection", entity.getCollection(), EntitySelectionElement.ALL, style);
|
84
|
text_accessionNumber = formFactory.createTextWithLabelElement(formElement, "Accession Number", entity.getAccessionNumber(), style);
|
85
|
|
86
|
//the first PrimaryMediaSource is used for storing the reference
|
87
|
Reference publishedIn = null;
|
88
|
for(IdentifiableSource source:media.getSources()){
|
89
|
if(source.getType()==OriginalSourceType.PrimaryMediaSource){
|
90
|
publishedIn = source.getCitation();
|
91
|
break;
|
92
|
}
|
93
|
}
|
94
|
selection_publishedIn = formFactory.createSelectionElement(Reference.class, //getConversationHolder(),
|
95
|
formElement, "Published in", publishedIn, EntitySelectionElement.ALL, style);
|
96
|
checkIsPublish = formFactory.createCheckbox(formElement, "Publish", entity.isPublish(), style);
|
97
|
|
98
|
mediaDetailElement = formFactory.createMediaDetailElement(formElement);
|
99
|
mediaDetailElement.setEntity(media);
|
100
|
}
|
101
|
}
|
102
|
|
103
|
@Override
|
104
|
public void handleEvent(Object eventSource) {
|
105
|
Media media = getEntity().getMediaSpecimen();
|
106
|
if(media==null){
|
107
|
media = Media.NewInstance();
|
108
|
getEntity().setMediaSpecimen(media);
|
109
|
}
|
110
|
if(eventSource==comboKindOfUnit){
|
111
|
getEntity().setKindOfUnit(comboKindOfUnit.getSelection());
|
112
|
}
|
113
|
else if(eventSource==textTitleLanguageString){
|
114
|
media.putTitle(textTitleLanguageString.getLanguageString());
|
115
|
}
|
116
|
else if(eventSource==date.getController()){
|
117
|
DateTime dateTime = date.getController().getDateTime();
|
118
|
media.setMediaCreated(dateTime);
|
119
|
}
|
120
|
else if(eventSource==selectionArtist){
|
121
|
media.setArtist(selectionArtist.getSelection());
|
122
|
}
|
123
|
else if(eventSource==textMethodLanguageString){
|
124
|
media.addDescription(textMethodLanguageString.getLanguageString());
|
125
|
}
|
126
|
else if (eventSource == selection_collection) {
|
127
|
getEntity().setCollection(selection_collection.getSelection());
|
128
|
}
|
129
|
else if (eventSource == text_accessionNumber) {
|
130
|
getEntity().setAccessionNumber(text_accessionNumber.getText());
|
131
|
}
|
132
|
else if(eventSource==selection_publishedIn){
|
133
|
IdentifiableSource primaryMediaSource = null;
|
134
|
for(IdentifiableSource source:media.getSources()){
|
135
|
if(source.getType()==OriginalSourceType.PrimaryMediaSource){
|
136
|
primaryMediaSource = source;
|
137
|
}
|
138
|
}
|
139
|
if(primaryMediaSource==null){
|
140
|
primaryMediaSource = IdentifiableSource.NewInstance(OriginalSourceType.PrimaryMediaSource);
|
141
|
media.addSource(primaryMediaSource);
|
142
|
}
|
143
|
else{
|
144
|
primaryMediaSource.setCitation(selection_publishedIn.getSelection());
|
145
|
}
|
146
|
}
|
147
|
else if(eventSource==checkIsPublish){
|
148
|
getEntity().setPublish(checkIsPublish.getSelection());
|
149
|
}
|
150
|
}
|
151
|
|
152
|
@Override
|
153
|
public void toggleAdvancedMediaView() {
|
154
|
if(mediaDetailElement!=null){
|
155
|
mediaDetailElement.toggleAdvancedMediaView();
|
156
|
}
|
157
|
}
|
158
|
|
159
|
public boolean isAdvancedMediaView() {
|
160
|
if(mediaDetailElement==null){
|
161
|
return false;
|
162
|
}
|
163
|
return mediaDetailElement.isAdvancedMediaView();
|
164
|
}
|
165
|
|
166
|
}
|