1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.editor.view.media.handler;
|
5
|
|
6
|
import org.eclipse.core.commands.AbstractHandler;
|
7
|
import org.eclipse.core.commands.ExecutionEvent;
|
8
|
import org.eclipse.core.commands.ExecutionException;
|
9
|
import org.eclipse.core.commands.common.NotDefinedException;
|
10
|
import org.eclipse.jface.viewers.ISelection;
|
11
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
12
|
import org.eclipse.ui.IEditorInput;
|
13
|
import org.eclipse.ui.IEditorPart;
|
14
|
import org.eclipse.ui.IWorkbenchPart;
|
15
|
import org.eclipse.ui.handlers.HandlerUtil;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
18
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
19
|
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
|
20
|
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorUtil;
|
21
|
import eu.etaxonomy.taxeditor.bulkeditor.input.OccurrenceEditorInput;
|
22
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
23
|
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
|
24
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.AddDerivedUnitFacadeMediaOperation;
|
25
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateTaxonDescriptionOperation;
|
26
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
27
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
28
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
29
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
30
|
|
31
|
/**
|
32
|
* <p>AddImageGalleryHandler class.</p>
|
33
|
*
|
34
|
* @author p.ciardelli
|
35
|
* @version $Id: $
|
36
|
*/
|
37
|
public class AddImageGalleryHandler 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
|
|
46
|
IWorkbenchPart part = HandlerUtil.getActivePart(event);
|
47
|
IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
|
48
|
|
49
|
|
50
|
IEditorPart editor = HandlerUtil.getActiveEditor(event);
|
51
|
IEditorInput input = editor.getEditorInput();
|
52
|
|
53
|
if (input instanceof TaxonEditorInput) {
|
54
|
Taxon taxon = ((TaxonEditorInput) input).getTaxon();
|
55
|
AbstractPostOperation<?> operation;
|
56
|
try {
|
57
|
// TODO use undo context specific to editor
|
58
|
operation = new CreateTaxonDescriptionOperation(event.getCommand().getName(),
|
59
|
EditorUtil.getUndoContext(), taxon, postOperationEnabled, true);
|
60
|
AbstractUtility.executeOperation(operation);
|
61
|
} catch (NotDefinedException e) {
|
62
|
MessagingUtils.warn(getClass(), "Command name not set.");
|
63
|
}
|
64
|
}
|
65
|
else if(input instanceof OccurrenceEditorInput){
|
66
|
BulkEditor bulkEditor = (BulkEditor) editor;
|
67
|
ISelection selection = bulkEditor.getSelectionProvider().getSelection();
|
68
|
|
69
|
if(selection instanceof IStructuredSelection){
|
70
|
Object element = ((IStructuredSelection) selection).getFirstElement();
|
71
|
if(element instanceof SpecimenOrObservationBase<?>){
|
72
|
try {
|
73
|
AbstractPostOperation<?> operation = new AddDerivedUnitFacadeMediaOperation(event.getCommand().getName(),
|
74
|
BulkEditorUtil.getUndoContext(), (SpecimenOrObservationBase<?>)element, postOperationEnabled);
|
75
|
AbstractUtility.executeOperation(operation);
|
76
|
} catch (NotDefinedException e) {
|
77
|
MessagingUtils.warn(getClass(), "Command name not set.");
|
78
|
}
|
79
|
}
|
80
|
}
|
81
|
}
|
82
|
return null;
|
83
|
}
|
84
|
|
85
|
}
|