From 3915821a57f59fed53c4fe969253b24671ff9010 Mon Sep 17 00:00:00 2001
From: Patrick Plitzner
Date: Thu, 1 Oct 2015 08:08:28 +0200
Subject: [PATCH] Pre-select country as named area type for country selection
for specimens (#2353)
---
.../selection/NamedAreaSelectionDialog.java | 27 +++++++++++++------
.../selection/SelectionDialogFactory.java | 17 ++++++++++--
.../ui/selection/EntitySelectionElement.java | 2 +-
3 files changed, 35 insertions(+), 11 deletions(-)
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/NamedAreaSelectionDialog.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/NamedAreaSelectionDialog.java
index b9c1b5c07..dc1ce081d 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/NamedAreaSelectionDialog.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/NamedAreaSelectionDialog.java
@@ -63,12 +63,12 @@ public class NamedAreaSelectionDialog extends
}else{
selectedVocabularies.remove(vocabulary);
}
-
initModel();
}
}
private Collection> selectedVocabularies;
+ private final ArrayList preselectedVocabularies;
/**
@@ -79,11 +79,12 @@ public class NamedAreaSelectionDialog extends
* @param namedArea
* A namedArea that should be selected when the dialog opens
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
+ * @param preselectedVocabularyUuids the {@link UUID}s of the pre-selected vocabularies
* @return a {@link eu.etaxonomy.cdm.model.location.NamedArea} object.
*/
- public static NamedArea select(Shell shell, ConversationHolder conversation, NamedArea namedArea) {
+ public static NamedArea select(Shell shell, ConversationHolder conversation, NamedArea namedArea, UUID... preselectedVocabularyUuids) {
NamedAreaSelectionDialog dialog = new NamedAreaSelectionDialog(shell, conversation,
- "Choose an area", false, namedArea);
+ "Choose an area", false, namedArea, preselectedVocabularyUuids);
return getSelectionFromDialog(dialog);
}
@@ -95,9 +96,17 @@ public class NamedAreaSelectionDialog extends
* @param title a {@link java.lang.String} object.
* @param multi a boolean.
* @param namedArea a {@link eu.etaxonomy.cdm.model.location.NamedArea} object.
+ * @param preselectedVocabularyUuids the {@link UUID}s of the pre-selected Vocabularies
*/
- protected NamedAreaSelectionDialog(Shell shell, ConversationHolder conversation, String title, boolean multi, NamedArea namedArea) {
+ protected NamedAreaSelectionDialog(Shell shell, ConversationHolder conversation, String title, boolean multi, NamedArea namedArea, UUID... preselectedVocabularyUuids) {
super(shell, conversation, title, multi, NamedAreaSelectionDialog.class.getCanonicalName(), namedArea);
+ preselectedVocabularies = new ArrayList();
+ for(int i=0;i vocabulary : getVocabularies()){
+ for(TermVocabulary vocabulary : getAvailableVocabularies()){
IncludeNamedAreaVocabulary action = new IncludeNamedAreaVocabulary(vocabulary);
menuManager.add(action);
- action.setChecked(true);
+ if(preselectedVocabularies.isEmpty() || preselectedVocabularies.contains(vocabulary)) {
+ action.setChecked(true);
+ }
}
}
@@ -130,10 +141,10 @@ public class NamedAreaSelectionDialog extends
/** {@inheritDoc} */
@Override
protected void init() {
- selectedVocabularies = getVocabularies();
+ selectedVocabularies = getAvailableVocabularies();
}
- private List> getVocabularies(){
+ private List> getAvailableVocabularies(){
List> vocabularies = CdmStore.getService(IVocabularyService.class).listByTermClass(NamedArea.class, null, null, null, null);
vocabularies.add(CdmStore.getService(IVocabularyService.class).find(Country.uuidCountryVocabulary));
return vocabularies;
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/SelectionDialogFactory.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/SelectionDialogFactory.java
index 93f7108d0..f6752d972 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/SelectionDialogFactory.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/SelectionDialogFactory.java
@@ -12,6 +12,7 @@ package eu.etaxonomy.taxeditor.ui.dialog.selection;
import org.eclipse.swt.widgets.Shell;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
import eu.etaxonomy.cdm.model.agent.AgentBase;
import eu.etaxonomy.cdm.model.agent.Institution;
import eu.etaxonomy.cdm.model.agent.Person;
@@ -25,6 +26,7 @@ import eu.etaxonomy.cdm.model.description.Feature;
import eu.etaxonomy.cdm.model.description.FeatureTree;
import eu.etaxonomy.cdm.model.description.PolytomousKey;
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
+import eu.etaxonomy.cdm.model.location.Country;
import eu.etaxonomy.cdm.model.location.NamedArea;
import eu.etaxonomy.cdm.model.molecular.Amplification;
import eu.etaxonomy.cdm.model.molecular.Primer;
@@ -39,6 +41,8 @@ import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.element.IEntityElement;
/**
* @author n.hoffmann
@@ -47,7 +51,11 @@ import eu.etaxonomy.taxeditor.model.MessagingUtils;
*/
public class SelectionDialogFactory {
- public static T getSelectionFromDialog(Class clazz, Shell shell, ConversationHolder conversation, T currentSelection){
+ public static T getSelectionFromDialog(Class clazz, Shell shell, ConversationHolder conversation, T currentSelection){
+ return getSelectionFromDialog(clazz, shell, conversation, currentSelection, null);
+ }
+
+ public static T getSelectionFromDialog(Class clazz, Shell shell, ConversationHolder conversation, T currentSelection, ICdmFormElement parentElement){
if(clazz.equals(Taxon.class)){
return (T) TaxonBaseSelectionDialog.selectTaxon(shell, conversation, (Taxon) currentSelection);
@@ -101,7 +109,12 @@ public class SelectionDialogFactory {
return (T) FieldUnitSelectionDialog.select(shell, conversation, (FieldUnit) currentSelection);
}
if(clazz.equals(NamedArea.class)){
- return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection);
+ if(parentElement instanceof IEntityElement && ((IEntityElement) parentElement).getEntity() instanceof DerivedUnitFacade){
+ return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection, Country.uuidCountryVocabulary);
+ }
+ else{
+ return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection);
+ }
}
if(clazz.equals(Collection.class)){
return (T) CollectionSelectionDialog.select(shell, conversation, (Collection) currentSelection);
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/EntitySelectionElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/EntitySelectionElement.java
index 88e9bb723..6f87d5e63 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/EntitySelectionElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/EntitySelectionElement.java
@@ -238,7 +238,7 @@ public class EntitySelectionElement extends
@Override
public void widgetSelected(SelectionEvent e) {
- T selection = SelectionDialogFactory.getSelectionFromDialog(clazz, getShell(), getConversationHolder(), getEntity());
+ T selection = SelectionDialogFactory.getSelectionFromDialog(clazz, getShell(), getConversationHolder(), getEntity(), getParentElement());
setSelectionInternal(selection);
}
--
2.34.1