From: k.luther Date: Mon, 29 Feb 2016 12:10:03 +0000 (+0100) Subject: fix #5289 X-Git-Tag: 4.0.0^2~120 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/83a0646794568efa909ca3a18a608f49fd71dd89 fix #5289 --- diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/RemotingDeleteTaxonNodeHandler.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/RemotingDeleteTaxonNodeHandler.java index 53d23d823..015ab9960 100644 --- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/RemotingDeleteTaxonNodeHandler.java +++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/RemotingDeleteTaxonNodeHandler.java @@ -1,153 +1,161 @@ -// $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.navigation.navigator.handler; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.operations.AbstractOperation; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.TreeSelection; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.handlers.HandlerUtil; - -import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator; -import eu.etaxonomy.cdm.api.service.config.TaxonNodeDeletionConfigurator; -import eu.etaxonomy.cdm.api.service.config.NodeDeletionConfigurator.ChildHandling; -import eu.etaxonomy.cdm.model.taxon.Classification; -import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode; -import eu.etaxonomy.cdm.model.taxon.TaxonNode; -import eu.etaxonomy.taxeditor.editor.EditorUtil; -import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels; -import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingDeleteTaxonNodeOperation; -import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler; -import eu.etaxonomy.taxeditor.ui.dialog.deleteConfigurator.DeleteConfiguratorDialog; - -/** - * @author cmathew - * @date 22 Jun 2015 - * - */ -public class RemotingDeleteTaxonNodeHandler extends RemotingCdmHandler { - - private TaxonDeletionConfigurator config; - private Set treeNodes; - - /** - * @param label - */ - public RemotingDeleteTaxonNodeHandler() { - super(TaxonNavigatorLabels.DELETE_TAXON_NODE_LABEL); - } - - /* (non-Javadoc) - * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent) - */ - @Override - public IStatus allowOperations(ExecutionEvent event) { - TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event); - - Iterator selectionIterator = selection.iterator(); - treeNodes = new HashSet(); - - while (selectionIterator.hasNext()){ - Object object = selectionIterator.next(); - if(object instanceof ITaxonTreeNode) { - treeNodes.add((ITaxonTreeNode) object); - } - } - boolean allEditorsClosed = true; - IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage(); - for (ITaxonTreeNode treeNode : treeNodes) { - if(treeNode instanceof TaxonNode) { - allEditorsClosed &= EditorUtil.closeObsoleteEditor((TaxonNode) treeNode, activePage); - } - } - if(!allEditorsClosed) { - return new Status(IStatus.WARNING, - "unknown", - TaxonNavigatorLabels.RELATED_EDITOR_NOT_CLOSED_MESSAGE); - } - - config = new TaxonDeletionConfigurator(); - - if (treeNodes.size() == 1 ){ - - ITaxonTreeNode treeNode = treeNodes.iterator().next(); - ITaxonTreeNode taxonNode = treeNode; - TaxonNodeDeletionConfigurator configNodes = new TaxonNodeDeletionConfigurator(); - if (taxonNode instanceof Classification && taxonNode.hasChildNodes()){ - if(!DeleteConfiguratorDialog.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 Status.CANCEL_STATUS; - } - } else if (taxonNode instanceof Classification && !taxonNode.hasChildNodes()){ - if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the classification?")){ - return Status.CANCEL_STATUS; - } - } else { - - if (taxonNode.hasChildNodes()){ - DeleteConfiguratorDialog dialog = new DeleteConfiguratorDialog( - 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); - config.setTaxonNodeConfig(configNodes); - } else if (result == 1){ - //move children - configNodes.setChildHandling(ChildHandling.MOVE_TO_PARENT); - config.setTaxonNodeConfig(configNodes); - } else if (result == 2){ - return Status.CANCEL_STATUS; - } - } else{ - if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(configNodes, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the selected node?")){ - return Status.CANCEL_STATUS; - } - config.setTaxonNodeConfig(configNodes); - } - } - } - return Status.OK_STATUS; - } - - /* (non-Javadoc) - * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent) - */ - @Override - public AbstractOperation prepareOperation(ExecutionEvent event) { - return new RemotingDeleteTaxonNodeOperation(event.getTrigger(), - false, - treeNodes, - config); - } - - /* (non-Javadoc) - * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete() - */ - @Override - public void onComplete() { - // TODO Auto-generated method stub - - } - -} +// $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.navigation.navigator.handler; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.operations.AbstractOperation; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.handlers.HandlerUtil; + +import eu.etaxonomy.cdm.api.application.CdmApplicationState; +import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator; +import eu.etaxonomy.cdm.api.service.config.TaxonNodeDeletionConfigurator; +import eu.etaxonomy.cdm.api.service.config.NodeDeletionConfigurator.ChildHandling; +import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; +import eu.etaxonomy.cdm.model.taxon.Classification; +import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; +import eu.etaxonomy.taxeditor.editor.EditorUtil; +import eu.etaxonomy.taxeditor.model.MessagingUtils; +import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels; +import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingDeleteTaxonNodeOperation; +import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler; +import eu.etaxonomy.taxeditor.ui.dialog.deleteConfigurator.DeleteConfiguratorDialog; + +/** + * @author cmathew + * @date 22 Jun 2015 + * + */ +public class RemotingDeleteTaxonNodeHandler extends RemotingCdmHandler { + + private TaxonDeletionConfigurator config; + private Set treeNodes; + + /** + * @param label + */ + public RemotingDeleteTaxonNodeHandler() { + super(TaxonNavigatorLabels.DELETE_TAXON_NODE_LABEL); + } + + /* (non-Javadoc) + * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent) + */ + @Override + public IStatus allowOperations(ExecutionEvent event) { + TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event); + + Iterator selectionIterator = selection.iterator(); + treeNodes = new HashSet(); + + while (selectionIterator.hasNext()){ + Object object = selectionIterator.next(); + if(object instanceof ITaxonTreeNode) { + treeNodes.add((ITaxonTreeNode) object); + } + } + boolean allEditorsClosed = true; + IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage(); + for (ITaxonTreeNode treeNode : treeNodes) { + if(treeNode instanceof TaxonNode) { + allEditorsClosed &= EditorUtil.closeObsoleteEditor((TaxonNode) treeNode, activePage); + } + } + if(!allEditorsClosed) { + return new Status(IStatus.WARNING, + "unknown", + TaxonNavigatorLabels.RELATED_EDITOR_NOT_CLOSED_MESSAGE); + } + + config = new TaxonDeletionConfigurator(); + + if (treeNodes.size() == 1 ){ + ITaxonTreeNode treeNode = treeNodes.iterator().next(); + ITaxonTreeNode taxonNode = treeNode; + taxonNode = CdmApplicationState.getCurrentAppConfig().getTaxonNodeService().load(taxonNode.getUuid()); + if (taxonNode == null){ + MessagingUtils.informationDialog("Node already deleted", "The taxon node was already deleted. Please reopen the taxon navigator to refresh the view."); + return Status.CANCEL_STATUS; + + } + TaxonNodeDeletionConfigurator configNodes = new TaxonNodeDeletionConfigurator(); + if (taxonNode instanceof Classification && taxonNode.hasChildNodes()){ + if(!DeleteConfiguratorDialog.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 Status.CANCEL_STATUS; + } + } else if (taxonNode instanceof Classification && !taxonNode.hasChildNodes()){ + if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the classification?")){ + return Status.CANCEL_STATUS; + } + } else { + + if (taxonNode.hasChildNodes()){ + DeleteConfiguratorDialog dialog = new DeleteConfiguratorDialog( + 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); + config.setTaxonNodeConfig(configNodes); + } else if (result == 1){ + //move children + configNodes.setChildHandling(ChildHandling.MOVE_TO_PARENT); + config.setTaxonNodeConfig(configNodes); + } else if (result == 2){ + return Status.CANCEL_STATUS; + } + } else{ + if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(configNodes, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the selected node?")){ + return Status.CANCEL_STATUS; + } + config.setTaxonNodeConfig(configNodes); + } + } + } + return Status.OK_STATUS; + } + + /* (non-Javadoc) + * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent) + */ + @Override + public AbstractOperation prepareOperation(ExecutionEvent event) { + return new RemotingDeleteTaxonNodeOperation(event.getTrigger(), + false, + treeNodes, + config); + } + + /* (non-Javadoc) + * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete() + */ + @Override + public void onComplete() { + // TODO Auto-generated method stub + + } + +}