1 |
3be6ef3e
|
n.hoffmann
|
/**
|
2 |
|
|
* Copyright (C) 2007 EDIT
|
3 |
0a534d09
|
Patric Plitzner
|
* European Distributed Institute of Taxonomy
|
4 |
3be6ef3e
|
n.hoffmann
|
* http://www.e-taxonomy.eu
|
5 |
0a534d09
|
Patric Plitzner
|
*
|
6 |
3be6ef3e
|
n.hoffmann
|
* 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 |
35861667
|
n.hoffmann
|
package eu.etaxonomy.taxeditor.editor.name.operation;
|
11 |
3be6ef3e
|
n.hoffmann
|
|
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 |
|
|
|
20 |
|
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
21 |
|
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
22 |
|
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
23 |
150b624d
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
24 |
41e2f693
|
Cherian Mathew
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
25 |
343457b6
|
Patric Plitzner
|
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
|
26 |
35861667
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
27 |
3be6ef3e
|
n.hoffmann
|
|
28 |
|
|
/**
|
29 |
|
|
* <p>ChangeConceptRelationshipTypeOperation class.</p>
|
30 |
|
|
*
|
31 |
|
|
* @author n.hoffmann
|
32 |
|
|
* @created 03.02.2009
|
33 |
|
|
* @version 1.0
|
34 |
|
|
*/
|
35 |
343457b6
|
Patric Plitzner
|
public class ChangeConceptRelationshipTypeOperation extends AbstractPostTaxonOperation {
|
36 |
0a534d09
|
Patric Plitzner
|
|
37 |
3be6ef3e
|
n.hoffmann
|
private Taxon relatedTaxon;
|
38 |
0a534d09
|
Patric Plitzner
|
|
39 |
3be6ef3e
|
n.hoffmann
|
private TaxonRelationship taxonRelationship;
|
40 |
0a534d09
|
Patric Plitzner
|
|
41 |
3be6ef3e
|
n.hoffmann
|
private TaxonRelationshipType oldRelationshipType;
|
42 |
0a534d09
|
Patric Plitzner
|
|
43 |
3be6ef3e
|
n.hoffmann
|
private TaxonRelationshipType newRelationshipType;
|
44 |
|
|
|
45 |
|
|
/**
|
46 |
|
|
* <p>Constructor for ChangeConceptRelationshipTypeOperation.</p>
|
47 |
|
|
*
|
48 |
|
|
* @param label a {@link java.lang.String} object.
|
49 |
|
|
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
|
50 |
|
|
* @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
|
51 |
|
|
* @param relatedTaxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
|
52 |
|
|
* @param type a {@link eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType} object.
|
53 |
35861667
|
n.hoffmann
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
54 |
3be6ef3e
|
n.hoffmann
|
*/
|
55 |
|
|
public ChangeConceptRelationshipTypeOperation(String label,
|
56 |
|
|
IUndoContext undoContext, Taxon taxon, Taxon relatedTaxon, TaxonRelationshipType type, IPostOperationEnabled postOperationEnabled) {
|
57 |
|
|
super(label, undoContext, taxon, postOperationEnabled);
|
58 |
|
|
this.relatedTaxon = relatedTaxon;
|
59 |
0a534d09
|
Patric Plitzner
|
|
60 |
3be6ef3e
|
n.hoffmann
|
Set<TaxonRelationship> taxonRelationships = taxon.getTaxonRelations(relatedTaxon);
|
61 |
0a534d09
|
Patric Plitzner
|
|
62 |
3be6ef3e
|
n.hoffmann
|
if(taxonRelationships.size() > 1){
|
63 |
61c51c84
|
Patrick Plitzner
|
MessagingUtils.warningDialog(ChangeConceptToSynonymOperation.CHANGE_CONCEPT_TO_SYNONYM_OPERATION_MULTI_REPS, this, ChangeConceptToSynonymOperation.CHANGE_CONCEPT_TO_SYNONYM_OPERATION_MULTI_REPS_MESSAGE);
|
64 |
3be6ef3e
|
n.hoffmann
|
return;
|
65 |
|
|
}
|
66 |
0a534d09
|
Patric Plitzner
|
|
67 |
3be6ef3e
|
n.hoffmann
|
this.taxonRelationship = taxonRelationships.iterator().next();
|
68 |
|
|
this.oldRelationshipType = taxonRelationship.getType();
|
69 |
|
|
this.newRelationshipType = type;
|
70 |
|
|
}
|
71 |
0a534d09
|
Patric Plitzner
|
|
72 |
3be6ef3e
|
n.hoffmann
|
/* (non-Javadoc)
|
73 |
|
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
74 |
|
|
*/
|
75 |
|
|
/** {@inheritDoc} */
|
76 |
|
|
@Override
|
77 |
|
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
78 |
|
|
throws ExecutionException {
|
79 |
0a534d09
|
Patric Plitzner
|
|
80 |
3be6ef3e
|
n.hoffmann
|
// Remove relatedTaxon and old relationship
|
81 |
|
|
// FIXME since taxon relationships come in a set, which relationships are we going to delete here?
|
82 |
0a534d09
|
Patric Plitzner
|
element.removeTaxon(relatedTaxon, oldRelationshipType);
|
83 |
3be6ef3e
|
n.hoffmann
|
monitor.worked(20);
|
84 |
0a534d09
|
Patric Plitzner
|
|
85 |
3be6ef3e
|
n.hoffmann
|
// Add new relationship
|
86 |
|
|
// TODO add microcitation for misapplied name to property sheet
|
87 |
0a534d09
|
Patric Plitzner
|
relatedTaxon.addTaxonRelation(element, newRelationshipType, null, null);
|
88 |
3be6ef3e
|
n.hoffmann
|
monitor.worked(40);
|
89 |
0a534d09
|
Patric Plitzner
|
|
90 |
3be6ef3e
|
n.hoffmann
|
return postExecute(relatedTaxon);
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
/* (non-Javadoc)
|
94 |
|
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
95 |
|
|
*/
|
96 |
|
|
/** {@inheritDoc} */
|
97 |
|
|
@Override
|
98 |
|
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
99 |
|
|
throws ExecutionException {
|
100 |
|
|
return execute(monitor, info);
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
/* (non-Javadoc)
|
104 |
|
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
105 |
|
|
*/
|
106 |
|
|
/** {@inheritDoc} */
|
107 |
|
|
@Override
|
108 |
|
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
109 |
|
|
throws ExecutionException {
|
110 |
|
|
// see FIXME in execute()
|
111 |
61c51c84
|
Patrick Plitzner
|
MessagingUtils.warn(this.getClass(), Messages.ChangeConceptRelationshipTypeOperation_NOT_IMPLEMENTED);
|
112 |
3be6ef3e
|
n.hoffmann
|
return null;
|
113 |
|
|
}
|
114 |
|
|
}
|