Add MediaViewSwitch to media collection elements
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 29 Jun 2015 10:01:12 +0000 (12:01 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 29 Jun 2015 11:35:37 +0000 (13:35 +0200)
Refactored code to use a static method that creates the IAction object.
This can be added by the GUI element itself.

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractEntityCollectionElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/DescriptionElementMediaSection.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/MediaDetailsSection.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/AbstractTogglableMediaDetailsSection.java [deleted file]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaMetaElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaViewSwitch.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/media/MediaSpecimenGeneralDetailSection.java

index 1060f986f725b795ee57650e37d4889344d7f52d..328b085939599c0a98963507aef0aa64a08d35e2 100644 (file)
@@ -52,6 +52,9 @@ public abstract class AbstractEntityCollectionElement<ENTITY> extends
 
        private final Composite container;
 
+       /**
+        * Composite "around" the actual content. Is used for control action like e.g. remove button
+        */
        private final Composite box;
 
        private Button btnRemove;
@@ -59,26 +62,6 @@ public abstract class AbstractEntityCollectionElement<ENTITY> extends
 
        private Color backgroundColor;
 
-       /**
-        * <p>
-        * Constructor for AbstractEntityCollectionElement.
-        * </p>
-        *
-        * @param style
-        *            a int.
-        * @param formFactory
-        *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
-        *            object.
-        * @param section
-        *            a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
-        *            object.
-        * @param entity
-        *            a ENTITY object.
-        * @param removeListener
-        *            a {@link org.eclipse.swt.events.SelectionListener} object.
-        * @param <ENTITY>
-        *            a ENTITY object.
-        */
        public AbstractEntityCollectionElement(CdmFormFactory formFactory,
                AbstractFormSection section, ENTITY entity,
                SelectionListener removeListener, Color backgroundColor, int style) {
@@ -97,7 +80,7 @@ public abstract class AbstractEntityCollectionElement<ENTITY> extends
                box.setBackgroundMode(SWT.INHERIT_DEFAULT);
                addControl(box);
 
-               TableWrapLayout boxLayout = LayoutConstants.LAYOUT(3, false);
+               TableWrapLayout boxLayout = LayoutConstants.LAYOUT(4, false);
                boxLayout.topMargin = 4;
                boxLayout.bottomMargin = 4;
                box.setLayout(boxLayout);
@@ -163,23 +146,8 @@ public abstract class AbstractEntityCollectionElement<ENTITY> extends
                // default implementation is empty
        }
 
-       /**
-        * <p>
-        * Setter for the field <code>entity</code>.
-        * </p>
-        *
-        * @param entity
-        *            a ENTITY object.
-        */
        public abstract void setEntity(ENTITY entity);
 
-       /**
-        * <p>
-        * Getter for the field <code>entity</code>.
-        * </p>
-        *
-        * @return a ENTITY object.
-        */
        @Override
     public ENTITY getEntity() {
                return entity;
@@ -196,17 +164,6 @@ public abstract class AbstractEntityCollectionElement<ENTITY> extends
            return null;
        }
 
-       /**
-        * <p>
-        * createControls
-        * </p>
-        *
-        * @param element
-        *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
-        *            object.
-        * @param style
-        *            a int.
-        */
        public abstract void createControls(ICdmFormElement element, int style);
 
        /**
@@ -223,13 +180,6 @@ public abstract class AbstractEntityCollectionElement<ENTITY> extends
                setBackground(selected ? SELECTED : getPersistentBackground());
        }
 
-       /*
-        * (non-Javadoc)
-        *
-        * @see
-        * eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org
-        * .eclipse.jface.util.PropertyChangeEvent)
-        */
        /** {@inheritDoc} */
        @Override
        public void propertyChange(PropertyChangeEvent event) {
@@ -242,14 +192,6 @@ public abstract class AbstractEntityCollectionElement<ENTITY> extends
                }
        }
 
-       /**
-        * <p>
-        * handleEvent
-        * </p>
-        *
-        * @param eventSource
-        *            a {@link java.lang.Object} object.
-        */
        public abstract void handleEvent(Object eventSource);
 
        /** {@inheritDoc} */
@@ -282,25 +224,14 @@ public abstract class AbstractEntityCollectionElement<ENTITY> extends
                return container;
        }
 
-       /**
-        * <p>
-        * Getter for the field <code>backgroundColor</code>.
-        * </p>
-        *
-        * @return the backgroundColor
-        */
        public Color getBackgroundColor() {
                return backgroundColor;
        }
 
