Project

General

Profile

Download (3.18 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2015 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.navigation.navigator.operation;
10

    
11
import java.util.HashSet;
12
import java.util.Set;
13
import java.util.UUID;
14

    
15
import org.eclipse.core.runtime.IAdaptable;
16
import org.eclipse.core.runtime.IProgressMonitor;
17

    
18
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
19
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
20
import eu.etaxonomy.cdm.api.service.UpdateResult;
21
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
22
import eu.etaxonomy.cdm.model.taxon.Classification;
23
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
24
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
25
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
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 = Messages.RemotingDeleteTaxonNodeOperation_DELETE_OP;
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

    
61

    
62
        if(treeNodes.size() == 1) {
63
            // when single node this is either a taxon or a classification
64
            ITaxonTreeNode node = treeNodes.iterator().next();
65
            if(node instanceof TaxonNode) {
66
                return CdmApplicationState.getCurrentAppConfig().getTaxonNodeService().deleteTaxonNode(((TaxonNode)node).getUuid(), config);
67
            } else if(node instanceof Classification) {
68
                entityType = Classification.class;
69
                return CdmApplicationState.getCurrentAppConfig().getClassificationService().delete(((Classification)node).getUuid());
70
            }
71
        } else {
72
            // when list we assume all are taxon nodes
73
            Set<UUID> treeNodeUuids = new HashSet<UUID>();
74
            ITaxonTreeNode entity = null;
75
            for(ITaxonTreeNode treeNode : treeNodes) {
76
                if(entity == null) {
77
                    entity = treeNode;
78
                }
79
                treeNodeUuids.add(treeNode.getUuid());
80
            }
81

    
82
            return CdmApplicationState.getCurrentAppConfig().getTaxonNodeService().deleteTaxonNodes(treeNodeUuids, new TaxonDeletionConfigurator());
83
        }
84
        return null;
85
    }
86

    
87
}
(6-6/10)