Project

General

Profile

Download (2.85 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2016 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.editor.key.polytomous.operation;
10

    
11
import org.eclipse.core.commands.ExecutionException;
12
import org.eclipse.core.commands.operations.IUndoContext;
13
import org.eclipse.core.runtime.IAdaptable;
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.core.runtime.IStatus;
16

    
17
import eu.etaxonomy.cdm.api.application.ICdmRepository;
18
import eu.etaxonomy.cdm.api.service.DeleteResult;
19
import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;
20
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
21
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
22
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
23
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
24
import eu.etaxonomy.taxeditor.model.MessagingUtils;
25
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
26
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
27
import eu.etaxonomy.taxeditor.store.CdmStore;
28
import eu.etaxonomy.taxeditor.store.StoreUtil;
29

    
30
/**
31
 * @author n.hoffmann
32
 */
33
public class DeleteNodeOperation extends AbstractPostOperation<PolytomousKeyNode> {
34

    
35
	private final PolytomousKeyNode node;
36
	private final boolean deleteChildren;
37

    
38
	public DeleteNodeOperation(String label, IUndoContext undoContext,
39
			PolytomousKeyNode node, IPostOperationEnabled postOperationEnabled, boolean deleteChildren) {
40
	    super(label, undoContext, node, postOperationEnabled);
41
	    HibernateProxyHelper.deproxy(node);
42
		this.node = node;
43
		this.deleteChildren = deleteChildren;
44
	}
45

    
46
	@Override
47
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
48
			throws ExecutionException {
49

    
50
		//parent.removeChild(node);
51
		ICdmRepository controller;
52

    
53
		controller = CdmStore.getCurrentApplicationConfiguration();
54

    
55
		IPolytomousKeyNodeService service = controller.getPolytomousKeyNodeService();
56
		DeleteResult result;
57

    
58
		if (node.getChildren().size()>0){
59
			if(deleteChildren) {
60
				result = service.delete(node.getUuid(), false);
61
			} else{
62
				result = service.delete(node.getUuid(), true);
63
			}
64
		} else{
65
			result = service.delete(node.getUuid(), true);
66
		}
67

    
68
		if (!result.isOk() || result.getExceptions().size() > 0){
69
			Exception t = StoreUtil.mergeUpdateResultExceptions(result);
70
			MessagingUtils.errorDialog(Messages.DeleteNodeOperation_DELETE_FAILED, getClass(),null, TaxeditorEditorPlugin.PLUGIN_ID, t, true);
71
		}
72
		return postExecute(null);
73
	}
74

    
75
	@Override
76
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
77
			throws ExecutionException {
78
		return execute(monitor, info);
79
	}
80

    
81
	@Override
82
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
83
			throws ExecutionException {
84
		return null;
85
	}
86
}
(3-3/5)