Project

General

Profile

« Previous | Next » 

Revision 3be6ef3e

Added by Niels Hoffmann over 13 years ago

performed javacscript:fix and worked on documentation

View differences:

taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/CreateSynonymInExistingHomotypicalGroupOperation.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.SynonymRelationship;
21
import eu.etaxonomy.cdm.model.taxon.Taxon;
22

  
23
/**
24
 * @author n.hoffmann
25
 * @created 02.02.2009
26
 * @version 1.0
27
 */
28
public class CreateSynonymInExistingHomotypicalGroupOperation extends
29
		AbstractPostOperation {
30

  
31
	private HomotypicalGroup group;
32
	private TaxonNameBase newSynonymName;
33

  
34
	private SynonymRelationship synonymRelationship;
35
	
36
	public CreateSynonymInExistingHomotypicalGroupOperation(String label,
37
			IUndoContext undoContext, Taxon taxon, HomotypicalGroup group, TaxonNameBase newSynonymName, IPostOperationEnabled postOperationEnabled) {
38
		super(label, undoContext, taxon, postOperationEnabled);
39
		this.group = group;
40
		this.newSynonymName = newSynonymName;
41
	}
42

  
43
	/* (non-Javadoc)
44
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
45
	 */
46
	@Override
47
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
48
			throws ExecutionException {
49
		
50
		// Add name to given homotypic group
51
		group.addTypifiedName(newSynonymName);
52
		monitor.worked(20);
53
		
54
		// Create a new synonym for the taxon
55
		// TODO add citations
56
		if(group.equals(taxon.getHomotypicGroup())){
57
			synonymRelationship = taxon.addHomotypicSynonymName(newSynonymName, null, null);
58
		}else{
59
			synonymRelationship = taxon.addHeterotypicSynonymName(newSynonymName);
60
		}
61
		monitor.worked(40);
62
		
63
//		Synonym affectedSynonym = null;
64
//		
65
//		for(Synonym synonym : group.getSynonymsInGroup(taxon.getSec())){
66
//			if(synonym.getName() == synonymName){
67
//				affectedSynonym = synonym;
68
//				break;
69
//			}
70
//		}
71
		
72
		return postExecute(synonymRelationship.getSynonym());
73
	}
74

  
75
	/* (non-Javadoc)
76
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
77
	 */
78
	@Override
79
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
80
			throws ExecutionException {
81
		return execute(monitor, info);
82
	}
83

  
84
	/* (non-Javadoc)
85
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
86
	 */
87
	@Override
88
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
89
			throws ExecutionException {
90

  
91
		taxon.removeSynonymRelation(synonymRelationship);
92
		
93
		return postExecute(null);
94
	}
95
}
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.SynonymRelationship;
21
import eu.etaxonomy.cdm.model.taxon.Taxon;
22

  
23
/**
24
 * <p>CreateSynonymInExistingHomotypicalGroupOperation class.</p>
25
 *
26
 * @author n.hoffmann
27
 * @created 02.02.2009
28
 * @version 1.0
29
 */
30
public class CreateSynonymInExistingHomotypicalGroupOperation extends
31
		AbstractPostOperation {
32

  
33
	private HomotypicalGroup group;
34
	private TaxonNameBase newSynonymName;
35

  
36
	private SynonymRelationship synonymRelationship;
37
	
38
	/**
39
	 * <p>Constructor for CreateSynonymInExistingHomotypicalGroupOperation.</p>
40
	 *
41
	 * @param label a {@link java.lang.String} object.
42
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
43
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
44
	 * @param group a {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup} object.
45
	 * @param newSynonymName a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase} object.
46
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object.
47
	 */
48
	public CreateSynonymInExistingHomotypicalGroupOperation(String label,
49
			IUndoContext undoContext, Taxon taxon, HomotypicalGroup group, TaxonNameBase newSynonymName, IPostOperationEnabled postOperationEnabled) {
50
		super(label, undoContext, taxon, postOperationEnabled);
51
		this.group = group;
52
		this.newSynonymName = newSynonymName;
53
	}
54

  
55
	/* (non-Javadoc)
56
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
57
	 */
58
	/** {@inheritDoc} */
59
	@Override
60
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
61
			throws ExecutionException {
62
		
63
		// Add name to given homotypic group
64
		group.addTypifiedName(newSynonymName);
65
		monitor.worked(20);
66
		
67
		// Create a new synonym for the taxon
68
		// TODO add citations
69
		if(group.equals(taxon.getHomotypicGroup())){
70
			synonymRelationship = taxon.addHomotypicSynonymName(newSynonymName, null, null);
71
		}else{
72
			synonymRelationship = taxon.addHeterotypicSynonymName(newSynonymName);
73
		}
74
		monitor.worked(40);
75
		
76
//		Synonym affectedSynonym = null;
77
//		
78
//		for(Synonym synonym : group.getSynonymsInGroup(taxon.getSec())){
79
//			if(synonym.getName() == synonymName){
80
//				affectedSynonym = synonym;
81
//				break;
82
//			}
83
//		}
84
		
85
		return postExecute(synonymRelationship.getSynonym());
86
	}
87

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

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

  
106
		taxon.removeSynonymRelation(synonymRelationship);
107
		
108
		return postExecute(null);
109
	}
110
}

Also available in: Unified diff