Project

General

Profile

Download (5.81 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.List;
14
import java.util.Set;
15
import java.util.UUID;
16

    
17
import org.eclipse.core.commands.ExecutionException;
18
import org.eclipse.core.commands.operations.IUndoContext;
19
import org.eclipse.core.runtime.IAdaptable;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.jface.dialogs.MessageDialog;
23

    
24
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
25
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
26
import eu.etaxonomy.cdm.api.service.DeleteResult;
27
import eu.etaxonomy.cdm.api.service.IClassificationService;
28
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
29
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
30
import eu.etaxonomy.cdm.model.common.CdmBase;
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

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

    
47
	private Set<ITaxonTreeNode> treeNodes;
48
	protected final TaxonDeletionConfigurator config;
49

    
50

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

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

    
87

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

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

    
103
				element = ((TaxonNode)taxonNode).getTaxon();
104

    
105
				DeleteResult result = service.deleteTaxonNode((TaxonNode)taxonNode, config);
106
				if (result.isError()){
107
					//TODO:Error message!
108
					MessageDialog.openError(null, "Delete failed", result.getExceptions().get(0).getMessage());
109
				}
110

    
111

    
112
			}else if(taxonNode != null && taxonNode instanceof Classification){
113
				Classification taxonomicTree = (Classification) taxonNode;
114
				/*if(taxonomicTree.hasChildNodes()){
115
					if(! MessageDialog.openConfirm(null, "Confirm Deletion", "The selected tree has children, do yu realy want to delete the whole tree with its children?")){
116
						return null;
117
					}
118
				}*/
119
				
120
				DeleteResult result = CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
121
				if (result.isError()){
122
					//TODO:Error message!
123
					MessageDialog.openError(null, "Delete failed", result.getExceptions().get(0).getMessage());
124
				}
125

    
126
				/*}else{
127
					try{
128
					CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
129
					}catch(ReferencedObjectUndeletableException e){
130
						throw new ExecutionException(e.getMessage());
131
					}
132
				}*/
133
			} else {
134
				
135
				List<UUID> result =service.deleteTaxonNodes(treeNodes, config);
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
}
(3-3/5)