ref #7865 Change method signature for checking for dirty taxa editors
authorPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 10 Apr 2019 07:01:51 +0000 (09:01 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 10 Apr 2019 07:01:51 +0000 (09:01 +0200)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/MoveDescriptionElementsHandlerE4.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/MoveDescriptionToOtherTaxonHandlerE4.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/operation/MoveDescriptionToOtherTaxonOperation.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/SetPublishFlagForSubtreeHandlerE4.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/SetSecReferenceForSubtreeHandlerE4.java

index 8143cec48e01d35037e0207bbfc880800e38c1dc..63228443bde124056407a3c0ee53cf601e5e0690 100644 (file)
@@ -54,6 +54,7 @@ import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
+import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
 
 /**
  * Utility for the editor package
@@ -237,23 +238,22 @@ public class EditorUtil extends AbstractUtility {
         return dirtyParts;
     }
 
-    public static Collection<MPart> checkForTaxonChanges(UUID taxonUUID, EPartService partService ){
+    public static Collection<IE4SavablePart> checkForTaxonChanges(UUID taxonUUID, EPartService partService ){
         Collection<MPart> parts = partService.getParts();
-        Collection<MPart> dirtyParts = new HashSet();
+        Collection<IE4SavablePart> dirtyParts = new HashSet<>();
         //check if part is already opened
-        boolean isDirty = false;
         for (MPart part : parts) {
             if(part.getObject() instanceof TaxonNameEditorE4
                     && ((TaxonNameEditorE4) part.getObject()).getTaxon()!=null
                     && ((TaxonNameEditorE4) part.getObject()).getTaxon().getUuid().equals(taxonUUID)){
                 if (part.isDirty()){
-                    dirtyParts.add(part);
+                    dirtyParts.add((IE4SavablePart) part);
                 }
 
                 break;
             }else if (taxonUUID == null){
                 if (part.isDirty() && (part.getObject() instanceof TaxonNameEditorE4 || (part.getObject() instanceof BulkEditorE4 && ((BulkEditorE4)part.getObject()).getEditorInput() instanceof TaxonEditorInput))){
-                    dirtyParts.add(part);
+                    dirtyParts.add((IE4SavablePart) part);
                 }
             }
         }
index ec335b365d0e396e55f696877f5d0ddda256a6a6..aff3d4edf5f9bae8a9335acd4f7a3ef413990e5f 100644 (file)
@@ -19,6 +19,7 @@ import java.util.UUID;
 
 import javax.inject.Named;
 
+import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.e4.core.di.annotations.CanExecute;
 import org.eclipse.e4.core.di.annotations.Execute;
 import org.eclipse.e4.core.di.annotations.Optional;
@@ -50,13 +51,13 @@ import eu.etaxonomy.taxeditor.editor.l10n.Messages;
 import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.MoveDescriptionElementsOperation;
-import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
 import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
+import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
 
 
 /**
@@ -158,46 +159,19 @@ public class MoveDescriptionElementsHandlerE4 implements IPostOperationEnabled{
             }
             newAcceptedTaxonNodeUuid = newAcceptedTaxonNode.getUuid();
 
-            Collection<MPart> targetEditors = EditorUtil.checkForChanges(targetTaxon.getUuid(), partService);
-
-            if (targetEditors != null || this.editor.isDirty()){
-                boolean proceed = MessageDialog.openQuestion(null,
-                        Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES, Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES_MESSAGE);
-                if( targetEditors.iterator().hasNext() ){
-                    MPart part = targetEditors.iterator().next();
-                    if (proceed) {
-                        if (part != null){
-                            if (part.getElementId().equals("eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4")){
-                                TaxonNameEditorE4 targetEditor = (TaxonNameEditorE4) WorkbenchUtility.getE4WrappedPart(part);
-
-                                targetEditor.save(AbstractUtility.getMonitor());
-                            }
-                            if (editor.isDirty()){
-                                editor.save(AbstractUtility.getMonitor());
-                            }
-                        } else {
-                            return;
-                        }
-                    }
+            Collection<IE4SavablePart> targetEditors = EditorUtil.checkForTaxonChanges(targetTaxon.getUuid(), partService);
+
+            if (!targetEditors.isEmpty() || this.editor.isDirty()){
+                if(MessageDialog.openQuestion(null,Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES, Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES_MESSAGE)){
+                    this.editor.save(new NullProgressMonitor());
+                    targetEditors.forEach(editor->editor.save(new NullProgressMonitor()));
+                    return;
+                }
+                else{
+                    return;
                 }
             }
 
-//            if ((targetEditor != null && targetEditor.getElementId().equals("eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4")) || this.editor.isDirty()){
-//                boolean proceed = MessageDialog.openQuestion(null,
-//                        Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES, Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES_MESSAGE);
-//                if (proceed) {
-//                    if (targetEditor != null){
-//                        e4WrappedPart = WorkbenchUtility.getE4WrappedPart(targetEditor);
-//                        ((TaxonNameEditorE4)e4WrappedPart).save(AbstractUtility.getMonitor());
-//                    }
-//                    if (editor.isDirty()){
-//                        editor.save(AbstractUtility.getMonitor());
-//                    }
-//                } else {
-//                    return;
-//                }
-//            }
-
             String moveMessage = String.format(Messages.MoveDescriptionElementsHandler_ELEMENTS_MOVED, editor.getTaxon());
 
             AbstractPostTaxonOperation operation = new MoveDescriptionElementsOperation(
index d0568702af43d260452ebb0ac038aefa0428a232..53807c373ce4b52b05914d81049d53d016bcb66d 100644 (file)
@@ -12,6 +12,7 @@ import java.util.UUID;
 
 import javax.inject.Named;
 
+import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.e4.core.di.annotations.CanExecute;
 import org.eclipse.e4.core.di.annotations.Execute;
 import org.eclipse.e4.core.di.annotations.Optional;
@@ -45,6 +46,7 @@ import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
 import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
+import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
 
 /**
  *
@@ -122,26 +124,16 @@ public class MoveDescriptionToOtherTaxonHandlerE4 implements IPostOperationEnabl
         newAcceptedTaxonNodeUuid = newAcceptedTaxonNode.getUuid();
         newAcceptedTaxonUuid = newAcceptedTaxonNode.getTaxon().getUuid();
 
-        Collection<MPart> targetEditors = EditorUtil.checkForChanges(newAcceptedTaxonUuid, partService);
-
-        if (targetEditors != null || this.editor.isDirty()){
-            boolean proceed = MessageDialog.openQuestion(null,
-                    Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES, Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES_MESSAGE);
-            if( targetEditors.iterator().hasNext() ){
-                MPart part = targetEditors.iterator().next();
-                if (proceed) {
-                    if (part != null){
-                        if (part.getElementId().equals("eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4")){
-                            TaxonNameEditorE4 targetEditor = (TaxonNameEditorE4) WorkbenchUtility.getE4WrappedPart(part);
-                            targetEditor.save(AbstractUtility.getMonitor());
-                        }
-                        if (editor.isDirty()){
-                            editor.save(AbstractUtility.getMonitor());
-                        }
-                    } else {
-                        return;
-                    }
-                }
+        Collection<IE4SavablePart> targetEditors = EditorUtil.checkForTaxonChanges(newAcceptedTaxonUuid, partService);
+
+        if (!targetEditors.isEmpty() || this.editor.isDirty()){
+            if(MessageDialog.openQuestion(null,Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES, Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES_MESSAGE)) {
+                this.editor.save(new NullProgressMonitor());
+                targetEditors.forEach(editor->editor.save(new NullProgressMonitor()));
+                return;
+            }
+            else{
+                return;
             }
         }
 
index 805b9afd885c8a6730338b5349ee7c77ab58f105..82345999406b3cbcfdf00239ad8aa08cc70cf757 100644 (file)
@@ -9,7 +9,6 @@
 
 package eu.etaxonomy.taxeditor.editor.view.descriptive.operation;
 
-import org.apache.commons.lang.StringUtils;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.commands.operations.IUndoContext;
 import org.eclipse.core.runtime.IAdaptable;
@@ -18,12 +17,8 @@ import org.eclipse.core.runtime.IStatus;
 
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.api.service.IDescriptionService;
-import eu.etaxonomy.cdm.model.common.Annotation;
-import eu.etaxonomy.cdm.model.common.AnnotationType;
-import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.model.description.TaxonDescription;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
-import eu.etaxonomy.taxeditor.editor.l10n.Messages;
 import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
@@ -72,21 +67,8 @@ public class MoveDescriptionToOtherTaxonOperation extends
        @Override
        public IStatus execute(IProgressMonitor monitor, IAdaptable info)
                        throws ExecutionException {
-
                monitor.worked(20);
                bind();
-
-               String moveMessage = String.format(Messages.MoveDescriptionToOtherTaxonOperation_MOVED_FROM, description.getTaxon());
-               if(description.isProtectedTitleCache()){
-                       String separator = ""; //$NON-NLS-1$
-                       if(!StringUtils.isBlank(description.getTitleCache())){
-                               separator = " - "; //$NON-NLS-1$
-                       }
-                       description.setTitleCache(description.getTitleCache() + separator + moveMessage, true);
-               }
-               Annotation annotation = Annotation.NewInstance(moveMessage, Language.getDefaultLanguage());
-               annotation.setAnnotationType(AnnotationType.TECHNICAL());
-               description.addAnnotation(annotation);
                CdmStore.getService(IDescriptionService.class).moveTaxonDescription(description.getUuid(), newAcceptedTaxonNode.getTaxon().getUuid());
                monitor.worked(40);
 
index 99f189034cd3ca65f055bbafbca935897bbb2407..d9d0a53a5d5af64a2f43221dc57734d823562ea6 100755 (executable)
@@ -32,15 +32,13 @@ import org.eclipse.swt.widgets.Shell;
 import eu.etaxonomy.cdm.api.service.config.PublishForSubtreeConfigurator;
 import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
-import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
-import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
 import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
 import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
 import eu.etaxonomy.taxeditor.navigation.navigator.operation.SetPublishForSubtreeOperation;
 import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
 import eu.etaxonomy.taxeditor.ui.dialog.configurator.SetPublishForSubtreeWizard;
-import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
+import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
 
 /**
  * @author k.luther
@@ -89,7 +87,7 @@ public class SetPublishFlagForSubtreeHandlerE4 extends RemotingCdmHandlerE4 {
                     "unknown", //$NON-NLS-1$
                     TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
         }
-        Collection<MPart> dirtyParts = EditorUtil.checkForTaxonChanges(null, partService);
+        Collection<IE4SavablePart> dirtyParts = EditorUtil.checkForTaxonChanges(null, partService);
 
         if (dirtyParts != null && !dirtyParts.isEmpty()){
             String[] buttonLables = {YES, NO,CANCEL};
@@ -103,21 +101,13 @@ public class SetPublishFlagForSubtreeHandlerE4 extends RemotingCdmHandlerE4 {
                 return Status.CANCEL_STATUS;
             }
 
-            Iterator<MPart> partIterator = dirtyParts.iterator();
+            Iterator<IE4SavablePart> partIterator = dirtyParts.iterator();
             while( partIterator.hasNext() ){
-                MPart part = partIterator.next();
+                IE4SavablePart part = partIterator.next();
                 if (proceed) {
                     if (part != null){
-                        if (part.getElementId().equals("eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4")){ //$NON-NLS-1$
-                            TaxonNameEditorE4 targetEditor = (TaxonNameEditorE4) WorkbenchUtility.getE4WrappedPart(part);
-                            targetEditor.save(new NullProgressMonitor());
-                        }else if (part.getElementId().equals("bulkeditor.editor")){ //$NON-NLS-1$
-                            BulkEditorE4 targetEditor = (BulkEditorE4) WorkbenchUtility.getE4WrappedPart(part);
-                            targetEditor.save(new NullProgressMonitor());
-                        }
-
+                        part.save(new NullProgressMonitor());
                     }
-
                 }
             }
         }
index 62e916aa839cbb99cb8b46b53d2748705526dd12..2163cf878505f968bf63c4c6fffff40776b8da70 100755 (executable)
@@ -31,15 +31,13 @@ import org.eclipse.swt.widgets.Shell;
 import eu.etaxonomy.cdm.api.service.config.SecundumForSubtreeConfigurator;
 import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
-import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
-import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
 import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
 import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
 import eu.etaxonomy.taxeditor.navigation.navigator.operation.SetSecundumForSubtreeOperation;
 import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
 import eu.etaxonomy.taxeditor.ui.dialog.configurator.SetSecundumForSubtreeConfigurationWizard;
-import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
+import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
 
 /**
  * @author k.luther
@@ -84,7 +82,7 @@ public class SetSecReferenceForSubtreeHandlerE4 extends RemotingCdmHandlerE4 {
                     "unknown", //$NON-NLS-1$
                     TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
         }
-        Collection<MPart> dirtyParts = EditorUtil.checkForTaxonChanges(null, partService);
+        Collection<IE4SavablePart> dirtyParts = EditorUtil.checkForTaxonChanges(null, partService);
 
         if (dirtyParts != null && !dirtyParts.isEmpty()){
             String[] buttonLables = {Messages.YES, Messages.NO,Messages.TreeNodeDropAdapter_CANCEL};
@@ -98,21 +96,13 @@ public class SetSecReferenceForSubtreeHandlerE4 extends RemotingCdmHandlerE4 {
                 return Status.CANCEL_STATUS;
             }
 
-            Iterator<MPart> partIterator = dirtyParts.iterator();
+            Iterator<IE4SavablePart> partIterator = dirtyParts.iterator();
             while( partIterator.hasNext() ){
-                MPart part = partIterator.next();
+                IE4SavablePart part = partIterator.next();
                 if (proceed) {
                     if (part != null){
-                        if (part.getElementId().equals("eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4")){ //$NON-NLS-1$
-                            TaxonNameEditorE4 targetEditor = (TaxonNameEditorE4) WorkbenchUtility.getE4WrappedPart(part);
-                            targetEditor.save(new NullProgressMonitor());
-                        }else if (part.getElementId().equals("bulkeditor.editor")){ //$NON-NLS-1$
-                            BulkEditorE4 targetEditor = (BulkEditorE4) WorkbenchUtility.getE4WrappedPart(part);
-                            targetEditor.save(new NullProgressMonitor());
-                        }
-
+                        part.save(new NullProgressMonitor());
                     }
-
                 }
             }
         }