Revision 3be6ef3e
Added by Niels Hoffmann over 13 years ago
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/ChangeConceptToSynonymOperation.java | ||
---|---|---|
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.operations; |
|
11 |
|
|
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.name.HomotypicalGroup; |
|
21 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
22 |
import eu.etaxonomy.cdm.model.taxon.SynonymRelationship; |
|
23 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
24 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; |
|
25 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; |
|
26 |
import eu.etaxonomy.taxeditor.store.StoreUtil; |
|
27 |
|
|
28 |
/** |
|
29 |
* @author p.ciardelli |
|
30 |
* @created 15.01.2009 |
|
31 |
* @version 1.0 |
|
32 |
* @author n.hoffmann |
|
33 |
*/ |
|
34 |
public class ChangeConceptToSynonymOperation extends |
|
35 |
AbstractPostOperation { |
|
36 |
|
|
37 |
private Taxon concept; |
|
38 |
|
|
39 |
private HomotypicalGroup homotypicalGroup; |
|
40 |
|
|
41 |
private TaxonRelationship taxonRelationship; |
|
42 |
private TaxonRelationshipType oldRelationshipType; |
|
43 |
|
|
44 |
private SynonymRelationship newSynonymRelationship; |
|
45 |
|
|
46 |
public ChangeConceptToSynonymOperation(String label, |
|
47 |
IUndoContext undoContext, Taxon taxon, Taxon concept, HomotypicalGroup homotypicalGroup, |
|
48 |
IPostOperationEnabled editor) { |
|
49 |
super(label, undoContext, taxon, editor); |
|
50 |
|
|
51 |
Set<TaxonRelationship> taxonRelationships = taxon.getTaxonRelations(concept); |
|
52 |
|
|
53 |
if(taxonRelationships.size() > 1){ |
|
54 |
StoreUtil.warningDialog("Multiple relations between taxa", this, "There are multiple relations between the " + |
|
55 |
"accepted and the related taxon. This case is not handled by the software yet"); |
|
56 |
return; |
|
57 |
} |
|
58 |
|
|
59 |
this.taxonRelationship = taxonRelationships.iterator().next(); |
|
60 |
this.oldRelationshipType = taxonRelationship.getType(); |
|
61 |
|
|
62 |
this.concept = concept; |
|
63 |
this.homotypicalGroup = homotypicalGroup != null ? homotypicalGroup : HomotypicalGroup.NewInstance(); |
|
64 |
} |
|
65 |
|
|
66 |
/* (non-Javadoc) |
|
67 |
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) |
|
68 |
*/ |
|
69 |
@Override |
|
70 |
public IStatus execute(IProgressMonitor monitor, IAdaptable info) |
|
71 |
throws ExecutionException { |
|
72 |
|
|
73 |
// Create new synonym using concept name |
|
74 |
TaxonNameBase<?, ?> synonymName = concept.getName(); |
|
75 |
|
|
76 |
// Remove concept relation from taxon |
|
77 |
taxon.removeTaxon(concept, oldRelationshipType); |
|
78 |
monitor.worked(20); |
|
79 |
|
|
80 |
// Add name to new homotypic group |
|
81 |
homotypicalGroup.addTypifiedName(synonymName); |
|
82 |
monitor.worked(40); |
|
83 |
|
|
84 |
// Create a new synonym for the taxon |
|
85 |
newSynonymRelationship = taxon.addHeterotypicSynonymName(synonymName); |
|
86 |
|
|
87 |
return postExecute(newSynonymRelationship.getSynonym()); |
|
88 |
} |
|
89 |
|
|
90 |
/* (non-Javadoc) |
|
91 |
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) |
|
92 |
*/ |
|
93 |
@Override |
|
94 |
public IStatus redo(IProgressMonitor monitor, IAdaptable info) |
|
95 |
throws ExecutionException { |
|
96 |
// TODO redo for change misapplied name ... |
|
97 |
return null; |
|
98 |
} |
|
99 |
|
|
100 |
/* (non-Javadoc) |
|
101 |
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) |
|
102 |
*/ |
|
103 |
@Override |
|
104 |
public IStatus undo(IProgressMonitor monitor, IAdaptable info) |
|
105 |
throws ExecutionException { |
|
106 |
// TODO undo for change misapplied name ... |
|
107 |
return null; |
|
108 |
} |
|
109 |
} |
|
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.operations; |
|
11 |
|
|
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.name.HomotypicalGroup; |
|
21 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
22 |
import eu.etaxonomy.cdm.model.taxon.SynonymRelationship; |
|
23 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
24 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; |
|
25 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; |
|
26 |
import eu.etaxonomy.taxeditor.store.StoreUtil; |
|
27 |
|
|
28 |
/** |
|
29 |
* <p>ChangeConceptToSynonymOperation class.</p> |
|
30 |
* |
|
31 |
* @author p.ciardelli |
|
32 |
* @author n.hoffmann |
|
33 |
* @created 15.01.2009 |
|
34 |
* @version 1.0 |
|
35 |
*/ |
|
36 |
public class ChangeConceptToSynonymOperation extends |
|
37 |
AbstractPostOperation { |
|
38 |
|
|
39 |
private Taxon concept; |
|
40 |
|
|
41 |
private HomotypicalGroup homotypicalGroup; |
|
42 |
|
|
43 |
private TaxonRelationship taxonRelationship; |
|
44 |
private TaxonRelationshipType oldRelationshipType; |
|
45 |
|
|
46 |
private SynonymRelationship newSynonymRelationship; |
|
47 |
|
|
48 |
/** |
|
49 |
* <p>Constructor for ChangeConceptToSynonymOperation.</p> |
|
50 |
* |
|
51 |
* @param label a {@link java.lang.String} object. |
|
52 |
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object. |
|
53 |
* @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object. |
|
54 |
* @param concept a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object. |
|
55 |
* @param homotypicalGroup a {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup} object. |
|
56 |
* @param editor a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object. |
|
57 |
*/ |
|
58 |
public ChangeConceptToSynonymOperation(String label, |
|
59 |
IUndoContext undoContext, Taxon taxon, Taxon concept, HomotypicalGroup homotypicalGroup, |
|
60 |
IPostOperationEnabled editor) { |
|
61 |
super(label, undoContext, taxon, editor); |
|
62 |
|
|
63 |
Set<TaxonRelationship> taxonRelationships = taxon.getTaxonRelations(concept); |
|
64 |
|
|
65 |
if(taxonRelationships.size() > 1){ |
|
66 |
StoreUtil.warningDialog("Multiple relations between taxa", this, "There are multiple relations between the " + |
|
67 |
"accepted and the related taxon. This case is not handled by the software yet"); |
|
68 |
return; |
|
69 |
} |
|
70 |
|
|
71 |
this.taxonRelationship = taxonRelationships.iterator().next(); |
|
72 |
this.oldRelationshipType = taxonRelationship.getType(); |
|
73 |
|
|
74 |
this.concept = concept; |
|
75 |
this.homotypicalGroup = homotypicalGroup != null ? homotypicalGroup : HomotypicalGroup.NewInstance(); |
|
76 |
} |
|
77 |
|
|
78 |
/* (non-Javadoc) |
|
79 |
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) |
|
80 |
*/ |
|
81 |
/** {@inheritDoc} */ |
|
82 |
@Override |
|
83 |
public IStatus execute(IProgressMonitor monitor, IAdaptable info) |
|
84 |
throws ExecutionException { |
|
85 |
|
|
86 |
// Create new synonym using concept name |
|
87 |
TaxonNameBase<?, ?> synonymName = concept.getName(); |
|
88 |
|
|
89 |
// Remove concept relation from taxon |
|
90 |
taxon.removeTaxon(concept, oldRelationshipType); |
|
91 |
monitor.worked(20); |
|
92 |
|
|
93 |
// Add name to new homotypic group |
|
94 |
homotypicalGroup.addTypifiedName(synonymName); |
|
95 |
monitor.worked(40); |
|
96 |
|
|
97 |
// Create a new synonym for the taxon |
|
98 |
newSynonymRelationship = taxon.addHeterotypicSynonymName(synonymName); |
|
99 |
|
|
100 |
return postExecute(newSynonymRelationship.getSynonym()); |
|
101 |
} |
|
102 |
|
|
103 |
/* (non-Javadoc) |
|
104 |
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) |
|
105 |
*/ |
|
106 |
/** {@inheritDoc} */ |
|
107 |
@Override |
|
108 |
public IStatus redo(IProgressMonitor monitor, IAdaptable info) |
|
109 |
throws ExecutionException { |
|
110 |
// TODO redo for change misapplied name ... |
|
111 |
return null; |
|
112 |
} |
|
113 |
|
|
114 |
/* (non-Javadoc) |
|
115 |
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) |
|
116 |
*/ |
|
117 |
/** {@inheritDoc} */ |
|
118 |
@Override |
|
119 |
public IStatus undo(IProgressMonitor monitor, IAdaptable info) |
|
120 |
throws ExecutionException { |
|
121 |
// TODO undo for change misapplied name ... |
|
122 |
return null; |
|
123 |
} |
|
124 |
} |
Also available in: Unified diff
performed javacscript:fix and worked on documentation