1
|
/**
|
2
|
* Copyright (C) 2018 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.descriptiveDataSet.matrix.handler;
|
10
|
|
11
|
import javax.inject.Named;
|
12
|
|
13
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
14
|
import org.eclipse.e4.core.di.annotations.Execute;
|
15
|
import org.eclipse.e4.ui.di.UISynchronize;
|
16
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
17
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
18
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
19
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
20
|
|
21
|
import eu.etaxonomy.cdm.api.service.IDescriptiveDataSetService;
|
22
|
import eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO;
|
23
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
24
|
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
|
25
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
26
|
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrixPart;
|
27
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
28
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
29
|
|
30
|
/**
|
31
|
* @author pplitzner
|
32
|
* @since Sep 7, 2018
|
33
|
*
|
34
|
*/
|
35
|
public abstract class CreateTaxonDescriptionHandler {
|
36
|
|
37
|
@Execute
|
38
|
public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart, UISynchronize sync) {
|
39
|
CharacterMatrixPart matrixPart = (CharacterMatrixPart) activePart.getObject();
|
40
|
if(StoreUtil.promptCheckIsDirty(matrixPart)){
|
41
|
return;
|
42
|
}
|
43
|
DescriptiveDataSet descriptiveDataSet = matrixPart.getDescriptiveDataSet();
|
44
|
TaxonNodeDto node = (TaxonNodeDto) matrixPart.getSelection().getFirstElement();
|
45
|
TaxonRowWrapperDTO taxonRowWrapperDTO = CdmStore.getService(IDescriptiveDataSetService.class)
|
46
|
.createTaxonDescription(descriptiveDataSet.getUuid(), node.getUuid(), getMarkerType(), getMarkerFlag());
|
47
|
matrixPart.getMatrix().getCdmEntitiySession().load(taxonRowWrapperDTO.getDescription(), true);
|
48
|
matrixPart.getMatrix().getDescriptions().add(taxonRowWrapperDTO);
|
49
|
}
|
50
|
|
51
|
protected abstract boolean getMarkerFlag();
|
52
|
|
53
|
|
54
|
protected abstract MarkerType getMarkerType();
|
55
|
|
56
|
@CanExecute
|
57
|
public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
|
58
|
MHandledMenuItem menuItem){
|
59
|
boolean canExecute = false;
|
60
|
IStructuredSelection selection = ((CharacterMatrixPart)activePart.getObject()).getSelection();
|
61
|
canExecute = selection.size()==1
|
62
|
&& selection.getFirstElement() instanceof TaxonNodeDto;
|
63
|
menuItem.setVisible(canExecute);
|
64
|
return canExecute;
|
65
|
}
|
66
|
|
67
|
}
|