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;

Also available in: Unified diff