Project

General

Profile

Download (3.41 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.view.concept.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

    
18
import eu.etaxonomy.cdm.model.taxon.Taxon;
19
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
20
import eu.etaxonomy.taxeditor.editor.name.operation.CreateNewTaxonBaseOperation;
21
import eu.etaxonomy.taxeditor.model.TaxonRelationshipTypeInverseContainer;
22
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
23

    
24
/**
25
 * <p>CreateConceptRelationOperation class.</p>
26
 *
27
 * @author p.ciardelli
28
 * @author n.hoffmann
29
 * @created 26.01.2009
30
 */
31
public class CreateConceptRelationOperation extends CreateNewTaxonBaseOperation {
32

    
33
	private final Taxon concept;
34
	private final TaxonRelationshipTypeInverseContainer taxonRelationshipTypeInverseContainer;
35

    
36
	/**
37
	 * <p>Constructor for CreateConceptRelationOperation.</p>
38
	 *
39
	 * @param label a {@link java.lang.String} object.
40
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
41
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
42
	 * @param concept a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
43
	 * @param taxonRelationshipType a {@link eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType} object.
44
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
45
	 */
46
	public CreateConceptRelationOperation(String label,
47
			IUndoContext undoContext, Taxon taxon, Taxon concept, TaxonRelationshipTypeInverseContainer taxonRelationshipTypeInverseContainer
48
			, IPostOperationEnabled postOperationEnabled) {
49
		super(label, undoContext, taxon, postOperationEnabled);
50
		this.concept = concept;
51
		this.taxonRelationshipTypeInverseContainer = taxonRelationshipTypeInverseContainer;
52
	}
53

    
54
	public CreateConceptRelationOperation(String label,
55
			IUndoContext undoContext, Taxon taxon, Taxon concept, TaxonRelationshipType taxonRelationshipType
56
			, IPostOperationEnabled postOperationEnabled) {
57
		this(label, undoContext, taxon, concept, new TaxonRelationshipTypeInverseContainer(taxonRelationshipType, false), postOperationEnabled);
58
	}
59

    
60
	@Override
61
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
62
			throws ExecutionException {
63

    
64
		monitor.worked(20);
65
		addToSaveList(concept);
66
		// add concept to taxon
67
		if(taxonRelationshipTypeInverseContainer.isInverse()){
68
			element.addTaxonRelation(concept, taxonRelationshipTypeInverseContainer.getType(), null, null);
69
		} else {
70
		    concept.addTaxonRelation(element, taxonRelationshipTypeInverseContainer.getType(), null, null);
71
		}
72
		monitor.worked(40);
73

    
74
		// redraw editor if exists
75
		return postExecute(concept);
76
	}
77

    
78
	@Override
79
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
80
			throws ExecutionException {
81
		return execute(monitor, info);
82
	}
83

    
84
	@Override
85
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
86
			throws ExecutionException {
87

    
88
	    element.removeTaxon(concept, taxonRelationshipTypeInverseContainer.getType());
89

    
90
		// redraw editor if exists
91
		return postExecute(null);
92
	}
93
}
(1-1/2)