Project

General

Profile

Revision 62306db3

ID62306db3cffdc2bc803c545a5519046046ca6983
Parent e10f18ed
Child 6fa5c755

Added by Katja Luther almost 2 years ago

ref #7793: fix named area and commonNameArea selection filter

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databaseAdmin/preferencePage/VokabularyAdminPreferences.java
68 68
        return composite;
69 69
    }
70 70

  
71
    @Override
72
    public boolean performOk() {
73
        PreferencesUtil.updateDBPreferences();
74
        return true;
75

  
76
    }
77

  
71 78

  
72 79
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java
145 145
    public static final String DISTRIBUTION_AREA_OCCURENCE_STATUS = "eu.etaxonomy.taxeditor.checklist.distributionAreaStatus";
146 146
    public static final String DISTRIBUTION_AREA_OCCURENCE_STATUS_GRAYED = "eu.etaxonomy.taxeditor.checklist.distributionAreaStatusGrayed";
147 147
    public static final String DISTRIBUTION_VOCABULARIES = "eu.etaxonomy.taxeditor.checklist.distributionVocabularies";
148
    public static final String DISTRIBUTION_VOCABULARIES_ALLOW_OVERRIDE = "eu.etaxonomy.taxeditor.checklist.distributionVocabulariesAllowOverride";
149
    public static final String DISTRIBUTION_VOCABULARIES_OVERRIDE = "eu.etaxonomy.taxeditor.checklist.distributionVocabulariesOverride";
148 150
    public static final String CHECKLIST_AREA_DISPLAY = "eu.etaxonomy.taxeditor.checklist.checklistAreaDisplay";
149 151
    public static final String CHECKLIST_AREA_DISPLAY_ID_IN_VOCABULARY = "IdInVocabulary";
150 152
    public static final String CHECKLIST_AREA_DISPLAY_TITLE = "Title";
......
262 264

  
263 265

  
264 266

  
267

  
265 268
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java
1704 1704
    //Distribution Editor
1705 1705
    preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
