Merge branch 'develop' into LibrAlign
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / media / MediaViewPart.java
index 67fc3ed3f1950e1ed770578336560bb23609c295..2cd347b2b48b0ed6b6fd3d588d2bda32a3090d88 100644 (file)
@@ -1,4 +1,3 @@
-// $Id$
 /**
 * Copyright (C) 2007 EDIT
 * European Distributed Institute of Taxonomy
@@ -23,14 +22,13 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Menu;
 import org.eclipse.swt.widgets.Tree;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IWorkbenchActionConstants;
 import org.eclipse.ui.IWorkbenchPart;
 
+import eu.etaxonomy.cdm.model.description.IDescribable;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
-import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
+import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveViewPart;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
 import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
@@ -40,24 +38,17 @@ import eu.etaxonomy.taxeditor.view.detail.DetailsViewPart;
 import eu.etaxonomy.taxeditor.view.supplementaldata.SupplementalDataViewPart;
 
 /**
- * <p>MediaViewPart class.</p>
- *
  * @author n.hoffmann
  * @created Jun 15, 2010
  * @version 1.0
  */
 public class MediaViewPart extends AbstractCdmEditorViewPart implements IPartContentHasDetails, IPartContentHasSupplementalData {
 
-       /** Constant <code>ID="eu.etaxonomy.taxeditor.editor.view.medi"{trunked}</code> */
        public static final String ID = "eu.etaxonomy.taxeditor.editor.view.media";
 
 
        private TreeViewer viewer;
 
-       /*
-        * (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#createViewer(org.eclipse.swt.widgets.Composite)
-        */
        /** {@inheritDoc} */
        @Override
        public void createViewer(Composite parent) {
@@ -83,9 +74,6 @@ public class MediaViewPart extends AbstractCdmEditorViewPart implements IPartCon
 
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#getInitialSelection()
-        */
        /** {@inheritDoc} */
        @Override
        protected ISelection getInitialSelection() {
@@ -107,44 +95,49 @@ public class MediaViewPart extends AbstractCdmEditorViewPart implements IPartCon
                        return;
                }
 
-        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
+        if (part instanceof DetailsViewPart || part instanceof SupplementalDataViewPart
+                || part instanceof DescriptiveViewPart) {
+            // 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){
+               if(part instanceof IPartContentHasMedia && ((IPartContentHasMedia) part).canAttachMedia()){
+                   if(selection instanceof IStructuredSelection){
                        Object firstElement = ((IStructuredSelection) selection).getFirstElement();
                        if(firstElement instanceof TreeNode){
                            showViewer(part, new StructuredSelection(((TreeNode) firstElement).getValue()));
+                           return;
                        }
-                       else{
+                       else if(firstElement!=null
+                           && firstElement instanceof IDescribable<?>){
                            showViewer(part, (IStructuredSelection) selection);
+                           return;
                        }
-                   }else{
-                       showEmptyPage();
                    }
                }
-               else{
-                   showEmptyPage();
-               }
+               showEmptyPage();
        }
 
        /** {@inheritDoc} */
        @Override
        public void changed(Object object) {
-               viewer.refresh();
-               //TODO: should be replaced with the possibility to set views dirty
-               // when we move to Eclipse 4
-               // take a look at ISaveblePart
-               if(part instanceof BulkEditor && !(object instanceof SpecimenOrObservationBase<?>)){
-                   ((BulkEditor) part).forceDirty();
-               }
-               super.changed(object);
+           viewer.expandToLevel(2);
+           viewer.refresh();
+           if(object != null){
+               StructuredSelection selection = new StructuredSelection(object);
+               viewer.setSelection(selection, true);
+           }
+           //TODO: should be replaced with the possibility to set views dirty
+           // when we move to Eclipse 4
+           // take a look at ISaveblePart
+           if(part instanceof BulkEditor && !(object instanceof SpecimenOrObservationBase<?>)){
+               ((BulkEditor) part).forceDirty();
+               IStructuredSelection selection = (IStructuredSelection) ((BulkEditor) part).getSelectionProvider().getSelection();
+            ((BulkEditor) part).changed(selection.getFirstElement());
+            
+           }
+           super.changed(object);
        }
 
        /** {@inheritDoc} */
@@ -153,13 +146,13 @@ public class MediaViewPart extends AbstractCdmEditorViewPart implements IPartCon
                return viewer;
        }
 
-       /**
-        * <p>onComplete</p>
-        *
-        * @return a boolean.
-        */
        @Override
     public boolean onComplete() {
                return true;
        }
+
+       @Override
+       protected String getViewName() {
+               return "Media";
+       }
 }