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