*/
package eu.etaxonomy.taxeditor.ui.section.media;
+import java.net.URISyntaxException;
+import java.util.List;
+import java.util.Set;
+
import org.eclipse.swt.events.SelectionListener;
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
import eu.etaxonomy.cdm.model.common.LanguageString;
import eu.etaxonomy.cdm.model.media.Media;
+import eu.etaxonomy.cdm.model.media.MediaRepresentation;
+import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
+import eu.etaxonomy.cdm.model.media.MediaUtils;
+import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.preference.Resources;
import eu.etaxonomy.taxeditor.store.CdmStore;
-import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
import eu.etaxonomy.taxeditor.ui.element.LanguageStringWithLabelElement;
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
+import eu.etaxonomy.taxeditor.ui.element.UriWithLabelElement;
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
*/
public class MediaElement extends AbstractEntityCollectionElement<Media> {
- private MediaRepresentationSection section_mediaRepresentation;
- private EntitySelectionElement<AgentBase> selection_artist;
- private LanguageStringWithLabelElement text_description;
- private LanguageStringWithLabelElement text_title;
-
- /**
- * <p>
- * Constructor for MediaElement.
- * </p>
- *
- * @param formElement
- * a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
- * object.
- * @param element
- * a {@link eu.etaxonomy.cdm.model.media.Media} object.
- * @param removeListener
- * a {@link org.eclipse.swt.events.SelectionListener} object.
- * @param style
- * a int.
- * @param cdmFormFactory
- * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
- * object.
- */
- public MediaElement(CdmFormFactory cdmFormFactory,
- AbstractFormSection formElement, Media element,
- SelectionListener removeListener, int style) {
- super(cdmFormFactory, formElement, element, removeListener, null, style);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * eu.etaxonomy.taxeditor.forms.entitysections.AbstractEntitySetElementComposite
- * #createControls(org.eclipse.swt.widgets.Composite, int)
- */
- /** {@inheritDoc} */
+ private EntitySelectionElement<AgentBase> selection_artist;
+ private LanguageStringWithLabelElement text_description;
+ private LanguageStringWithLabelElement text_title;
+ private UriWithLabelElement textUri;
+ private MediaRepresentationSection section_mediaRepresentation;
+
+ private CheckboxElement checkBoxShowAdvancedView;
+ private MediaRepresentationPart singleMediaRepresentationPart;
+ private ICdmFormElement parentFormElement;
+ private int style;
+
+ /**
+ * <p>
+ * Constructor for MediaElement.
+ * </p>
+ *
+ * @param formElement
+ * a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
+ * object.
+ * @param element
+ * a {@link eu.etaxonomy.cdm.model.media.Media} object.
+ * @param removeListener
+ * a {@link org.eclipse.swt.events.SelectionListener} object.
+ * @param style
+ * a int.
+ * @param cdmFormFactory
+ * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
+ * object.
+ */
+ public MediaElement(CdmFormFactory cdmFormFactory,
+ AbstractFormSection<?> formElement, Media element,
+ SelectionListener removeListener, int style) {
+ super(cdmFormFactory, formElement, element, removeListener, null, style);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * eu.etaxonomy.taxeditor.forms.entitysections.AbstractEntitySetElementComposite
+ * #createControls(org.eclipse.swt.widgets.Composite, int)
+ */
+ /** {@inheritDoc} */
@Override
public void createControls(ICdmFormElement element, int style) {
+ this.parentFormElement = element;
+ this.style = style;
text_title = formFactory.createLanguageStringWithLabelElement(element, "Title", null, style);
selection_artist = formFactory.createSelectionElement(AgentBase.class, getConversationHolder(), element, "Artist", null, EntitySelectionElement.ALL, style);
text_description = formFactory.createLanguageStringWithLabelElement(element, "Description", null, 100, style);
- section_mediaRepresentation = formFactory.createMediaRepresentationSection(getConversationHolder(), element, style);
- section_mediaRepresentation.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
- }
-
- /** {@inheritDoc} */
- @Override
- public void setEntity(Media element) {
- this.entity = element;
- section_mediaRepresentation.setEntity(element);
- selection_artist.setEntity((TeamOrPersonBase) HibernateProxyHelper
- .deproxy(element.getArtist()));
-
- text_description.setLanguageString(element.getDescription(CdmStore
- .getDefaultLanguage()));
-
- LanguageString title = element.getTitle(CdmStore.getDefaultLanguage());
-
- if (title == null) {
- title = LanguageString.NewInstance("",
- CdmStore.getDefaultLanguage());
- }
-
- text_title.setLanguageString(title);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * eu.etaxonomy.taxeditor.section.AbstractEntityCollectionElement#handleEvent
- * (java.lang.Object)
- */
- /** {@inheritDoc} */
- @Override
- public void handleEvent(Object eventSource) {
- if (eventSource == selection_artist) {
- getEntity().setArtist(selection_artist.getSelection());
- } else if (eventSource == text_description) {
- getEntity().addDescription(text_description.getLanguageString());
- } else if (eventSource == text_title) {
- getEntity().putTitle(text_title.getLanguageString());
- if (getParentElement() instanceof AbstractCdmDetailSection) {
- ((AbstractCdmDetailSection) getParentElement()).updateTitle();
- }
- }
- firePropertyChangeEvent(this);
- }
+ checkBoxShowAdvancedView = formFactory.createCheckbox(element, "Advanced Media View", false, style);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void setEntity(Media element) {
+ this.entity = element;
+ if(singleMediaRepresentationPart==null){
+ singleMediaRepresentationPart = MediaUtils.initFirstMediaRepresentationPart(element);
+ }
+ showAdvancedView(isAdvancedMediaView());
+
+ selection_artist.setEntity((TeamOrPersonBase<?>) HibernateProxyHelper
+ .deproxy(element.getArtist()));
+
+ text_description.setLanguageString(element.getDescription(CdmStore
+ .getDefaultLanguage()));
+
+ LanguageString title = element.getTitle(CdmStore.getDefaultLanguage());
+
+ if (title == null) {
+ title = LanguageString.NewInstance("", CdmStore.getDefaultLanguage());
+ }
+
+ text_title.setLanguageString(title);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * eu.etaxonomy.taxeditor.section.AbstractEntityCollectionElement#handleEvent
+ * (java.lang.Object)
+ */
+ /** {@inheritDoc} */
+ @Override
+ public void handleEvent(Object eventSource) {
+ if (eventSource == selection_artist) {
+ getEntity().setArtist(selection_artist.getSelection());
+ } else if (eventSource == text_description) {
+ getEntity().addDescription(text_description.getLanguageString());
+ } else if (eventSource == text_title) {
+ getEntity().putTitle(text_title.getLanguageString());
+ if (getParentElement() instanceof AbstractCdmDetailSection) {
+ ((AbstractCdmDetailSection<?>) getParentElement()).updateTitle();
+ }
+ }
+ else if(eventSource==textUri){
+ textUri.setBackground(getPersistentBackground());
+ try {
+ singleMediaRepresentationPart.setUri(textUri.getUri());
+ } catch (URISyntaxException e) {
+ textUri.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
+ }
+ }
+ else if(eventSource==checkBoxShowAdvancedView){
+ showAdvancedView(checkBoxShowAdvancedView.getSelection());
+ }
+ }
+
+ /**
+ * @param showAdvancedView
+ */
+ private void showAdvancedView(boolean showAdvancedView) {
+ if(showAdvancedView){
+ if(textUri!=null){
+ removeElementsAndControls(textUri);
+ }
+ section_mediaRepresentation = formFactory.createMediaRepresentationSection(getConversationHolder(), parentFormElement, style);
+ section_mediaRepresentation.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+ section_mediaRepresentation.setEntity(getEntity());
+ }
+ else{
+ if(section_mediaRepresentation!=null){
+ removeElementsAndControls(section_mediaRepresentation);
+ }
+ textUri = formFactory.createUriWithLabelElement(parentFormElement, "Media URI", null, style);
+ textUri.setUri(singleMediaRepresentationPart.getUri());
+ textUri.getLayoutComposite().layout();
+ }
+ }
+
+ private boolean isAdvancedMediaView(){
+ if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_ADVANCED_MEDIA_SECTION)){
+ return true;
+ }
+ Set<MediaRepresentation> representations = entity.getRepresentations();
+ if(representations.size()>1){
+ return true;
+ }
+ if(representations.size()==1){
+ List<MediaRepresentationPart> parts = representations.iterator().next().getParts();
+ if(parts.size()>1){
+ return true;
+ }
+ }
+ return false;
+ }
+
}