Project

General

Profile

Download (6.05 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
				}
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

    
118
				DeleteResult result = CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
119
				if (result.isError() && !result.getExceptions().isEmpty()){
120
					//TODO:Error message!
121
					MessageDialog.openError(null, "Delete failed", result.getExceptions().iterator().next().getMessage());
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

    
133
				DeleteResult result =service.deleteTaxonNodes(treeNodes, config);
134
				if (result.isError() && !result.getExceptions().isEmpty()){
135
					//TODO:Error message!
136
					MessageDialog.openError(null, "Delete failed", result.getExceptions().iterator().next().getMessage());
137
				}
138
			}
139

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

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

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