Project

General

Profile

Download (3.55 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2011 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
package eu.etaxonomy.taxeditor.editor.view.checklist.handler;
10

    
11
import org.eclipse.core.commands.AbstractHandler;
12
import org.eclipse.core.commands.ExecutionEvent;
13
import org.eclipse.core.commands.ExecutionException;
14
import org.eclipse.core.commands.common.NotDefinedException;
15
import org.eclipse.ui.IEditorInput;
16
import org.eclipse.ui.IEditorPart;
17
import org.eclipse.ui.IWorkbenchPart;
18
import org.eclipse.ui.forms.editor.FormEditor;
19
import org.eclipse.ui.handlers.HandlerUtil;
20

    
21
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
22
import eu.etaxonomy.cdm.model.taxon.Taxon;
23
import eu.etaxonomy.taxeditor.editor.EditorUtil;
24
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
25
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4;
26
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateSpecimenDescriptionOperation;
27
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateTaxonDescriptionOperation;
28
import eu.etaxonomy.taxeditor.model.AbstractUtility;
29
import eu.etaxonomy.taxeditor.model.MessagingUtils;
30
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
31
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
32

    
33
/**
34
 * <p>AddDescriptionHandler class.</p>
35
 *
36
 * @author p.ciardelli
37
 * @created 11.08.2009
38
 * @version 1.0
39
 */
40
public class CreateDescriptionHandler extends AbstractHandler {
41

    
42
	/* (non-Javadoc)
43
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
44
	 */
45
	/** {@inheritDoc} */
46
	@Override
47
    public Object execute(ExecutionEvent event) throws ExecutionException {
48
		IWorkbenchPart part = HandlerUtil.getActivePart(event);
49
		IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
50

    
51
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
52
		if (editor instanceof FormEditor) {
53
			editor = ((FormEditor) editor).getActiveEditor();
54
		}
55
		IEditorInput input = editor.getEditorInput();
56
		AbstractPostOperation<?> operation;
57

    
58
		// taxon description
59
		if (input instanceof TaxonEditorInput) {
60
			Taxon taxon = ((TaxonEditorInput) input).getTaxon();
61
			try {
62
			    operation = createTaxonOperation(event.getCommand().getName(), taxon, postOperationEnabled);
63
				AbstractUtility.executeOperation(operation);
64
			} catch (NotDefinedException e) {
65
				MessagingUtils.warn(getClass(), "Command name not set."); //$NON-NLS-1$
66
			}
67
		}
68
		// specimen description
69
		else if(part instanceof FactualDataPartE4){
70
		    Object viewerInput = ((FactualDataPartE4)part).getViewer().getInput();
71
		    if(viewerInput instanceof SpecimenOrObservationBase<?>){
72
		        try {
73
		            operation = new CreateSpecimenDescriptionOperation(event.getCommand().getName(), EditorUtil.getUndoContext(), (SpecimenOrObservationBase<?>) viewerInput, postOperationEnabled);
74
		            AbstractUtility.executeOperation(operation);
75
		        } catch (NotDefinedException e) {
76
		        	MessagingUtils.warn(getClass(), "Command name not set."); //$NON-NLS-1$
77
		        }
78
		    }
79
		}
80
		return null;
81
	}
82

    
83
	   /** {@inheritDoc} */
84
    protected CreateTaxonDescriptionOperation createTaxonOperation(String eventLabel, Taxon taxon, IPostOperationEnabled postOperationEnabled) {
85
        return new CreateTaxonDescriptionOperation(eventLabel, EditorUtil.getUndoContext(), taxon, postOperationEnabled);
86
    }
87

    
88
}
(2-2/3)