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.operation.RemotingCdmDefaultOperation;
|
21
|
|
22
|
/**
|
23
|
* @author k.luther
|
24
|
* @date 17.11.2016
|
25
|
*
|
26
|
*/
|
27
|
public class InsertPolytomousKeyNodeOperation extends RemotingCdmDefaultOperation {
|
28
|
|
29
|
private final PolytomousKeyNode parentNode;
|
30
|
|
31
|
private final static String LABEL = "Insert new polytomous key node";
|
32
|
|
33
|
/**
|
34
|
* @param label
|
35
|
* @param action
|
36
|
* @param source
|
37
|
* @param async
|
38
|
*/
|
39
|
public InsertPolytomousKeyNodeOperation(Object source,
|
40
|
boolean async,
|
41
|
PolytomousKeyNode parentNode) {
|
42
|
super(LABEL, Action.Create, source, async);
|
43
|
this.parentNode = parentNode;
|
44
|
}
|
45
|
|
46
|
/**
|
47
|
* {@inheritDoc}
|
48
|
*/
|
49
|
@Override
|
50
|
protected CdmBase doSimpleExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
|
51
|
PolytomousKeyNode childNode = PolytomousKeyNode.NewInstance();
|
52
|
List<PolytomousKeyNode> newChildren = parentNode.getChildren();
|
53
|
List<PolytomousKeyNode> copy = new ArrayList<PolytomousKeyNode>();
|
54
|
for (PolytomousKeyNode node: newChildren) {
|
55
|
copy.add(node);
|
56
|
}
|
57
|
parentNode.addChild(childNode, 0);
|
58
|
for (PolytomousKeyNode node: copy){
|
59
|
childNode.addChild(node);
|
60
|
}
|
61
|
|
62
|
return childNode;
|
63
|
}
|
64
|
|
65
|
}
|