commit e9a587e77f574b72800b16b53a07d3ca4066d2da
Author: Patric Plitzner <p.plitzner@bgbm.org>
Date:   Mon Feb 16 13:57:01 2015 +0000

     - added configurator settings to taxon deletion dialog

diff --git a/.gitattributes b/.gitattributes
index 95a3ad7ce..dc32f59a7 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1410,6 +1410,8 @@ eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/bar/Authent
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/EnumComboElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/TermComboElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/DefaultLanguageDialog.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/DeleteConfiguratorDialog.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/DeleteTaxonConfiguratorDialog.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/LoginDialog.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/UriDialog.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/AbstractFilteredCdmEnumSelectionDialog.java -text
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/DeleteHandler.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/DeleteHandler.java
index cf7ae81e4..d492be604 100644
--- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/DeleteHandler.java
+++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/DeleteHandler.java
@@ -17,7 +17,6 @@ import java.util.Set;
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.IHandler;
 import org.eclipse.core.commands.common.NotDefinedException;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.TreeSelection;
@@ -34,13 +33,15 @@ import eu.etaxonomy.cdm.model.common.ITreeNode;
 import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
-import eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonNodeDaoHibernateImpl;
 import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
 import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
 import eu.etaxonomy.taxeditor.navigation.navigator.operation.DeleteOperation;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
+import eu.etaxonomy.taxeditor.ui.dialog.DeleteConfiguratorDialog;
+import eu.etaxonomy.taxeditor.ui.dialog.DeleteTaxonConfiguratorDialog;
 
 /**
  * <p>DeleteTreeNodeHandler class.</p>
@@ -49,7 +50,7 @@ import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
  * @created 06.04.2009
  * @version 1.0
  */
