From f4114c4dd38c82de3a220c795ef95d88a80b87b5 Mon Sep 17 00:00:00 2001 From: "a.theys" Date: Fri, 27 Jan 2012 16:49:08 +0000 Subject: [PATCH] AT: commiting latest changes to the Palm Use data extension --- .../userecords/UseRecordDetailElement.java | 428 ++++++++++++++++-- .../view/userecords/UseRecordsViewer.java | 16 +- 2 files changed, 411 insertions(+), 33 deletions(-) diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/userecords/UseRecordDetailElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/userecords/UseRecordDetailElement.java index b385976cf..d84982f95 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/userecords/UseRecordDetailElement.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/userecords/UseRecordDetailElement.java @@ -24,7 +24,9 @@ import eu.etaxonomy.cdm.model.description.DescriptionElementBase; import eu.etaxonomy.cdm.model.description.Modifier; import eu.etaxonomy.cdm.model.description.State; import eu.etaxonomy.cdm.model.description.StateData; +import eu.etaxonomy.cdm.remote.controller.VocabularyController; import eu.etaxonomy.taxeditor.store.CdmStore; +import eu.etaxonomy.taxeditor.store.TermManager; import eu.etaxonomy.taxeditor.store.TermStore; import eu.etaxonomy.taxeditor.ui.combo.TermComboElement; import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; @@ -47,7 +49,9 @@ public class UseRecordDetailElement extends private TermComboElement combo_UseCategory; private TermComboElement combo_UseSubCategory; private TermComboElement combo_PlantPart; - + private TermComboElement combo_Country; + private TermComboElement combo_HumanGroup; + private TermComboElement combo_EthnicGroup; // private AbstractDetailedDescriptionDetailElement detailElement; /* @@ -74,20 +78,16 @@ public class UseRecordDetailElement extends // "Order Relevant", entity.getOrderRelevant(), style); combo_UseCategory = formFactory.createTermComboElement(State.class, this, "Use Category", null, style); combo_UseCategory.addSelectionListener(this); - combo_UseSubCategory = formFactory.createTermComboElement(State.class, this, "Use Sub Category", null, style); + combo_UseSubCategory = formFactory.createTermComboElement(State.class, this, "Use SubCategory", null, style); + combo_Country = formFactory.createTermComboElement(Modifier.class, this, "Country", null, style); combo_PlantPart = formFactory.createTermComboElement(Modifier.class, this, "Plant Part", null, style); - // List listOfTerms = TermStore.getTerms(State.class,null , - // false); - - // UUID uuidUseCategory = - // UUID.fromString("2bb365af-ce6c-4196-a30b-e69b05099ed0"); - // TermVocabulary termVoc = - // CdmStore.getService(IVocabularyService.class).find(uuidUseCategory); - List termsToAdd = setUseCategoryComboTerms(TermStore.getTerms(State.class, null, false)); + combo_HumanGroup = formFactory.createTermComboElement(Modifier.class, this, "Human Group", null, style); + combo_HumanGroup.addSelectionListener(this); + combo_EthnicGroup = formFactory.createTermComboElement(Modifier.class, this, "Ethnic Group", null, style); - List plantPartsToAdd = setPlantPartsComboTerms(TermStore.getTerms(Modifier.class, null, false)); - // combo_UseCategory.setTerms(setUseCategoryComboTerms(listOfTerms)); - combo_UseCategory.setTerms(termsToAdd); + + List termsUseCategory = setUseCategoryComboTerms(TermStore.getTerms(State.class, null, false)); + combo_UseCategory.setTerms(termsUseCategory); combo_UseCategory.setSelection(useCategorySelection()); List termsSubCategory = setUseCategoryComboTerms(TermStore.getTerms(State.class, null, false), combo_UseCategory.getSelection()); @@ -101,9 +101,26 @@ public class UseRecordDetailElement extends else { combo_UseSubCategory.setEnabled(false); } + List plantPartsToAdd = setPlantPartsComboTerms(TermStore.getTerms(Modifier.class, null, false)); combo_PlantPart.setTerms(plantPartsToAdd); combo_PlantPart.setSelection(plantPartSelection()); + List countriesToAdd = setCountryComboTerms(TermStore.getTerms(Modifier.class, null, false)); + combo_Country.setTerms(countriesToAdd); + combo_Country.setSelection(countrySelection()); + + List humanGroupToAdd = setHumanGroupComboTerms(TermStore.getTerms(Modifier.class, null, false)); + combo_HumanGroup.setTerms(humanGroupToAdd); + combo_HumanGroup.setSelection(humanGroupSelection()); + + List ethnicGroupToAdd = setEthnicGroupComboTerms(TermStore.getTerms(Modifier.class, null, false), combo_HumanGroup.getSelection()); + if (ethnicGroupToAdd != null) { + combo_EthnicGroup.setTerms(ethnicGroupToAdd); + combo_EthnicGroup.setSelection(ethnicGroupSelection()); + combo_EthnicGroup.setEnabled(true); + } else { + combo_EthnicGroup.setEnabled(false); + } // getPreferredTerms(State.class)); // UseSubCategory_stateData = @@ -123,8 +140,8 @@ public class UseRecordDetailElement extends } - - + + private Modifier plantPartSelection() { /*if(!getEntity().getModifiers().isEmpty()) { for (Modifier modifier : getEntity().getModifiers()) { @@ -148,17 +165,131 @@ public class UseRecordDetailElement extends } return null;*/ //for testing purposes - + int countMods = 0; Modifier modiftoreturn = Modifier.NewInstance(); if (!getEntity().getModifiers().isEmpty()) { for (Modifier modifier : getEntity().getModifiers()){ - modiftoreturn = modifier; + if(countMods == 0) { + modiftoreturn = modifier; + } + countMods++; } return modiftoreturn; } return null; } + + private Modifier countrySelection() { + /*if(!getEntity().getModifiers().isEmpty()) { + for (Modifier modifier : getEntity().getModifiers()) { + if (modifier.getMarkers() != null) { + for (Marker marker : modifier.getMarkers()) { + if(marker.getMarkerType().getTitleCache().equals("Country")) { + return modifier; + } + else { + return null; + } + } + } + else { + return null; + } + + } + } else { + return null; + } + return null;*/ + //for testing purposes + int countMods = 0; + Modifier modiftoreturn = Modifier.NewInstance(); + if (!getEntity().getModifiers().isEmpty()) { + for (Modifier modifier : getEntity().getModifiers()){ + if(countMods == 1) { + modiftoreturn = modifier; + } + countMods++; + } + return modiftoreturn; + } + return null; + } + + private Modifier humanGroupSelection() { + /*if(!getEntity().getModifiers().isEmpty()) { + for (Modifier modifier : getEntity().getModifiers()) { + if (modifier.getMarkers() != null) { + for (Marker marker : modifier.getMarkers()) { + if(marker.getMarkerType().getTitleCache().equals("Human Group")) { + return modifier; + } + else { + return null; + } + } + } + else { + return null; + } + + } + } else { + return null; + } + return null;*/ + //for testing purposes + int countMods =0; + Modifier modiftoreturn = Modifier.NewInstance(); + if (!getEntity().getModifiers().isEmpty()) { + for (Modifier modifier : getEntity().getModifiers()){ + if (countMods == 2) { + modiftoreturn = modifier; + } + countMods++; + } + return modiftoreturn; + } + return null; + } + + private Modifier ethnicGroupSelection() { + /*if(!getEntity().getModifiers().isEmpty()) { + for (Modifier modifier : getEntity().getModifiers()) { + if (modifier.getMarkers() != null) { + for (Marker marker : modifier.getMarkers()) { + if(marker.getMarkerType().getTitleCache().equals("Human Group")) { + return modifier; + } + else { + return null; + } + } + } + else { + return null; + } + + } + } else { + return null; + } + return null;*/ + //for testing purposes + int countMods =0; + Modifier modiftoreturn = Modifier.NewInstance(); + if (!getEntity().getModifiers().isEmpty()) { + for (Modifier modifier : getEntity().getModifiers()){ + if (countMods == 3) { + modiftoreturn = modifier; + } + countMods++; + } + return modiftoreturn; + } + return null; + } private State useCategorySelection() { /*if (!getEntity().getStates().isEmpty()) { @@ -187,6 +318,8 @@ public class UseRecordDetailElement extends return null; } + + private State useSubCategorySelection() { /*if (!getEntity().getStates().isEmpty() && combo_UseCategory.getSelection() != null) { for (StateData statedata : getEntity().getStates()) { @@ -204,6 +337,7 @@ public class UseRecordDetailElement extends return null; } return null;*/ + //for testing purposes int countStates =0; for (StateData state : getEntity().getStates()) { if ((countStates == 1)) { @@ -219,8 +353,25 @@ public class UseRecordDetailElement extends List termsToAdd = new ArrayList(); for (Modifier term : listOfTerms) { - if ((term.getPartOf() != null) - && (term.getPartOf().getTitleCache().equals("Plant Part"))) { + if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals("Plant Part"))) { + termsToAdd.add(term); + } + else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals("Plant Part"))) { + termsToAdd.add(term); + } + } + + return termsToAdd; + } + + private List setCountryComboTerms(List listOfTerms) { + List termsToAdd = new ArrayList(); + for (Modifier term : listOfTerms) { + + if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals("Country"))) { + termsToAdd.add(term); + } + else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals("Country"))) { termsToAdd.add(term); } } @@ -228,12 +379,15 @@ public class UseRecordDetailElement extends return termsToAdd; } + private List setUseCategoryComboTerms(List listOfTerms) { List termsToAdd = new ArrayList(); for (State term : listOfTerms) { - if ((term.getPartOf() != null) - && (term.getPartOf().getTitleCache().equals("Use Category"))) { + if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals("Use Category"))) { + termsToAdd.add(term); + } + else if ((term.getVocabulary() !=null) && (term.getPartOf() == null) && (term.getVocabulary().getTitleCache().equals("Use Category"))) { termsToAdd.add(term); } } @@ -247,9 +401,10 @@ public class UseRecordDetailElement extends if (combo_UseCategory.getSelection() != null) { for (State term : listOfTerms) { - if ((term.getPartOf() != null) - && (term.getPartOf().getTitleCache() - .equals(selectedUseCategory.getTitleCache()))) { + if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(selectedUseCategory.getTitleCache()))) { + termsToAdd.add(term); + } + else if ((term.getVocabulary() !=null) && (term.getVocabulary().getTitleCache().equals(selectedUseCategory.getTitleCache()))) { termsToAdd.add(term); } @@ -260,9 +415,9 @@ public class UseRecordDetailElement extends if (stateData.getModifyingText().get(CdmStore.getDefaultLanguage()) != null) { if ((stateData.getState() != null) && (stateData.getModifyingText().get(CdmStore.getDefaultLanguage()).getText() == "Use Category")) { for (State term : listOfTerms) { - if ((term.getPartOf() != null) - && (term.getPartOf().getTitleCache() - .equals(stateData.getState().getTitleCache()))) { + if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(stateData.getState().getTitleCache()))) { + termsToAdd.add(term); + } else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals(stateData.getState().getTitleCache()))) { termsToAdd.add(term); } } @@ -280,6 +435,61 @@ public class UseRecordDetailElement extends // TODO Auto-generated method stub return termsToAdd; } + + private List setEthnicGroupComboTerms(List listOfTerms, + Modifier selectedHumangroup) { + List termsToAdd = new ArrayList(); + if (combo_HumanGroup.getSelection() != null) { + for (Modifier term : listOfTerms) { + + if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(selectedHumangroup.getTitleCache()))) { + termsToAdd.add(term); + } + else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals(selectedHumangroup.getTitleCache()))) { + termsToAdd.add(term); + } + } + } + else if (!getEntity().getModifiers().isEmpty()) { + for (Modifier modifier : getEntity().getModifiers()) { + if (modifier.getMarkers() != null) { + for (Marker marker : modifier.getMarkers()) { + if(marker.getMarkerType().getTitleCache().equals("Human Group")) { + for (Modifier term : listOfTerms) { + if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(modifier.getTitleCache()))) { + termsToAdd.add(modifier); + } else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals(modifier.getTitleCache()))) { + termsToAdd.add(modifier); + } + } + + } + } + } + } + } else { + return null; + } + + return termsToAdd; + } + + + private List setHumanGroupComboTerms(List listOfTerms) { + List termsToAdd = new ArrayList(); + for (Modifier term : listOfTerms) { + + if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals("Human Group"))) { + termsToAdd.add(term); + } + else if ((term.getVocabulary() != null) && (term.getPartOf() == null) && (term.getVocabulary().getTitleCache().equals("Human Group"))) { + termsToAdd.add(term); + } + } + + return termsToAdd; + } + /** {@inheritDoc} */ @Override @@ -436,8 +646,154 @@ public class UseRecordDetailElement extends } } } + if (eventSource == combo_Country) { + if (combo_Country.getSelection() != null) { + Set modifiers = getEntity().getModifiers(); + if(!modifiers.isEmpty()) { + for (Modifier modifier : modifiers) { + if (modifier.getMarkers() != null) { + for (Marker marker : modifier.getMarkers()) { + if (marker.getMarkerType().getTitleCache().equals("Country")) { + /*getEntity().removeModifier(modifier); + Modifier plantPart = combo_PlantPart.getSelection(); + plantPart.addMarker(marker); + getEntity().addModifier(plantPart);*/ + getEntity().addModifier(combo_Country.getSelection()); + } + else { + /*MarkerType markerType = MarkerType.NewInstance("Country", "Country", null); + Marker markerPlantPart = Marker.NewInstance(markerType, false); + Modifier plantPart = combo_PlantPart.getSelection(); + plantPart.addMarker(markerPlantPart); + getEntity().addModifier(plantPart);*/ + getEntity().addModifier(combo_Country.getSelection()); + } + + + } + + } + else { + /*MarkerType markerType = MarkerType.NewInstance("Country", "Country", null); + Marker marker = Marker.NewInstance(markerType, false); + Modifier plantPart = combo_PlantPart.getSelection(); + plantPart.addMarker(marker); + getEntity().addModifier(plantPart);*/ + getEntity().addModifier(combo_Country.getSelection()); + } + + } + } + else { + /*MarkerType markerType = MarkerType.NewInstance("Country", "Country", null); + Marker marker = Marker.NewInstance(markerType, false); + Modifier plantPart = combo_PlantPart.getSelection(); + plantPart.addMarker(marker); + getEntity().addModifier(plantPart);*/ + getEntity().addModifier(combo_Country.getSelection()); + } + } + } + if (eventSource == combo_HumanGroup) { + if (combo_HumanGroup.getSelection() != null) { + Set modifiers = getEntity().getModifiers(); + if(!modifiers.isEmpty()) { + for (Modifier modifier : modifiers) { + if (modifier.getMarkers() != null) { + for (Marker marker : modifier.getMarkers()) { + if (marker.getMarkerType().getTitleCache().equals("Human Group")) { + /*getEntity().removeModifier(modifier); + Modifier plantPart = combo_PlantPart.getSelection(); + plantPart.addMarker(marker); + getEntity().addModifier(plantPart);*/ + getEntity().addModifier(combo_HumanGroup.getSelection()); + } + else { + /*MarkerType markerType = MarkerType.NewInstance("Human Group", "Human Group", null); + Marker markerPlantPart = Marker.NewInstance(markerType, false); + Modifier plantPart = combo_PlantPart.getSelection(); + plantPart.addMarker(markerPlantPart); + getEntity().addModifier(plantPart);*/ + getEntity().addModifier(combo_HumanGroup.getSelection()); + } + + + } + + } + else { + /*MarkerType markerType = MarkerType.NewInstance("Human Group", "Human Group", null); + Marker marker = Marker.NewInstance(markerType, false); + Modifier plantPart = combo_PlantPart.getSelection(); + plantPart.addMarker(marker); + getEntity().addModifier(plantPart);*/ + getEntity().addModifier(combo_HumanGroup.getSelection()); + } + + } + } + else { + /*MarkerType markerType = MarkerType.NewInstance("Human Group", "Human Group", null); + Marker marker = Marker.NewInstance(markerType, false); + Modifier plantPart = combo_PlantPart.getSelection(); + plantPart.addMarker(marker); + getEntity().addModifier(plantPart);*/ + getEntity().addModifier(combo_HumanGroup.getSelection()); + } + } + combo_EthnicGroup.setEnabled(true); + } + if (eventSource == combo_EthnicGroup) { + if (combo_EthnicGroup.getSelection() != null) { + Set modifiers = getEntity().getModifiers(); + if(!modifiers.isEmpty()) { + for (Modifier modifier : modifiers) { + if (modifier.getMarkers() != null) { + for (Marker marker : modifier.getMarkers()) { + if (marker.getMarkerType().getTitleCache().equals("Ethnic Group")) { + /*getEntity().removeModifier(modifier); + Modifier plantPart = combo_PlantPart.getSelection(); + plantPart.addMarker(marker); + getEntity().addModifier(plantPart);*/ + getEntity().addModifier(combo_EthnicGroup.getSelection()); + } + else { + /*MarkerType markerType = MarkerType.NewInstance("Ethnic Group", "Ethnic Group", null); + Marker markerPlantPart = Marker.NewInstance(markerType, false); + Modifier plantPart = combo_PlantPart.getSelection(); + plantPart.addMarker(markerPlantPart); + getEntity().addModifier(plantPart);*/ + getEntity().addModifier(combo_EthnicGroup.getSelection()); + } + + + } + + } + else { + /*MarkerType markerType = MarkerType.NewInstance("Ethnic Group", "Ethnic Group", null); + Marker marker = Marker.NewInstance(markerType, false); + Modifier plantPart = combo_PlantPart.getSelection(); + plantPart.addMarker(marker); + getEntity().addModifier(plantPart);*/ + getEntity().addModifier(combo_EthnicGroup.getSelection()); + } + + } + } + else { + /*MarkerType markerType = MarkerType.NewInstance("Ethnic Group", "Ethnic Group", null); + Marker marker = Marker.NewInstance(markerType, false); + Modifier plantPart = combo_PlantPart.getSelection(); + plantPart.addMarker(marker); + getEntity().addModifier(plantPart);*/ + getEntity().addModifier(combo_EthnicGroup.getSelection()); + } + } + } } + /** {@inheritDoc} */ @Override @@ -448,17 +804,25 @@ public class UseRecordDetailElement extends @Override public void widgetSelected(SelectionEvent e) { - State selectedUseCategory = combo_UseCategory.getSelection(); - if (selectedUseCategory != null) { - combo_UseSubCategory.setTerms(setUseCategoryComboTerms( - TermStore.getTerms(State.class, null, false), - selectedUseCategory)); + Object eventSource = e.getSource(); + This is causing an error on purpose fix the if statement below + if(eventSource == combo_UseCategory) { + State selectedUseCategory = combo_UseCategory.getSelection(); + if (selectedUseCategory != null) { + combo_UseSubCategory.setTerms(setUseCategoryComboTerms(TermStore.getTerms(State.class, null, false),selectedUseCategory)); /* * selectedLanguageString = getMultilanguageText().get( * selectedLanguage); * * element_languageString.setLanguageString(selectedLanguageString); */ + } + } + if (eventSource == combo_HumanGroup) { + Modifier selectedHumanGroup = combo_HumanGroup.getSelection(); + if (selectedHumanGroup != null) { + combo_EthnicGroup.setTerms(setEthnicGroupComboTerms(TermStore.getTerms(Modifier.class, null, false), selectedHumanGroup)); + } } } diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/userecords/UseRecordsViewer.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/userecords/UseRecordsViewer.java index d587b3fc2..1c4485e98 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/userecords/UseRecordsViewer.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/userecords/UseRecordsViewer.java @@ -6,6 +6,7 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.forms.widgets.Section; +import eu.etaxonomy.cdm.model.common.TermVocabulary; import eu.etaxonomy.cdm.model.description.DescriptionBase; import eu.etaxonomy.cdm.model.description.DescriptionElementBase; import eu.etaxonomy.cdm.model.reference.Reference; @@ -31,6 +32,7 @@ import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceDetailSection; import eu.etaxonomy.taxeditor.ui.section.taxon.ParsingMessagesSection; import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonBaseDetailSection; import eu.etaxonomy.taxeditor.ui.section.userecords.UseRecordDetailSection; +import eu.etaxonomy.taxeditor.ui.section.vocabulary.TermVocabularyDetailSection; import eu.etaxonomy.taxeditor.view.AbstractCdmDataViewer; import eu.etaxonomy.taxeditor.view.AbstractCdmViewPart; @@ -61,7 +63,10 @@ public class UseRecordsViewer extends AbstractCdmDataViewer { } else if (getInput() instanceof DescriptionElementBase) { createUseRecordSection(rootElement); - } + } else if (getInput() instanceof TermVocabulary) { + createTermVocabularySection(rootElement); + + } /*if (getInput() instanceof TaxonBase) { if (currentViewPart != VIEW_PART.TAXON) { @@ -158,6 +163,15 @@ public class UseRecordsViewer extends AbstractCdmDataViewer { addPart(parsingMessagesSection); } + private void createTermVocabularySection(RootElement parent) { + destroySections(); + + TermVocabularyDetailSection termVocabularyDetailSection = (TermVocabularyDetailSection) formFactory + .createCdmDetailSection(DetailType.TERM_VOCABULARY, + getConversationHolder(), parent, this, Section.TWISTIE + | Section.EXPANDED); + addPart(termVocabularyDetailSection); + } private void createUseRecordSection(RootElement parent) { destroySections(); -- 2.34.1