Project

General

Profile

Download (4 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
 * @version 1.0
31
 */
32
public class CreateConceptRelationOperation extends CreateNewTaxonBaseOperation {
33

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

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

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

    
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
		monitor.worked(20);
72
		addToSaveList(concept);
73
		// add concept to taxon
74
		if(taxonRelationshipTypeInverseContainer.isInverse()){
75
			element.addTaxonRelation(concept, taxonRelationshipTypeInverseContainer.getType(), null, null);
76
		} else {
77
		    concept.addTaxonRelation(element, taxonRelationshipTypeInverseContainer.getType(), null, null);
78
		}
79
		monitor.worked(40);
80

    
81
		// redraw editor if exists
82
		return postExecute(concept);
83
	}
84

    
85
	/* (non-Javadoc)
86
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
87
	 */
88
	/** {@inheritDoc} */
89
	@Override
90
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
91
			throws ExecutionException {
92
		return execute(monitor, info);
93
	}
94

    
95
	/* (non-Javadoc)
96
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
97
	 */
98
	/** {@inheritDoc} */
99
	@Override
100
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
101
			throws ExecutionException {
102

    
103
	    element.removeTaxon(concept, taxonRelationshipTypeInverseContainer.getType());
104

    
105
		// redraw editor if exists
106
		return postExecute(null);
107
	}
108
}
(1-1/2)