e57cbfbf728e562f367b2b2657fb5176270cea01
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / derivate / handler / CreateFieldUnitHandler.java
1 package eu.etaxonomy.taxeditor.editor.view.derivate.handler;
2
3 import org.eclipse.core.commands.AbstractHandler;
4 import org.eclipse.core.commands.ExecutionEvent;
5 import org.eclipse.core.commands.ExecutionException;
6
7 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
8 import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
9 import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
10 import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
11 import eu.etaxonomy.taxeditor.model.AbstractUtility;
12 import eu.etaxonomy.taxeditor.model.MessagingUtils;
13 import eu.etaxonomy.taxeditor.store.CdmStore;
14
15 public class CreateFieldUnitHandler extends AbstractHandler {
16
17 @Override
18 public Object execute(ExecutionEvent event) throws ExecutionException {
19 if(AbstractUtility.getActivePart() instanceof DerivateView){
20 DerivateView derivateView = (DerivateView)AbstractUtility.getActivePart();
21 if(derivateView.isDirty()){
22 MessagingUtils.warningDialog(DerivateView.VIEW_HAS_UNSAVED_CHANGES, this, DerivateView.YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION);
23 return null;
24 }
25 FieldUnit fieldUnit = FieldUnit.NewInstance();
26 CdmStore.getService(IOccurrenceService.class).save(fieldUnit);
27 derivateView.getConversationHolder().commit();
28 DerivateViewEditorInput input = (DerivateViewEditorInput) derivateView.getEditorInput();
29 input.addRootUuid(fieldUnit.getUuid());
30 derivateView.refreshTree();
31 }
32 return null;
33 }
34
35 }