-       /**
-        * <p>
-        * getConversationHolder
-        * </p>
-        *
-        * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
-        *         object.
-        */
+    public Composite getBox() {
+        return box;
+    }
+
        @Override
     public ConversationHolder getConversationHolder() {
                if (getParentElement() instanceof IConversationEnabled) {
index 60a2bd209f11c83357d6468c25e3f1d23f0f9fde..d39f91432a92fc1eca6e2033189dfadfa296d781 100644 (file)
@@ -12,12 +12,6 @@ package eu.etaxonomy.taxeditor.ui.section.description;
 
 import java.util.Collection;
 
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.action.ToolBarManager;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Control;
-
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.Feature;
@@ -25,7 +19,6 @@ import eu.etaxonomy.cdm.model.media.Media;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
-import eu.etaxonomy.taxeditor.ui.section.media.ITogglableMediaElement;
 
 /**
  * <p>DescriptionElementMediaSection class.</p>
@@ -87,27 +80,5 @@ public class DescriptionElementMediaSection extends
                getEntity().removeMedia(element);
        }
 
-    @Override
-    protected Control createToolbar() {
-        ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
-
-        final String label = "Change View Type";
-
-        Action addAction = new Action(label, IAction.AS_PUSH_BUTTON) {
-            @Override
-            public void run() {
-                if(isExpanded()){
-                    if(getEntityCollectionElement() instanceof ITogglableMediaElement){
-                        ((ITogglableMediaElement) getEntityCollectionElement()).toggleAdvancedMediaView();
-                    }
-                }
-            }
-        };
-        addAction.setToolTipText(label);
-
-        toolBarManager.add(addAction);
-
-        return toolBarManager.createControl(this);
-    }
 
 }
index 5bb0e1b4aa209a9a12b24ca5c250f4380551a0e1..502ceaae5a578299e990c3880db20df9d533795e 100644 (file)
@@ -19,7 +19,6 @@ import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
-import eu.etaxonomy.taxeditor.ui.section.media.AbstractTogglableMediaDetailsSection;
 import eu.etaxonomy.taxeditor.ui.section.media.MediaMetaElement;
 
 /**
@@ -29,7 +28,9 @@ import eu.etaxonomy.taxeditor.ui.section.media.MediaMetaElement;
  * @created Jun 15, 2010
  * @version 1.0
  */
-public class MediaDetailsSection extends AbstractTogglableMediaDetailsSection<Media> {
+public class MediaDetailsSection extends AbstractCdmDetailSection<Media> {
+
+    private MediaMetaElement mediaMetaElement;
 
        public MediaDetailsSection(CdmFormFactory formFactory, ConversationHolder conversation,
                        ICdmFormElement parentElement,
@@ -39,10 +40,10 @@ public class MediaDetailsSection extends AbstractTogglableMediaDetailsSection<Me
 
        @Override
     public void setEntity(Media entity) {
-               if(getTogglableMediaElement() != null){
+               if(mediaMetaElement != null){
                        this.removeElements();
                }
-               setTogglableMediaElement((MediaMetaElement) formFactory.createEntityCollectionElement(this, entity, null, null, ExpandableComposite.EXPANDED));
+               mediaMetaElement = (MediaMetaElement) formFactory.createEntityCollectionElement(this, entity, null, null, ExpandableComposite.EXPANDED);
                super.setEntity(entity);
                setSectionTitle();
         setTextClient(createToolbar());
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/AbstractTogglableMediaDetailsSection.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/AbstractTogglableMediaDetailsSection.java
deleted file mode 100644 (file)
index 9a78854..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-// $Id$
-/**
-* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-
-package eu.etaxonomy.taxeditor.ui.section.media;
-
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.action.ToolBarManager;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Control;
-
-import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
-import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
-import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
-import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
-
-/**
- *
- * @author pplitzner
- * @date Jun 25, 2015
- *
- */
-public abstract class AbstractTogglableMediaDetailsSection<ENTITY> extends AbstractCdmDetailSection<ENTITY> {
-
-       private ITogglableMediaElement togglableMediaElement;
-
-       public AbstractTogglableMediaDetailsSection(CdmFormFactory formFactory, ConversationHolder conversation,
-                       ICdmFormElement parentElement,
-                       ISelectionProvider selectionProvider, int style) {
-               super(formFactory, conversation, parentElement, selectionProvider, style);
-       }
-
-       @Override
-    protected Control createToolbar() {
-        ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
-
-        final String label = "Change View Type";
-
-        Action addAction = new Action(label, IAction.AS_PUSH_BUTTON) {
-            @Override
-            public void run() {
-                if(togglableMediaElement!=null){
-                    togglableMediaElement.toggleAdvancedMediaView();
-                }
-            }
-        };
-        addAction.setToolTipText(label);
-
-        toolBarManager.add(addAction);
-
-        return toolBarManager.createControl(this);
-    }
-
-    public void setTogglableMediaElement(ITogglableMediaElement togglableMediaElement) {
-        this.togglableMediaElement = togglableMediaElement;
-    }
-
-    public ITogglableMediaElement getTogglableMediaElement() {
-        return togglableMediaElement;
-    }
-
-}
index 67dd752ccbc37948b3f7ae09c575cb9408932704..aa51d360596433e3e939b1a7d471c36e967194a0 100644 (file)
@@ -3,7 +3,11 @@
  */
 package eu.etaxonomy.taxeditor.ui.section.media;
 
+import org.eclipse.jface.action.IAction;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Button;
 
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.agent.AgentBase;
@@ -41,7 +45,16 @@ public class MediaMetaElement extends AbstractEntityCollectionElement<Media> imp
     /** {@inheritDoc} */
     @Override
     public void createControls(ICdmFormElement element, int style) {
-
+        final IAction switchAction = MediaViewSwitch.createSwitch(MediaMetaElement.this);
+        Button btnToggleAdvancedMediaView = new Button(getBox(), style);
+        btnToggleAdvancedMediaView.setText(switchAction.getText());
+        btnToggleAdvancedMediaView.setToolTipText(switchAction.getText());
+        btnToggleAdvancedMediaView.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                switchAction.run();
+            }
+        });
         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, true, style);
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaViewSwitch.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaViewSwitch.java
new file mode 100644 (file)
index 0000000..0506ebf
--- /dev/null
@@ -0,0 +1,43 @@
+// $Id$
+/**
+* Copyright (C) 2015 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.ui.section.media;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+
+/**
+ * Adds a switch to a section with an {@link ITogglableMediaElement}
+ * to allow switching between simple and advanced media view
+ * @author pplitzner
+ * @date Jun 29, 2015
+ *
+ */
+public class MediaViewSwitch {
+
+    /**
+     * Creates an {@link IAction} for the given {@link ITogglableMediaElement}
+     * that switches between the two states of the element.
+     */
+    public static IAction createSwitch(final ITogglableMediaElement togglableMediaElement) {
+        final String label = "Change View Type";
+
+        Action switchAction = new Action(label, IAction.AS_PUSH_BUTTON) {
+            @Override
+            public void run() {
+                if(togglableMediaElement!=null){
+                    togglableMediaElement.toggleAdvancedMediaView();
+                }
+            }
+        };
+        switchAction.setToolTipText(label);
+
+        return switchAction;
+    }
+}
index fc9eb82dc214a61c24b4fcfab5987ef57839b8e5..0a26d31e499c232578bba0558b82e3b576527f69 100644 (file)
@@ -9,7 +9,10 @@
 */
 package eu.etaxonomy.taxeditor.ui.section.occurrence.media;
 
+import org.eclipse.jface.action.ToolBarManager;
 import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Control;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
@@ -17,14 +20,17 @@ import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
-import eu.etaxonomy.taxeditor.ui.section.media.AbstractTogglableMediaDetailsSection;
+import eu.etaxonomy.taxeditor.ui.section.media.ITogglableMediaElement;
+import eu.etaxonomy.taxeditor.ui.section.media.MediaViewSwitch;
 
 /**
  * @author pplitzner
  * @date 12.12.2013
  *
  */
-public class MediaSpecimenGeneralDetailSection extends AbstractTogglableMediaDetailsSection<MediaSpecimen> {
+public class MediaSpecimenGeneralDetailSection extends AbstractCdmDetailSection<MediaSpecimen> {
+
+    private ITogglableMediaElement togglableMediaElement;
 
     public MediaSpecimenGeneralDetailSection(CdmFormFactory formFactory,
             ConversationHolder conversation, ICdmFormElement parentElement,
@@ -45,8 +51,16 @@ public class MediaSpecimenGeneralDetailSection extends AbstractTogglableMediaDet
     @Override
     protected AbstractCdmDetailElement<MediaSpecimen> createCdmDetailElement(AbstractCdmDetailSection<MediaSpecimen> parentElement, int style) {
         MediaSpecimenGeneralDetailElement mediaSpecimenGeneralDetailElement = formFactory.createMediaSpecimenGeneralDetailElement(parentElement);
-        setTogglableMediaElement(mediaSpecimenGeneralDetailElement);
+        togglableMediaElement = mediaSpecimenGeneralDetailElement;
         return mediaSpecimenGeneralDetailElement;
     }
 
+    @Override
+    protected Control createToolbar() {
+        ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
+        toolBarManager.add(MediaViewSwitch.createSwitch(togglableMediaElement));
+        return toolBarManager.createControl(this);
+    }
+
+
 }