ref #9337, #9287: show details of term and supplemental data of term node
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / e4 / details / DetailsPartE4.java
index 21a772fff4211a053c3decd9f1d353d1f5570fd2..cf8d5743931aec2c11237ef685ccc14d70cc18df 100644 (file)
@@ -11,14 +11,14 @@ package eu.etaxonomy.taxeditor.view.e4.details;
 
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
-import javax.inject.Named;
 
-import org.eclipse.e4.core.di.annotations.Optional;
+import org.eclipse.e4.core.contexts.ContextInjectionFactory;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.services.log.Logger;
 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
-import org.eclipse.e4.ui.services.IServiceConstants;
-import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.SWTException;
 import org.eclipse.swt.widgets.Composite;
 
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
@@ -27,7 +27,12 @@ import eu.etaxonomy.taxeditor.l10n.Messages;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
 import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
+import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
+import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
+import eu.etaxonomy.taxeditor.view.e4.supplementaldata.SupplementalDataPartE4;
 import eu.etaxonomy.taxeditor.workbench.part.ISelectionElementEditingPart;
 
 /**
@@ -35,37 +40,38 @@ import eu.etaxonomy.taxeditor.workbench.part.ISelectionElementEditingPart;
  * @date 18.07.2017
  *
  */
-public class DetailsPartE4 extends AbstractCdmEditorPartE4{
+public class DetailsPartE4 extends AbstractCdmEditorPartE4 implements IPartContentHasSupplementalData, IPartContentHasFactualData {
+       @Inject
+       private Logger logger;
 
-    private ISelectionChangedListener selectionChangedListener;
-
-    @Inject
-    private ESelectionService selService;
-
-    @Inject
+       @Inject
     public DetailsPartE4() {
     }
 
     @PostConstruct
-    public void create(Composite parent) {
-        viewer = new DetailsViewerE4(parent, this);
+    public void create(Composite parent, MPart thisPart, IEclipseContext context) {
+
+        this.thisPart = thisPart;
+
+        viewer = ContextInjectionFactory.make(DetailsViewerE4.class, context);
+        ((DetailsViewerE4)viewer).init(parent, this);
 
         // Propagate selection from viewer
         selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
         viewer.addSelectionChangedListener(selectionChangedListener);
     }
 
-    @Inject
-    @Optional
-    public void selectionChanged(
-            @Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
-            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
-            MPart thisPart){
-        if(activePart==thisPart){
+    @Override
+    public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
+        if (activePart==thisPart){
             return;
         }
 
         Object partObject = createPartObject(activePart);
+        if (partObject instanceof SupplementalDataPartE4 ) {
+            // do not show empty page
+            return;
+        }
 
         if(partObject instanceof IPartContentHasDetails){
             IStructuredSelection structuredSelection = createSelection(selection);
@@ -88,10 +94,16 @@ public class DetailsPartE4 extends AbstractCdmEditorPartE4{
                     return;
                 }
             }
+
+            //FIXME this is a temporary workaround to fix selection handling for supplemental data view
+            // Now the supp data view gets double selection from details view and name editor (see #7126)
+
+            viewer.setSelection(structuredSelection, false);
+
             showViewer(structuredSelection, activePart, viewer);
-            return;
-        }
-        else if(selectionProvidingPart!=null && selectionProvidingPart.isVisible()){
+
+
+
             return;
         }
         else{
@@ -100,13 +112,29 @@ public class DetailsPartE4 extends AbstractCdmEditorPartE4{
         }
     }
 
-//    protected void showEmptyPage() {
-//        super.showEmptyPage();
-//        if(viewer!=null){
-//            viewer.showEmptyPage();
-//        }
-//        selectionProvidingPart = null;
-//    }
+    public void refreshSelection(){
+        selectionChanged_internal(new StructuredSelection(this.viewer.getInput()), selectionProvidingPart, thisPart);
+    }
+
+    @Override
+    protected void showEmptyPage() {
+        super.showEmptyPage();
+        if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed() ){
+               try{
+                       ((DetailsViewerE4)viewer).destroySections();
+               }catch(SWTException e){
+                       if (PreferencesUtil.isShowUpWidgetIsDisposedMessages() && e.getMessage().equals("Widget is disposed")){
+                    MessagingUtils.errorDialog("Widget is disposed",
+                            null,
+                            MessagingUtils.WIDGET_IS_DISPOSED_MESSAGE,
+                            null,
+                            e,
+                            true);
+
+                }
+               }
+        }
+    }
 
     @Override
     protected String getViewName(){