Project

General

Profile

Revision 0a1dde23

ID0a1dde2393323d6754c7791d6608f2bfda97154d
Parent 853dcb0b
Child 40e3002f

Added by Patrick Plitzner about 4 years ago

fix #6049 Store vocabulary filters for NamedArea selection dialogs in
preferences
- when passing pre-selected vocabularies programmatically these will
ignore the preferences and will always be selected

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/NamedAreaSelectionDialog.java
34 34
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
35 35
import eu.etaxonomy.taxeditor.model.MessagingUtils;
36 36
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
37
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
37 38
import eu.etaxonomy.taxeditor.store.CdmStore;
38 39

  
39 40
/**
......
62 63
			}else{
63 64
				selectedVocabularies.remove(vocabulary);
64 65
			}
66
			PreferencesUtil.getPreferenceStore().setValue(getPrefKey(vocabulary), isChecked());
65 67
			initModel();
66 68
		}
67 69
	}
......
89 91

  
90 92
	protected NamedAreaSelectionDialog(Shell shell, ConversationHolder conversation, String title, boolean multi, NamedArea namedArea, UUID... preselectedVocabularyUuids) {
91 93
		super(shell, conversation, title, multi, NamedAreaSelectionDialog.class.getCanonicalName(), namedArea);
92
		if(preselectedVocabularyUuids.length>0){
93
		    preselectedVocabularies = new ArrayList<TermVocabulary>();
94
		    for(int i=0;i<preselectedVocabularyUuids.length;i++){
95
		        TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
96
		        preselectedVocabularies.add(preselectedVocabulary);
97
		    }
98
		    selectedVocabularies.retainAll(preselectedVocabularies);
99
		    initModel();//re-init to consider pre-selected vocabularies
94
		preselectedVocabularies = new ArrayList<TermVocabulary>();
95
		for(int i=0;i<preselectedVocabularyUuids.length;i++){
96
			TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
97
			preselectedVocabularies.add(preselectedVocabulary);
100 98
		}
99
		Collection<TermVocabulary> tempSelectedVocabularies = new HashSet<>();
100
		for(TermVocabulary vocabulary:selectedVocabularies){
101
			if(preselectedVocabularies.contains(vocabulary)
102
					|| PreferencesUtil.getPreferenceStore().getBoolean(getPrefKey(vocabulary))){
103
				tempSelectedVocabularies.add(vocabulary);
104
			}
105
		}
106
		selectedVocabularies = tempSelectedVocabularies;
107
		initModel();//re-init to consider pre-selected vocabularies
101 108
	}
102 109

  
103 110
	/** {@inheritDoc} */
......
109 116
		for(TermVocabulary<NamedArea> vocabulary : getAvailableVocabularies()){
110 117
			IncludeNamedAreaVocabulary action = new IncludeNamedAreaVocabulary(vocabulary);
111 118
			menuManager.add(action);
112
			if(preselectedVocabularies==null || preselectedVocabularies.isEmpty() || preselectedVocabularies.contains(vocabulary)) {
119
			if(preselectedVocabularies.contains(vocabulary)) {
113 120
			    action.setChecked(true);
114 121
			}
122
			else{
123
				action.setChecked(PreferencesUtil.getPreferenceStore().getBoolean(getPrefKey(vocabulary)));
124
			}
115 125
		}
116 126
	}
127
	
128
	private String getPrefKey(TermVocabulary vocabulary){
129
		return NamedAreaSelectionDialog.class.toString()+vocabulary.getUuid();
130
	}
117 131

  
118 132
	/** {@inheritDoc} */
119 133
	@Override
......
133 147
	@Override
134 148
	protected void init() {
135 149
		selectedVocabularies = getAvailableVocabularies();
150
		for(TermVocabulary vocabulary:selectedVocabularies){
151
			PreferencesUtil.getPreferenceStore().setDefault(getPrefKey(vocabulary), true);
152
		}
136 153
	}
137 154

  
138 155
	private List<TermVocabulary> getAvailableVocabularies(){
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/SelectionDialogFactory.java
45 45
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
46 46
import eu.etaxonomy.taxeditor.ui.element.IEntityElement;
47 47
import eu.etaxonomy.taxeditor.ui.section.agent.TeamMemberElement;
48
import eu.etaxonomy.taxeditor.ui.section.description.detail.DistributionDetailElement;
49 48
import eu.etaxonomy.taxeditor.ui.section.name.AuthorshipDetailElement;
50 49
import eu.etaxonomy.taxeditor.ui.section.reference.NomenclaturalReferenceDetailElement;
51 50

  
......
126 125
		    return (T) SpecimenOrObservationBaseSelectionDialog.select(shell, conversation, (SpecimenOrObservationBase) currentSelection);
127 126
		}
128 127
		if(clazz.equals(NamedArea.class)){
129
		    if(parentElement instanceof DistributionDetailElement){
130
//                return (T) NamedAreaSelectionForDistributionDialog.select(shell, conversation, (NamedArea) currentSelection, CdmStore.getTermManager().getPreferredVocabulary(TermType.NamedArea));
131
                return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection, Country.uuidCountryVocabulary);
132
		    }else if(parentElement instanceof IEntityElement && ((IEntityElement) parentElement).getEntity() instanceof DerivedUnitFacade){
128
		    if(parentElement instanceof IEntityElement && ((IEntityElement) parentElement).getEntity() instanceof DerivedUnitFacade){
133 129
		        return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection, Country.uuidCountryVocabulary);
134 130
		    }
135 131
		    else{

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)