Project

General

Profile

Download (4.44 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
 * @version 1.0
36
 */
37
public class ChangeConceptRelationshipTypeOperation extends AbstractPostTaxonOperation {
38

    
39
	private Taxon relatedTaxon;
40

    
41
	private TaxonRelationship taxonRelationship;
42

    
43
	private TaxonRelationshipType oldRelationshipType;
44

    
45
	private TaxonRelationshipType newRelationshipType;
46

    
47
	/**
48
	 * <p>Constructor for ChangeConceptRelationshipTypeOperation.</p>
49
	 *
50
	 * @param label a {@link java.lang.String} object.
51
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
52
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
53
	 * @param relatedTaxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
54
	 * @param type a {@link eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType} object.
55
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
56
	 */
57
	public ChangeConceptRelationshipTypeOperation(String label,
58
			IUndoContext undoContext, Taxon taxon, Taxon relatedTaxon, TaxonRelationshipType type, IPostOperationEnabled postOperationEnabled) {
59
		super(label, undoContext, taxon, postOperationEnabled);
60
		this.relatedTaxon = relatedTaxon;
61

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

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

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

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

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

    
87
        // Add new relationship
88
		// TODO add microcitation for misapplied name to property sheet
89
	//	relatedTaxon.addTaxonRelation(element, newRelationshipType, null, null);
90
		this.taxonRelationship.setType(newRelationshipType);
91
		monitor.worked(40);
92
		EventUtility.postEvent(WorkbenchEventConstants.REFRESH_DETAILS, true);
93
		return postExecute(relatedTaxon);
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
	/** {@inheritDoc} */
100
	@Override
101
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
102
			throws ExecutionException {
103
		return execute(monitor, info);
104
	}
105

    
106
	/* (non-Javadoc)
107
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
108
	 */
109
	/** {@inheritDoc} */
110
	@Override
111
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
112
			throws ExecutionException {
113
		// see FIXME in execute()
114
		MessagingUtils.warn(this.getClass(), Messages.ChangeConceptRelationshipTypeOperation_NOT_IMPLEMENTED);
115
		return null;
116
	}
117
}
(1-1/15)