Project

General

Profile

Download (5.58 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.application.ICdmApplicationConfiguration;
23
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
24
import eu.etaxonomy.cdm.api.service.IClassificationService;
25
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
26
import eu.etaxonomy.cdm.api.service.ITaxonService;
27
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
28
import eu.etaxonomy.cdm.api.service.exception.DataChangeNoRollbackException;
29
import eu.etaxonomy.cdm.model.common.CdmBase;
30
import eu.etaxonomy.cdm.model.common.ITreeNode;
31
import eu.etaxonomy.cdm.model.taxon.Classification;
32
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
33
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
34
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
35
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
36
import eu.etaxonomy.taxeditor.store.CdmStore;
37
import eu.etaxonomy.taxeditor.store.StoreUtil;
38

    
39
/**
40
 * <p>DeleteTreeNodeOperation class.</p>
41
 *
42
 * @author n.hoffmann
43
 * @created Jan 20, 2010
44
 * @version 1.0
45
 */
46
public class DeleteOperation extends AbstractPersistentPostOperation{
47

    
48
	private Set<ITaxonTreeNode> treeNodes;
49
	private TaxonDeletionConfigurator config;
50

    
51

    
52
	/**
53
	 * <p>Constructor for DeleteTreeNodeOperation.</p>
54
	 *
55
	 * @param label a {@link java.lang.String} object.
56
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
57
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
58
	 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
59
	 * @param treeNodes a {@link java.util.Set} object.
60
	 */
61
	public DeleteOperation(String label, IUndoContext undoContext,
62
			ITaxonTreeNode taxonNode, TaxonDeletionConfigurator config,
63
			IPostOperationEnabled postOperationEnabled,
64
			IConversationEnabled conversationEnabled) {
65
		super(label, undoContext, postOperationEnabled, conversationEnabled);
66
		this.taxonNode = (ITaxonTreeNode)CdmBase.deproxy(taxonNode, CdmBase.class);
67
		this.config = config;
68
	}
69

    
70
	/**
71
	 * <p>Constructor for DeleteTreeNodeOperation.</p>
72
	 *
73
	 * @param label a {@link java.lang.String} object.
74
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
75
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
76
	 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
77
	 * @param treeNodes a {@link java.util.Set} object.
78
	 */
79
	public DeleteOperation(String label, IUndoContext undoContext,
80
			Set<ITaxonTreeNode> treeNodes, TaxonDeletionConfigurator config,
81
			IPostOperationEnabled postOperationEnabled,
82
			IConversationEnabled conversationEnabled) {
83
		super(label, undoContext, postOperationEnabled, conversationEnabled);
84
		this.treeNodes = treeNodes;
85
		this.config = config;
86
	}
87
	
88

    
89
	/* (non-Javadoc)
90
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
91
	 */
92
	/** {@inheritDoc} */
93
	@Override
94
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
95
			throws ExecutionException {
96

    
97
		bind();
98
		monitor.worked(20);
99
		ICdmApplicationConfiguration controller = CdmStore.getCurrentApplicationConfiguration();
100
		ITaxonNodeService service = controller.getTaxonNodeService();
101
			if(taxonNode != null && taxonNode instanceof TaxonNode){
102
				//((TaxonNode) treeNode).delete();
103

    
104
				taxon = ((TaxonNode)taxonNode).getTaxon();
105
				try {
106
					service.deleteTaxonNode((TaxonNode)taxonNode, config);
107
				} catch (DataChangeNoRollbackException e) {
108
					
109
					throw new ExecutionException(e.getMessage());
110
					
111
				}
112
				
113
			}else if(taxonNode != null && taxonNode instanceof Classification){
114
				Classification taxonomicTree = (Classification) taxonNode;
115
				if(taxonomicTree.hasChildNodes()){
116
					StoreUtil.warningDialog("Tree is not empty", this, "It is not possible to delete a Taxonomic Tree that " +
117
							"is not empty. Please delete included taxa first");
118
				}else{
119
					CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
120
				}
121
			} else {
122
				try {
123
					service.deleteTaxonNodes(treeNodes, config);
124
				} catch (DataChangeNoRollbackException e) {
125
					throw new ExecutionException(e.getMessage());
126
				}
127
			}
128
		
129
		monitor.worked(40);
130
		return postExecute(null);
131
	}
132

    
133
	/* (non-Javadoc)
134
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
135
	 */
136
	/** {@inheritDoc} */
137
	@Override
138
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
139
			throws ExecutionException {
140
		return null;
141
	}
142

    
143
	/* (non-Javadoc)
144
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
145
	 */
146
	/** {@inheritDoc} */
147
	@Override
148
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
149
			throws ExecutionException {
150
		return null;
151
	}
152
}
(2-2/4)