Project

General

Profile

Download (2.25 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2016 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.editor.key.polytomous.operation;
10

    
11
import java.util.ArrayList;
12
import java.util.List;
13

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

    
17
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
18
import eu.etaxonomy.cdm.model.common.CdmBase;
19
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
20
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
21
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
22
import eu.etaxonomy.taxeditor.operation.RemotingCdmDefaultOperation;
23

    
24
/**
25
 * @author k.luther
26
 * @date 17.11.2016
27
 *
28
 */
29
public class InsertPolytomousKeyNodeOperation extends RemotingCdmDefaultOperation  {
30

    
31
    private final PolytomousKeyNode parentNode;
32

    
33
    private final static String LABEL = Messages.InsertPolytomousKeyNodeOperation_INSERT_KEY;
34

    
35
    /**
36
    *
37
    */
38
   protected IPostOperationEnabled postOperationEnabled;
39

    
40
    /**
41
     * @param label
42
     * @param action
43
     * @param source
44
     * @param async
45
     */
46
    public InsertPolytomousKeyNodeOperation(Object source,
47
            boolean async,
48
            PolytomousKeyNode parentNode, IPostOperationEnabled postOperationEnabled) {
49
        super(LABEL, Action.Create, source, async);
50
        this.parentNode = parentNode;
51
        this.postOperationEnabled = postOperationEnabled;
52
    }
53

    
54
    /**
55
     * {@inheritDoc}
56
     */
57
    @Override
58
    protected CdmBase doSimpleExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
59
        PolytomousKeyNode childNode = PolytomousKeyNode.NewInstance();
60
        List<PolytomousKeyNode> newChildren = parentNode.getChildren();
61
        List<PolytomousKeyNode> copy = new ArrayList<PolytomousKeyNode>();
62
        for (PolytomousKeyNode node: newChildren) {
63
            copy.add(node);
64
        }
65
        parentNode.addChild(childNode, 0);
66
        for (PolytomousKeyNode node: copy){
67
           childNode.addChild(node);
68
        }
69
        this.postOperationEnabled.postOperation(childNode);
70
        return childNode;
71
    }
72

    
73
}
(3-3/5)