1
|
/**
|
2
|
* Copyright (C) 2009 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.definedterm.e4.handler;
|
10
|
import java.util.ArrayList;
|
11
|
import java.util.HashSet;
|
12
|
import java.util.List;
|
13
|
import java.util.Set;
|
14
|
import java.util.UUID;
|
15
|
import java.util.stream.Collectors;
|
16
|
|
17
|
import org.eclipse.e4.core.di.annotations.Execute;
|
18
|
import org.eclipse.e4.ui.model.application.MApplication;
|
19
|
import org.eclipse.e4.ui.model.application.commands.MParameter;
|
20
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
21
|
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
|
22
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
23
|
import org.eclipse.e4.ui.workbench.modeling.EModelService;
|
24
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
25
|
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
|
26
|
|
27
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
28
|
import eu.etaxonomy.cdm.model.common.ICdmBase;
|
29
|
import eu.etaxonomy.cdm.model.description.Feature;
|
30
|
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
|
31
|
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
|
32
|
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
|
33
|
import eu.etaxonomy.cdm.model.term.TermType;
|
34
|
import eu.etaxonomy.cdm.model.term.TermVocabulary;
|
35
|
import eu.etaxonomy.cdm.persistence.dto.FeatureDto;
|
36
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
37
|
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
|
38
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
39
|
import eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermEditorE4;
|
40
|
import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
|
41
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
42
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
43
|
|
44
|
|
45
|
/**
|
46
|
* @author pplitzner
|
47
|
* @since Aug 22, 2017
|
48
|
*/
|
49
|
public class OpenDefinedTermEditorHandlerE4 {
|
50
|
|
51
|
@Execute
|
52
|
public void execute(EPartService partService, MHandledMenuItem menuItem, MApplication application, EModelService modelService) {
|
53
|
|
54
|
String commandId = menuItem.getCommand().getElementId();
|
55
|
List<MParameter> parameters = menuItem.getParameters();
|
56
|
TermType termType = null;
|
57
|
for (MParameter param: parameters){
|
58
|
try{
|
59
|
termType = TermType.getByKey(param.getValue());
|
60
|
}catch(Exception e){
|
61
|
|
62
|
}
|
63
|
}
|
64
|
|
65
|
|
66
|
//
|
67
|
// TermType termType = TermType.getByUuid(termTypeUuid);
|
68
|
if(termType != null){
|
69
|
TermType type = termType;
|
70
|
TermEditorInput termEditorInput = new TermEditorInput(termType);
|
71
|
List<MPart> alreadyOpenedEditors = partService.getParts().stream()
|
72
|
.filter(part->part.getObject()!=null && part.getObject() instanceof DefinedTermEditorE4)
|
73
|
.filter(part->((DefinedTermEditorE4)part.getObject()).getDefinedTermEditorInput().getTermType().equals(type))
|
74
|
.collect(Collectors.toList());
|
75
|
if(!alreadyOpenedEditors.isEmpty()){
|
76
|
//there should never be more than one already opened editor
|
77
|
//so we just open the first
|
78
|
partService.activate(alreadyOpenedEditors.iterator().next());
|
79
|
}
|
80
|
else{
|
81
|
MPart part = partService.createPart(eu.etaxonomy.taxeditor.store.AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_DEFINEDTERM);
|
82
|
MPartStack editorAreaPartStack = WorkbenchUtility.getEditorAreaPartStack(application, modelService);
|
83
|
if(editorAreaPartStack!=null){
|
84
|
editorAreaPartStack.getChildren().add(part);
|
85
|
}
|
86
|
part = partService.showPart(part, PartState.ACTIVATE);
|
87
|
DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) part.getObject();
|
88
|
termEditor.init(termEditorInput, menuItem.getLocalizedLabel());
|
89
|
}
|
90
|
}else{
|
91
|
List<UuidAndTitleCache<? extends ICdmBase>> termUuidAndTitleCaches = (List<UuidAndTitleCache<? extends ICdmBase>> ) menuItem.getTransientData().get(commandId+".uuid");
|
92
|
Set<TermType> termTypes = new HashSet<>();
|
93
|
Set<UUID> termUuids = new HashSet<>();
|
94
|
for (UuidAndTitleCache<?> uuidAndTitleCache: termUuidAndTitleCaches){
|
95
|
termUuids.add(uuidAndTitleCache.getUuid());
|
96
|
}
|
97
|
List<DefinedTermBase> terms = CdmStore.getService(ITermService.class).load(new ArrayList<>(termUuids), null);
|
98
|
|
99
|
for (DefinedTermBase term: terms){
|
100
|
// TermType type = termType;
|
101
|
TermEditorInput termEditorInput = new TermEditorInput(term.getTermType());
|
102
|
List<MPart> alreadyOpenedEditors = partService.getParts().stream()
|
103
|
.filter(part->part.getObject()!=null && part.getObject() instanceof DefinedTermEditorE4)
|
104
|
.filter(part->((DefinedTermEditorE4)part.getObject()).getDefinedTermEditorInput().getTermType().equals(term.getTermType()))
|
105
|
.collect(Collectors.toList());
|
106
|
if(!alreadyOpenedEditors.isEmpty()){
|
107
|
//there should never be more than one already opened editor
|
108
|
//so we just open the first
|
109
|
MPart openPart = alreadyOpenedEditors.iterator().next();
|
110
|
partService.activate(openPart);
|
111
|
|
112
|
|
113
|
}
|
114
|
else{
|
115
|
MPart part = partService.createPart(eu.etaxonomy.taxeditor.store.AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_DEFINEDTERM);
|
116
|
MPartStack editorAreaPartStack = WorkbenchUtility.getEditorAreaPartStack(application, modelService);
|
117
|
if(editorAreaPartStack!=null){
|
118
|
editorAreaPartStack.getChildren().add(part);
|
119
|
}
|
120
|
part = partService.showPart(part, PartState.ACTIVATE);
|
121
|
DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) part.getObject();
|
122
|
termEditor.init(termEditorInput, menuItem.getLocalizedLabel());
|
123
|
TermDto dto = null;
|
124
|
FeatureDto featureDto = null;
|
125
|
if (term instanceof Feature){
|
126
|
Feature feature = (Feature)term;
|
127
|
Set<TermVocabularyDto> supportedCategoricalEnumerations = new HashSet<>();
|
128
|
if (feature.getSupportedCategoricalEnumerations()!= null && !feature.getSupportedCategoricalEnumerations().isEmpty()){
|
129
|
for (TermVocabulary voc: feature.getSupportedCategoricalEnumerations()){
|
130
|
supportedCategoricalEnumerations.add(TermVocabularyDto.fromVocabulary(voc));
|
131
|
}
|
132
|
}
|
133
|
Set<TermVocabularyDto> recommendedModifierEnumerations = new HashSet<>();
|
134
|
if (feature.getRecommendedModifierEnumeration()!= null && !feature.getRecommendedModifierEnumeration().isEmpty()){
|
135
|
for (TermVocabulary voc: feature.getRecommendedModifierEnumeration()){
|
136
|
recommendedModifierEnumerations.add(TermVocabularyDto.fromVocabulary(voc));
|
137
|
}
|
138
|
}
|
139
|
Set<TermDto> recommendedMeasurementUnits = new HashSet<>();
|
140
|
if (feature.getRecommendedMeasurementUnits()!= null && !feature.getRecommendedMeasurementUnits().isEmpty()){
|
141
|
for (MeasurementUnit unit: feature.getRecommendedMeasurementUnits()){
|
142
|
recommendedMeasurementUnits.add(TermDto.fromTerm(unit));
|
143
|
}
|
144
|
}
|
145
|
Set<TermDto> recommendedStatisticalMeasures = new HashSet<>();
|
146
|
if (feature.getRecommendedStatisticalMeasures()!= null && !feature.getRecommendedStatisticalMeasures().isEmpty()){
|
147
|
for (StatisticalMeasure measures: feature.getRecommendedStatisticalMeasures()){
|
148
|
recommendedStatisticalMeasures.add(TermDto.fromTerm(measures));
|
149
|
}
|
150
|
}
|
151
|
|
152
|
|
153
|
featureDto = new FeatureDto(term.getUuid(), term.getRepresentations(), term.getPartOf() != null? term.getPartOf().getUuid(): null, term.getKindOf() != null? term.getKindOf().getUuid(): null,
|
154
|
term.getVocabulary()!= null? term.getVocabulary().getUuid(): null, null, term.getIdInVocabulary(), term.getVocabulary()!= null?term.getVocabulary().getRepresentations(): null, feature.isAvailableForTaxon(),
|
155
|
feature.isAvailableForTaxonName(),feature.isAvailableForOccurrence(), feature.getTitleCache(), feature.isSupportsCategoricalData(), feature.isSupportsQuantitativeData(),
|
156
|
supportedCategoricalEnumerations, recommendedModifierEnumerations, recommendedMeasurementUnits, recommendedStatisticalMeasures);
|
157
|
|
158
|
}else{
|
159
|
dto = TermDto.fromTerm(term);
|
160
|
}
|
161
|
termEditor.getViewer().expandToLevel(dto, 1);
|
162
|
if (featureDto != null){
|
163
|
termEditor.setSelection(featureDto);
|
164
|
}else{
|
165
|
termEditor.setSelection(dto);
|
166
|
}
|
167
|
|
168
|
|
169
|
|
170
|
}
|
171
|
}
|
172
|
|
173
|
}
|
174
|
}
|
175
|
}
|