Project

General

Profile

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

    
11
package eu.etaxonomy.taxeditor.navigation.navigator.operation;
12

    
13
import java.util.Set;
14

    
15
import org.eclipse.core.commands.ExecutionException;
16
import org.eclipse.core.commands.operations.IUndoContext;
17
import org.eclipse.core.runtime.IAdaptable;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.IStatus;
20

    
21
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
22
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
23
import eu.etaxonomy.cdm.api.service.IClassificationService;
24
import eu.etaxonomy.cdm.api.service.ITaxonService;
25
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
26
import eu.etaxonomy.cdm.api.service.exception.DataChangeNoRollbackException;
27
import eu.etaxonomy.cdm.model.taxon.Classification;
28
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
29
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
30
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
31
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
32
import eu.etaxonomy.taxeditor.store.CdmStore;
33
import eu.etaxonomy.taxeditor.store.StoreUtil;
34

    
35
/**
36
 * <p>DeleteTreeNodeOperation class.</p>
37
 *
38
 * @author n.hoffmann
39
 * @created Jan 20, 2010
40
 * @version 1.0
41
 */
42
public class DeleteOperation extends AbstractPersistentPostOperation{
43

    
44
	private Set<ITaxonTreeNode> treeNodes;
45

    
46

    
47
	/**
48
	 * <p>Constructor for DeleteTreeNodeOperation.</p>
49
	 *
50
	 * @param label a {@link java.lang.String} object.
51
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
52
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
53
	 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
54
	 * @param treeNodes a {@link java.util.Set} object.
55
	 */
56
	public DeleteOperation(String label, IUndoContext undoContext,
57
			Set<ITaxonTreeNode> treeNodes,
58
			IPostOperationEnabled postOperationEnabled,
59
			IConversationEnabled conversationEnabled) {
60
		super(label, undoContext, postOperationEnabled, conversationEnabled);
61
		this.treeNodes = treeNodes;
62
	}
63

    
64

    
65
	/* (non-Javadoc)
66
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
67
	 */
68
	/** {@inheritDoc} */
69
	@Override
70
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
71
			throws ExecutionException {
72

    
73
		bind();
74
		monitor.worked(20);
75
        for (ITaxonTreeNode treeNode : treeNodes){
76
			if(treeNode instanceof TaxonNode){
77
				//((TaxonNode) treeNode).delete();
78
				CdmApplicationController controller;
79
				taxon = ((TaxonNode) treeNode).getTaxon();
80
				controller = (CdmApplicationController) CdmStore.getCurrentApplicationConfiguration();
81
				
82
				ITaxonService service = controller.getTaxonService();
83
				try {
84
					
85
					service.deleteTaxon(taxon, new TaxonDeletionConfigurator(), ((TaxonNode) treeNode).getClassification());
86
					
87
				} catch (DataChangeNoRollbackException e) {
88
					// TODO Auto-generated catch block
89
					e.printStackTrace();
90
					
91
				}
92
				
93
			}else if(treeNode instanceof Classification){
94
				Classification taxonomicTree = (Classification) treeNode;
95
				if(taxonomicTree.hasChildNodes()){
96
					StoreUtil.warningDialog("Tree is not empty", this, "It is not possible to delete a Taxonomic Tree that " +
97
							"is not empty. Please delete included taxa first");
98
				}else{
99
					CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
100
				}
101
			}
102
		}
103
		monitor.worked(40);
104
		return postExecute(null);
105
	}
106

    
107
	/* (non-Javadoc)
108
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
109
	 */
110
	/** {@inheritDoc} */
111
	@Override
112
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
113
			throws ExecutionException {
114
		return null;
115
	}
116

    
117
	/* (non-Javadoc)
118
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
119
	 */
120
	/** {@inheritDoc} */
121
	@Override
122
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
123
			throws ExecutionException {
124
		return null;
125
	}
126
}
(2-2/4)