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