- moved toggle button to the top-right corner of the Media(Specimen)Section (#3339)
authorPatric Plitzner <p.plitzner@bgbm.org>
Fri, 5 Sep 2014 06:50:13 +0000 (06:50 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Fri, 5 Sep 2014 06:50:13 +0000 (06:50 +0000)
 - Changed label

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/MediaDetailElement.java
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/occurrence/media/MediaSpecimenGeneralDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/media/MediaSpecimenGeneralDetailSection.java

index e5a67e4005c091ed637ee48d42238cf7f9a4f596..d97c62333cf7472f5ff7820bf1803aa3f3336ada 100644 (file)
 
 package eu.etaxonomy.taxeditor.ui.section.description;
 
+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 org.eclipse.ui.forms.widgets.ExpandableComposite;
 import org.eclipse.ui.forms.widgets.TableWrapLayout;
 
@@ -61,6 +66,34 @@ public class MediaDetailsSection extends AbstractCdmDetailSection<Media> {
 
        }
 
+       @Override
+    protected Control createToolbar() {
+        ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
+
+        final String label;
+        if(element_media.isAdvancedMediaView()){
+            label = "Use simple media view";
+        }
+        else{
+            label = "Use advanced media view";
+        }
+
+        Action addAction = new Action("Use advanced media view", IAction.AS_PUSH_BUTTON) {
+            /* (non-Javadoc)
+             * @see org.eclipse.jface.action.Action#run()
+             */
+            @Override
+            public void run() {
+                element_media.toggleAdvancedMediaView();
+            }
+        };
+        addAction.setToolTipText(label);
+
+        toolBarManager.add(addAction);
+
+        return toolBarManager.createControl(this);
+    }
+
        /**
         * <p>setEntity</p>
         *
@@ -74,6 +107,7 @@ public class MediaDetailsSection extends AbstractCdmDetailSection<Media> {
                element_media = (MediaMetaElement) formFactory.createEntityCollectionElement(this, entity, null, null, ExpandableComposite.EXPANDED);
                super.setEntity(entity);
                setSectionTitle();
+        setTextClient(createToolbar());
                layout();
        }
 
index 0ba36fe84717aea3f28dc62624cc667fb5ce1838..769964958be8d65e48f67975e3b502a676d9cf4a 100644 (file)
@@ -13,11 +13,6 @@ import java.net.URISyntaxException;
 import java.util.List;
 import java.util.Set;
 
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.widgets.Button;
-
 import eu.etaxonomy.cdm.model.media.Media;
 import eu.etaxonomy.cdm.model.media.MediaRepresentation;
 import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
@@ -41,7 +36,7 @@ public class MediaDetailElement extends AbstractCdmDetailElement<Media>{
     private UriWithLabelElement textUri;
     private MediaRepresentationSection section_mediaRepresentation;
 
-    private Button checkBoxShowAdvancedView;
+    private boolean isAdvancedMediaView;
     private MediaRepresentationPart singleMediaRepresentationPart;
     private ICdmFormElement parentFormElement;
     private int style;
@@ -61,20 +56,6 @@ public class MediaDetailElement extends AbstractCdmDetailElement<Media>{
     protected void createControls(ICdmFormElement formElement, Media entity, int style) {
         this.parentFormElement = formElement;
         this.style = style;
-        checkBoxShowAdvancedView = formFactory.createButton(formElement.getLayoutComposite(), "Advanced Media View", SWT.CHECK | style);
-        checkBoxShowAdvancedView.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
-        checkBoxShowAdvancedView.addSelectionListener(new SelectionListener() {
-
-            @Override
-            public void widgetSelected(SelectionEvent e) {
-                showAdvancedView(checkBoxShowAdvancedView.getSelection());
-            }
-
-            @Override
-            public void widgetDefaultSelected(SelectionEvent e) {
-
-            }
-        });
     }
 
     /* (non-Javadoc)
@@ -86,7 +67,8 @@ public class MediaDetailElement extends AbstractCdmDetailElement<Media>{
         if(singleMediaRepresentationPart==null){
             singleMediaRepresentationPart = MediaUtils.initFirstMediaRepresentationPart(entity);
         }
-        showAdvancedView(isAdvancedMediaView());
+        initIsAdvancedMediaView();
+        showAdvancedView();
 
     }
 
@@ -103,16 +85,18 @@ public class MediaDetailElement extends AbstractCdmDetailElement<Media>{
                 textUri.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
             }
         }
-        else if(eventSource==checkBoxShowAdvancedView){
-            showAdvancedView(checkBoxShowAdvancedView.getSelection());
-        }
+    }
+
+    public void toggleAdvancedMediaView(){
+        isAdvancedMediaView = !isAdvancedMediaView;
+        showAdvancedView();
     }
 
     /**
      * @param showAdvancedView
      */
-    private void showAdvancedView(boolean showAdvancedView) {
-        if(showAdvancedView){
+    private void showAdvancedView() {
+        if(isAdvancedMediaView){
             if(textUri!=null){
                 removeElementsAndControls(textUri);
             }
@@ -130,28 +114,31 @@ public class MediaDetailElement extends AbstractCdmDetailElement<Media>{
         }
     }
 
-    private boolean isAdvancedMediaView(){
+    private void initIsAdvancedMediaView(){
         if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_ADVANCED_MEDIA_SECTION)){
-            checkBoxShowAdvancedView.setSelection(true);
-            checkBoxShowAdvancedView.setEnabled(false);
-            return true;
+            isAdvancedMediaView = true;
+            return;
         }
         Set<MediaRepresentation> representations = getEntity().getRepresentations();
         if(representations.size()>1){
-            checkBoxShowAdvancedView.setSelection(true);
-            checkBoxShowAdvancedView.setEnabled(false);
-            return true;
+            isAdvancedMediaView = true;
+            return;
         }
         if(representations.size()==1){
             List<MediaRepresentationPart> parts = representations.iterator().next().getParts();
             if(parts.size()>1){
-                checkBoxShowAdvancedView.setSelection(true);
-                checkBoxShowAdvancedView.setEnabled(false);
-                return true;
+                isAdvancedMediaView =  true;
+                return;
             }
         }
-        return false;
+        isAdvancedMediaView =  false;
     }
 
+    /**
+     * @return
+     */
+    public boolean isAdvancedMediaView() {
+        return isAdvancedMediaView;
+    }
 
 }
index 4f9f4588869bd457e25dd4478f792d34458bce9b..78960e311d49f68f4dcea6823ee8fe19cadd4762 100644 (file)
@@ -96,6 +96,10 @@ public class MediaMetaElement extends AbstractEntityCollectionElement<Media> {
         text_title.setLanguageString(title);
     }
 
+    public void toggleAdvancedMediaView(){
+        mediaDetailElement.toggleAdvancedMediaView();
+    }
+
     /*
      * (non-Javadoc)
      *
@@ -117,4 +121,11 @@ public class MediaMetaElement extends AbstractEntityCollectionElement<Media> {
             }
         }
     }
+
+    /**
+     * @return
+     */
+    public boolean isAdvancedMediaView() {
+        return mediaDetailElement.isAdvancedMediaView();
+    }
 }
index 67359cd6e5e9462626930c4e031e18bd22294628..fa748ef736fd5c4da507336fef72eeabc380131a 100644 (file)
@@ -158,4 +158,12 @@ public class MediaSpecimenGeneralDetailElement extends AbstractCdmDetailElement<
         }
     }
 
