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.model.TaxonRelationshipTypeInverseContainer;
|
21
|
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
|
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 AbstractPostTaxonOperation {
|
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
|
/* (non-Javadoc)
|
62
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
63
|
*/
|
64
|
/** {@inheritDoc} */
|
65
|
@Override
|
66
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
67
|
throws ExecutionException {
|
68
|
|
69
|
monitor.worked(20);
|
70
|
// add concept to taxon
|
71
|
if(taxonRelationshipTypeInverseContainer.isInverse()){
|
72
|
element.addTaxonRelation(concept, taxonRelationshipTypeInverseContainer.getType(), null, null);
|
73
|
} else {
|
74
|
concept.addTaxonRelation(element, taxonRelationshipTypeInverseContainer.getType(), null, null);
|
75
|
}
|
76
|
monitor.worked(40);
|
77
|
|
78
|
// redraw editor if exists
|
79
|
return postExecute(concept);
|
80
|
}
|
81
|
|
82
|
/* (non-Javadoc)
|
83
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
84
|
*/
|
85
|
/** {@inheritDoc} */
|
86
|
@Override
|
87
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
88
|
throws ExecutionException {
|
89
|
return execute(monitor, info);
|
90
|
}
|
91
|
|
92
|
/* (non-Javadoc)
|
93
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
94
|
*/
|
95
|
/** {@inheritDoc} */
|
96
|
@Override
|
97
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
98
|
throws ExecutionException {
|
99
|
|
100
|
element.removeTaxon(concept, taxonRelationshipTypeInverseContainer.getType());
|
101
|
|
102
|
// redraw editor if exists
|
103
|
return postExecute(null);
|
104
|
}
|
105
|
}
|