Project

General

Profile

Download (2.87 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.handler;
11

    
12
import org.apache.log4j.Logger;
13
import org.eclipse.core.commands.AbstractHandler;
14
import org.eclipse.core.commands.ExecutionEvent;
15
import org.eclipse.core.commands.ExecutionException;
16
import org.eclipse.core.commands.IHandler;
17
import org.eclipse.core.commands.common.NotDefinedException;
18
import org.eclipse.swt.widgets.Shell;
19
import org.eclipse.ui.handlers.HandlerUtil;
20

    
21
import eu.etaxonomy.cdm.model.taxon.Synonym;
22
import eu.etaxonomy.cdm.model.taxon.Taxon;
23
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
24
import eu.etaxonomy.taxeditor.editor.EditorUtil;
25
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
26
import eu.etaxonomy.taxeditor.editor.Page;
27
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
28
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptRelationshipTypeOperation;
29
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToMisapplicationOperation;
30
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
31

    
32
/**
33
 * <p>ChangeToMisapplicationHandler class.</p>
34
 *
35
 * @author n.hoffmann
36
 * @created 21.04.2009
37
 * @version 1.0
38
 */
39
public class ChangeToMisapplicationHandler extends AbstractHandler implements
40
		IHandler {
41
	private static final Logger logger = Logger
42
			.getLogger(ChangeToMisapplicationHandler.class);
43

    
44
	/* (non-Javadoc)
45
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
46
	 */
47
	/** {@inheritDoc} */
48
	@Override
49
    public Object execute(ExecutionEvent event) throws ExecutionException {
50
		TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(
51
				Page.NAME);
52
		Shell shell = HandlerUtil.getActiveShell(event);
53
		MultiPageTaxonEditor multiPageTaxonEditor = EditorUtil.getActiveMultiPageTaxonEditor();
54
		if (!EditorUtil.forceUserSave(multiPageTaxonEditor, shell)) {
55
            return null;
56
        }
57
		Object selectedElement = EditorUtil.getSelection(event).getFirstElement();
58

    
59
		AbstractPostOperation operation = null;
60
		try {
61
			if(selectedElement instanceof Taxon){
62
				operation = new ChangeConceptRelationshipTypeOperation(event.getCommand().getName(),
63
										editor.getUndoContext(), editor.getTaxon(), (Taxon) selectedElement, TaxonRelationshipType.MISAPPLIED_NAME_FOR(), editor);
64
			}
65
			if(selectedElement instanceof Synonym){
66
				operation = new ChangeSynonymToMisapplicationOperation(event.getCommand().getName(),
67
						editor.getUndoContext(), editor.getTaxon(), (Synonym) selectedElement, editor);
68
			}
69

    
70

    
71
			EditorUtil.executeOperation(operation);
72

    
73
		} catch (NotDefinedException e) {
74
			logger.warn("Command name not set"); //$NON-NLS-1$
75
		}
76

    
77
		return null;
78
	}
79
}
(3-3/15)