ref #6905, #6597 Move part initialisation to sub classes
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / e4 / AbstractCdmEditorPartE4.java
index a066de4c3b716f19e1b861db0c20049715f8246d..35467c5fc0e38bf22e80a892959e86431ddd3ee2 100644 (file)
@@ -8,12 +8,12 @@
 */
 package eu.etaxonomy.taxeditor.view.e4;
 
-import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 
+import org.eclipse.e4.ui.di.PersistState;
 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
 import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.swt.widgets.Composite;
+import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.ui.IEditorPart;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
@@ -21,23 +21,20 @@ import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
+import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
+import eu.etaxonomy.taxeditor.workbench.part.ISelectionElementEditingPart;
 
 /**
  * @author pplitzner
  * @since Aug 10, 2017
  *
  */
-public abstract class AbstractCdmEditorPartE4 implements IConversationEnabled, IDirtyMarkable{
+public abstract class AbstractCdmEditorPartE4 implements IConversationEnabled, IDirtyMarkable, ISelectionElementEditingPart{
 
     protected AbstractCdmDataViewerE4 viewer;
 
     protected MPart selectionProvidingPart;
 
-    @PostConstruct
-    public void create(Composite parent) {
-        viewer = createViewer(parent);
-    }
-
     /** {@inheritDoc} */
     @Override
     public void changed(Object object) {
@@ -55,7 +52,7 @@ public abstract class AbstractCdmEditorPartE4 implements IConversationEnabled, I
         }
     }
 
-    public void showViewer(IStructuredSelection selection, MPart activePart){
+    protected void showViewer(IStructuredSelection selection, MPart activePart){
         if(viewer!=null){
             Object element = selection.getFirstElement();
             if(selection.getFirstElement()!=null){
@@ -65,7 +62,30 @@ public abstract class AbstractCdmEditorPartE4 implements IConversationEnabled, I
         }
     }
 
-    public void showEmptyPage() {
+    protected Object createPartObject(MPart activePart) {
+        Object partObject = activePart;
+        Object wrappedPart = WorkbenchUtility.getE4WrappedPart(activePart);
+        if(wrappedPart!=null){
+            partObject = wrappedPart;
+        }
+        return partObject;
+    }
+
+    protected IStructuredSelection createSelection(Object selection) {
+        if(selection==null){
+            return null;
+        }
+        IStructuredSelection structuredSelection;
+        if(!(selection instanceof IStructuredSelection)){
+            structuredSelection = new StructuredSelection(selection);
+        }
+        else{
+            structuredSelection = (IStructuredSelection) selection;
+        }
+        return structuredSelection;
+    }
+
+    protected void showEmptyPage() {
         if(viewer!=null){
             viewer.showEmptyPage();
         }
@@ -83,8 +103,21 @@ public abstract class AbstractCdmEditorPartE4 implements IConversationEnabled, I
         return null;
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Object getSelectionProvidingPart() {
+        return selectionProvidingPart;
+    }
+
     @PreDestroy
-    public void dispose() {
+    private void dispose() {
+    }
+
+    @PersistState
+    private void persistState(){
+
     }
 
     /**
@@ -103,5 +136,4 @@ public abstract class AbstractCdmEditorPartE4 implements IConversationEnabled, I
 
     protected abstract String getViewName();
 
-    protected abstract AbstractCdmDataViewerE4 createViewer(Composite parent);
 }