import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.swt.widgets.Shell;
-import eu.etaxonomy.cdm.api.application.CdmApplicationState;
import eu.etaxonomy.cdm.api.service.config.NodeDeletionConfigurator.ChildHandling;
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
import eu.etaxonomy.cdm.api.service.config.TaxonNodeDeletionConfigurator;
import eu.etaxonomy.cdm.model.taxon.Classification;
-import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
-import eu.etaxonomy.cdm.model.taxon.Synonym;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
import eu.etaxonomy.taxeditor.editor.EditorUtil;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
public class RemotingDeleteTaxonNodeHandlerE4 extends RemotingCdmHandlerE4 {
private TaxonDeletionConfigurator config;
- private Set<ITaxonTreeNode> treeNodes;
+ private Set<TaxonNodeDto> treeNodes;
+ private Set<TaxonNodeDto> classifications;
+
+ private Set<TaxonNode> taxonNodes;
+ private Set<Classification> classificationList;
public RemotingDeleteTaxonNodeHandlerE4() {
super(TaxonNavigatorLabels.DELETE_TAXON_NODE_LABEL);
MHandledMenuItem menuItem) {
Iterator<?> selectionIterator = selection.iterator();
- treeNodes = new HashSet<ITaxonTreeNode>();
+ treeNodes = new HashSet();
+ boolean containsNodeWithChildren = false;
+ boolean containsClassification = false;
+ boolean containsTaxonNodes = false;
+ classifications = new HashSet();
while (selectionIterator.hasNext()){
Object object = selectionIterator.next();
- if(object instanceof ITaxonTreeNode) {
- treeNodes.add((ITaxonTreeNode) object);
+ if (object instanceof TaxonNodeDto && ((TaxonNodeDto)object).getTaxonUuid() == null){
+ TaxonNodeDto dto = (TaxonNodeDto)object;
+ classifications.add(dto);
+ containsClassification = true;
+ }else if(object instanceof TaxonNodeDto) {
+ treeNodes.add((TaxonNodeDto) object);
}
}
- for (ITaxonTreeNode treeNode : treeNodes) {
- if(treeNode instanceof TaxonNode) {
- EditorUtil.closeObsoleteEditor((TaxonNode) treeNode, partService);
- }
+ for (TaxonNodeDto treeNode : treeNodes) {
+ EditorUtil.closeObsoleteEditor(treeNode, partService);
}
config = new TaxonDeletionConfigurator();
+ Iterator it = treeNodes.iterator();
- if (treeNodes.size() == 1 ){
- ITaxonTreeNode treeNode = treeNodes.iterator().next();
- ITaxonTreeNode taxonNode = treeNode;
- if (taxonNode instanceof TaxonNode && !((TaxonNode)taxonNode).hasTaxon()){
- taxonNode = CdmApplicationState.getCurrentAppConfig().getClassificationService().load(((TaxonNode)taxonNode).getClassification().getUuid());
- }else{
- taxonNode = CdmApplicationState.getCurrentAppConfig().getTaxonNodeService().load(taxonNode.getUuid());
- }
- treeNodes = new HashSet<ITaxonTreeNode>();
- treeNodes.add(taxonNode);
- if (taxonNode == null){
+ treeNodes = new HashSet();
+ while (it.hasNext()){
+ TaxonNodeDto treeNode = (TaxonNodeDto) it.next();
+
+ treeNodes.add(treeNode);
+ if (treeNode == null){
MessagingUtils.informationDialog(Messages.RemotingDeleteTaxonNodeHandler_NODE_DELETED, Messages.RemotingDeleteTaxonNodeHandler_NODE_DELETED_MESSAGE);
return Status.CANCEL_STATUS;
}
+ if (treeNode instanceof TaxonNodeDto){
+ containsTaxonNodes = true;
+ if (treeNode.getTaxonomicChildrenCount()>0){
+ containsNodeWithChildren = true;
+ }
+ }
+
+
+ }
+
+ for (TaxonNodeDto rootNode: classifications){
+
+ if (rootNode.getTaxonomicChildrenCount() > 0) {
+ containsNodeWithChildren = true;
+ }
+
+ }
TaxonNodeDeletionConfigurator configNodes = new TaxonNodeDeletionConfigurator();
- if (taxonNode instanceof Classification) {
+ if (containsClassification && !containsTaxonNodes) {
String message;
- if (taxonNode.hasChildNodes()) {
+ if (containsClassification && containsNodeWithChildren) {
message = DeleteHandlerE4.DO_YOU_REALLY_WANT_TO_DELETE_THE_CLASSIFICATION+DeleteHandlerE4.THE_TREE_HAS_CHILDREN_THEY_WILL_BE_DELETED_TOO;
} else {
message = DeleteHandlerE4.DO_YOU_REALLY_WANT_TO_DELETE_THE_CLASSIFICATION;
}
}
else {
+ String confirmMessage= treeNodes.size() == 1?DeleteHandlerE4.DO_YOU_REALLY_WANT_TO_DELETE_THE_SELECTED_NODE:DeleteHandlerE4.DO_YOU_REALLY_WANT_TO_DELETE_THE_SELECTED_NODE_S;
+ if (containsNodeWithChildren){
- if (taxonNode.hasChildNodes()){
- DeleteConfiguratorDialog dialog = new DeleteConfiguratorDialog(
+ DeleteConfiguratorDialog dialog = new DeleteConfiguratorDialog(
config,
shell,
DeleteHandlerE4.CONFIRM_DELETION,
null,
- DeleteHandlerE4.DO_YOU_REALLY_WANT_TO_DELETE_THE_SELECTED_NODE_S+DeleteHandlerE4.THERE_ARE_CHILDNODES_WHICH_WILL_BE_DELETED_TOO,
+ DeleteHandlerE4.DO_YOU_REALLY_WANT_TO_DELETE_THE_SELECTED_NODE+DeleteHandlerE4.THERE_ARE_CHILDNODES_WHICH_WILL_BE_DELETED_TOO,
MessageDialog.WARNING, new String[] { DeleteHandlerE4.DELETE_ALL_CHILDREN,
DeleteHandlerE4.MOVE_CHILDREN_TO_PARENT_NODE, DeleteHandlerE4.SKIP }, 0);
int result = dialog.open();
//move children
configNodes.setChildHandling(ChildHandling.MOVE_TO_PARENT);
config.setTaxonNodeConfig(configNodes);
- } else if (result == 2){
+ } else {
return Status.CANCEL_STATUS;
}
} else{
- if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(configNodes, shell, DeleteHandlerE4.CONFIRM_DELETION, DeleteHandlerE4.DO_YOU_REALLY_WANT_TO_DELETE_THE_SELECTED_NODE_S)){
+
+ DeleteConfiguratorDialog dialog = new DeleteConfiguratorDialog(
+ config,
+ shell,
+ DeleteHandlerE4.CONFIRM_DELETION,
+ null,
+ confirmMessage,
+ MessageDialog.WARNING, new String[] { DeleteHandlerE4.DELETE, DeleteHandlerE4.SKIP }, 0);
+ int result = dialog.open();
+ if (result == 0){
+ //delete all children
+ configNodes.setChildHandling(ChildHandling.DELETE);
+ config.setTaxonNodeConfig(configNodes);
+ } else {
return Status.CANCEL_STATUS;
}
- config.setTaxonNodeConfig(configNodes);
+// if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(configNodes, shell, DeleteHandlerE4.CONFIRM_DELETION, DeleteHandlerE4.DO_YOU_REALLY_WANT_TO_DELETE_THE_SELECTED_NODE_S)){
+// return Status.CANCEL_STATUS;
+// }
+// config.setTaxonNodeConfig(configNodes);
}
}
- }
+// }
return Status.OK_STATUS;
}
return new RemotingDeleteTaxonNodeOperation(getTrigger(),
false,
treeNodes,
+ classifications,
config);
}
@CanExecute
private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
boolean canExecute = false;
- canExecute = !selection.isEmpty() && !(selection.getFirstElement() instanceof Synonym);
+ Object selectionElement = selection.getFirstElement();
+
+ canExecute = (selectionElement instanceof TaxonNodeDto) ||
+ (selectionElement instanceof TaxonNode && ((TaxonNode)selectionElement).getTaxon() == null);
menuItem.setVisible(canExecute);
return canExecute;
}
@Override
public void onComplete() {
+
+// CdmApplicationState.getCurrentDataChangeService()
+// .fireChangeEvent(new CdmChangeEvent(Action.Delete, treeNodes, this), true);
}
/**