From: Patric Plitzner
Date: Thu, 21 Aug 2014 07:52:52 +0000 (+0000)
Subject: - generalized simple user interface to add media (#3339)
X-Git-Tag: 3.6.0~482
X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/1987e065e5f33971f781193daf90dbc061eb74b0
- generalized simple user interface to add media (#3339)
---
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/AbstractCdmFormElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/AbstractCdmFormElement.java
index 586950edf..8c5f2b21d 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/AbstractCdmFormElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/AbstractCdmFormElement.java
@@ -140,7 +140,35 @@ public abstract class AbstractCdmFormElement implements ICdmFormElement {
}
/**
- * removeElements
+ * Remove all child {@link ICdmFormElement}s and child {@link Control}s
+ * of the given and the element itself.
+ * @param formElement The element to remove
+ */
+ public void removeElementsAndControls(ICdmFormElement formElement){
+ for(ICdmFormElement childElement : formElement.getElements()){
+ // recursion
+ childElement.removeElements();
+
+ // unregister selection arbitrator
+ if(childElement instanceof ISelectableElement){
+ SelectionArbitrator selectionArbitrator = ((ISelectableElement) childElement).getSelectionArbitrator();
+ if(selectionArbitrator != null){
+ formFactory.destroySelectionArbitrator(selectionArbitrator);
+ }
+ }
+
+ // unregister from property changes
+ formFactory.removePropertyChangeListener(childElement);
+
+ // dispose of the controls
+ removeControls(childElement);
+ }
+ removeControls(formElement);
+ }
+
+ /**
+ * Removes all child {@link ICdmFormElement}s and child {@link Control}s
+ * and the element itself.
*/
@Override
public void removeElements(){
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/TextWithLabelElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/TextWithLabelElement.java
index 06de77302..4f5c86ca2 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/TextWithLabelElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/TextWithLabelElement.java
@@ -233,8 +233,4 @@ public class TextWithLabelElement extends AbstractCdmFormElement implements Modi
text.setTextLimit(limit);
}
- public void setVisible(boolean visible){
- text.setVisible(visible);
- label.setVisible(visible);
- }
}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaElement.java
index f23efb26d..2d9a7c274 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaElement.java
@@ -7,17 +7,7 @@ import java.net.URISyntaxException;
import java.util.List;
import java.util.Set;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.FormAttachment;
-import org.eclipse.swt.layout.FormData;
-import org.eclipse.swt.layout.FormLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.model.agent.AgentBase;
@@ -26,6 +16,7 @@ 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;
@@ -60,7 +51,6 @@ public class MediaElement extends AbstractEntityCollectionElement {
private CheckboxElement checkBoxShowAdvancedView;
private MediaRepresentationPart singleMediaRepresentationPart;
- private boolean isAdvancedMediaView;
private ICdmFormElement parentFormElement;
private int style;
@@ -83,7 +73,7 @@ public class MediaElement extends AbstractEntityCollectionElement {
* object.
*/
public MediaElement(CdmFormFactory cdmFormFactory,
- AbstractFormSection formElement, Media element,
+ AbstractFormSection> formElement, Media element,
SelectionListener removeListener, int style) {
super(cdmFormFactory, formElement, element, removeListener, null, style);
}
@@ -103,20 +93,19 @@ public class MediaElement extends AbstractEntityCollectionElement {
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);
- checkBoxShowAdvancedView = formFactory.createCheckbox(element, "Show Advance Media View", false, style);
- textUri = formFactory.createUriWithLabelElement(parentFormElement, "Media URI", null, style);
- section_mediaRepresentation = formFactory.createMediaRepresentationSection(getConversationHolder(), parentFormElement, style);
- section_mediaRepresentation.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+ checkBoxShowAdvancedView = formFactory.createCheckbox(element, "Advanced Media View", false, style);
}
/** {@inheritDoc} */
@Override
public void setEntity(Media element) {
this.entity = element;
- initRepresentationMode();
- showAdvancedView(isAdvancedMediaView);
+ if(singleMediaRepresentationPart==null){
+ singleMediaRepresentationPart = MediaUtils.initFirstMediaRepresentationPart(element);
+ }
+ showAdvancedView(isAdvancedMediaView());
- selection_artist.setEntity((TeamOrPersonBase) HibernateProxyHelper
+ selection_artist.setEntity((TeamOrPersonBase>) HibernateProxyHelper
.deproxy(element.getArtist()));
text_description.setLanguageString(element.getDescription(CdmStore
@@ -125,13 +114,10 @@ public class MediaElement extends AbstractEntityCollectionElement {
LanguageString title = element.getTitle(CdmStore.getDefaultLanguage());
if (title == null) {
- title = LanguageString.NewInstance("",
- CdmStore.getDefaultLanguage());
+ title = LanguageString.NewInstance("", CdmStore.getDefaultLanguage());
}
text_title.setLanguageString(title);
-
-
}
/*
@@ -151,7 +137,7 @@ public class MediaElement extends AbstractEntityCollectionElement {
} else if (eventSource == text_title) {
getEntity().putTitle(text_title.getLanguageString());
if (getParentElement() instanceof AbstractCdmDetailSection) {
- ((AbstractCdmDetailSection) getParentElement()).updateTitle();
+ ((AbstractCdmDetailSection>) getParentElement()).updateTitle();
}
}
else if(eventSource==textUri){
@@ -171,72 +157,39 @@ public class MediaElement extends AbstractEntityCollectionElement {
* @param showAdvancedView
*/
private void showAdvancedView(boolean showAdvancedView) {
-// removeElements();
-// text_title = formFactory.createLanguageStringWithLabelElement(parentFormElement, "Title", null, style);
-// selection_artist = formFactory.createSelectionElement(AgentBase.class, getConversationHolder(), parentFormElement, "Artist", null, EntitySelectionElement.ALL, style);
-// text_description = formFactory.createLanguageStringWithLabelElement(parentFormElement, "Description", null, 100, style);
-// checkBoxShowAdvancedView = formFactory.createCheckbox(parentFormElement, "Show Advance Media View", false, style);
if(showAdvancedView){
-// removeElement(textUri);
-// removeControl(textUri.getMainControl());
- section_mediaRepresentation.setVisible(true);
- textUri.setVisible(false);
+ 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{
-// removeElement(section_mediaRepresentation);
-// removeControl(section_mediaRepresentation);
- section_mediaRepresentation.setVisible(false);
- textUri.setVisible(true);
- textUri.setUri(getMediaRepresentationPart(getEntity()).getUri());
+ if(section_mediaRepresentation!=null){
+ removeElementsAndControls(section_mediaRepresentation);
+ }
+ textUri = formFactory.createUriWithLabelElement(parentFormElement, "Media URI", null, style);
+ textUri.setUri(singleMediaRepresentationPart.getUri());
+ textUri.getLayoutComposite().layout();
}
-// parentFormElement.getLayoutComposite().layout();
-// getParentElement().getLayoutComposite().layout();
}
- private void initRepresentationMode(){
+ private boolean isAdvancedMediaView(){
if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_ADVANCED_MEDIA_SECTION)){
- isAdvancedMediaView = true;
- return;
+ return true;
}
Set representations = entity.getRepresentations();
if(representations.size()>1){
- isAdvancedMediaView = true;
- return;
+ return true;
}
if(representations.size()==1){
List parts = representations.iterator().next().getParts();
if(parts.size()>1){
- isAdvancedMediaView = true;
- return;
- }
- }
- isAdvancedMediaView = false;
- }
-
- private MediaRepresentationPart getMediaRepresentationPart(Media media) {
- if(singleMediaRepresentationPart==null){
- Set representations = media.getRepresentations();
- if(representations!=null && representations.size()>0){
- MediaRepresentation mediaRepresentation = representations.iterator().next();
- List parts = mediaRepresentation.getParts();
- if(parts!=null && parts.size()>0){
- singleMediaRepresentationPart = parts.iterator().next();
- }
- else{
- singleMediaRepresentationPart = MediaRepresentationPart.NewInstance(null, null);
- mediaRepresentation.addRepresentationPart(singleMediaRepresentationPart);
- }
- }
- else{
- singleMediaRepresentationPart = MediaRepresentationPart.NewInstance(null, null);
-
- MediaRepresentation mediaRepresentation = MediaRepresentation.NewInstance();
- mediaRepresentation.addRepresentationPart(singleMediaRepresentationPart);
- media.addRepresentation(mediaRepresentation);
+ return true;
}
}
- return singleMediaRepresentationPart;
+ return false;
}
}