Merge branch 'develop' into LibrAlign
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / key / polytomous / operation / DeleteNodeOperation.java
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 import org.eclipse.jface.dialogs.MessageDialog;
12
13 import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
14 import eu.etaxonomy.cdm.api.service.DeleteResult;
15 import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;
16 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
17 import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
18 import eu.etaxonomy.taxeditor.bulkeditor.internal.TaxeditorBulkeditorPlugin;
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
33
34 public DeleteNodeOperation(String label, IUndoContext undoContext,
35 PolytomousKeyNode node, IPostOperationEnabled postOperationEnabled) {
36 super(label, undoContext, node, postOperationEnabled);
37 HibernateProxyHelper.deproxy(node, PolytomousKeyNode.class);
38 this.node = node;
39 this.parent = node.getParent();
40 }
41
42 /*
43 * (non-Javadoc)
44 *
45 * @see
46 * org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse
47 * .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
48 */
49 @Override
50 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
51 throws ExecutionException {
52
53 //parent.removeChild(node);
54 ICdmApplicationConfiguration controller;
55
56 controller = CdmStore.getCurrentApplicationConfiguration();
57
58 IPolytomousKeyNodeService service = controller.getPolytomousKeyNodeService();
59 DeleteResult result;
60
61 if (node.getChildren().size()>0){
62 if(! MessageDialog.openQuestion(null, "Confirm deletion of children", "The selected node has children, do you want to delete them, too?")) {
63 result = service.delete(node.getUuid(), false);
64 } else{
65 result = service.delete(node.getUuid(), true);
66 }
67 } else{
68 result = service.delete(node.getUuid(), true);
69 }
70
71 if (!result.isOk() || result.getExceptions().size() > 0){
72 Exception t = new Exception();
73 if (result.getExceptions().size() >1){
74 for (Exception e:result.getExceptions()){
75 t.addSuppressed(e);
76 }
77 }else {
78 t = result.getExceptions().iterator().next();
79 }
80 MessagingUtils.errorDialog("Exception occured. Delete not possible", getClass(),null, TaxeditorBulkeditorPlugin.PLUGIN_ID, t, true);
81 }
82 return postExecute(null);
83 }
84
85 /*
86 * (non-Javadoc)
87 *
88 * @see
89 * org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse
90 * .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
91 */
92 @Override
93 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
94 throws ExecutionException {
95 return execute(monitor, info);
96 }
97
98 /*
99 * (non-Javadoc)
100 *
101 * @see
102 * org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse
103 * .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
104 */
105 @Override
106 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
107 throws ExecutionException {
108 // TODO Auto-generated method stub
109 return null;
110 }
111
112 }