ref #7065: refresh open nameEditors when using update subtree operations
authorKatja Luther <k.luther@bgbm.org>
Wed, 10 Jan 2018 09:21:59 +0000 (10:21 +0100)
committerKatja Luther <k.luther@bgbm.org>
Wed, 10 Jan 2018 09:21:59 +0000 (10:21 +0100)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/SetSecReferenceForSubtreeHandlerE4.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/SetSecundumForSubtreeOperation.java

index e47aafa50caa3366e2d2fb4a72e7f8d5be3b9c87..35566143f89158cf35bee52e6f12224205ae78e0 100644 (file)
@@ -124,12 +124,18 @@ public class EditorUtil extends AbstractUtility {
         Collection<MPart> parts = partService.getParts();
         //check if part is already opened
         for (MPart part : parts) {
+               if (part.getObject() instanceof TaxonNameEditorE4){
+                       System.out.println(((TaxonNameEditorE4) part.getObject()).getTaxon().getUuid() + " - " + ((TaxonNameEditorE4) part.getObject()).getTaxon().getTitleCache());
+                       System.out.println(input.getTaxon().getUuid() + " - " + input.getTaxon().getTitleCache());
+               }
             if(part.getObject() instanceof TaxonNameEditorE4
                     && ((TaxonNameEditorE4) part.getObject()).getTaxon()!=null
-                    && ((TaxonNameEditorE4) part.getObject()).getTaxon().equals(input.getTaxon())){
+                    && ((TaxonNameEditorE4) part.getObject()).getTaxon().getUuid().equals(input.getTaxon().getUuid())){
                 //close part to invoke refresh for new part
                 partService.hidePart(part);
-                break;
+                TaxonNameEditorE4 editor = (TaxonNameEditorE4) part.getObject();
+                editor.init(input);
+                return;
             }
         }
         MPart part = partService.createPart(NAME_EDITOR_ID);
@@ -330,4 +336,20 @@ public class EditorUtil extends AbstractUtility {
             }
         }
     }
+    
+    public static void updateEditor(TaxonNode taxonNode, EPartService partService, MApplication application){
+        String treeIndex = taxonNode.treeIndex();
+        Collection<MPart> parts = partService.getParts();
+        for (MPart part : parts) {
+            Object object = part.getObject();
+            if(object instanceof TaxonNameEditorE4){
+                TaxonNameEditorE4 taxonEditor = (TaxonNameEditorE4)object;
+                TaxonNode node = taxonEditor.getEditorInput().getTaxonNode();
+                if(node.treeIndex().startsWith(treeIndex)){
+                       TaxonEditorInputE4 input = TaxonEditorInputE4.NewInstanceFromTaxonBase(node.getTaxon().getUuid());
+                       taxonEditor.init(input);
+                }
+            }
+        }
+    }
 }
