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.descriptive.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.IWorkbenchPart;
|
16
|
import org.eclipse.ui.handlers.HandlerUtil;
|
17
|
|
18
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
19
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
20
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
21
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
22
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveViewPart;
|
23
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateSpecimenDescriptionOperation;
|
24
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateTaxonDescriptionOperation;
|
25
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
26
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
27
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
28
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
29
|
|
30
|
/**
|
31
|
* <p>AddDescriptionHandler class.</p>
|
32
|
*
|
33
|
* @author p.ciardelli
|
34
|
* @created 11.08.2009
|
35
|
* @version 1.0
|
36
|
*/
|
37
|
public class CreateDescriptionHandler extends AbstractHandler {
|
38
|
|
39
|
/* (non-Javadoc)
|
40
|
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
41
|
*/
|
42
|
/** {@inheritDoc} */
|
43
|
@Override
|
44
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
45
|
IWorkbenchPart part = HandlerUtil.getActivePart(event);
|
46
|
IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
|
47
|
AbstractPostOperation<?> operation;
|
48
|
if(part instanceof DescriptiveViewPart){
|
49
|
Object viewerInput = ((DescriptiveViewPart)part).getViewer().getInput();
|
50
|
if(viewerInput instanceof SpecimenOrObservationBase<?>){
|
51
|
try {
|
52
|
operation = new CreateSpecimenDescriptionOperation(event.getCommand().getName(), EditorUtil.getUndoContext(), (SpecimenOrObservationBase<?>) viewerInput, postOperationEnabled);
|
53
|
AbstractUtility.executeOperation(operation);
|
54
|
} catch (NotDefinedException e) {
|
55
|
MessagingUtils.warn(getClass(), "Command name not set."); //$NON-NLS-1$
|
56
|
}
|
57
|
}
|
58
|
if(viewerInput instanceof TaxonBase){
|
59
|
try{
|
60
|
operation = createTaxonOperation(event.getCommand().getName(), (Taxon) viewerInput, postOperationEnabled);
|
61
|
AbstractUtility.executeOperation(operation);
|
62
|
} catch (NotDefinedException e) {
|
63
|
MessagingUtils.warn(getClass(), "Command name not set."); //$NON-NLS-1$
|
64
|
}
|
65
|
|
66
|
}
|
67
|
}
|
68
|
return null;
|
69
|
}
|
70
|
|
71
|
/** {@inheritDoc} */
|
72
|
protected CreateTaxonDescriptionOperation createTaxonOperation(String eventLabel, Taxon taxon, IPostOperationEnabled postOperationEnabled) {
|
73
|
return new CreateTaxonDescriptionOperation(eventLabel, EditorUtil.getUndoContext(), taxon, postOperationEnabled);
|
74
|
}
|
75
|
|
76
|
}
|