Project

General

Profile

Download (4.76 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

    
11
package eu.etaxonomy.taxeditor.navigation.navigator.operation;
12

    
13
import org.eclipse.core.commands.ExecutionException;
14
import org.eclipse.core.commands.operations.IUndoContext;
15
import org.eclipse.core.runtime.IAdaptable;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.Status;
19
import org.eclipse.jface.dialogs.MessageDialog;
20

    
21
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
22
import eu.etaxonomy.cdm.api.service.DeleteResult;
23
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
24
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
25
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
26
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
27
import eu.etaxonomy.cdm.model.taxon.Taxon;
28
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
29
import eu.etaxonomy.taxeditor.model.MessagingUtils;
30
import eu.etaxonomy.taxeditor.navigation.internal.TaxeditorNavigationPlugin;
31
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
32
import eu.etaxonomy.taxeditor.store.CdmStore;
33

    
34
/**
35
 * <p>ChangeAcceptedTaxonToSynonymOperation class.</p>
36
 *
37
 * @author n.hoffmann
38
 * @created Jan 4, 2010
39
 * @version 1.0
40
 */
41
public class ChangeAcceptedTaxonToSynonymOperation extends
42
	DeleteOperation {
43

    
44
	private final TaxonNode newAcceptedTaxonNode;
45

    
46
	//private TaxonNode oldTaxonNode;
47

    
48
	/**
49
	 * <p>Constructor for ChangeAcceptedTaxonToSynonymOperation.</p>
50
	 *
51
	 * @param label a {@link java.lang.String} object.
52
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
53
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
54
	 * @param oldTaxonNode a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
55
	 * @param newAcceptedTaxonNode a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
56
	 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
57
	 */
58
	public ChangeAcceptedTaxonToSynonymOperation(String label,
59
			IUndoContext undoContext, ITaxonTreeNode oldTaxonNode, TaxonNode newAcceptedTaxonNode,
60
			IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled) {
61
		super(label, undoContext, oldTaxonNode, new TaxonDeletionConfigurator(),postOperationEnabled, conversationEnabled);
62
		this.newAcceptedTaxonNode = newAcceptedTaxonNode;
63
	}
64

    
65

    
66
	/* (non-Javadoc)
67
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
68
	 */
69
	/** {@inheritDoc} */
70
	@Override
71
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
72
			throws ExecutionException {
73

    
74
		monitor.worked(20);
75
		bind();
76
    	Taxon oldTaxon = (Taxon) HibernateProxyHelper.deproxy(((TaxonNode) taxonNode).getTaxon());
77
		try {
78
		    DeleteResult result = CdmStore.getService(ITaxonNodeService.class).makeTaxonNodeASynonymOfAnotherTaxonNode((TaxonNode) taxonNode, newAcceptedTaxonNode, null, null, null);
79
        
80
		    if (!result.getExceptions().isEmpty() && result.isOk()){
81
		    	String separator = ", ";
82
			    String exceptionString = "";
83
			    for (Exception exception : result.getExceptions()) {
84
		            exceptionString += exception.getLocalizedMessage()+separator;
85
		        }
86
				
87
		    	MessagingUtils.informationDialog("Synonym created but taxon is not deleted.", exceptionString);		    	
88
		    } else if (result.isAbort() || result.isError()){
89
		    	MessagingUtils.errorDialog("Synonym could not created", null, result.toString(), TaxeditorNavigationPlugin.PLUGIN_ID, null, true);
90
		    }
91
		} catch (IllegalArgumentException e) {
92
            MessagingUtils.errorDialog("Operation failed", this, e.getMessage(), TaxeditorNavigationPlugin.PLUGIN_ID, e, false);
93
            return Status.CANCEL_STATUS;
94
        }
95
		
96
		monitor.worked(40);
97

    
98
		return postExecute(oldTaxon);
99
	}
100

    
101
	/* (non-Javadoc)
102
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
103
	 */
104
	/** {@inheritDoc} */
105
	@Override
106
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
107
			throws ExecutionException {
108
		// TODO Auto-generated method stub
109
		return null;
110
	}
111

    
112
	/* (non-Javadoc)
113
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
114
	 */
115
	/** {@inheritDoc} */
116
	@Override
117
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
118
			throws ExecutionException {
119
		// TODO Auto-generated method stub
120
		return null;
121
	}
122
}
(1-1/5)