Project

General

Profile

Download (3.39 KB) Statistics
| Branch: | Tag: | Revision:
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.ICdmApplicationConfiguration;
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.model.MessagingUtils;
19
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
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 AbstractPostOperation<PolytomousKeyNode> {
28

    
29
	private final PolytomousKeyNode parent;
30
	private final PolytomousKeyNode node;
31
	private final boolean deleteChildren;
32

    
33
	public DeleteNodeOperation(String label, IUndoContext undoContext,
34
			PolytomousKeyNode node, IPostOperationEnabled postOperationEnabled, boolean deleteChildren) {
35
	    super(label, undoContext, node, postOperationEnabled);
36
	    HibernateProxyHelper.deproxy(node, PolytomousKeyNode.class);
37
		this.node = node;
38
		this.parent = node.getParent();
39
		this.deleteChildren = deleteChildren;
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(deleteChildren) {
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
}
(2-2/5)