1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2015 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.navigation.navigator.operation;
|
11
|
|
12
|
import java.util.HashSet;
|
13
|
import java.util.Set;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.eclipse.core.runtime.IAdaptable;
|
17
|
import org.eclipse.core.runtime.IProgressMonitor;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
20
|
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
|
21
|
import eu.etaxonomy.cdm.api.service.UpdateResult;
|
22
|
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
|
23
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
24
|
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
|
25
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
26
|
import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
|
27
|
|
28
|
/**
|
29
|
* @author cmathew
|
30
|
* @date 22 Jun 2015
|
31
|
*
|
32
|
*/
|
33
|
public class RemotingDeleteTaxonNodeOperation extends RemotingCdmUpdateOperation {
|
34
|
|
35
|
private final static String LABEL = "Delete Taxon Node operation";
|
36
|
|
37
|
private final Set<ITaxonTreeNode> treeNodes;
|
38
|
private final TaxonDeletionConfigurator config;
|
39
|
|
40
|
/**
|
41
|
* @param label
|
42
|
* @param action
|
43
|
* @param source
|
44
|
* @param async
|
45
|
*/
|
46
|
public RemotingDeleteTaxonNodeOperation(Object source,
|
47
|
boolean async,
|
48
|
Set<ITaxonTreeNode> treeNodes,
|
49
|
TaxonDeletionConfigurator config) {
|
50
|
super(LABEL, Action.Delete, source, async);
|
51
|
this.treeNodes = treeNodes;
|
52
|
this.config = config;
|
53
|
}
|
54
|
|
55
|
/* (non-Javadoc)
|
56
|
* @see eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation#doUpdateExecute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
57
|
*/
|
58
|
@Override
|
59
|
protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
|
60
|
if(treeNodes.size() == 1) {
|
61
|
// when single node this is either a taxon or a classification
|
62
|
ITaxonTreeNode node = treeNodes.iterator().next();
|
63
|
if(node instanceof TaxonNode) {
|
64
|
return CdmApplicationState.getCurrentAppConfig().getTaxonNodeService().deleteTaxonNode(((TaxonNode)node).getUuid(), config);
|
65
|
} else if(node instanceof Classification) {
|
66
|
entityType = Classification.class;
|
67
|
return CdmApplicationState.getCurrentAppConfig().getClassificationService().delete(((Classification)node).getUuid());
|
68
|
}
|
69
|
} else {
|
70
|
// when list we assume all are taxon nodes
|
71
|
Set<UUID> treeNodeUuids = new HashSet<UUID>();
|
72
|
ITaxonTreeNode entity = null;
|
73
|
for(ITaxonTreeNode treeNode : treeNodes) {
|
74
|
if(entity == null) {
|
75
|
entity = treeNode;
|
76
|
}
|
77
|
treeNodeUuids.add(treeNode.getUuid());
|
78
|
}
|
79
|
|
80
|
return CdmApplicationState.getCurrentAppConfig().getTaxonNodeService().deleteTaxonNodes(treeNodeUuids, new TaxonDeletionConfigurator());
|
81
|
}
|
82
|
return null;
|
83
|
}
|
84
|
|
85
|
}
|