+    public void toogleAdvancedMediaView() {
+        mediaDetailElement.toggleAdvancedMediaView();
+    }
+
+    public boolean isAdvancedMediaView() {
+        return mediaDetailElement.isAdvancedMediaView();
+    }
+
 }
\ No newline at end of file
index 48df3b4ab47c1c6b16f9e7f3abcb3f876e5d7145..49dbea3a7c2e6dc7cf0037ed1023bfbad949a4ce 100644 (file)
@@ -9,7 +9,12 @@
 */
 package eu.etaxonomy.taxeditor.ui.section.occurrence.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.cdm.model.occurrence.MediaSpecimen;
@@ -26,6 +31,8 @@ import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
  */
 public class MediaSpecimenGeneralDetailSection  extends AbstractCdmDetailSection<MediaSpecimen> {
 
+    private MediaSpecimenGeneralDetailElement mediaSpecimenGeneralDetailElement;
+
     /**
      * @param formFactory
      * @param conversation
@@ -76,11 +83,40 @@ public class MediaSpecimenGeneralDetailSection  extends AbstractCdmDetailSection
         }
     }
 
+    @Override
+    protected Control createToolbar() {
+        ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
+
+        final String label;
+
+        if(mediaSpecimenGeneralDetailElement.isAdvancedMediaView()){
+            label = "Use simple media view";
+        }
+        else{
+            label = "Use advanced media view";
+        }
+        Action addAction = new Action("Use advanced media view", IAction.AS_PUSH_BUTTON) {
+            /* (non-Javadoc)
+             * @see org.eclipse.jface.action.Action#run()
+             */
+            @Override
+            public void run() {
+                mediaSpecimenGeneralDetailElement.toogleAdvancedMediaView();
+            }
+        };
+        addAction.setToolTipText(label);
+
+        toolBarManager.add(addAction);
+
+        return toolBarManager.createControl(this);
+    }
+
     /* (non-Javadoc)
      * @see eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection#createCdmDetailElement(eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection, int)
      */
     @Override
     protected AbstractCdmDetailElement<MediaSpecimen> createCdmDetailElement(AbstractCdmDetailSection<MediaSpecimen> parentElement, int style) {
-        return formFactory.createMediaSpecimenGeneralDetailElement(parentElement);
+        mediaSpecimenGeneralDetailElement = formFactory.createMediaSpecimenGeneralDetailElement(parentElement);
+        return mediaSpecimenGeneralDetailElement;
     }
 }