rename some eu.*.Abstract*E4 classes
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / concept / e4 / ConceptViewPartE4.java
index 7c4ad3d6a1a183bedf4b8033dd7dc0d3689cdb37..d401847eeabb59a715bc7d543c36281669719b5e 100644 (file)
@@ -9,6 +9,9 @@
 
 package eu.etaxonomy.taxeditor.editor.view.concept.e4;
 
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Map.Entry;
 
 import javax.annotation.PostConstruct;
@@ -24,19 +27,15 @@ import org.eclipse.swt.widgets.Composite;
 
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
-import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
-import eu.etaxonomy.taxeditor.editor.key.AbstractGraphKeyEditor;
+import eu.etaxonomy.taxeditor.editor.key.e4.AbstractGraphKeyEditor;
 import eu.etaxonomy.taxeditor.editor.l10n.Messages;
-import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
 import eu.etaxonomy.taxeditor.editor.view.concept.ConceptContentProvider;
 import eu.etaxonomy.taxeditor.editor.view.concept.ConceptLabelProvider;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4;
 import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4;
-import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
 import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
-import eu.etaxonomy.taxeditor.model.LineSelection;
-import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
+import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPart;
 import eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4;
 import eu.etaxonomy.taxeditor.view.e4.supplementaldata.SupplementalDataPartE4;
 
@@ -46,7 +45,7 @@ import eu.etaxonomy.taxeditor.view.e4.supplementaldata.SupplementalDataPartE4;
  * @date 21.08.2017
  *
  */
-public class ConceptViewPartE4 extends AbstractCdmEditorPartE4
+public class ConceptViewPartE4 extends AbstractCdmEditorPart
 implements IPartContentHasDetails, IPartContentHasSupplementalData{
 
     @Override
@@ -54,8 +53,11 @@ implements IPartContentHasDetails, IPartContentHasSupplementalData{
         if(activePart==thisPart){
             return;
         }
-        viewer.getControl().setEnabled(true);
-        Object partObject = createPartObject(activePart);
+        if (!viewer.getControl().isDisposed()){
+            viewer.getControl().setEnabled(true);
+        }
+        Object partObject = getPartObject(activePart);
+        IStructuredSelection structuredSelection = createSelection(selection);
 
         if (partObject instanceof DetailsPartE4 || partObject instanceof SupplementalDataPartE4
                 || partObject instanceof FactualDataPartE4|| partObject instanceof MediaViewPartE4) {
@@ -63,23 +65,11 @@ implements IPartContentHasDetails, IPartContentHasSupplementalData{
             // description selected in this view
             return;
         }
-        else if(partObject instanceof BulkEditor && selection instanceof LineSelection){
-                       if(((LineSelection) selection).getFirstElement() instanceof Taxon){
-                               showViewer((LineSelection) selection, activePart, viewer);
-                       }
-                       else{
-                               showEmptyPage();
-                       }
-                       return;
-               }
                else if(partObject instanceof AbstractGraphKeyEditor){
                        showEmptyPage();
                }
-               else if(partObject instanceof TaxonNameEditorE4){
-                   Taxon taxon = ((TaxonNameEditorE4) partObject).getTaxon();
-                   if(taxon!=null){
-                       showViewer(new StructuredSelection(taxon), activePart, viewer);
-                   }
+               else if(selection!=null){
+                   showViewer(structuredSelection, activePart, viewer);
                }
                else {
                    showEmptyPage();
@@ -103,7 +93,7 @@ implements IPartContentHasDetails, IPartContentHasSupplementalData{
                viewer = conceptViewer;
 
                // Propagate selection from viewer
-        selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
+        selectionChangedListener = (event -> selService.setSelection(viewer.getSelection()));
         viewer.addSelectionChangedListener(selectionChangedListener);
 
         //create context menu
@@ -126,11 +116,13 @@ implements IPartContentHasDetails, IPartContentHasSupplementalData{
                @Override
                public ISelection getSelection() {
                        ISelection selection = super.getSelection();
+                       List<TaxonRelationship> relationships = new ArrayList<>();
                        if(selection instanceof IStructuredSelection && !selection.isEmpty()){
-                               Object firstElement = ((IStructuredSelection) selection).getFirstElement();
-                               TaxonRelationship taxonRelationship = ((Entry<TaxonRelationship, Taxon>)firstElement).getKey();
-                               return new StructuredSelection(taxonRelationship);
-
+                           for(Iterator iter = ((IStructuredSelection) selection).iterator();iter.hasNext();){
+                               Object object = iter.next();
+                               relationships.add(((Entry<TaxonRelationship, Taxon>)object).getKey());
+                           }
+                           return new StructuredSelection(relationships);
                        }
                        return selection;
                }