Project

General

Profile

Download (6.44 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
import org.eclipse.jface.dialogs.MessageDialog;
21

    
22
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
23
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
24
import eu.etaxonomy.cdm.api.service.DeleteResult;
25
import eu.etaxonomy.cdm.api.service.IClassificationService;
26
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
27
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
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
	protected 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

    
103
				DeleteResult result = service.deleteTaxonNode((TaxonNode)taxonNode, config);
104
				if (result.isError() && !result.getExceptions().isEmpty()){
105
					//TODO:Error message!
106
					MessageDialog.openError(null, "Delete failed", result.getExceptions().iterator().next().getMessage());
107
				} else if (!result.getExceptions().isEmpty()){
108
					String separator = ", ";
109
				    String exceptionString = "";
110
				    for (Exception exception : result.getExceptions()) {
111
			            exceptionString += exception.getLocalizedMessage()+separator;
112
			        }
113
					MessageDialog.openInformation(null, "Delete of the node was successful but the taxon could not be deleted.", exceptionString);
114
				}
115

    
116

    
117
			}else if(taxonNode != null && taxonNode instanceof Classification){
118
				Classification taxonomicTree = (Classification) taxonNode;
119
				/*if(taxonomicTree.hasChildNodes()){
120
					if(! MessageDialog.openConfirm(null, "Confirm Deletion", "The selected tree has children, do yu realy want to delete the whole tree with its children?")){
121
						return null;
122
					}
123
				}*/
124

    
125
				DeleteResult result = CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
126
				if (result.isError() && !result.getExceptions().isEmpty()){
127
					//TODO:Error message!
128
					MessageDialog.openError(null, "Delete failed", result.getExceptions().iterator().next().getMessage());
129
				}
130

    
131
				/*}else{
132
					try{
133
					CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
134
					}catch(ReferencedObjectUndeletableException e){
135
						throw new ExecutionException(e.getMessage());
136
					}
137
				}*/
138
			} else {
139

    
140
				DeleteResult result =service.deleteTaxonNodes(treeNodes, config);
141
				if (result.isError() && !result.getExceptions().isEmpty()){
142
					//TODO:Error message!
143
					MessageDialog.openError(null, "Delete failed", result.getExceptions().iterator().next().getMessage());
144
				}
145
			}
146

    
147
		monitor.worked(40);
148
		return postExecute(null);
149
	}
150

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

    
161
	/* (non-Javadoc)
162
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
163
	 */
164
	/** {@inheritDoc} */
165
	@Override
166
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
167
			throws ExecutionException {
168
		return null;
169
	}
170
}
(3-3/5)