c55cff77a96035aaf81e50f9bc0ece33eb28f7a1
[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.IPolytomousKeyNodeService;
16 import eu.etaxonomy.cdm.api.service.ITaxonService;
17 import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
18 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
19 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
20 import eu.etaxonomy.taxeditor.store.CdmStore;
21
22 /**
23 * @author n.hoffmann
24 *
25 */
26 public class DeleteNodeOperation extends AbstractPostTaxonOperation {
27
28 private final PolytomousKeyNode parent;
29 private final PolytomousKeyNode node;
30
31 public DeleteNodeOperation(String label, IUndoContext undoContext,
32 PolytomousKeyNode node, IPostOperationEnabled postOperationEnabled) {
33 super(label, undoContext, postOperationEnabled);
34 this.node = node;
35 this.parent = node.getParent();
36 }
37
38 /*
39 * (non-Javadoc)
40 *
41 * @see
42 * org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse
43 * .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
44 */
45 @Override
46 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
47 throws ExecutionException {
48
49 //parent.removeChild(node);
50 ICdmApplicationConfiguration controller;
51
52 controller = (ICdmApplicationConfiguration) CdmStore.getCurrentApplicationConfiguration();
53
54 IPolytomousKeyNodeService service = controller.getPolytomousKeyNodeService();
55 if (node.getChildren().size()>0){
56 if(! MessageDialog.openQuestion(null, "Confirm deletion of children", "The selected node has children, do you want to delete them, too?")) {
57 service.delete(node, false);
58 } else{
59 service.delete(node, true);
60 }
61 } else{
62 service.delete(node, true);
63 }
64 return postExecute(null);
65 }
66
67 /*
68 * (non-Javadoc)
69 *
70 * @see
71 * org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse
72 * .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
73 */
74 @Override
75 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
76 throws ExecutionException {
77 return execute(monitor, info);
78 }
79
80 /*
81 * (non-Javadoc)
82 *
83 * @see
84 * org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse
85 * .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
86 */
87 @Override
88 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
89 throws ExecutionException {
90 // TODO Auto-generated method stub
91 return null;
92 }
93
94 }