Project

General

Profile

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

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

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

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

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

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

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

    
70
				// Remove synonym from taxon
71

    
72
				ICdmApplicationConfiguration controller;
73

    
74
				controller = CdmStore.getCurrentApplicationConfiguration();
75

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

    
80
				} else {
81

    
82
					DeleteResult result = service.deleteSynonym(synonym.getUuid(), element.getUuid(), null);
83
					if (result.isError()){
84
						MessageDialog.openError(null, "Delete failed", result.getExceptions().get(0).getMessage());
85
					}
86
				}
87
			//	taxon.removeSynonym(synonym);
88
//				CdmStore.getTaxonService().deleteSynonymRelationships(synonym);
89
//				CdmStore.getTaxonService().delete(synonym);
90

    
91
				monitor.worked(40);
92

    
93
				// Redraw editor if exists
94

    
95
				return postExecute(element);
96
	}
97

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

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

    
116
		// Add synonym to taxon
117
		for (SynonymRelationshipType synonymType : synonymTypes){
118
			element.addSynonym(synonym, synonymType);
119
		}
120

    
121
		// Redraw editor if exists
122
		return postExecute(synonym);
123
	}
124
}
(14-14/19)