ref #9337: open in... vocabulary
authorKatja Luther <k.luther@bgbm.org>
Thu, 17 Jun 2021 13:04:31 +0000 (15:04 +0200)
committerKatja Luther <k.luther@bgbm.org>
Thu, 17 Jun 2021 13:04:31 +0000 (15:04 +0200)
eu.etaxonomy.taxeditor.store/fragment.e4xmi
eu.etaxonomy.taxeditor.store/plugin.xml
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/DefinedTermEditorE4.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/handler/OpenDefinedTermEditorHandlerE4.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/input/TermEditorInput.java

index dc2316873cb04dae00eea6e6f9d95a8d7b3a1910..31826ccd714640f4a51acfa4b852c0300dba8e62 100644 (file)
     <elements xsi:type="commands:Command" xmi:id="_8aaicD4fEeuM4JU-Ch98ZA" elementId="eu.etaxonomy.taxeditor.store.command.OpenTermTreeEditor" commandName="Open Term Tree Editor">
       <parameters xmi:id="_8aaicT4fEeuM4JU-Ch98ZA" elementId="eu.etaxonomy.taxeditor.store.commandparameter.termType" name="TermType" optional="false"/>
     </elements>
+    <elements xsi:type="commands:Command" xmi:id="_MkieEMKuEeufc9n3VJNAaA" elementId="eu.etaxonomy.taxeditor.store.command.featureTree.createFeatureTree_flat" commandName="%command.commandname.flat_tree"/>
+    <elements xsi:type="commands:Command" xmi:id="_ukIJAMKuEeufc9n3VJNAaA" elementId="eu.etaxonomy.taxeditor.store.command.featureTree.createFeatureTree_ordered" commandName="%command.commandname.ordered_tree"/>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_swGH0GhvEee3K4uKJljEYg" featurename="handlers" parentElementId="xpath:/">
     <elements xsi:type="commands:Handler" xmi:id="_rVEdIGcjEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.featuretree.e4.handler.RemoveFeatureHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.termtree.e4.handler.RemoveTermHandler" command="_fNBtQGcjEee0qLTtA2ZpVQ"/>
index b7f69eedbb1474a448aced3fcce914d0dc9a2595..f9e95dd45057b5f58aab44a1823b594a46bff2bd 100755 (executable)
          viewerName="%viewCommandMapping.viewerName.TAXON_NODE_WIZARD">
    </viewCommandMapping>
     <viewCommandMapping
-         commandId="eu.etaxonomy.taxeditor.store.openDefinedTermEditor"
-         selection="eu.etaxonomy.cdm.persistence.dto.TermNodeDto"
+         commandId="eu.etaxonomy.taxeditor.store.command.OpenDefinedTermEditor"
+         selection="eu.etaxonomy.cdm.model.term.DefinedTermBase"
          viewerName="Vocabulary">
    </viewCommandMapping>
 </extension>
index eff0f6db75887eb6ed2cf00219904612c59bff97..f4254a7aa3a7361ed964bc39a717dbdcdef8bd0c 100644 (file)
@@ -8,8 +8,10 @@
  */
 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;
@@ -36,6 +38,7 @@ import org.eclipse.swt.dnd.Transfer;
 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;
@@ -183,6 +186,11 @@ IPartContentHasDetails, IPartContentHasSupplementalData, IE4SavablePart, IContex
            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);
        }
 
@@ -190,16 +198,25 @@ IPartContentHasDetails, IPartContentHasSupplementalData, IE4SavablePart, IContex
     @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();
@@ -319,4 +336,27 @@ IPartContentHasDetails, IPartContentHasSupplementalData, IE4SavablePart, IContex
     @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
index ba78640e12cbfa07aecb4ee272e188c98906286f..2a6e51a1380c53160b4095909be96bf1e15c802e 100644 (file)
@@ -7,7 +7,11 @@
  * 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;
@@ -20,9 +24,21 @@ import org.eclipse.e4.ui.workbench.modeling.EModelService;
 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;
 
 
@@ -39,10 +55,14 @@ public class OpenDefinedTermEditorHandlerE4 {
            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){
@@ -67,6 +87,89 @@ public class OpenDefinedTermEditorHandlerE4 {
                    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
index 1f01db1ea8c7b3c1344815123ad0e46d38fe1583..8c42b04aaaf835114ce72379e032c7ec2e6dd09f 100644 (file)
@@ -68,6 +68,7 @@ public class TermEditorInput extends AbstractDefinedTermEditorInput<DefinedTerm>
                }
                List<TermVocabularyDto> vocs = CdmStore.getService(IVocabularyService.class).findVocabularyDtoByTermType(termType, false);
                vocabularies.addAll(vocs);
+
        }
 
        public Set<TermVocabularyDto> getVocabularies() {