Project

General

Profile

Download (3.88 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.event.EventUtility;
25
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
26
import eu.etaxonomy.taxeditor.model.MessagingUtils;
27
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
28
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
29

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

    
38
	private Taxon relatedTaxon;
39

    
40
	private TaxonRelationship taxonRelationship;
41

    
42
	private TaxonRelationshipType oldRelationshipType;
43

    
44
	private TaxonRelationshipType newRelationshipType;
45

    
46
	/**
47
	 * <p>Constructor for ChangeConceptRelationshipTypeOperation.</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 relatedTaxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
53
	 * @param type a {@link eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType} object.
54
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
55
	 */
56
	public ChangeConceptRelationshipTypeOperation(String label,
57
			IUndoContext undoContext, Taxon taxon, Taxon relatedTaxon, TaxonRelationshipType type, IPostOperationEnabled postOperationEnabled) {
58
		super(label, undoContext, taxon, postOperationEnabled);
59
		this.relatedTaxon = relatedTaxon;
60

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

    
63
		if(taxonRelationships != null && taxonRelationships.size() > 1){
64
			MessagingUtils.warningDialog(ChangeConceptToSynonymOperation.CHANGE_CONCEPT_TO_SYNONYM_OPERATION_MULTI_REPS, this, ChangeConceptToSynonymOperation.CHANGE_CONCEPT_TO_SYNONYM_OPERATION_MULTI_REPS_MESSAGE);
65
			return;
66
		}
67

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

    
73
	@Override
74
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
75
			throws ExecutionException {
76

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

    
82
        // Add new relationship
83
		// TODO add microcitation for misapplied name to property sheet
84
	//	relatedTaxon.addTaxonRelation(element, newRelationshipType, null, null);
85
		this.taxonRelationship.setType(newRelationshipType);
86
		monitor.worked(40);
87
		EventUtility.postEvent(WorkbenchEventConstants.REFRESH_DETAILS, true);
88
		return postExecute(relatedTaxon);
89
	}
90

    
91
	@Override
92
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
93
			throws ExecutionException {
94
		return execute(monitor, info);
95
	}
96

    
97
	@Override
98
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
99
			throws ExecutionException {
100
		// see FIXME in execute()
101
		MessagingUtils.warn(this.getClass(), Messages.ChangeConceptRelationshipTypeOperation_NOT_IMPLEMENTED);
102
		return null;
103
	}
104
}
(1-1/15)