Project

General

Profile

Download (3.06 KB) Statistics
| Branch: | Tag: | Revision:
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
                return CdmApplicationState.getCurrentAppConfig().getClassificationService().delete(((Classification)node).getUuid());
67
            }
68
        } else {
69
            // when list we assume all are taxon nodes
70
            Set<UUID> treeNodeUuids = new HashSet<UUID>();
71
            ITaxonTreeNode entity = null;
72
            for(ITaxonTreeNode treeNode : treeNodes) {
73
                if(entity == null) {
74
                    entity = treeNode;
75
                }
76
                treeNodeUuids.add(treeNode.getUuid());
77
            }
78

    
79
            return CdmApplicationState.getCurrentAppConfig().getTaxonNodeService().deleteTaxonNodes(treeNodeUuids, new TaxonDeletionConfigurator());
80
        }
81
        return null;
82
    }
83

    
84
}
(7-7/9)