1706 1706
    if (preference != null){
1707
        if (!prefStore.getBoolean(DISTRIBUTION_AREA_PREFRENCES_ACTIVE_OVERRIDE) ||  !preference.isAllowOverride()){
1707
        if (!prefStore.getBoolean(DISTRIBUTION_VOCABULARIES_OVERRIDE) ||  !preference.isAllowOverride()){
1708 1708
            prefStore.setValue(DISTRIBUTION_VOCABULARIES, preference.getValue());
1709
            prefStore.setValue(DISTRIBUTION_VOCABULARIES_ALLOW_OVERRIDE, preference.getValue());
1709 1710
        }
1711
    }else{
1712
        prefStore.setValue(DISTRIBUTION_VOCABULARIES_ALLOW_OVERRIDE,true);
1713
        prefStore.setToDefault(DISTRIBUTION_VOCABULARIES);
1710 1714
    }
1711 1715

  
1712 1716
    preference = getPreferenceFromDB(PreferencePredicate.DistributionEditorActivated);
......
1734 1738

  
1735 1739
    preference = getPreferenceFromDB(PreferencePredicate.CommonNameAreaVocabularies);
1736 1740
    if (preference != null){
1737
        if (!prefStore.getBoolean(COMMON_NAME_AREA_VOCABULARIES_OVERRIDE) ||  !preference.isAllowOverride()){
1741
        if (!prefStore.getBoolean(COMMON_NAME_AREA_VOCABULARIES) ||  !preference.isAllowOverride()){
1738 1742
            prefStore.setValue(COMMON_NAME_AREA_VOCABULARIES, preference.getValue());
1743
            prefStore.setValue(COMMON_NAME_AREA_VOCABULARIES_ALLOW_OVERRIDE, preference.isAllowOverride());
1739 1744
        }
1745
    }else{
1746
        prefStore.setToDefault(COMMON_NAME_AREA_VOCABULARIES);
1747
        prefStore.setValue(COMMON_NAME_AREA_VOCABULARIES_ALLOW_OVERRIDE, true);
1740 1748
    }
1741 1749

  
1742 1750
    preference = getPreferenceFromDB(PreferencePredicate.CommonNameReferencesWithMarker);
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/CommonNameNamedAreaSelectionDialog.java
8 8
*/
9 9
package eu.etaxonomy.taxeditor.ui.dialog.selection;
10 10

  
11
import java.util.ArrayList;
12
import java.util.List;
11 13
import java.util.UUID;
12 14

  
15
import org.apache.commons.lang.StringUtils;
13 16
import org.eclipse.swt.widgets.Shell;
14 17

  
18
import eu.etaxonomy.cdm.api.service.IVocabularyService;
19
import eu.etaxonomy.cdm.model.common.TermType;
20
import eu.etaxonomy.cdm.model.common.TermVocabulary;
15 21
import eu.etaxonomy.cdm.model.location.NamedArea;
16 22
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
17 23
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
18 25

  
19 26
/**
20 27
 * @author k.luther
......
40 47

  
41 48
    private static UUID[] createVocabularyUuidList() {
42 49
        String preselectedVocString = PreferencesUtil.getPreferenceStore().getString(IPreferenceKeys.COMMON_NAME_AREA_VOCABULARIES);
50
        if (StringUtils.isBlank(preselectedVocString)){
51
            return null;
52
        }
43 53
        String[] preselectedVocArray = preselectedVocString.split(";");
44 54
        UUID[] uuidList = new UUID[preselectedVocArray.length];
45 55
        int i = 0;
......
49 59
        }
50 60
        return uuidList;
51 61
    }
62
    @Override
63
    protected void init() {
64
        vocabularies = getAvailableVocabularies();
65
    }
66

  
67

  
68
    protected List<TermVocabulary> getAvailableVocabularies(){
69
        List<TermVocabulary> vocabularies = new ArrayList();
70

  
71
        if (!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.COMMON_NAME_AREA_VOCABULARIES_ALLOW_OVERRIDE)){
72
            UUID[] preselectedVocabularyUuids = createVocabularyUuidList();
73

  
74
            for(int i=0;i<preselectedVocabularyUuids.length;i++){
75
                TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
76
                vocabularies.add(preselectedVocabulary);
77
            }
78
        }else{
79
            vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null);
80
        }
81
        return vocabularies;
82
    }
52 83

  
53 84
    /**
54 85
     * Creates a filtered selection dialog to select a named area.
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/FilterDialog.java
24 24
import org.eclipse.swt.widgets.Control;
25 25
import org.eclipse.swt.widgets.Shell;
26 26

  
27
import eu.etaxonomy.cdm.api.service.IVocabularyService;
28
import eu.etaxonomy.cdm.model.common.TermType;
29 27
import eu.etaxonomy.cdm.model.common.TermVocabulary;
30 28
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
31
import eu.etaxonomy.taxeditor.store.CdmStore;
32 29

  
33 30
/**
34 31
 * @author k.luther
......
48 45
    /**
49 46
     * @param parentShell
50 47
     */
51
    protected FilterDialog(Shell parentShell, Object preferenceId, List<TermVocabulary> selectedVocabularies) {
48
    protected FilterDialog(Shell parentShell, Object preferenceId, List<TermVocabulary> selectedVocabularies, List<TermVocabulary> vocabularies) {
52 49
        super(parentShell);
53
        vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null);
50
        this.vocabularies = vocabularies;
54 51
        this.preferenceId = preferenceId;
55 52
        this.selectedVocabularies = selectedVocabularies;
56 53
        this.tempSelectedVocabularies = new ArrayList();
57 54
        this.tempSelectedVocabularies.addAll(selectedVocabularies);
58
       
59
       
55

  
56

  
60 57
    }
61 58

  
62 59
    @Override
......
114 111

  
115 112
    @Override
116 113
    protected void okPressed(){
117
    	
114

  
118 115
        for (TermVocabulary voc: vocabularies){
119 116
            if (tempSelectedVocabularies.contains(voc)){
120 117
                PreferencesUtil.getPreferenceStore().setValue(getPrefKey(voc), false);
......
126 123
        }
127 124
        super.okPressed();
128 125
    }
129
    
126

  
130 127
    private String getPrefKey(TermVocabulary vocabulary){
131 128
        return "hide_"+NamedAreaSelectionDialog.class.getCanonicalName()+vocabulary.getUuid()+preferenceId;
132 129
    }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/NamedAreaSelectionDialog.java
13 13
import java.util.List;
14 14
import java.util.UUID;
15 15

  
16
import org.apache.commons.lang.StringUtils;
16 17
import org.eclipse.jface.action.Action;
17 18
import org.eclipse.jface.action.IAction;
18 19
import org.eclipse.jface.dialogs.Dialog;
......
68 69
	}
69 70

  
70 71
	protected List<TermVocabulary> selectedVocabularies;
71
    protected ArrayList<TermVocabulary> preselectedVocabularies;
72
    protected List<TermVocabulary> vocabularies;
72 73

  
73 74

  
74 75

  
......
97 98
		super(shell, //conversation,
98 99
		        title, multi, NamedAreaSelectionDialog.class.getCanonicalName(), namedArea);
99 100

  
100
		preselectedVocabularies = new ArrayList<TermVocabulary>();
101
		selectedVocabularies = new ArrayList<TermVocabulary>();
102
		this.preferenceID = preferenceId;
101 103
		if (preselectedVocabularyUuids == null || preselectedVocabularyUuids.length == 0){
102 104
		    preselectedVocabularyUuids = createVocabularyUuidList();
103 105
		}
104
		for(int i=0;i<preselectedVocabularyUuids.length;i++){
105
			TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
106
			preselectedVocabularies.add(preselectedVocabulary);
106
		if (preselectedVocabularyUuids != null){
107
    		for(int i=0;i<preselectedVocabularyUuids.length;i++){
108
    			TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
109
    			selectedVocabularies.add(preselectedVocabulary);
110
    		}
107 111
		}
108 112

  
109 113

  
......
113 117

  
114 118
    protected List<TermVocabulary> createSelectedVocabularies() {
115 119
        List<TermVocabulary> tempSelectedVocabularies = new ArrayList<TermVocabulary>();
116
        for(TermVocabulary vocabulary:selectedVocabularies){
117
			if(preselectedVocabularies.contains(vocabulary)
120
        for(TermVocabulary vocabulary:vocabularies){
121
			if((selectedVocabularies.contains(vocabulary) && !PreferencesUtil.getPreferenceStore().getBoolean(getPrefKey(vocabulary)))
118 122
					|| !PreferencesUtil.getPreferenceStore().getBoolean(getPrefKey(vocabulary))){
119 123
				tempSelectedVocabularies.add(vocabulary);
120 124
			}
......
124 128

  
125 129
    private static UUID[] createVocabularyUuidList() {
126 130
        String preselectedVocString = PreferencesUtil.getPreferenceStore().getString(IPreferenceKeys.DISTRIBUTION_VOCABULARIES);
131
        if (StringUtils.isBlank(preselectedVocString)){
132
            return null;
133
        }
127 134
        String[] preselectedVocArray = preselectedVocString.split(";");
128 135
        UUID[] uuidList = new UUID[preselectedVocArray.length];
129 136
        int i = 0;
......
154 161
	/** {@inheritDoc} */
155 162
	@Override
156 163
	protected void init() {
157
		selectedVocabularies = getAvailableVocabularies();
164
		vocabularies = getAvailableVocabularies();
158 165
	}
159 166

  
160 167
	private List<TermVocabulary> getAvailableVocabularies(){
161
		List<TermVocabulary> vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null);
168
	    vocabularies = new ArrayList();
169
	    if (!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.DISTRIBUTION_VOCABULARIES_ALLOW_OVERRIDE)){
170
            UUID[] preselectedVocabularyUuids = createVocabularyUuidList();
171

  
172
            for(int i=0;i<preselectedVocabularyUuids.length;i++){
173
                TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
174
                vocabularies.add(preselectedVocabulary);
175
            }
176
        }else{
177
            vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null);
178
        }
179
		//List<TermVocabulary> vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null);
162 180
		return vocabularies;
163 181
	}
164 182

  
......
223 241
                        String text = null;
224 242
                        if (source instanceof Button){
225 243
                            Shell shell = ((Button)source).getShell();
226
                            Dialog dialog = new FilterDialog(getShell(), preferenceID, selectedVocabularies);
244
                            Dialog dialog = new FilterDialog(getShell(), preferenceID, selectedVocabularies, vocabularies);
227 245
                            if(dialog!=null){
228 246
                                dialog.open();
229 247
                            }
......
247 265

  
248 266
        }
249 267

  
250
    /**
251
     *
252
     */
253
    public void setSelectedVocabularies() {
254
        // TODO Auto-generated method stub
255 268

  
256
    }
257 269

  
258 270
    /* (non-Javadoc)
259 271
     * @see eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog#callService(java.lang.String)
260 272
     */
261 273
    @Override
262 274
    void callService(String pattern) {
263
        model = CdmStore.getService(ITermService.class).getUuidAndTitleCache(selectedVocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage());
275
        if (selectedVocabularies == null || selectedVocabularies.size() == 0){
276
            model = CdmStore.getService(ITermService.class).getUuidAndTitleCache(vocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage());
277
        }else{
278
            model = CdmStore.getService(ITermService.class).getUuidAndTitleCache(selectedVocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage());
279
        }
264 280
    }
265 281

  
266 282
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)