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