Revision 3be6ef3e
Added by Niels Hoffmann over 13 years ago
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/ChangeHomotypicGroupOperation.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 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.name.HomotypicalGroup; |
|
19 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
20 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
|
21 |
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType; |
|
22 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
23 |
|
|
24 |
/** |
|
25 |
* Change the homotypical group of a given synonym. |
|
26 |
* |
|
27 |
* @author n.hoffmann |
|
28 |
* @created 19.01.2009 |
|
29 |
* @version 1.0 |
|
30 |
*/ |
|
31 |
public class ChangeHomotypicGroupOperation extends AbstractPostOperation { |
|
32 |
|
|
33 |
/** |
|
34 |
* The synonym to be moved. |
|
35 |
*/ |
|
36 |
private Synonym synonym; |
|
37 |
/** |
|
38 |
* The former homotypical group the synonym belonged to |
|
39 |
*/ |
|
40 |
private HomotypicalGroup oldHomotypicalGroup; |
|
41 |
/** |
|
42 |
* The homotypical group the synonym is to be moved to |
|
43 |
*/ |
|
44 |
private HomotypicalGroup newHomotypicalGroup; |
|
45 |
|
|
46 |
public ChangeHomotypicGroupOperation(String label, IUndoContext undoContext, |
|
47 |
Taxon taxon, Synonym synonym, HomotypicalGroup newHomotypicalGroup, IPostOperationEnabled editor) { |
|
48 |
super(label, undoContext, taxon, editor); |
|
49 |
|
|
50 |
this.synonym = synonym; |
|
51 |
if(synonym == null){ |
|
52 |
throw new IllegalArgumentException( |
|
53 |
"A null synonym was provided."); |
|
54 |
} |
|
55 |
|
|
56 |
this.oldHomotypicalGroup = synonym.getHomotypicGroup(); |
|
57 |
this.newHomotypicalGroup = newHomotypicalGroup != null ? newHomotypicalGroup : HomotypicalGroup.NewInstance(); |
|
58 |
} |
|
59 |
|
|
60 |
/* (non-Javadoc) |
|
61 |
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) |
|
62 |
*/ |
|
63 |
@Override |
|
64 |
public IStatus execute(IProgressMonitor monitor, IAdaptable info) |
|
65 |
throws ExecutionException { |
|
66 |
|
|
67 |
// Get synonym name |
|
68 |
TaxonNameBase<?, ?> synonymName = synonym.getName(); |
|
69 |
monitor.worked(20); |
|
70 |
|
|
71 |
// TODO pass in homotypical group's taxon in case we are dragging from one editor to another |
|
72 |
|
|
73 |
// Switch groups |
|
74 |
oldHomotypicalGroup.removeTypifiedName(synonymName); |
|
75 |
monitor.worked(40); |
|
76 |
|
|
77 |
newHomotypicalGroup.addTypifiedName(synonymName); |
|
78 |
|
|
79 |
if(! synonym.getAcceptedTaxa().contains(taxon)){ |
|
80 |
for(Taxon acceptedTaxon : synonym.getAcceptedTaxa()){ |
|
81 |
acceptedTaxon.removeSynonym(synonym); |
|
82 |
} |
|
83 |
|
|
84 |
SynonymRelationshipType type = SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF(); |
|
85 |
if(newHomotypicalGroup.getTypifiedNames().contains(taxon.getName())){ |
|
86 |
type = SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF(); |
|
87 |
} |
|
88 |
|
|
89 |
taxon.addSynonym(synonym, type); |
|
90 |
} |
|
91 |
|
|
92 |
// Redraw editor if it exists |
|
93 |
return postExecute(synonym); |
|
94 |
} |
|
95 |
|
|
96 |
/* (non-Javadoc) |
|
97 |
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) |
|
98 |
*/ |
|
99 |
@Override |
|
100 |
public IStatus redo(IProgressMonitor monitor, IAdaptable info) |
|
101 |
throws ExecutionException { |
|
102 |
return execute(monitor, info); |
|
103 |
} |
|
104 |
|
|
105 |
/* (non-Javadoc) |
|
106 |
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) |
|
107 |
*/ |
|
108 |
@Override |
|
109 |
public IStatus undo(IProgressMonitor monitor, IAdaptable info) |
|
110 |
throws ExecutionException { |
|
111 |
|
|
112 |
// Get synonym name |
|
113 |
TaxonNameBase<?, ?> synonymName = this.synonym.getName(); |
|
114 |
if(synonymName == null){ |
|
115 |
// TODO |
|
116 |
} |
|
117 |
|
|
118 |
// TODO pass in homotypical group's taxon in case we are dragging from one editor to another |
|
119 |
|
|
120 |
// Switch groups |
|
121 |
newHomotypicalGroup.removeTypifiedName(synonymName); |
|
122 |
oldHomotypicalGroup.addTypifiedName(synonymName); |
|
123 |
|
|
124 |
// Redraw editor if it exists |
|
125 |
return postExecute(synonym); |
|
126 |
} |
|
127 |
} |
|
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 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.name.HomotypicalGroup; |
|
19 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
20 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
|
21 |
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType; |
|
22 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
23 |
|
|
24 |
/** |
|
25 |
* Change the homotypical group of a given synonym. |
|
26 |
* |
|
27 |
* @author n.hoffmann |
|
28 |
* @created 19.01.2009 |
|
29 |
* @version 1.0 |
|
30 |
*/ |
|
31 |
public class ChangeHomotypicGroupOperation extends AbstractPostOperation { |
|
32 |
|
|
33 |
/** |
|
34 |
* The synonym to be moved. |
|
35 |
*/ |
|
36 |
private Synonym synonym; |
|
37 |
/** |
|
38 |
* The former homotypical group the synonym belonged to |
|
39 |
*/ |
|
40 |
private HomotypicalGroup oldHomotypicalGroup; |
|
41 |
/** |
|
42 |
* The homotypical group the synonym is to be moved to |
|
43 |
*/ |
|
44 |
private HomotypicalGroup newHomotypicalGroup; |
|
45 |
|
|
46 |
/** |
|
47 |
* <p>Constructor for ChangeHomotypicGroupOperation.</p> |
|
48 |
* |
|
49 |
* @param label a {@link java.lang.String} object. |
|
50 |
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object. |
|
51 |
* @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object. |
|
52 |
* @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object. |
|
53 |
* @param newHomotypicalGroup a {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup} object. |
|
54 |
* @param editor a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object. |
|
55 |
*/ |
|
56 |
public ChangeHomotypicGroupOperation(String label, IUndoContext undoContext, |
|
57 |
Taxon taxon, Synonym synonym, HomotypicalGroup newHomotypicalGroup, IPostOperationEnabled editor) { |
|
58 |
super(label, undoContext, taxon, editor); |
|
59 |
|
|
60 |
this.synonym = synonym; |
|
61 |
if(synonym == null){ |
|
62 |
throw new IllegalArgumentException( |
|
63 |
"A null synonym was provided."); |
|
64 |
} |
|
65 |
|
|
66 |
this.oldHomotypicalGroup = synonym.getHomotypicGroup(); |
|
67 |
this.newHomotypicalGroup = newHomotypicalGroup != null ? newHomotypicalGroup : HomotypicalGroup.NewInstance(); |
|
68 |
} |
|
69 |
|
|
70 |
/* (non-Javadoc) |
|
71 |
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) |
|
72 |
*/ |
|
73 |
/** {@inheritDoc} */ |
|
74 |
@Override |
|
75 |
public IStatus execute(IProgressMonitor monitor, IAdaptable info) |
|
76 |
throws ExecutionException { |
|
77 |
|
|
78 |
// Get synonym name |
|
79 |
TaxonNameBase<?, ?> synonymName = synonym.getName(); |
|
80 |
monitor.worked(20); |
|
81 |
|
|
82 |
// TODO pass in homotypical group's taxon in case we are dragging from one editor to another |
|
83 |
|
|
84 |
// Switch groups |
|
85 |
oldHomotypicalGroup.removeTypifiedName(synonymName); |
|
86 |
monitor.worked(40); |
|
87 |
|
|
88 |
newHomotypicalGroup.addTypifiedName(synonymName); |
|
89 |
|
|
90 |
if(! synonym.getAcceptedTaxa().contains(taxon)){ |
|
91 |
for(Taxon acceptedTaxon : synonym.getAcceptedTaxa()){ |
|
92 |
acceptedTaxon.removeSynonym(synonym); |
|
93 |
} |
|
94 |
|
|
95 |
SynonymRelationshipType type = SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF(); |
|
96 |
if(newHomotypicalGroup.getTypifiedNames().contains(taxon.getName())){ |
|
97 |
type = SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF(); |
|
98 |
} |
|
99 |
|
|
100 |
taxon.addSynonym(synonym, type); |
|
101 |
} |
|
102 |
|
|
103 |
// Redraw editor if it exists |
|
104 |
return postExecute(synonym); |
|
105 |
} |
|
106 |
|
|
107 |
/* (non-Javadoc) |
|
108 |
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) |
|
109 |
*/ |
|
110 |
/** {@inheritDoc} */ |
|
111 |
@Override |
|
112 |
public IStatus redo(IProgressMonitor monitor, IAdaptable info) |
|
113 |
throws ExecutionException { |
|
114 |
return execute(monitor, info); |
|
115 |
} |
|
116 |
|
|
117 |
/* (non-Javadoc) |
|
118 |
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) |
|
119 |
*/ |
|
120 |
/** {@inheritDoc} */ |
|
121 |
@Override |
|
122 |
public IStatus undo(IProgressMonitor monitor, IAdaptable info) |
|
123 |
throws ExecutionException { |
|
124 |
|
|
125 |
// Get synonym name |
|
126 |
TaxonNameBase<?, ?> synonymName = this.synonym.getName(); |
|
127 |
if(synonymName == null){ |
|
128 |
// TODO |
|
129 |
} |
|
130 |
|
|
131 |
// TODO pass in homotypical group's taxon in case we are dragging from one editor to another |
|
132 |
|
|
133 |
// Switch groups |
|
134 |
newHomotypicalGroup.removeTypifiedName(synonymName); |
|
135 |
oldHomotypicalGroup.addTypifiedName(synonymName); |
|
136 |
|
|
137 |
// Redraw editor if it exists |
|
138 |
return postExecute(synonym); |
|
139 |
} |
|
140 |
} |
Also available in: Unified diff
performed javacscript:fix and worked on documentation