Add button for advanced media view to media attached to desccriptions
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 29 Jun 2015 05:04:53 +0000 (07:04 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 29 Jun 2015 11:35:37 +0000 (13:35 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractEntityCollectionSection.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/DescriptionElementMediaSection.java

index d349a64eed00b0506616e692277a58aa18a9e4ac..482b9455ea46ab3de5a81d718770047a79672f49 100644 (file)
@@ -55,9 +55,6 @@ import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 
 public abstract class AbstractEntityCollectionSection<ENTITY, ELEMENT> extends AbstractFormSection<ENTITY> implements IExpansionListener, Observer {
 
-       /**
-     *
-     */
     private static final EnumSet<CRUD> UPDATE = EnumSet.of(CRUD.UPDATE);
 
     protected Composite container;
@@ -66,17 +63,8 @@ public abstract class AbstractEntityCollectionSection<ENTITY, ELEMENT> extends A
 
        private String title;
 
-       /**
-        * <p>Constructor for AbstractEntityCollectionSection.</p>
-        *
-        * @param conversation
-        * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
-        * @param style a int.
-        * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
-        * @param title a {@link java.lang.String} object.
-        * @param <ENTITY> a ENTITY object.
-        * @param <ELEMENT> a ELEMENT object.
-        */
+    private AbstractEntityCollectionElement entityCollectionElement;
+
        public AbstractEntityCollectionSection(CdmFormFactory formFactory, ConversationHolder conversation, ICdmFormElement parentElement, String title, int style) {
                super(formFactory, parentElement, ExpandableComposite.CLIENT_INDENT | style);
                this.title = title;
@@ -98,9 +86,6 @@ public abstract class AbstractEntityCollectionSection<ENTITY, ELEMENT> extends A
                ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
 
                Action addAction = new Action("add", IAction.AS_PUSH_BUTTON){
-                       /* (non-Javadoc)
-                        * @see org.eclipse.jface.action.Action#run()
-                        */
                        @Override
                        public void run() {
                                ELEMENT element = createNewElement();
@@ -141,11 +126,6 @@ public abstract class AbstractEntityCollectionSection<ENTITY, ELEMENT> extends A
                setTextClient(null);
        }
 
-       /**
-        * <p>setEntity</p>
-        *
-        * @param entity a ENTITY object.
-        */
        @Override
        public void setEntity(ENTITY entity) {
                if(entity != null){
@@ -217,9 +197,6 @@ public abstract class AbstractEntityCollectionSection<ENTITY, ELEMENT> extends A
                reflow();
        }
 
-       /**
-        * <p>createEmptyContent</p>
-        */
        protected void createEmptyContent(){
                label_empty = formFactory.createLabel(getLayoutComposite(), getEmptyString());
        }
@@ -254,12 +231,9 @@ public abstract class AbstractEntityCollectionSection<ENTITY, ELEMENT> extends A
         * @param backgroundColor a {@link org.eclipse.swt.graphics.Color} object.
         */
        protected void createElementComposite(ELEMENT element, SelectionListener removeListener, Color backgroundColor){
-               formFactory.createEntityCollectionElement(this, element, removeListener, backgroundColor, SWT.NULL);
+               entityCollectionElement = formFactory.createEntityCollectionElement(this, element, removeListener, backgroundColor, SWT.NULL);
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.forms.section.AbstractEditorFormSection#setBackground(org.eclipse.swt.graphics.Color)
-        */
        /** {@inheritDoc} */
        @Override
        public void setBackground(Color color) {
@@ -319,9 +293,6 @@ public abstract class AbstractEntityCollectionSection<ENTITY, ELEMENT> extends A
                internalUpdateSection(true);
        }
 
-       /* (non-Javadoc)
-        * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
-        */
        @Override
     public void update(Observable o, Object arg){
            if(o instanceof LoginManager){
@@ -337,6 +308,10 @@ public abstract class AbstractEntityCollectionSection<ENTITY, ELEMENT> extends A
         }
     }
 
+    public AbstractEntityCollectionElement getEntityCollectionElement() {
+        return entityCollectionElement;
+    }
+
        /**
         * Get the specific collection of this entity
         *
index 10608b3b000f88dc24ec6805e2e15b6e293981c1..60a2bd209f11c83357d6468c25e3f1d23f0f9fde 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* 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.
 */
@@ -12,6 +12,12 @@ 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;
@@ -19,6 +25,7 @@ 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>
@@ -29,20 +36,12 @@ import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
  */
 public class DescriptionElementMediaSection extends
                AbstractEntityCollectionSection<DescriptionElementBase, Media> {
-       
-       /**
-        * <p>Constructor for DescriptionElementMediaSection.</p>
-        *
-        * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
-        * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
-        * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
-        * @param style a int.
-        */
+
        public DescriptionElementMediaSection(CdmFormFactory cdmFormFactory, ConversationHolder conversation,
                        ICdmFormElement parentElement, int style) {
                super(cdmFormFactory, conversation, parentElement, "Media", style);
        }
-       
+
        /** {@inheritDoc} */
        @Override
        public void setEntity(DescriptionElementBase entity) {
@@ -87,5 +86,28 @@ public class DescriptionElementMediaSection extends
        public void removeElement(Media element) {
                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);
+    }
+
 }