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