Project

General

Profile

Download (4.36 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 org.eclipse.core.commands.ExecutionException;
13
import org.eclipse.core.commands.operations.IUndoContext;
14
import org.eclipse.core.runtime.IAdaptable;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.ui.IWorkbenchPage;
18

    
19
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
20
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
21
import eu.etaxonomy.cdm.api.service.ITaxonService;
22
import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
23
import eu.etaxonomy.cdm.api.service.config.TaxonBaseDeletionConfigurator;
24
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
25
import eu.etaxonomy.cdm.model.reference.Reference;
26
import eu.etaxonomy.cdm.model.taxon.Taxon;
27
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
28
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
29
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
30
import eu.etaxonomy.taxeditor.store.CdmStore;
31

    
32
/**
33
 * <p>DeleteMisapplicationOperation class.</p>
34
 *
35
 * @author p.ciardelli
36
 * @created 16.01.2009
37
 */
38
public class DeleteMisapplicationOperation extends DeleteTaxonBaseOperation {
39

    
40
	private final Taxon misapplication;
41

    
42
	private Reference citation;
43

    
44
	private String microcitation;
45

    
46
	/**
47
	 * <p>Constructor for DeleteMisapplicationOperation.</p>
48
	 *
49
	 * @param label a {@link java.lang.String} object.
50
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
51
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
52
	 * @param misapplication a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
53
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
54
	 */
55
	public DeleteMisapplicationOperation(String label, IUndoContext undoContext, TaxonBaseDeletionConfigurator configurator,IWorkbenchPage activePage,
56
            Taxon taxon, Taxon misapplication, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled,ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
57
		//super(label, undoContext, taxon, postOperationEnabled);
58
	    super(label, undoContext, configurator, activePage, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled);
59
		this.misapplication = misapplication;
60
		this.element = taxon;
61
	}
62

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

    
71
		// Find misapplication relation, save citation information
72

    
73
//		for (TaxonRelationship relationship : element.getTaxonRelations()) {
74
//			if (relationship.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())
75
//					&& relationship.getFromTaxon().equals(misapplication)) {
76
//				citation = relationship.getCitation();
77
//				microcitation = relationship.getCitationMicroReference();
78
//			}
79
//		}
80
		monitor.worked(20);
81

    
82
		// Remove misapplied name relation from taxon
83
		element.removeTaxon(misapplication, TaxonRelationshipType.MISAPPLIED_NAME_FOR());
84
		ICdmApplicationConfiguration controller;
85

    
86
		controller = CdmStore.getCurrentApplicationConfiguration();
87

    
88
		ITaxonService service = controller.getTaxonService();
89
		TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
90
		NameDeletionConfigurator nameConfig = new NameDeletionConfigurator();
91
		nameConfig.setRemoveAllNameRelationships(true);
92
		config.setNameDeletionConfig(nameConfig);
93
		result = service.deleteTaxon(misapplication.getUuid(), config, null);
94
		monitor.worked(40);
95

    
96
		return postExecute(null);
97
	}
98

    
99
	/** {@inheritDoc} */
100
	@Override
101
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
102
			throws ExecutionException {
103
		return execute(monitor, info);
104
	}
105

    
106
	/** {@inheritDoc} */
107
	@Override
108
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
109
			throws ExecutionException {
110

    
111
		element.addMisappliedName(misapplication, citation, microcitation);
112

    
113

    
114
		return postExecute(misapplication);
115
	}
116
}
(12-12/19)