Project

General

Profile

Download (4.24 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.toString());
85
					} else if (!result.getUpdatedObjects().isEmpty()){
86
						MessageDialog.openInformation(null, "Delete successfull", "The Synonym could be deleted, but there is an updated object: " + result.toString());
87
					}
88
				}
89
			//	taxon.removeSynonym(synonym);
90
//				CdmStore.getTaxonService().deleteSynonymRelationships(synonym);
91
//				CdmStore.getTaxonService().delete(synonym);
92

    
93
				monitor.worked(40);
94

    
95
				// Redraw editor if exists
96

    
97
				return postExecute(element);
98
	}
99

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

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

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

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