ref #7073: keep the details view when clicking on supplemental data
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / AbstractCdmViewPart.java
index 27be236e307398262fb4612ca8fef58a28b159ef..ac6544ddc65f42d6980fbafc3110dd1b3e9bea5e 100644 (file)
@@ -1,4 +1,3 @@
-// $Id$
 /**
  * Copyright (C) 2007 EDIT
  * European Distributed Institute of Taxonomy
@@ -24,7 +23,6 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.ui.ISelectionListener;
 import org.eclipse.ui.ISelectionService;
-import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.part.PageBook;
 import org.eclipse.ui.part.ViewPart;
 
@@ -32,7 +30,6 @@ import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
-import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
@@ -51,7 +48,7 @@ public abstract class AbstractCdmViewPart extends ViewPart implements ISelection
 
     public static IStructuredSelection EMPTY_SELECTION = new StructuredSelection();
 
-    protected IWorkbenchPart part;
+    protected Object part;
 
     private PageBook pageBook;
 
@@ -76,11 +73,8 @@ public abstract class AbstractCdmViewPart extends ViewPart implements ISelection
         setInitialSelection();
     }
 
-    /**
-     *
-     */
     private void setInitialSelection() {
-        selectionChanged(AbstractUtility.getActivePart(), getInitialSelection());
+//        selectionChanged(AbstractUtility.getActiveWorkbenchPart(), getInitialSelection());
     }
 
     /**
@@ -96,6 +90,7 @@ public abstract class AbstractCdmViewPart extends ViewPart implements ISelection
      * <p>showEmptyPage</p>
      */
     public void showEmptyPage(){
+       setPartName(createPartTitle(null));
         pageBook.showPage(emptySelectionLabel);
     }
 
@@ -105,13 +100,17 @@ public abstract class AbstractCdmViewPart extends ViewPart implements ISelection
      * @param part a {@link org.eclipse.ui.IWorkbenchPart} object.
      * @param selection a {@link org.eclipse.jface.viewers.ISelection} object.
      */
-    public void showViewer(IWorkbenchPart part, IStructuredSelection selection){
+    public void showViewer(Object part, IStructuredSelection selection){
         this.part = part;
 
         Object element = selection.getFirstElement();
+      //avoid widget is disposed exceptions
+        if (getViewer().getControl()==null || getViewer().getControl().isDisposed()){
+            return;
+        }
 
+        setPartName(createPartTitle(element));
         getViewer().setInput(element);
-
         showViewer();
     }
 
@@ -186,7 +185,7 @@ public abstract class AbstractCdmViewPart extends ViewPart implements ISelection
     }
 
     @Override
-    public  List<CdmBase> getRootEntities() {
+    public  List<? extends CdmBase> getRootEntities() {
         return Arrays.asList((CdmBase)getViewer().getInput());
     }
 
@@ -220,4 +219,13 @@ public abstract class AbstractCdmViewPart extends ViewPart implements ISelection
         // TODO Auto-generated method stub
         return null;
     }
+
+       protected String createPartTitle(Object selectedObject){
+           if(selectedObject!=null){
+               return getViewName()+": "+selectedObject; //$NON-NLS-1$
+           }
+        return getViewName();
+       }
+
+    protected abstract String getViewName();
 }