Project

General

Profile

Download (4.21 KB) Statistics
| Branch: | Tag: | Revision:
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.name.operation;
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.taxon.Taxon;
21
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
22
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
23
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
24
import eu.etaxonomy.taxeditor.model.MessagingUtils;
25
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
26
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
27

    
28
/**
29
 * <p>ChangeConceptRelationshipTypeOperation class.</p>
30
 *
31
 * @author n.hoffmann
32
 * @created 03.02.2009
33
 * @version 1.0
34
 */
35
public class ChangeConceptRelationshipTypeOperation extends AbstractPostTaxonOperation {
36

    
37
	private Taxon relatedTaxon;
38

    
39
	private TaxonRelationship taxonRelationship;
40

    
41
	private TaxonRelationshipType oldRelationshipType;
42

    
43
	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
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
54
	 */
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

    
60
		Set<TaxonRelationship> taxonRelationships = taxon.getTaxonRelations(relatedTaxon);
61

    
62
		if(taxonRelationships.size() > 1){
63
			MessagingUtils.warningDialog(ChangeConceptToSynonymOperation.CHANGE_CONCEPT_TO_SYNONYM_OPERATION_MULTI_REPS, this, ChangeConceptToSynonymOperation.CHANGE_CONCEPT_TO_SYNONYM_OPERATION_MULTI_REPS_MESSAGE);
64
			return;
65
		}
66

    
67
		this.taxonRelationship = taxonRelationships.iterator().next();
68
		this.oldRelationshipType = taxonRelationship.getType();
69
		this.newRelationshipType = type;
70
	}
71

    
72
	/* (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

    
80
		// Remove relatedTaxon and old relationship
81
		// FIXME since taxon relationships come in a set, which relationships are we going to delete here?
82
	    element.removeTaxon(relatedTaxon, oldRelationshipType);
83
		monitor.worked(20);
84

    
85
        // Add new relationship
86
		// TODO add microcitation for misapplied name to property sheet
87
		relatedTaxon.addTaxonRelation(element, newRelationshipType, null, null);
88
		monitor.worked(40);
89

    
90
		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
		MessagingUtils.warn(this.getClass(), Messages.ChangeConceptRelationshipTypeOperation_NOT_IMPLEMENTED);
112
		return null;
113
	}
114
}
(1-1/19)