1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.editor.key.polytomous.operation;
|
5
|
|
6
|
import org.eclipse.core.commands.ExecutionException;
|
7
|
import org.eclipse.core.commands.operations.IUndoContext;
|
8
|
import org.eclipse.core.runtime.IAdaptable;
|
9
|
import org.eclipse.core.runtime.IProgressMonitor;
|
10
|
import org.eclipse.core.runtime.IStatus;
|
11
|
|
12
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
13
|
import eu.etaxonomy.cdm.api.service.DeleteResult;
|
14
|
import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;
|
15
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
16
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
17
|
import eu.etaxonomy.taxeditor.bulkeditor.internal.TaxeditorBulkeditorPlugin;
|
18
|
import eu.etaxonomy.taxeditor.editor.Messages;
|
19
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
20
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
21
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
22
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
23
|
|
24
|
/**
|
25
|
* @author n.hoffmann
|
26
|
*
|
27
|
*/
|
28
|
public class DeleteNodeOperation extends AbstractPostOperation<PolytomousKeyNode> {
|
29
|
|
30
|
private final PolytomousKeyNode parent;
|
31
|
private final PolytomousKeyNode node;
|
32
|
private final boolean deleteChildren;
|
33
|
|
34
|
public DeleteNodeOperation(String label, IUndoContext undoContext,
|
35
|
PolytomousKeyNode node, IPostOperationEnabled postOperationEnabled, boolean deleteChildren) {
|
36
|
super(label, undoContext, node, postOperationEnabled);
|
37
|
HibernateProxyHelper.deproxy(node, PolytomousKeyNode.class);
|
38
|
this.node = node;
|
39
|
this.parent = node.getParent();
|
40
|
this.deleteChildren = deleteChildren;
|
41
|
}
|
42
|
|
43
|
/*
|
44
|
* (non-Javadoc)
|
45
|
*
|
46
|
* @see
|
47
|
* org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse
|
48
|
* .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
49
|
*/
|
50
|
@Override
|
51
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
52
|
throws ExecutionException {
|
53
|
|
54
|
//parent.removeChild(node);
|
55
|
ICdmRepository controller;
|
56
|
|
57
|
controller = CdmStore.getCurrentApplicationConfiguration();
|
58
|
|
59
|
IPolytomousKeyNodeService service = controller.getPolytomousKeyNodeService();
|
60
|
DeleteResult result;
|
61
|
|
62
|
if (node.getChildren().size()>0){
|
63
|
if(deleteChildren) {
|
64
|
result = service.delete(node.getUuid(), false);
|
65
|
} else{
|
66
|
result = service.delete(node.getUuid(), true);
|
67
|
}
|
68
|
} else{
|
69
|
result = service.delete(node.getUuid(), true);
|
70
|
}
|
71
|
|
72
|
if (!result.isOk() || result.getExceptions().size() > 0){
|
73
|
Exception t = new Exception();
|
74
|
if (result.getExceptions().size() >1){
|
75
|
for (Exception e:result.getExceptions()){
|
76
|
t.addSuppressed(e);
|
77
|
}
|
78
|
}else {
|
79
|
t = result.getExceptions().iterator().next();
|
80
|
}
|
81
|
MessagingUtils.errorDialog(Messages.DeleteNodeOperation_DELETE_FAILED, getClass(),null, TaxeditorBulkeditorPlugin.PLUGIN_ID, t, true);
|
82
|
}
|
83
|
return postExecute(null);
|
84
|
}
|
85
|
|
86
|
/*
|
87
|
* (non-Javadoc)
|
88
|
*
|
89
|
* @see
|
90
|
* org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse
|
91
|
* .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
92
|
*/
|
93
|
@Override
|
94
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
95
|
throws ExecutionException {
|
96
|
return execute(monitor, info);
|
97
|
}
|
98
|
|
99
|
/*
|
100
|
* (non-Javadoc)
|
101
|
*
|
102
|
* @see
|
103
|
* org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse
|
104
|
* .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
105
|
*/
|
106
|
@Override
|
107
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
108
|
throws ExecutionException {
|
109
|
// TODO Auto-generated method stub
|
110
|
return null;
|
111
|
}
|
112
|
|
113
|
}
|