*/
package eu.etaxonomy.taxeditor.editor.definedterm.e4;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import javax.annotation.PostConstruct;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.IMemento;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
this.input = input;
viewer.setInput(input.getVocabularies());
+ for (TermVocabularyDto voc:input.getVocabularies()){
+ for (TermDto dto: this.contentProvider.getChildTerms(voc)){
+ voc.addTerm(dto);;
+ }
+ }
thisPart.setLabel(label);
}
@Persist
public void save(IProgressMonitor monitor) {
getConversationHolder().commit();
+ List<DefinedTermBase> terms = new ArrayList<>();
+ List<TermVocabulary> vocs = new ArrayList<>();
for(TermBase term:changedTerms){
if(term.isInstanceOf(DefinedTermBase.class)){
DefinedTermBase<?> definedTermBase = (DefinedTermBase<?>) term;
- CdmStore.getService(ITermService.class).merge(definedTermBase);
+ terms.add(definedTermBase);
+
}
else if(term.isInstanceOf(TermVocabulary.class)){
TermVocabulary<?> voc = (TermVocabulary<?>) term;
- CdmStore.getService(IVocabularyService.class).merge(voc);
+ vocs.add(voc);
}
}
+ if (!terms.isEmpty()){
+ CdmStore.getService(ITermService.class).merge(terms, true);
+ }
+ if (!vocs.isEmpty()){
+ CdmStore.getService(IVocabularyService.class).merge(vocs, true);
+ }
setDirty(false);
input.initialiseVocabularies();
changedTerms.clear();
@Override
public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
}
+
+ public void setSelection(TermDto toBeSelected){
+ TreeItem[] children = viewer.getTree().getItems();
+ for (TreeItem con: children){
+ if (con.getData() == toBeSelected){
+ this.viewer.setSelection(new StructuredSelection(toBeSelected));
+ return;
+ }else {
+ if (con instanceof TreeItem){
+ TreeItem[] items = con.getItems();
+ for (TreeItem item:items){
+ if(item.getData() != null && item.getData() instanceof TermDto ){
+ if(((TermDto)item.getData()).getUuid().equals(toBeSelected.getUuid())){
+ this.viewer.setSelection(new StructuredSelection(toBeSelected));
+ return;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ }
}
\ No newline at end of file
* See LICENSE.TXT at the top of this package for the full license terms.
*/
package eu.etaxonomy.taxeditor.editor.definedterm.e4.handler;
+import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
+import java.util.UUID;
import java.util.stream.Collectors;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
+import eu.etaxonomy.cdm.api.service.ITermService;
+import eu.etaxonomy.cdm.model.common.ICdmBase;
+import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.MeasurementUnit;
+import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
+import eu.etaxonomy.cdm.model.term.DefinedTermBase;
import eu.etaxonomy.cdm.model.term.TermType;
+import eu.etaxonomy.cdm.model.term.TermVocabulary;
+import eu.etaxonomy.cdm.persistence.dto.FeatureDto;
+import eu.etaxonomy.cdm.persistence.dto.TermDto;
+import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
+import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
import eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermEditorE4;
import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
+import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
List<MParameter> parameters = menuItem.getParameters();
TermType termType = null;
for (MParameter param: parameters){
- termType = TermType.getByKey(param.getValue());
+ try{
+ termType = TermType.getByKey(param.getValue());
+ }catch(Exception e){
+
+ }
}
-// UUID termTypeUuid = (UUID) menuItem.getTransientData().get(commandId+".termTypeUuid");
+
//
// TermType termType = TermType.getByUuid(termTypeUuid);
if(termType != null){
DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) part.getObject();
termEditor.init(termEditorInput, menuItem.getLocalizedLabel());
}
+ }else{
+ List<UuidAndTitleCache<? extends ICdmBase>> termUuidAndTitleCaches = (List<UuidAndTitleCache<? extends ICdmBase>> ) menuItem.getTransientData().get(commandId+".uuid");
+ Set<TermType> termTypes = new HashSet<>();
+ Set<UUID> termUuids = new HashSet<>();
+ for (UuidAndTitleCache<?> uuidAndTitleCache: termUuidAndTitleCaches){
+ termUuids.add(uuidAndTitleCache.getUuid());
+ }
+ List<DefinedTermBase> terms = CdmStore.getService(ITermService.class).load(new ArrayList<>(termUuids), null);
+
+ for (DefinedTermBase term: terms){
+// TermType type = termType;
+ TermEditorInput termEditorInput = new TermEditorInput(term.getTermType());
+ List<MPart> alreadyOpenedEditors = partService.getParts().stream()
+ .filter(part->part.getObject()!=null && part.getObject() instanceof DefinedTermEditorE4)
+ .filter(part->((DefinedTermEditorE4)part.getObject()).getDefinedTermEditorInput().getTermType().equals(term.getTermType()))
+ .collect(Collectors.toList());
+ if(!alreadyOpenedEditors.isEmpty()){
+ //there should never be more than one already opened editor
+ //so we just open the first
+ MPart openPart = alreadyOpenedEditors.iterator().next();
+ partService.activate(openPart);
+
+
+ }
+ else{
+ MPart part = partService.createPart(eu.etaxonomy.taxeditor.store.AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_DEFINEDTERM);
+ MPartStack editorAreaPartStack = WorkbenchUtility.getEditorAreaPartStack(application, modelService);
+ if(editorAreaPartStack!=null){
+ editorAreaPartStack.getChildren().add(part);
+ }
+ part = partService.showPart(part, PartState.ACTIVATE);
+ DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) part.getObject();
+ termEditor.init(termEditorInput, menuItem.getLocalizedLabel());
+ TermDto dto = null;
+ FeatureDto featureDto = null;
+ if (term instanceof Feature){
+ Feature feature = (Feature)term;
+ Set<TermVocabularyDto> supportedCategoricalEnumerations = new HashSet<>();
+ if (feature.getSupportedCategoricalEnumerations()!= null && !feature.getSupportedCategoricalEnumerations().isEmpty()){
+ for (TermVocabulary voc: feature.getSupportedCategoricalEnumerations()){
+ supportedCategoricalEnumerations.add(TermVocabularyDto.fromVocabulary(voc));
+ }
+ }
+ Set<TermVocabularyDto> recommendedModifierEnumerations = new HashSet<>();
+ if (feature.getRecommendedModifierEnumeration()!= null && !feature.getRecommendedModifierEnumeration().isEmpty()){
+ for (TermVocabulary voc: feature.getRecommendedModifierEnumeration()){
+ recommendedModifierEnumerations.add(TermVocabularyDto.fromVocabulary(voc));
+ }
+ }
+ Set<TermDto> recommendedMeasurementUnits = new HashSet<>();
+ if (feature.getRecommendedMeasurementUnits()!= null && !feature.getRecommendedMeasurementUnits().isEmpty()){
+ for (MeasurementUnit unit: feature.getRecommendedMeasurementUnits()){
+ recommendedMeasurementUnits.add(TermDto.fromTerm(unit));
+ }
+ }
+ Set<TermDto> recommendedStatisticalMeasures = new HashSet<>();
+ if (feature.getRecommendedStatisticalMeasures()!= null && !feature.getRecommendedStatisticalMeasures().isEmpty()){
+ for (StatisticalMeasure measures: feature.getRecommendedStatisticalMeasures()){
+ recommendedStatisticalMeasures.add(TermDto.fromTerm(measures));
+ }
+ }
+
+
+ featureDto = new FeatureDto(term.getUuid(), term.getRepresentations(), term.getPartOf() != null? term.getPartOf().getUuid(): null, term.getKindOf() != null? term.getKindOf().getUuid(): null,
+ term.getVocabulary()!= null? term.getVocabulary().getUuid(): null, null, term.getIdInVocabulary(), term.getVocabulary()!= null?term.getVocabulary().getRepresentations(): null, feature.isAvailableForTaxon(),
+ feature.isAvailableForTaxonName(),feature.isAvailableForOccurrence(), feature.getTitleCache(), feature.isSupportsCategoricalData(), feature.isSupportsQuantitativeData(),
+ supportedCategoricalEnumerations, recommendedModifierEnumerations, recommendedMeasurementUnits, recommendedStatisticalMeasures);
+
+ }else{
+ dto = TermDto.fromTerm(term);
+ }
+ termEditor.getViewer().expandToLevel(dto, 1);
+ if (featureDto != null){
+ termEditor.setSelection(featureDto);
+ }else{
+ termEditor.setSelection(dto);
+ }
+
+
+
+ }
+ }
+
}
}
}
\ No newline at end of file