-public class DeleteHandler extends AbstractHandler implements IHandler{
+public class DeleteHandler extends AbstractHandler{
 
 	protected IWorkbenchPage activePage;
 	protected TaxonNavigator taxonNavigator;
@@ -64,11 +65,6 @@ public class DeleteHandler extends AbstractHandler implements IHandler{
 
 		TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
 
-		String plural = selection.size() > 1 ? "s" : "";
-		// Prompt user for confirmation
-		
-		
-
 		Iterator selectionIterator = selection.iterator();
 		Set<ITaxonTreeNode> treeNodes = new HashSet<ITaxonTreeNode>();
 
@@ -85,28 +81,34 @@ public class DeleteHandler extends AbstractHandler implements IHandler{
 			}
 		}
 		AbstractPostOperation operation = null;
+		TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
 		if (treeNodes.size() == 1 ){
 			try {
-				
+
 				ITaxonTreeNode treeNode = treeNodes.iterator().next();
 				ITaxonTreeNode taxonNode =treeNode;
 				TaxonNodeDeletionConfigurator configNodes = new TaxonNodeDeletionConfigurator();
-				TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
 				if (taxonNode instanceof Classification && taxonNode.hasChildNodes()){
-					if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the classification? The tree has children, they will be deleted, too.")){
+					if(!DeleteTaxonConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the classification? The tree has children, they will be deleted, too.")){
 						return null;
 					}
 				} else if (taxonNode instanceof Classification && !taxonNode.hasChildNodes()){
-					if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the classification?")){
+					if(!DeleteTaxonConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the classification?")){
 						return null;
 					}
 				} else {
+
 					if (taxonNode.hasChildNodes()){
-						MessageDialog dialog = new MessageDialog(HandlerUtil.getActiveShell(event), "Confirm Deletion", null,
-							    "Do you really want to delete the selected node? It has childnodes, they will be deleted, too.", MessageDialog.WARNING, new String[] { "Delete all children",
-							  "Move children to parent node", "Skip" }, 0);
+                        DeleteConfiguratorDialog dialog = new DeleteTaxonConfiguratorDialog(
+                                config,
+                                HandlerUtil.getActiveShell(event),
+                                "Confirm Deletion",
+                                null,
+                                "Do you really want to delete the selected node? It has childnodes, they will be deleted, too.",
+                                MessageDialog.WARNING, new String[] { "Delete all children",
+                                        "Move children to parent node", "Skip" }, 0);
 						int result = dialog.open();
-						
+
 						if (result == 0){
 							//delete all children
 							configNodes.setChildHandling(ChildHandling.DELETE);
@@ -118,15 +120,15 @@ public class DeleteHandler extends AbstractHandler implements IHandler{
 						} else if (result == 2){
 							//skip
 							return null;
-							
+
 						}
 					}else{
-						if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the selected node?")){
+						if(!DeleteTaxonConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the selected node?")){
 							return null;
 						}
 					}
 				}
-	
+
 				if (allEditorsClosed){
 					/*if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the selected nodes?")){
 						return null;
@@ -134,27 +136,27 @@ public class DeleteHandler extends AbstractHandler implements IHandler{
 						operation = new DeleteOperation(
 								event.getCommand().getName(), NavigationUtil.getUndoContext(),
 								taxonNode, config, taxonNavigator, taxonNavigator);
-			
-						NavigationUtil.executeOperation(operation);
+
+						AbstractUtility.executeOperation(operation);
 						//}
 				}
-	
-		
-	
+
+
+
 			} catch (NotDefinedException e) {
 				MessagingUtils.warn(getClass(), "Command name not set");
 			}
 		} else{
 			try{
-				if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the selected nodes?")){
+				if(!DeleteTaxonConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the selected nodes?")){
 					return null;
 				}
 				if (allEditorsClosed){
 					operation = new DeleteOperation(
 							event.getCommand().getName(), NavigationUtil.getUndoContext(),
 							treeNodes, new TaxonDeletionConfigurator(), taxonNavigator, taxonNavigator);
-		
-					NavigationUtil.executeOperation(operation);
+
+					AbstractUtility.executeOperation(operation);
 				}
 			}catch (NotDefinedException e) {
 				MessagingUtils.warn(getClass(), "Command name not set");
@@ -168,8 +170,8 @@ public class DeleteHandler extends AbstractHandler implements IHandler{
 		for (IEditorReference ref : activePage.getEditorReferences()) {
 			try {
 				String treeIndex = ((ITreeNode)taxonNode).treeIndex();
-				
-				
+
+
 				IEditorInput input = ref.getEditorInput();
 				if (input instanceof TaxonEditorInput) {
 					TaxonNode node = ((TaxonEditorInput) input).getTaxonNode();
@@ -177,7 +179,7 @@ public class DeleteHandler extends AbstractHandler implements IHandler{
 					if( ((ITreeNode) node).treeIndex().startsWith(treeIndex)){
 					//if (taxonNode.equals(node)) {
 						result &= activePage.closeEditor(ref.getEditor(false), true);
-						
+
 					}
 				}
 			} catch (PartInitException e) {
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/DeleteConfiguratorDialog.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/DeleteConfiguratorDialog.java
new file mode 100644
index 000000000..843ff14fb
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/DeleteConfiguratorDialog.java
@@ -0,0 +1,86 @@
+// $Id$
+/**
+* Copyright (C) 2015 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.ui.dialog;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+
+import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
+
+/**
+ * Abstract subclass of MessageDialog providing the functionality to configure
+ * a {@link DeleteConfiguratorBase}
+ * @author pplitzner
+ * @date Jan 28, 2015
+ *
+ */
+public abstract class DeleteConfiguratorDialog extends MessageDialog implements Listener{
+
+    public DeleteConfiguratorDialog(Shell parentShell, String dialogTitle,
+            Image dialogTitleImage, String dialogMessage, int dialogImageType, String[] dialogButtonLabels, int defaultIndex) {
+        super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, defaultIndex);
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+     */
+    @Override
+    protected Control createDialogArea(Composite parent) {
+        Composite composite = (Composite) super.createDialogArea(parent);
+
+        createCheckBoxes(composite);
+
+        return composite;
+    }
+
+    protected abstract void createCheckBoxes(Composite parent);
+
+    /**
+     * @param kind
+     * @return
+     */
+    static String[] getButtonLabels(int kind) {
+        String[] dialogButtonLabels;
+        switch (kind) {
+        case ERROR:
+        case INFORMATION:
+        case WARNING: {
+            dialogButtonLabels = new String[] { IDialogConstants.OK_LABEL };
+            break;
+        }
+        case CONFIRM: {
+            dialogButtonLabels = new String[] { IDialogConstants.OK_LABEL,
+                    IDialogConstants.CANCEL_LABEL };
+            break;
+        }
+        case QUESTION: {
+            dialogButtonLabels = new String[] { IDialogConstants.YES_LABEL,
+                    IDialogConstants.NO_LABEL };
+            break;
+        }
+        case QUESTION_WITH_CANCEL: {
+            dialogButtonLabels = new String[] { IDialogConstants.YES_LABEL,
+                    IDialogConstants.NO_LABEL,
+                    IDialogConstants.CANCEL_LABEL };
+            break;
+        }
+        default: {
+            throw new IllegalArgumentException(
+                    "Illegal value for kind in MessageDialog.open()"); //$NON-NLS-1$
+        }
+        }
+        return dialogButtonLabels;
+    }
+}
\ No newline at end of file
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/DeleteTaxonConfiguratorDialog.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/DeleteTaxonConfiguratorDialog.java
new file mode 100644
index 000000000..e7a822cf5
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/DeleteTaxonConfiguratorDialog.java
@@ -0,0 +1,77 @@
+// $Id$
+/**
+* Copyright (C) 2015 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.ui.dialog;
+
+import org.apache.log4j.Logger;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Shell;
+
+import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
+
+/**
+ * @author pplitzner
+ * @date Jan 28, 2015
+ *
+ */
+public class DeleteTaxonConfiguratorDialog extends DeleteConfiguratorDialog {
+
+    @SuppressWarnings("unused")
+    private final Logger logger = Logger.getLogger(DeleteTaxonConfiguratorDialog.class);
+
+    private final TaxonDeletionConfigurator configurator;
+    private Button btnDeleteName;
+
+    /**
+     * @param configurator
+     * @param parentShell
+     * @param dialogTitle
+     * @param dialogTitleImage
+     * @param dialogMessage
+     * @param dialogImageType
+     * @param dialogButtonLabels
+     * @param defaultIndex
+     */
+    public DeleteTaxonConfiguratorDialog(TaxonDeletionConfigurator configurator, Shell parentShell, String dialogTitle,
+            Image dialogTitleImage, String dialogMessage,int dialogImageType, String[] dialogButtonLabels, int defaultIndex) {
+        super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, defaultIndex);
+        this.configurator = configurator;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
+     */
+    @Override
+    public void handleEvent(Event event) {
+        if(event.widget==btnDeleteName){
+            configurator.setDeleteNameIfPossible(btnDeleteName.getSelection());
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.ui.dialog.DeleteConfiguratorDialog#createCheckBoxes()
+     */
+    @Override
+    protected void createCheckBoxes(Composite parent) {
+        btnDeleteName = new Button(parent, SWT.CHECK);
+        btnDeleteName.setText("Delete taxon name if possible");
+        btnDeleteName.addListener(SWT.Selection, this);
+        btnDeleteName.setSelection(configurator.isDeleteNameIfPossible());
+    }
+
+    public static boolean openConfirmWithConfigurator(TaxonDeletionConfigurator configurator, Shell parent, String title, String message) {
+        DeleteTaxonConfiguratorDialog dialog = new DeleteTaxonConfiguratorDialog(configurator, parent, title, getDefaultImage(), message, QUESTION, getButtonLabels(QUESTION), 0);
+        return dialog.open() == 0;
+    }
+
+}
