1
|
/**
|
2
|
* Copyright (C) 2020 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 java.util.ArrayList;
|
12
|
import java.util.Collection;
|
13
|
import java.util.Iterator;
|
14
|
import java.util.List;
|
15
|
|
16
|
import javax.inject.Named;
|
17
|
|
18
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
19
|
import org.eclipse.e4.core.di.annotations.Execute;
|
20
|
import org.eclipse.e4.ui.di.UISynchronize;
|
21
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
22
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
23
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
24
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
25
|
import org.eclipse.jface.window.Window;
|
26
|
|
27
|
import eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO;
|
28
|
import eu.etaxonomy.cdm.persistence.dto.SpecimenNodeWrapper;
|
29
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
30
|
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
|
31
|
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrixPart;
|
32
|
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.SpecimenSelectionDialog;
|
33
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
34
|
|
35
|
/**
|
36
|
* @author k.luther
|
37
|
* @since May 11, 2020
|
38
|
*/
|
39
|
public class AddDescriptionHandler {
|
40
|
@Execute
|
41
|
public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart, UISynchronize sync) {
|
42
|
|
43
|
// dependent on the selection the specimens are filtered
|
44
|
CharacterMatrixPart matrixPart = (CharacterMatrixPart) activePart.getObject();
|
45
|
// if(StoreUtil.promptCheckIsDirty(matrixPart)){
|
46
|
// return;
|
47
|
// }
|
48
|
CharacterMatrix matrix = matrixPart.getMatrix();
|
49
|
IStructuredSelection selection = matrixPart.getSelection();
|
50
|
List<String> treeIndexList = null;
|
51
|
if(selection.size()>0){
|
52
|
treeIndexList = new ArrayList<>();
|
53
|
Iterator iterator = selection.iterator();
|
54
|
while (iterator.hasNext()){
|
55
|
Object element = iterator.next();
|
56
|
if (element instanceof TaxonNodeDto){
|
57
|
TaxonNodeDto taxonRow = (TaxonNodeDto) element;
|
58
|
String treeIndex = taxonRow.getTreeIndex();
|
59
|
treeIndexList.add(treeIndex);
|
60
|
}
|
61
|
}
|
62
|
|
63
|
}
|
64
|
|
65
|
SpecimenSelectionDialog dialog = new SpecimenSelectionDialog(matrix.getShell(), matrix, treeIndexList);
|
66
|
if(dialog.open()==Window.OK){
|
67
|
Collection<SpecimenNodeWrapper> wrappers = dialog.getSpecimen();
|
68
|
if(wrappers.stream().anyMatch(wrapper->wrapper.getTaxonDescriptionUuid()==null)
|
69
|
&& !MessagingUtils.confirmDialog(
|
70
|
"Create Taxon Association",
|
71
|
"Some specimens are not linked with taxon via IndividualsAssociation yet.\n"
|
72
|
+ "Do you want to create this association?")){
|
73
|
return;
|
74
|
}
|
75
|
matrix.addRowsToMatrix(wrappers);
|
76
|
wrappers.forEach(wrapper->matrix.getSpecimenCache().remove(wrapper));
|
77
|
|
78
|
}
|
79
|
}
|
80
|
|
81
|
@CanExecute
|
82
|
public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
|
83
|
MHandledMenuItem menuItem){
|
84
|
CharacterMatrixPart matrixPart = (CharacterMatrixPart) activePart.getObject();
|
85
|
IStructuredSelection selection = matrixPart.getSelection();
|
86
|
boolean canExecute = (selection.isEmpty() ||
|
87
|
!(selection.getFirstElement() instanceof SpecimenRowWrapperDTO) );
|
88
|
|
89
|
return canExecute;
|
90
|
|
91
|
}
|
92
|
}
|