index 411be0878a9ed50a1754d85f30d60c4bbefcbf3b..c2a1d77ea24b71c457754df065993966f0f303f1 100755 (executable)
@@ -114,6 +114,7 @@ public class SetSecReferenceForSubtreeHandlerE4 extends RemotingCdmHandlerE4 {
                 new SetSecundumForSubtreeOperation(getTrigger(),
                         true,
                         taxonNode.getUuid(),
+                        partService, activePart, application,
                         configurator);
 
         return operation;
index 47a1f1b627fb574adfde1fd2353aa3a9ed7038b9..d65d1cd972d278f1e56283a3ab044f9cd5151f0f 100755 (executable)
@@ -8,8 +8,11 @@
 */
 package eu.etaxonomy.taxeditor.navigation.navigator.operation;
 
+import java.util.Set;
 import java.util.UUID;
 
+import javax.inject.Inject;
+
 import org.apache.log4j.Logger;
 import org.eclipse.core.runtime.Assert;
 import org.eclipse.core.runtime.IAdaptable;
@@ -17,7 +20,12 @@ import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.e4.ui.di.UISynchronize;
+import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.workbench.modeling.EPartService;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.progress.IProgressConstants;
 
 import eu.etaxonomy.cdm.api.application.CdmApplicationException;
@@ -27,6 +35,14 @@ import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
 import eu.etaxonomy.cdm.api.service.UpdateResult;
 import eu.etaxonomy.cdm.api.service.config.SecundumForSubtreeConfigurator;
 import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.taxon.Synonym;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
 import eu.etaxonomy.taxeditor.operation.IPostMoniteredOperationEnabled;
@@ -44,7 +60,12 @@ public class SetSecundumForSubtreeOperation extends RemotingCdmUpdateOperation i
             .getLogger(SetSecundumForSubtreeOperation.class);
     UUID parentUuid;
     SecundumForSubtreeConfigurator config;
-
+    EPartService partService;
+    MPart activePart;
+    MApplication application;
+    
+    @Inject 
+    UISynchronize sync;
 
     /**
      * @param label
@@ -55,13 +76,19 @@ public class SetSecundumForSubtreeOperation extends RemotingCdmUpdateOperation i
     public SetSecundumForSubtreeOperation(Object source,
             boolean async,
             UUID taxonNodeUuid,
+            EPartService partService,
+            MPart activePart,
+            MApplication application,
             SecundumForSubtreeConfigurator config) {
         super(LABEL, Action.Update, source, async);
         parentUuid = taxonNodeUuid;
         this.config = config;
         this.updateResult = new UpdateResult();
+        this.partService= partService;
+        this.activePart = activePart;
+        this.application = application;
     }
-
+   
     /**
      * {@inheritDoc}
      */
@@ -88,35 +115,48 @@ public class SetSecundumForSubtreeOperation extends RemotingCdmUpdateOperation i
         final Display display = Display.getDefault();
 
         Job job = new Job(Messages.SetSecundumForSubtreeOperation_SET_SEC_TASK) {
-
-
             @Override
             protected IStatus run(IProgressMonitor monitor) {
 
                try {
-//                     eu.etaxonomy.cdm.common.monitor.IProgressMonitor cdmMonitor =  CdmProgressMonitorAdapter.CreateMonitor(monitor);
-//                     config.setMonitor(cdmMonitor);
-                                       ITaxonNodeService taxonService = CdmApplicationState.getService(ITaxonNodeService.class);
-//                                     taxonService.setSecundumForSubtree(config.getSubtreeUuid(), config.getNewSecundum(), config.isIncludeAcceptedTaxa(), config.isIncludeSynonyms(), config.isOverwriteExistingAccepted(), config.isOverwriteExistingSynonyms(), config.isIncludeSharedTaxa(), config.isEmptySecundumDetail(), null);
-                                       updateResult = taxonService.setSecundumForSubtree(config);
-
-//                                     Display.getDefault().asyncExec(new Runnable() {
-//                        @Override
-//                        public void run() {
-//                            AbstractUtility.executeMoniteredOperation("Update: " + config.getClass().getSimpleName(),
-//                                    uuid,
-//                                    1000,
-//                                    false,
-//                                    SetSecundumForSubtreeOperation.this,
-//                                    null);
-//                        }
-//                     });
-
-               } catch (CdmApplicationException e) {
+                                       ITaxonNodeService taxonNodeService = CdmApplicationState.getService(ITaxonNodeService.class);
+                                       TaxonNode subtreeNode = taxonNodeService.load(config.getSubtreeUuid());
+                                       updateResult = taxonNodeService.setSecundumForSubtree(config);
+                                       
+                                       for (CdmBase object: updateResult.getUpdatedObjects()){
+                                               Taxon taxon = null;
+                                               TaxonNode node = null;
+                                               if (object instanceof Taxon){
+                                                       taxon = HibernateProxyHelper.deproxy(object, Taxon.class);
+                                                       node = taxon.getTaxonNode(subtreeNode.getClassification());
+                                                       
+                                               }else if (object instanceof Synonym){
+                                                       Synonym syn = HibernateProxyHelper.deproxy(object, Synonym.class);
+                                                       taxon = syn.getAcceptedTaxon();
+                                                       node = taxon.getTaxonNode(subtreeNode.getClassification());
+                                               }
+                                               
+                                               Display.getDefault().asyncExec(new Runnable() {
+                                                   public void run() {
+                                                       for (MPart part : partService.getParts()){
+                                                                       Object object = part.getObject();
+                                                                       if (object instanceof TaxonNameEditorE4){
+                                                                               Set<TaxonNode> nodes = ((TaxonNameEditorE4)object).getTaxon().getTaxonNodes();
+                                                                               for (TaxonNode node: nodes){
+                                                                                       if (node.treeIndex().startsWith(subtreeNode.treeIndex())){
+                                                                                               EditorUtil.updateEditor(node, partService, application);                                                                                   
+                                                                                       }
+                                                                                               
+                                                                               }
+                                                                       }
+                                                               } 
+                                                   }
+                                               });
+                                       }
+                       } catch (CdmApplicationException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                }
-//
                return Status.OK_STATUS;
 
             }