- added support for image gallery creation for FieldUnits (#4389)
authorPatric Plitzner <p.plitzner@bgbm.org>
Mon, 22 Sep 2014 06:49:28 +0000 (06:49 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Mon, 22 Sep 2014 06:49:28 +0000 (06:49 +0000)
 - added support for DerivateView to MediaView

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/operation/AddDerivedUnitFacadeMediaOperation.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/MediaContentProvider.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/MediaViewPart.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/AddExistingMediaHandler.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/AddImageGalleryHandler.java

index 8949898d79629cff51e6323b1c776b9957586812..1cc320d3308a529ff502d9bb61b81a868dbe71cc 100644 (file)
@@ -9,6 +9,9 @@ import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.util.LocalSelectionTransfer;
 import org.eclipse.jface.viewers.AbstractTreeViewer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.viewers.TreeNode;
 import org.eclipse.jface.viewers.TreeViewer;
@@ -31,23 +34,24 @@ import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
 import eu.etaxonomy.cdm.model.molecular.Sequence;
 import eu.etaxonomy.cdm.model.molecular.SingleRead;
-import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.taxeditor.model.IContextListener;
 import eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider;
 import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
 import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
+import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
 import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
 
 /**
- * Displays the derivate hierarchy of all derivates having one single {@link FieldUnit} as root.
+ * Displays the derivate hierarchy of the specimen specified in the editor input.
  *
  */
 public class DerivateView extends EditorPart implements IPartContentHasFactualData, IDirtyMarkableSelectionProvider,
-        IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IContextListener {
+        IConversationEnabled, IPartContentHasDetails, IPartContentHasMedia, IPartContentHasSupplementalData,
+        IContextListener, ISelectionChangedListener {
 
        /**
      * Key used for storing a single DerivateView in a memento
@@ -73,6 +77,8 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
 
     private Set<SingleRead> multiLinkSingleReads;
 
+    private ISelection selection = null;
+
     /**
      * Default constructor
      */
@@ -93,6 +99,8 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
         viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
         // Propagate selection from viewer
         getSite().setSelectionProvider(viewer);
+        //listen to selection changes
+        viewer.addSelectionChangedListener(this);
 
         //create context menu
         MenuManager menuManager = new MenuManager();
@@ -319,4 +327,19 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
 //        }
     }
 
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
+     */
+    @Override
+    public void selectionChanged(SelectionChangedEvent event) {
+        this.selection  = event.getSelection();
+    }
+
+    /**
+     * @return the selection
+     */
+    public ISelection getSelection() {
+        return selection;
+    }
+
 }
index f0522ba8be0417c33608cf45036133ded0512f8a..e99964df309e233d1d4e7e642f9e094d41176f22 100644 (file)
@@ -15,6 +15,7 @@ import org.eclipse.core.commands.operations.IUndoContext;
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
 
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
@@ -56,11 +57,23 @@ public class AddDerivedUnitFacadeMediaOperation extends AbstractPostTaxonOperati
                try {
                    if(specimen instanceof FieldUnit){
                        facade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.FieldUnit, (FieldUnit) specimen);
-                       facade.getFieldObjectImageGallery(true);
+                       if(facade.hasFieldObjectImageGallery()){
+                           MessagingUtils.informationDialog("Image gallery creation failed", "Only one image gallery is possible.");
+                           return Status.CANCEL_STATUS;
+                       }
+                       else{
+                           facade.getFieldObjectImageGallery(true);
+                       }
                    }
                    else if(specimen instanceof DerivedUnit){
                        facade = DerivedUnitFacade.NewInstance((DerivedUnit)specimen);
-                       facade.getDerivedUnitImageGallery(true);
+                       if(facade.hasDerivedUnitImageGallery()){
+                           MessagingUtils.informationDialog("Image gallery creation failed", "Only one image gallery is possible.");
+                           return Status.CANCEL_STATUS;
+                       }
+                       else{
+                           facade.getDerivedUnitImageGallery(true);
+                       }
                    }
                } catch (DerivedUnitFacadeNotSupportedException e) {
                        MessagingUtils.error(getClass(), e);
index 751b345455d5e526ec16855d904121b747dab9e1..9fda8be48f5dd208769fe2dece4ee55207c1ec04 100644 (file)
@@ -1,16 +1,16 @@
 // $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.
 */
 
 package eu.etaxonomy.taxeditor.editor.view.media;
 
-import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -26,6 +26,8 @@ import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.SpecimenDescription;
 import eu.etaxonomy.cdm.model.media.Media;
 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
+import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
@@ -40,10 +42,11 @@ import eu.etaxonomy.taxeditor.model.MessagingUtils;
 public class MediaContentProvider implements ITreeContentProvider{
 
        private static final Object[] NO_CHILDREN = new Object[0];
-       
+
        /** {@inheritDoc} */
-       public Object[] getChildren(Object parentElement) {
-                               
+       @Override
+    public Object[] getChildren(Object parentElement) {
+
                if (parentElement instanceof TaxonEditorInput) {
                        Taxon taxon = ((TaxonEditorInput) parentElement).getTaxon();
                        if(taxon == null){
@@ -55,90 +58,92 @@ public class MediaContentProvider implements ITreeContentProvider{
                                if(description.isImageGallery()){
                                        imageGalleries.add(description);
                                }
-                       }                       
-                       return imageGalleries.toArray(); 
+                       }
+                       return imageGalleries.toArray();
                }
                else if (parentElement instanceof DescriptionBase) {
                        if (((DescriptionBase) parentElement).isImageGallery()) {
                                return getImages((DescriptionBase) parentElement).toArray();
-                       } 
+                       }
                }
                else if (parentElement instanceof DerivedUnit){
                        try {
                                DerivedUnitFacade facade = DerivedUnitFacade.NewInstance((DerivedUnit) parentElement);
-               
-                               // TODO at the moment we always create image galleries because the facade is like so.
-                               // this should definitely change and we want to use normal getters and setters here
-                               List<DescriptionBase> derivedUnitFacadeImageGalleries = new ArrayList<DescriptionBase>(2);
-                               
+
                                SpecimenDescription derivedUnitImageGallery = facade.getDerivedUnitImageGallery(false);
-                               SpecimenDescription fieldObjectImageGallery = facade.getFieldObjectImageGallery(false);
-                               
+
                                if(derivedUnitImageGallery != null){
-                                       derivedUnitFacadeImageGalleries.add(derivedUnitImageGallery);
-                               }
-                               
-                               if(fieldObjectImageGallery != null){
-                                       derivedUnitFacadeImageGalleries.add(fieldObjectImageGallery);
+                                       return Collections.singleton(derivedUnitImageGallery).toArray();
                                }
-                               
-                               return derivedUnitFacadeImageGalleries.toArray();
-                               
+
                        } catch (DerivedUnitFacadeNotSupportedException e) {
                                MessagingUtils.error(this.getClass(), "DerivedUnitFacadeNotSupportedException when trying to instantiate DerivedUnitFacade", e);
                        }
                }
-               
+               else if (parentElement instanceof FieldUnit){
+                       DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.FieldUnit, (FieldUnit) parentElement);
+
+                       SpecimenDescription fieldObjectImageGallery = facade.getFieldObjectImageGallery(false);
+
+                       if(fieldObjectImageGallery != null){
+                           return Collections.singleton(fieldObjectImageGallery).toArray();
+                       }
+               }
                return NO_CHILDREN;
        }
 
        /** {@inheritDoc} */
-       public Object getParent(Object element) {
+       @Override
+    public Object getParent(Object element) {
                // TODO Auto-generated method stub
                return null;
        }
 
        /** {@inheritDoc} */
-       public boolean hasChildren(Object element) {
+       @Override
+    public boolean hasChildren(Object element) {
                return (getChildren(element).length > 0);
        }
 
        /** {@inheritDoc} */
-       public Object[] getElements(Object inputElement) {
+       @Override
+    public Object[] getElements(Object inputElement) {
                return getChildren(inputElement);
        }
 
        /**
         * <p>dispose</p>
         */
-       public void dispose() {}
+       @Override
+    public void dispose() {}
 
        /** {@inheritDoc} */
-       public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
-       
+       @Override
+    public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
+
        private List<Media> getImages(DescriptionBase description){
                Assert.isTrue(description.isImageGallery(), "Description should have the imageGallery flag set.");
-               
+
                Set<DescriptionElementBase> elements = description.getElements();
                if (elements != null) {
                        // by definition, image galleries have only one description element
                        if(elements.size() > 1){
                                MessagingUtils.error(this.getClass(), "There should be one and only one description element to hold the images. Found: " + elements.size() + " InDescription ID: " + description.getUuid(), null);
                        }
-                                               
+
                        DescriptionElementBase element = elements.iterator().next();
-                       
+
                        return element.getMedia();
                }
                return null;
        }
-       
+
        private SpecimenDescription createDerivedUnitFacadeImageGallery(DerivedUnitFacade facade){
                SpecimenDescription description = SpecimenDescription.NewInstance();
                description.setImageGallery(true);
-               
-               
-               
+
+
+
                return description;
        }
 }
index 43bf658bf86934c03bdaa488ba26a20200a924f2..0ae94206a036b3a8a28c83b9f6acaf89d0893623 100644 (file)
@@ -15,6 +15,7 @@ import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeNode;
 import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.swt.SWT;
@@ -35,6 +36,8 @@ import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
 import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
 import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
 import eu.etaxonomy.taxeditor.view.AbstractCdmEditorViewPart;
+import eu.etaxonomy.taxeditor.view.detail.DetailsViewPart;
+import eu.etaxonomy.taxeditor.view.supplementaldata.SupplementalDataViewPart;
 
 /**
  * <p>MediaViewPart class.</p>
@@ -100,13 +103,28 @@ public class MediaViewPart extends AbstractCdmEditorViewPart implements IPartCon
                        return;
                }
 
-               if(part instanceof MultiPageTaxonEditor){
-                       IEditorInput input = ((IEditorPart) part).getEditorInput();
-                       showViewer(part, new StructuredSelection(input));
+        if(part instanceof DetailsViewPart || part instanceof SupplementalDataViewPart){
+            // do not show empty page as these views are also used to edit the description selected in this view
+            return;
+        }
+
+               if(part instanceof IPartContentHasMedia){
+                   if(part instanceof MultiPageTaxonEditor){
+                       IEditorInput input = ((IEditorPart) part).getEditorInput();
+                       showViewer(part, new StructuredSelection(input));
+                   }
+                   else if(selection instanceof IStructuredSelection){
+                       Object firstElement = ((IStructuredSelection) selection).getFirstElement();
+                       if(firstElement instanceof TreeNode){
+                           showViewer(part, new StructuredSelection(((TreeNode) firstElement).getValue()));
+                       }
+                       else{
+                           showViewer(part, (IStructuredSelection) selection);
+                       }
+                   }
                }
-
-               else if(part instanceof IPartContentHasMedia && selection instanceof IStructuredSelection){
-                       showViewer(part, (IStructuredSelection) selection);
+               else{
+                   showEmptyPage();
                }
        }
 
index 67910e1f84423123951cb33aebd2a72ea14c29b5..097849cf05a2f948fb1f11a7521a65abb12303d2 100644 (file)
@@ -25,13 +25,14 @@ public class AddExistingMediaHandler extends CreateMediaHandler {
             DescriptionBase description) {
         AbstractPostOperation operation = null;
         try {
-
             //select media
             Media media = MediaSelectionDialog.select(AbstractUtility.getShell(), null, null);
-            // TODO use undo context specific to editor
-            operation = new AddExistingMediaToImageGalleryOperation(media, event.getCommand().getName(),
-                    EditorUtil.getUndoContext(), description, postOperationEnabled);
-            AbstractUtility.executeOperation(operation);
+            if(media!=null){
+                // TODO use undo context specific to editor
+                operation = new AddExistingMediaToImageGalleryOperation(media, event.getCommand().getName(),
+                        EditorUtil.getUndoContext(), description, postOperationEnabled);
+                AbstractUtility.executeOperation(operation);
+            }
         } catch (NotDefinedException e) {
             MessagingUtils.warn(getClass(), "Command name not set.");
         }
index a1e79087daaf5154b786cb63730ecdaf582754c7..00ec54f6e42058c573ec5b5d2495545f3c991209 100644 (file)
@@ -9,6 +9,7 @@ import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.commands.common.NotDefinedException;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeNode;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IWorkbenchPart;
@@ -21,6 +22,8 @@ import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorUtil;
 import eu.etaxonomy.taxeditor.bulkeditor.input.OccurrenceEditorInput;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
+import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
+import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.AddDerivedUnitFacadeMediaOperation;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateTaxonDescriptionOperation;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
@@ -65,21 +68,36 @@ public class AddImageGalleryHandler extends AbstractHandler {
                else if(input instanceof OccurrenceEditorInput){
                    BulkEditor bulkEditor = (BulkEditor) editor;
                    ISelection selection = bulkEditor.getSelectionProvider().getSelection();
-
-                   if(selection instanceof IStructuredSelection){
-                       Object element = ((IStructuredSelection) selection).getFirstElement();
-                       if(element instanceof SpecimenOrObservationBase<?>){
-                           try {
-                               AbstractPostOperation<?> operation = new AddDerivedUnitFacadeMediaOperation(event.getCommand().getName(),
-                                       BulkEditorUtil.getUndoContext(), (SpecimenOrObservationBase<?>)element, postOperationEnabled);
-                               AbstractUtility.executeOperation(operation);
-                           } catch (NotDefinedException e) {
-                               MessagingUtils.warn(getClass(), "Command name not set.");
-                           }
-                       }
-                   }
+                   invokeOperation(event, postOperationEnabled, selection);
+               }
+               else if(input instanceof DerivateViewEditorInput){
+                   ISelection selection = ((DerivateView)editor).getSelection();
+                   invokeOperation(event, postOperationEnabled, selection);
                }
                return null;
        }
 
+    /**
+     * @param event
+     * @param postOperationEnabled
+     * @param selection
+     */
+    private void invokeOperation(ExecutionEvent event, IPostOperationEnabled postOperationEnabled, ISelection selection) {
+        if(selection instanceof IStructuredSelection){
+            Object element = ((IStructuredSelection) selection).getFirstElement();
+            if(element instanceof TreeNode){
+                element = ((TreeNode) element).getValue();
+            }
+            if(element instanceof SpecimenOrObservationBase<?>){
+                try {
+                    AbstractPostOperation<?> operation = new AddDerivedUnitFacadeMediaOperation(event.getCommand().getName(),
+                            BulkEditorUtil.getUndoContext(), (SpecimenOrObservationBase<?>)element, postOperationEnabled);
+                    AbstractUtility.executeOperation(operation);
+                } catch (NotDefinedException e) {
+                    MessagingUtils.warn(getClass(), "Command name not set.");
+                }
+            }
+        }
+    }
+
 }