Project

General

Profile

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

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

    
45
	private Set<ITaxonTreeNode> treeNodes;
46
	private final TaxonDeletionConfigurator config;
47

    
48

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

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

    
85

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

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

    
101
				element = ((TaxonNode)taxonNode).getTaxon();
102
				try {
103
					service.deleteTaxonNode((TaxonNode)taxonNode, config);
104
				} catch (DataChangeNoRollbackException e) {
105

    
106
					throw new ExecutionException(e.getMessage());
107

    
108
				}
109

    
110
			}else if(taxonNode != null && taxonNode instanceof Classification){
111
				Classification taxonomicTree = (Classification) taxonNode;
112
				/*if(taxonomicTree.hasChildNodes()){
113
					if(! MessageDialog.openConfirm(null, "Confirm Deletion", "The selected tree has children, do yu realy want to delete the whole tree with its children?")){
114
						return null;
115
					}
116
				}*/
117
				try{
118
					CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
119
				}catch(ReferencedObjectUndeletableException e){
120
					throw new ExecutionException(e.getMessage());
121
				}
122

    
123

    
124
				/*}else{
125
					try{
126
					CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
127
					}catch(ReferencedObjectUndeletableException e){
128
						throw new ExecutionException(e.getMessage());
129
					}
130
				}*/
131
			} else {
132
				try {
133
					service.deleteTaxonNodes(treeNodes, config);
134
				} catch (DataChangeNoRollbackException e) {
135
					throw new ExecutionException(e.getMessage());
136
				}
137
			}
138

    
139
		monitor.worked(40);
140
		return postExecute(null);
141
	}
142

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

    
153
	/* (non-Javadoc)
154
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
155
	 */
156
	/** {@inheritDoc} */
157
	@Override
158
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
159
			throws ExecutionException {
160
		return null;
161
	}
162
}
(2-2/4)