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
|
|
17
|
import org.eclipse.core.commands.ExecutionException;
|
18
|
import org.eclipse.core.commands.operations.IUndoContext;
|
19
|
import org.eclipse.core.runtime.IAdaptable;
|
20
|
import org.eclipse.core.runtime.IProgressMonitor;
|
21
|
import org.eclipse.core.runtime.IStatus;
|
22
|
import org.eclipse.core.runtime.Status;
|
23
|
|
24
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
25
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
26
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
27
|
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
|
28
|
import eu.etaxonomy.cdm.model.taxon.IllegalAncestryException;
|
29
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
30
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
31
|
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
|
32
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
33
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
|
34
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
35
|
|
36
|
/**
|
37
|
* Change the taxonomic parent of a given taxon.
|
38
|
*
|
39
|
* @author n.hoffmann
|
40
|
* @created 16.01.2009
|
41
|
* @version 1.0
|
42
|
*/
|
43
|
public class MoveTaxonOperation extends AbstractPersistentPostOperation {
|
44
|
|
45
|
/**
|
46
|
* A reference to the new taxonomical parent.
|
47
|
*/
|
48
|
private final ITaxonTreeNode newParentTreeNode;
|
49
|
/**
|
50
|
* A reference to the former taxonomical parents
|
51
|
*/
|
52
|
private final Map<TaxonNode, ITaxonTreeNode> oldParentTreeNodes;
|
53
|
|
54
|
private final Set<TaxonNode> taxonNodes;
|
55
|
|
56
|
private final ICdmEntitySessionEnabled cdmEntitySessionEnabled;
|
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,
|
68
|
IUndoContext undoContext,
|
69
|
Set<TaxonNode> taxonNodes,
|
70
|
ITaxonTreeNode newParentTreeNode,
|
71
|
IPostOperationEnabled postOperationEnabled,
|
72
|
IConversationEnabled conversationEnabled,
|
73
|
ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
|
74
|
super(label, undoContext, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled);
|
75
|
|
76
|
this.taxonNodes = taxonNodes;
|
77
|
|
78
|
this.newParentTreeNode = newParentTreeNode;
|
79
|
|
80
|
// Save old parent ITaxonTreeNodes for undo
|
81
|
oldParentTreeNodes = new HashMap<TaxonNode, ITaxonTreeNode>();
|
82
|
for(TaxonNode taxonNode : taxonNodes){
|
83
|
this.oldParentTreeNodes.put(taxonNode, taxonNode.getParent());
|
84
|
}
|
85
|
|
86
|
this.cdmEntitySessionEnabled = cdmEntitySessionEnabled;
|
87
|
}
|
88
|
|
89
|
/* (non-Javadoc)
|
90
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
91
|
*/
|
92
|
/** {@inheritDoc} */
|
93
|
@Override
|
94
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
95
|
throws ExecutionException {
|
96
|
bind();
|
97
|
monitor.worked(20);
|
98
|
|
99
|
Set<CdmBase> affectedObjects = new HashSet<CdmBase>();
|
100
|
try {
|
101
|
for (TaxonNode taxonNode : taxonNodes){
|
102
|
TaxonNode newTaxonNode = CdmStore.getService( ITaxonNodeService.class).moveTaxonNode(taxonNode.getUuid(), newParentTreeNode.getUuid());
|
103
|
affectedObjects.add(newTaxonNode.getParent());
|
104
|
//FIXME:Remoting testing until UpdateResult is ready
|
105
|
affectedObjects.add(newTaxonNode.getParent().getParent());
|
106
|
cdmEntitySessionEnabled.getCdmEntitySession().update(newTaxonNode, affectedObjects);
|
107
|
monitor.worked(2);
|
108
|
}
|
109
|
|
110
|
|
111
|
|
112
|
} catch(IllegalAncestryException e) {
|
113
|
MessagingUtils.warningDialog("Illegal ancestry", this, e.getMessage());
|
114
|
}
|
115
|
monitor.worked(40);
|
116
|
|
117
|
return postExecute(null);
|
118
|
}
|
119
|
|
120
|
/* (non-Javadoc)
|
121
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
122
|
*/
|
123
|
/** {@inheritDoc} */
|
124
|
@Override
|
125
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
126
|
throws ExecutionException {
|
127
|
return execute(monitor, info);
|
128
|
}
|
129
|
|
130
|
/* (non-Javadoc)
|
131
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
132
|
*/
|
133
|
/** {@inheritDoc} */
|
134
|
@Override
|
135
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
136
|
throws ExecutionException {
|
137
|
MessagingUtils.warn(this.getClass(), "Not implemented yet.");
|
138
|
|
139
|
// iterate over oldParentTreeNodes, delete each TaxonNode from its actual parent and add to its former parent
|
140
|
|
141
|
return Status.OK_STATUS;
|
142
|
}
|
143
|
}
|