e473b32bfabcadbb5f20296293191fdd2fa9d8a5
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / media / MediaElement.java
1 /**
2 *
3 */
4 package eu.etaxonomy.taxeditor.ui.section.media;
5
6 import org.eclipse.swt.events.SelectionListener;
7
8 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
9 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
10 import eu.etaxonomy.cdm.model.common.LanguageString;
11 import eu.etaxonomy.cdm.model.media.Media;
12 import eu.etaxonomy.taxeditor.store.CdmStore;
13 import eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection;
14 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
15 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.EntityDetailType;
16 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.SelectionType;
17 import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
18 import eu.etaxonomy.taxeditor.ui.forms.LanguageStringWithLabelElement;
19 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
20 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
21 import eu.etaxonomy.taxeditor.ui.selection.AgentSelectionElement;
22
23 /**
24 * <p>
25 * MediaElement class.
26 * </p>
27 *
28 * @author n.hoffmann
29 * @created Nov 17, 2009
30 * @version 1.0
31 */
32 public class MediaElement extends AbstractEntityCollectionElement<Media> {
33
34 private MediaRepresentationSection section_mediaRepresentation;
35 private AgentSelectionElement selection_artist;
36 private LanguageStringWithLabelElement text_description;
37 private LanguageStringWithLabelElement text_title;
38
39 /**
40 * <p>
41 * Constructor for MediaElement.
42 * </p>
43 *
44 * @param formElement
45 * a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection}
46 * object.
47 * @param element
48 * a {@link eu.etaxonomy.cdm.model.media.Media} object.
49 * @param removeListener
50 * a {@link org.eclipse.swt.events.SelectionListener} object.
51 * @param style
52 * a int.
53 * @param cdmFormFactory
54 * a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory}
55 * object.
56 */
57 public MediaElement(CdmFormFactory cdmFormFactory,
58 AbstractFormSection formElement, Media element,
59 SelectionListener removeListener, int style) {
60 super(cdmFormFactory, formElement, element, removeListener, null, style);
61 }
62
63 /*
64 * (non-Javadoc)
65 *
66 * @see
67 * eu.etaxonomy.taxeditor.forms.entitysections.AbstractEntitySetElementComposite
68 * #createControls(org.eclipse.swt.widgets.Composite, int)
69 */
70 /** {@inheritDoc} */
71 @Override
72 public void createControls(ICdmFormElement element, int style) {
73 text_title = formFactory.createLanguageStringWithLabelElement(element,
74 "Title", null, style);
75 selection_artist = (AgentSelectionElement) formFactory
76 .createSelectionElement(SelectionType.AGENT,
77 getConversationHolder(), element, "Artist", null,
78 AgentSelectionElement.DEFAULT, style);
79 text_description = formFactory.createLanguageStringWithLabelElement(
80 element, "Description", null, 100, style);
81 section_mediaRepresentation = (MediaRepresentationSection) formFactory
82 .createEntityDetailSection(
83 EntityDetailType.MEDIAREPRESENTATION,
84 getConversationHolder(), element, style);
85 section_mediaRepresentation.setLayoutData(CdmFormFactory
86 .FILL_HORIZONTALLY(2, 1));
87 }
88
89 /** {@inheritDoc} */
90 @Override
91 public void setEntity(Media element) {
92 this.entity = element;
93 section_mediaRepresentation.setEntity(element);
94 selection_artist.setEntity((TeamOrPersonBase) HibernateProxyHelper
95 .deproxy(element.getArtist()));
96
97 text_description.setLanguageString(element.getDescription(CdmStore
98 .getDefaultLanguage()));
99
100 LanguageString title = element.getTitle(CdmStore.getDefaultLanguage());
101
102 if (title == null) {
103 title = LanguageString.NewInstance("",
104 CdmStore.getDefaultLanguage());
105 }
106
107 text_title.setLanguageString(title);
108 }
109
110 /*
111 * (non-Javadoc)
112 *
113 * @see
114 * eu.etaxonomy.taxeditor.section.AbstractEntityCollectionElement#handleEvent
115 * (java.lang.Object)
116 */
117 /** {@inheritDoc} */
118 @Override
119 public void handleEvent(Object eventSource) {
120 if (eventSource == selection_artist) {
121 getEntity().setArtist(selection_artist.getSelection());
122 } else if (eventSource == text_description) {
123 getEntity().addDescription(text_description.getLanguageString());
124 } else if (eventSource == text_title) {
125 getEntity().putTitle(text_title.getLanguageString());
126 if (getParentElement() instanceof AbstractCdmDetailSection) {
127 ((AbstractCdmDetailSection) getParentElement()).updateTitle();
128 }
129 }
130 }
131 }