Project

General

Profile

Download (4.47 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.editor.name.operation;
11

    
12
import java.util.Set;
13

    
14
import org.eclipse.core.commands.ExecutionException;
15
import org.eclipse.core.commands.operations.IUndoContext;
16
import org.eclipse.core.runtime.IAdaptable;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.IStatus;
19

    
20
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
21
import eu.etaxonomy.cdm.api.service.DeleteResult;
22
import eu.etaxonomy.cdm.api.service.ITaxonService;
23
import eu.etaxonomy.cdm.model.taxon.Synonym;
24
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
25
import eu.etaxonomy.cdm.model.taxon.Taxon;
26
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
27
import eu.etaxonomy.taxeditor.model.DeleteResultMessagingUtils;
28
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
29
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
30
import eu.etaxonomy.taxeditor.store.CdmStore;
31

    
32
/**
33
 * <p>DeleteSynonymOperation class.</p>
34
 *
35
 * @author p.ciardelli
36
 * @created 14.01.2009
37
 * @version 1.0
38
 */
39
public class DeleteSynonymOperation extends AbstractPostTaxonOperation {
40

    
41
	private final Synonym synonym;
42
	private Set<SynonymRelationshipType> synonymTypes;
43

    
44
	/**
45
	 * <p>Constructor for DeleteSynonymOperation.</p>
46
	 *
47
	 * @param label a {@link java.lang.String} object.
48
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
49
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
50
	 * @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
51
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
52
	 */
53
	public DeleteSynonymOperation(String label, IUndoContext undoContext,
54
			Taxon taxon, Synonym synonym, IPostOperationEnabled postOperationEnabled) {
55
		super(label, undoContext, taxon, postOperationEnabled);
56
		this.synonym = synonym;
57
	}
58

    
59
	/* (non-Javadoc)
60
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
61
	 */
62
	/** {@inheritDoc} */
63
	@Override
64
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
65
			throws ExecutionException {
66

    
67
		// Store synonymRelationshipType for later undo operations
68
				synonymTypes = synonym.getRelationType(element);
69
				monitor.worked(20);
70

    
71
				// Remove synonym from taxon
72

    
73
				ICdmApplicationConfiguration controller;
74

    
75
				controller = CdmStore.getCurrentApplicationConfiguration();
76

    
77
				ITaxonService service = controller.getTaxonService();
78
				if (synonym.getId() == 0){
79
					element.removeSynonym(synonym);
80

    
81
				} else {
82
//TODO: this should be moved to the handler, the operations should not contain ui code
83
					DeleteResult result = service.deleteSynonym(synonym.getUuid(), element.getUuid(), null);
84
					if (result.isError()){
85
						DeleteResultMessagingUtils.messageDialogWithDetails(result, "Delete failed", TaxeditorEditorPlugin.PLUGIN_ID);
86
					} else if (!result.getUpdatedObjects().isEmpty()){
87
					    DeleteResultMessagingUtils.messageDialogWithDetails(result, "The Synonym could be deleted, but related object(s) could not be deleted", TaxeditorEditorPlugin.PLUGIN_ID);
88
					}
89
				}
90
			//	taxon.removeSynonym(synonym);
91
//				CdmStore.getTaxonService().deleteSynonymRelationships(synonym);
92
//				CdmStore.getTaxonService().delete(synonym);
93

    
94
				monitor.worked(40);
95

    
96
				// Redraw editor if exists
97

    
98
				return postExecute(element);
99
	}
100

    
101
	/* (non-Javadoc)
102
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
103
	 */
104
	/** {@inheritDoc} */
105
	@Override
106
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
107
			throws ExecutionException {
108
		return execute(monitor, info);
109
	}
110

    
111
	/* (non-Javadoc)
112
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
113
	 */
114
	/** {@inheritDoc} */
115
	@Override
116
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
117
			throws ExecutionException {
118

    
119
		// Add synonym to taxon
120
		for (SynonymRelationshipType synonymType : synonymTypes){
121
			element.addSynonym(synonym, synonymType);
122
		}
123

    
124
		// Redraw editor if exists
125
		return postExecute(synonym);
126
	}
127
}
(14-14/19)