1
|
/**
|
2
|
* Copyright (C) 2007 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
|
|
10
|
package eu.etaxonomy.taxeditor.navigation.navigator.operation;
|
11
|
|
12
|
import java.util.HashMap;
|
13
|
import java.util.HashSet;
|
14
|
import java.util.Map;
|
15
|
import java.util.Set;
|
16
|
import java.util.UUID;
|
17
|
|
18
|
import org.eclipse.core.commands.ExecutionException;
|
19
|
import org.eclipse.core.commands.operations.IUndoContext;
|
20
|
import org.eclipse.core.runtime.IAdaptable;
|
21
|
import org.eclipse.core.runtime.IProgressMonitor;
|
22
|
import org.eclipse.core.runtime.IStatus;
|
23
|
import org.eclipse.core.runtime.Status;
|
24
|
|
25
|
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
|
26
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
27
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
28
|
import eu.etaxonomy.cdm.api.service.UpdateResult;
|
29
|
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
|
30
|
import eu.etaxonomy.cdm.model.taxon.IllegalAncestryException;
|
31
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
32
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
33
|
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
|
34
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
35
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
36
|
|
37
|
/**
|
38
|
* Change the taxonomic parent of a given taxon.
|
39
|
*
|
40
|
* @author n.hoffmann
|
41
|
* @created 16.01.2009
|
42
|
* @version 1.0
|
43
|
*/
|
44
|
public class MoveTaxonOperation extends AbstractPersistentPostOperation {
|
45
|
|
46
|
/**
|
47
|
* A reference to the new taxonomical parent.
|
48
|
*/
|
49
|
private ITaxonTreeNode newParentTreeNode;
|
50
|
/**
|
51
|
* A reference to the former taxonomical parents
|
52
|
*/
|
53
|
//private Map<TaxonNode, ITaxonTreeNode> oldParentTreeNodes;
|
54
|
|
55
|
private TaxonNode taxonNode;
|
56
|
private boolean moveToParentNode;
|
57
|
/**
|
58
|
* <p>Constructor for MoveTaxonOperation.</p>
|
59
|
*
|
60
|
* @param label a {@link java.lang.String} object.
|
61
|
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
|
62
|
* @param taxonNodes a {@link java.util.Set} object.
|
63
|
* @param newParentTreeNode a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
|
64
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
65
|
* @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
|
66
|
*/
|
67
|
public MoveTaxonOperation(String label, IUndoContext undoContext,
|
68
|
TaxonNode taxonNodeToMove, ITaxonTreeNode newParentTreeNode, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled, boolean moveToParentNode) {
|
69
|
super(label, undoContext, postOperationEnabled, conversationEnabled);
|
70
|
|
71
|
this.taxonNode = taxonNodeToMove;
|
72
|
/*for (TaxonNode node:taxonNodes){
|
73
|
this.taxonNodes.add(service.load(node.getUuid()));
|
74
|
}*/
|
75
|
|
76
|
this.newParentTreeNode = newParentTreeNode;
|
77
|
this.moveToParentNode = moveToParentNode;
|
78
|
// Save old parent ITaxonTreeNodes for undo
|
79
|
|
80
|
//this.parentNode = taxonNode.getParent();
|
81
|
}
|
82
|
|
83
|
/* (non-Javadoc)
|
84
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
85
|
*/
|
86
|
/** {@inheritDoc} */
|
87
|
@Override
|
88
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
89
|
throws ExecutionException {
|
90
|
bind();
|
91
|
monitor.worked(20);
|
92
|
|
93
|
UpdateResult result = CdmStore.getService(ITaxonNodeService.class).moveTaxonNode(this.taxonNode.getUuid(),newParentTreeNode.getUuid(), moveToParentNode);
|
94
|
// try {
|
95
|
// for (TaxonNode taxonNode : taxonNodes){
|
96
|
// TaxonNode newTaxonNode = newParentTreeNode.addChildNode(taxonNode,
|
97
|
// newParentTreeNode.getReference(), newParentTreeNode.getMicroReference());
|
98
|
// //taxonNodes.add(newTaxonNode);
|
99
|
//
|
100
|
// monitor.worked(2);
|
101
|
// }
|
102
|
// } catch(IllegalAncestryException e) {
|
103
|
// MessagingUtils.warningDialog("Illegal ancestry", this, e.getMessage());
|
104
|
// }
|
105
|
monitor.worked(40);
|
106
|
|
107
|
return postExecute(null);
|
108
|
}
|
109
|
|
110
|
/* (non-Javadoc)
|
111
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
112
|
*/
|
113
|
/** {@inheritDoc} */
|
114
|
@Override
|
115
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
116
|
throws ExecutionException {
|
117
|
return execute(monitor, info);
|
118
|
}
|
119
|
|
120
|
/* (non-Javadoc)
|
121
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
122
|
*/
|
123
|
/** {@inheritDoc} */
|
124
|
@Override
|
125
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
126
|
throws ExecutionException {
|
127
|
MessagingUtils.warn(this.getClass(), "Not implemented yet.");
|
128
|
|
129
|
// iterate over oldParentTreeNodes, delete each TaxonNode from its actual parent and add to its former parent
|
130
|
|
131
|
return Status.OK_STATUS;
|
132
|
}
|
133
|
}
|