ref #8233 Ask for saving before cloning type designation
authorPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 10 Apr 2019 15:31:23 +0000 (17:31 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 10 Apr 2019 15:31:44 +0000 (17:31 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/TypeDesignationSection.java

index 1e5d53b..2b67955 100644 (file)
@@ -50,6 +50,7 @@ import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
 import eu.etaxonomy.taxeditor.ui.section.name.operation.DeleteTypeDesignationOperation;
 import eu.etaxonomy.taxeditor.ui.section.name.type.CloneTypeWizard;
 import eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4;
+import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
 
 /**
  * @author n.hoffmann
@@ -71,9 +72,15 @@ public class TypeDesignationSection extends AbstractEntityCollectionSection<Taxo
                    || getEntity().getTypeDesignations().stream().noneMatch(designation->designation instanceof SpecimenTypeDesignation)){
                return;
            }
-           Action addAction = new Action(Messages.TypeDesignationSection_CREATE_DUPLICATE, IAction.AS_PUSH_BUTTON){
+           Action cloneAction = new Action(Messages.TypeDesignationSection_CREATE_DUPLICATE, IAction.AS_PUSH_BUTTON){
             @Override
             public void run() {
+                DetailsPartE4 detailsView = AbstractUtility.getDetailsView(getFormFactory().getContext().get((EPartService.class)));
+                if(detailsView!=null
+                        && detailsView.getSelectionProvidingPart().getObject() instanceof IE4SavablePart
+                        && StoreUtil.promptCheckIsDirty(((IE4SavablePart)detailsView.getSelectionProvidingPart().getObject()))){
+                    return;
+                }
                 CloneTypeWizard wizard = new CloneTypeWizard(getEntity());
                 WizardDialog dialog = new WizardDialog(getShell(), wizard);
 
@@ -89,20 +96,20 @@ public class TypeDesignationSection extends AbstractEntityCollectionSection<Taxo
                         MessagingUtils.warningDialog(Messages.TypeDesignationSection_DUPLICATE_FAILED, this, result.getExceptions().toString());
                     }
                     StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
-                    internalUpdateSection(true);
+                    internalUpdateSection(false);
                 }
             }
         };
-        addAction.setImageDescriptor(new ImageDescriptor() {
+        cloneAction.setImageDescriptor(new ImageDescriptor() {
 
             @Override
             public ImageData getImageData() {
                 return ImageResources.getImage(ImageResources.COPY_ICON).getImageData();
             }
         });
-        addAction.setToolTipText(Messages.TypeDesignationSection_CREATE_DUPLICATE);
+        cloneAction.setToolTipText(Messages.TypeDesignationSection_CREATE_DUPLICATE);
 
-        toolBarManager.add(addAction);
+        toolBarManager.add(cloneAction);
        }
 
        @Override