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.common.CdmBase;
|
9
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
10
|
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
|
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
|
fieldUnit = CdmBase.deproxy(CdmStore.getService(IOccurrenceService.class).save(fieldUnit), FieldUnit.class);
|
27
|
derivateView.getConversationHolder().commit();
|
28
|
derivateView.addFieldUnit(fieldUnit);
|
29
|
derivateView.refreshTree();
|
30
|
}
|
31
|
return null;
|
32
|
}
|
33
|
|
34
|
}
|