set selection after facts creation
authorKatja Luther <k.luther@bgbm.org>
Mon, 29 Jun 2020 11:21:56 +0000 (13:21 +0200)
committerKatja Luther <k.luther@bgbm.org>
Mon, 29 Jun 2020 11:22:44 +0000 (13:22 +0200)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/FactualDataPartE4.java

index 450540c..723d166 100644 (file)
@@ -23,6 +23,7 @@ import org.eclipse.e4.core.di.annotations.Optional;
 import org.eclipse.e4.ui.di.UIEventTopic;
 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
 import org.eclipse.e4.ui.services.EMenuService;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.ITreeContentProvider;
 import org.eclipse.jface.viewers.StructuredSelection;
@@ -55,6 +56,7 @@ import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveViewerSorter;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.NameDescriptionFilter;
 import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4;
 import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
+import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
 import eu.etaxonomy.taxeditor.model.FeatureNodeContainerTree;
 import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
 import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
@@ -199,26 +201,21 @@ public class FactualDataPartE4 extends AbstractCdmEditorPartE4
         if (featureNodeContainerCache.isEmpty()){
 //            return;
         }
-//        if(object instanceof DescriptionElementBase){
-//            DescriptionElementBase descriptionElement = (DescriptionElementBase) object;
-//            DescriptionBase description = descriptionElement.getInDescription();
-////            FeatureNodeContainerTree containerTree = featureNodeContainerCache.get(description);
-//
-////            FeatureNodeContainer featureNodeContainer = containerTree.getFeatureNodeContainerForDescriptionElement(descriptionElement);
-////            ((AbstractTreeViewer) viewer).expandToLevel(featureNodeContainer, 1);
-//
-//        }
-
-
         viewer.refresh();
+        super.changed(object);
         ((TreeViewer) viewer).setExpandedElements(expandedObjects);
-
-        if(object != null){
+        if(object instanceof DescriptionElementBase){
+            DescriptionElementBase descriptionElement = (DescriptionElementBase) object;
+            DescriptionBase description = descriptionElement.getInDescription();
+            FeatureNodeContainerTree containerTree = featureNodeContainerCache.get(description);
+            FeatureNodeContainer featureNodeContainer = containerTree.getFeatureNodeContainerForDescriptionElement(descriptionElement);
+            ((AbstractTreeViewer) viewer).expandToLevel(featureNodeContainer, 2);
             StructuredSelection selection = new StructuredSelection(object);
             viewer.setSelection(selection, true);
         }
-//        selectionProvidingPart.setDirty(true);
-        super.changed(object);
+
+
+
     }
 
     @Inject
@@ -236,6 +233,22 @@ public class FactualDataPartE4 extends AbstractCdmEditorPartE4
 
     @Inject
     @Optional
+    private void updateView(@UIEventTopic(WorkbenchEventConstants.REFRESH_FACTS)Object element){
+
+        Object[] expandedObjects = ((TreeViewer)viewer).getExpandedElements();
+
+
+        viewer.refresh();
+        ((TreeViewer)viewer).collapseAll();
+        if (expandedObjects.length>0){
+            ((TreeViewer)viewer).setExpandedElements(expandedObjects);
+        }
+        ((TreeViewer)viewer).setExpandedState(element, true);
+
+    }
+
+    @Inject
+    @Optional
     private void updateView(@UIEventTopic(WorkbenchEventConstants.CURRENT_ACTIVE_EDITOR)ITaxonEditor editor){
         if(editor == null){
             featureNodeContainerCache.clear();