Project

General

Profile

« Previous | Next » 

Revision 3915821a

Added by Patrick Plitzner over 8 years ago

Pre-select country as named area type for country selection for
specimens (#2353)

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/NamedAreaSelectionDialog.java
63 63
			}else{
64 64
				selectedVocabularies.remove(vocabulary);
65 65
			}
66

  
67 66
			initModel();
68 67
		}
69 68
	}
70 69

  
71 70
	private Collection<TermVocabulary<NamedArea>> selectedVocabularies;
71
    private final ArrayList<TermVocabulary> preselectedVocabularies;
72 72

  
73 73

  
74 74
	/**
......
79 79
	 * @param namedArea
80 80
	 * 				A namedArea that should be selected when the dialog opens
81 81
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
82
	 * @param preselectedVocabularyUuids the {@link UUID}s of the pre-selected vocabularies
82 83
	 * @return a {@link eu.etaxonomy.cdm.model.location.NamedArea} object.
83 84
	 */
84
	public static NamedArea select(Shell shell, ConversationHolder conversation, NamedArea namedArea) {
85
	public static NamedArea select(Shell shell, ConversationHolder conversation, NamedArea namedArea, UUID... preselectedVocabularyUuids) {
85 86
		NamedAreaSelectionDialog dialog = new NamedAreaSelectionDialog(shell, conversation,
86
				"Choose an area", false, namedArea);
87
				"Choose an area", false, namedArea, preselectedVocabularyUuids);
87 88
		return getSelectionFromDialog(dialog);
88 89
	}
89 90

  
......
95 96
	 * @param title a {@link java.lang.String} object.
96 97
	 * @param multi a boolean.
97 98
	 * @param namedArea a {@link eu.etaxonomy.cdm.model.location.NamedArea} object.
99
	 * @param preselectedVocabularyUuids the {@link UUID}s of the pre-selected Vocabularies
98 100
	 */
99
	protected NamedAreaSelectionDialog(Shell shell, ConversationHolder conversation, String title, boolean multi, NamedArea namedArea) {
101
	protected NamedAreaSelectionDialog(Shell shell, ConversationHolder conversation, String title, boolean multi, NamedArea namedArea, UUID... preselectedVocabularyUuids) {
100 102
		super(shell, conversation, title, multi, NamedAreaSelectionDialog.class.getCanonicalName(), namedArea);
103
		preselectedVocabularies = new ArrayList<TermVocabulary>();
104
		for(int i=0;i<preselectedVocabularyUuids.length;i++){
105
		    TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
106
            preselectedVocabularies.add(preselectedVocabulary);
107
		}
108
		selectedVocabularies.retainAll(preselectedVocabularies);
109
		initModel();//re-init to consider pre-selected vocabularies
101 110
	}
102 111

  
103 112
	/** {@inheritDoc} */
......
106 115

  
107 116
		super.fillViewMenu(menuManager);
108 117

  
109
		for(TermVocabulary<NamedArea> vocabulary : getVocabularies()){
118
		for(TermVocabulary<NamedArea> vocabulary : getAvailableVocabularies()){
110 119
			IncludeNamedAreaVocabulary action = new IncludeNamedAreaVocabulary(vocabulary);
111 120
			menuManager.add(action);
112
			action.setChecked(true);
121
			if(preselectedVocabularies.isEmpty() || preselectedVocabularies.contains(vocabulary)) {
122
			    action.setChecked(true);
123
			}
113 124
		}
114 125
	}
115 126

  
......
130 141
	/** {@inheritDoc} */
131 142
	@Override
132 143
	protected void init() {
133
		selectedVocabularies = getVocabularies();
144
		selectedVocabularies = getAvailableVocabularies();
134 145
	}
135 146

  
136
	private List<TermVocabulary<NamedArea>> getVocabularies(){
147
	private List<TermVocabulary<NamedArea>> getAvailableVocabularies(){
137 148
		List<TermVocabulary<NamedArea>> vocabularies = CdmStore.getService(IVocabularyService.class).listByTermClass(NamedArea.class, null, null, null, null);
138 149
		vocabularies.add(CdmStore.getService(IVocabularyService.class).find(Country.uuidCountryVocabulary));
139 150
		return vocabularies;
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/SelectionDialogFactory.java
12 12
import org.eclipse.swt.widgets.Shell;
13 13

  
14 14
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
15
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
15 16
import eu.etaxonomy.cdm.model.agent.AgentBase;
16 17
import eu.etaxonomy.cdm.model.agent.Institution;
17 18
import eu.etaxonomy.cdm.model.agent.Person;
......
25 26
import eu.etaxonomy.cdm.model.description.FeatureTree;
26 27
import eu.etaxonomy.cdm.model.description.PolytomousKey;
27 28
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
29
import eu.etaxonomy.cdm.model.location.Country;
28 30
import eu.etaxonomy.cdm.model.location.NamedArea;
29 31
import eu.etaxonomy.cdm.model.molecular.Amplification;
30 32
import eu.etaxonomy.cdm.model.molecular.Primer;
......
39 41
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
40 42
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
41 43
import eu.etaxonomy.taxeditor.model.MessagingUtils;
44
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
45
import eu.etaxonomy.taxeditor.ui.element.IEntityElement;
42 46

  
43 47
/**
44 48
 * @author n.hoffmann
......
47 51
 */
48 52
public class SelectionDialogFactory {
49 53

  
50
	public static <T extends ICdmBase> T getSelectionFromDialog(Class<T> clazz, Shell shell, ConversationHolder conversation, T currentSelection){
54
    public static <T extends ICdmBase> T getSelectionFromDialog(Class<T> clazz, Shell shell, ConversationHolder conversation, T currentSelection){
55
        return getSelectionFromDialog(clazz, shell, conversation, currentSelection, null);
56
    }
57

  
58
	public static <T extends ICdmBase> T getSelectionFromDialog(Class<T> clazz, Shell shell, ConversationHolder conversation, T currentSelection, ICdmFormElement parentElement){
51 59

  
52 60
		if(clazz.equals(Taxon.class)){
53 61
			return (T) TaxonBaseSelectionDialog.selectTaxon(shell, conversation, (Taxon) currentSelection);
......
101 109
			return (T) FieldUnitSelectionDialog.select(shell, conversation, (FieldUnit) currentSelection);
102 110
		}
103 111
		if(clazz.equals(NamedArea.class)){
104
			return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection);
112
		    if(parentElement instanceof IEntityElement && ((IEntityElement) parentElement).getEntity() instanceof DerivedUnitFacade){
113
		        return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection, Country.uuidCountryVocabulary);
114
		    }
115
		    else{
116
		        return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection);
117
		    }
105 118
		}
106 119
		if(clazz.equals(Collection.class)){
107 120
			return (T) CollectionSelectionDialog.select(shell, conversation, (Collection) currentSelection);
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/EntitySelectionElement.java
238 238

  
239 239
	@Override
240 240
    public void widgetSelected(SelectionEvent e) {
241
		T selection = SelectionDialogFactory.getSelectionFromDialog(clazz, getShell(), getConversationHolder(), getEntity());
241
		T selection = SelectionDialogFactory.getSelectionFromDialog(clazz, getShell(), getConversationHolder(), getEntity(), getParentElement());
242 242
		setSelectionInternal(selection);
243 243
	}
244 244

  

Also available in: Unified diff