2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.ui
.section
.media
;
13 import org
.eclipse
.swt
.SWT
;
14 import org
.eclipse
.swt
.events
.SelectionListener
;
16 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
17 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
18 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
19 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
20 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
21 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
22 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
23 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
24 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.MediaSelectionDialog
;
25 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractFormSection
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectableElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.MultilanguageTextElement
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.SelectionArbitrator
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.TimePeriodElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailSection
;
33 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractEntityCollectionElement
;
34 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
38 * @created Nov 17, 2009
40 public class MediaMetaElement
extends AbstractEntityCollectionElement
<Media
> implements ISelectableElement
, ITogglableMediaElement
{
42 private EntitySelectionElement
<AgentBase
> selection_artist
;
43 private MultilanguageTextElement text_description
;
44 private MultilanguageTextElement text_title
;
45 private MediaDetailElement mediaDetailElement
;
46 private TimePeriodElement mediaCreated
;
47 private SelectionArbitrator selectionArbitrator
;
49 public MediaMetaElement(CdmFormFactory cdmFormFactory
,
50 AbstractFormSection
<?
> formElement
, Media element
,
51 SelectionListener removeListener
, int style
) {
52 super(cdmFormFactory
, formElement
, element
, removeListener
, null, style
);
53 //make element selectable
54 if(cdmFormFactory
.getSelectionProvider() != null){
55 selectionArbitrator
= cdmFormFactory
.createSelectionArbitrator(this);
60 public void createControls(ICdmFormElement element
, int style
) {
62 setWarnForReferencingObjects(element
, 2);
63 text_title
= formFactory
.createMultiLanguageTextElement(element
, "Title", getEntity().getAllTitles(), 50, style
);
65 selection_artist
= formFactory
.createSelectionElement(AgentBase
.class,
66 element
, "Artist", null, EntitySelectionElement
.ALL
, style
);
67 addElement(selection_artist
);
69 mediaCreated
= formFactory
.createTimePeriodElement(element
, "Media Created", getEntity().getMediaCreated(), style
);
70 addElement(mediaCreated
);
72 text_description
= formFactory
.createMultiLanguageTextElement(element
, "Description", null, 50, SWT
.WRAP
);
76 mediaDetailElement
= formFactory
.createMediaDetailElement(element
);
78 ICdmFormElement grandGrandParent
= getParentElement().getParentElement().getParentElement();
79 Class
<?
> clazz
= null;
80 if (grandGrandParent
!= null){
81 clazz
= grandGrandParent
.getClass();
83 //TODO: find a nicer solution
84 if (grandGrandParent
!= null && clazz
!= null && clazz
.getName().equals("eu.etaxonomy.taxeditor.ui.element.AbstractCdmEntityWizardPage$WizardPageRootElement")){
85 mediaDetailElement
.setShowImage(false);
87 addElement(mediaDetailElement
);
94 public void setEntity(Media element
) {
95 this.entity
= element
;
96 if (mediaDetailElement
!= null){
97 mediaDetailElement
.setEntity(element
);
99 selection_artist
.setEntity(HibernateProxyHelper
100 .deproxy(element
.getArtist()));
102 if (text_description
!= null) {
103 text_description
.setMultilanguageText(element
.getAllDescriptions());
109 public void createTitle() {
110 // LanguageString title = this.entity.getTitle(CdmStore.getDefaultLanguage());
111 // Map<Language, LanguageString> languageStrings = entity.getAllTitles();
112 // if (title == null || title.getText().contains("empty media")) {
113 // entity.getAllTitles().remove(title);
114 // title = LanguageString.NewInstance(entity.getTitleCache(), CdmStore.getDefaultLanguage());
116 // if (!title.getText().contains("empty media")){
117 // languageStrings.put(CdmStore.getDefaultLanguage(), title);
120 text_title
.setMultilanguageText(this.entity
.getAllTitles());
124 protected Media
selectFromDialog() {
126 setEntity(MediaSelectionDialog
.select(AbstractUtility
.getShell(), //null,
132 public void toggleAdvancedMediaView(){
133 mediaDetailElement
.toggleAdvancedMediaView();
137 public void handleEvent(Object eventSource
) {
138 if (eventSource
== selection_artist
) {
139 getEntity().setArtist(selection_artist
.getSelection());
140 } else if (eventSource
== text_description
) {
141 text_description
.getMultilanguageText().values()
142 .forEach(languageString
-> getEntity().putDescription(languageString
));
143 } else if (eventSource
== text_title
) {
144 text_title
.getMultilanguageText().values()
145 .forEach(languageString
-> getEntity().putTitle(languageString
));
146 if (getParentElement() instanceof AbstractCdmDetailSection
) {
147 ((AbstractCdmDetailSection
<?
>) getParentElement()).updateTitle();
149 } else if (eventSource
== mediaCreated
){
150 TimePeriod date
= mediaCreated
.getTimePeriod();
151 getEntity().setMediaCreated(date
);
156 public SelectionArbitrator
getSelectionArbitrator() {
157 return selectionArbitrator
;
160 public MediaDetailElement
getMediaDetailElement(){
161 return mediaDetailElement
;