1
|
package eu.etaxonomy.taxeditor.editor.view.dataimport;
|
2
|
|
3
|
import java.util.Iterator;
|
4
|
|
5
|
import org.eclipse.core.commands.AbstractHandler;
|
6
|
import org.eclipse.core.commands.ExecutionEvent;
|
7
|
import org.eclipse.core.commands.ExecutionException;
|
8
|
import org.eclipse.jface.viewers.ISelection;
|
9
|
import org.eclipse.jface.viewers.StructuredSelection;
|
10
|
import org.eclipse.ui.IWorkbenchPart;
|
11
|
import org.eclipse.ui.IWorkbenchWindow;
|
12
|
import org.eclipse.ui.PlatformUI;
|
13
|
|
14
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
15
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
16
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
17
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
18
|
|
19
|
|
20
|
public class SaveSpecimenCommand extends AbstractHandler {
|
21
|
|
22
|
/* (non-Javadoc)
|
23
|
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
24
|
*/
|
25
|
@Override
|
26
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
27
|
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
|
28
|
final ISelection selection = window.getActivePage().getSelection();
|
29
|
if(selection instanceof StructuredSelection){
|
30
|
StructuredSelection structuredSelection = (StructuredSelection)selection;
|
31
|
Iterator<?> iterator = structuredSelection.iterator();
|
32
|
while(iterator.hasNext()){
|
33
|
Object next = iterator.next();
|
34
|
if(next instanceof SpecimenOrObservationBase){
|
35
|
IWorkbenchPart activePart = AbstractUtility.getActivePart();
|
36
|
if(activePart instanceof DataImportEditor){
|
37
|
SpecimenImportEditor dataImportEditor = (SpecimenImportEditor)activePart;
|
38
|
CdmStore.getService(IOccurrenceService.class).saveOrUpdate((SpecimenOrObservationBase<?>) next);
|
39
|
dataImportEditor.getConversationHolder().commit(true);
|
40
|
}
|
41
|
}
|
42
|
}
|
43
|
}
|
44
|
return null;
|
45
|
}
|
46
|
|
47
|
}
|