Project

General

Profile

Revision 9457da34

ID9457da34b9e8a380eb4a7541820bfcbfb1cdbf64
Parent 2046cfa7
Child f4cc04f2

Added by Katja Luther over 1 year ago

fix #7312: fix immediately saving of preference changes

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/ChecklistEditorGeneralPreference.java
29 29
public class ChecklistEditorGeneralPreference extends CdmPreferencePage {
30 30

  
31 31
    boolean isEditorActivated;
32
    boolean isShowRank;
33
    boolean isSortByVocabularyOrder;
34
    boolean isShowSymbol;
35
    boolean isShowIdInVocabulary;
32 36
    Composite child ;
33 37

  
34 38
    @Override
......
44 48
            @Override
45 49
            public void widgetSelected(SelectionEvent e) {
46 50
                isEditorActivated = activateCheckButton.getSelection();
47
                PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DISTRIBUTION_AREA_PREFRENCES_ACTIVE, isEditorActivated);
51

  
48 52
                if(isEditorActivated){
49 53
                    child.setVisible(true);
50 54
                    child.setEnabled(true);
......
66 70

  
67 71
        button_openFeatureTree.setText("Open Distribution Selection Wizard");
68 72
        final Button showIdInVocabulary = new Button(child, SWT.CHECK);
69
        boolean isShowIdInVocabulary = PreferencesUtil.isShowIdInVocabularyInChecklistEditor();
73
        isShowIdInVocabulary = PreferencesUtil.isShowIdInVocabularyInChecklistEditor();
70 74
        showIdInVocabulary.setText("Show Id in Vocabulary instead of full title of the areas");
71 75
        showIdInVocabulary.setSelection(isShowIdInVocabulary);
72 76
        showIdInVocabulary.addSelectionListener(new SelectionAdapter(){
73 77
            @Override
74 78
            public void widgetSelected(SelectionEvent e) {
75
                boolean isShowIdInVocabulary = showIdInVocabulary.getSelection();
76
                PreferencesUtil.setShowIdInVocabularyInChecklistEditor(isShowIdInVocabulary);
79
                isShowIdInVocabulary = showIdInVocabulary.getSelection();
80

  
77 81
             }
78 82
        });
79 83

  
80 84
        final Button showSymbol = new Button(child, SWT.CHECK);
81
        boolean isShowSymbol = PreferencesUtil.isShowSymbolInChecklistEditor();
85
        isShowSymbol = PreferencesUtil.isShowSymbolInChecklistEditor();
82 86
        showSymbol.setText("Show Symbol of the Status, if existing");
83 87
        showSymbol.setSelection(isShowSymbol);
84 88
        showSymbol.addSelectionListener(new SelectionAdapter(){
85 89
            @Override
86 90
            public void widgetSelected(SelectionEvent e) {
87
                boolean isShowSymbol = showSymbol.getSelection();
88
                PreferencesUtil.setShowSymbolInChecklistEditor(isShowSymbol);
91
                isShowSymbol = showSymbol.getSelection();
89 92
             }
90 93
        });
91 94
        PreferencesUtil.recursiveSetEnabled(button_openFeatureTree, CdmStore.isActive());
92
        boolean isShowRank = PreferencesUtil.isShowRankInChecklistEditor();
95
        isShowRank = PreferencesUtil.isShowRankInChecklistEditor();
93 96
        final Button activateRankButton = new Button(child, SWT.CHECK);
94 97
        activateRankButton.setText("Show Rank in Distribution Editor");
95 98
        activateRankButton.setSelection(isShowRank);
96 99
        activateRankButton.addSelectionListener(new SelectionAdapter(){
97 100
            @Override
98 101
            public void widgetSelected(SelectionEvent e) {
99
                boolean isShowRank = activateRankButton.getSelection();
100
                PreferencesUtil.setShowRankInChecklistEditor(isShowRank);
102
                isShowRank = activateRankButton.getSelection();
101 103
            }
102 104
        });
103 105
        final Button sortNamedAreaByVocabularyOrder = new Button(child, SWT.CHECK);
104
        boolean isSortByVocabularyOrder = PreferencesUtil.isSortNamedAreaByOrderInVocabulary();
106
        isSortByVocabularyOrder = PreferencesUtil.isSortNamedAreaByOrderInVocabulary();
105 107
        sortNamedAreaByVocabularyOrder.setText("Sort Areas by Order in Vocabulary");
106 108
        sortNamedAreaByVocabularyOrder.setSelection(isSortByVocabularyOrder);
107 109
        sortNamedAreaByVocabularyOrder.addSelectionListener(new SelectionAdapter(){
108 110
            @Override
109 111
            public void widgetSelected(SelectionEvent e) {
110
                boolean isSortByVocabularyOrder = sortNamedAreaByVocabularyOrder.getSelection();
111
                PreferencesUtil.setSortNamedAreasByOrderInVocabulary(isSortByVocabularyOrder);
112
                isSortByVocabularyOrder = sortNamedAreaByVocabularyOrder.getSelection();
112 113
             }
113 114
        });
114 115

  
......
121 122
        return composite;
122 123
    }
123 124

  
125
    @Override
126
    public boolean performOk() {
127
        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DISTRIBUTION_AREA_PREFRENCES_ACTIVE, isEditorActivated);
128
        PreferencesUtil.setSortNamedAreasByOrderInVocabulary(isSortByVocabularyOrder);
129
        PreferencesUtil.setShowRankInChecklistEditor(isShowRank);
130
        PreferencesUtil.setShowSymbolInChecklistEditor(isShowSymbol);
131
        PreferencesUtil.setShowIdInVocabularyInChecklistEditor(isShowIdInVocabulary);
132
        return true;
133
    }
134

  
124 135
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/OrderPreferences.java
39 39
                public void widgetSelected(SelectionEvent e) {
40 40
                    if(isRestoreTaxonNavigator != activateRestoreNavigatorButton.getSelection()) {
41 41
                        isRestoreTaxonNavigator = activateRestoreNavigatorButton.getSelection();
42
                        PreferencesUtil.setStoreNavigatorState(isRestoreTaxonNavigator);
42

  
43 43
                    }
44 44
                }
45 45

  
......
75 75
	                	isNaturalOrderActivated = activateNaturalOrderCheckButton.getSelection();
76 76
	                	if (isAlphabeticalOrderActivated && isNaturalOrderActivated){
77 77
	                		isAlphabeticalOrderActivated = false;
78
	                		PreferencesUtil.setSortNodesStrictlyAlphabetically(isAlphabeticalOrderActivated);
78

  
79 79
	            		}
80 80
	            		if (isRankAndNameOrderActivated && isNaturalOrderActivated){
81 81
	            			isRankAndNameOrderActivated = false;
82 82
	            		}
83
	                	PreferencesUtil.setSortNodesNaturally(isNaturalOrderActivated);
83

  
84 84
                        isSelectionChanged = true;
85 85
                    }else{
86 86
                        isSelectionChanged = false;
......
95 95
	            		isAlphabeticalOrderActivated = activateAlphabeticallyOrderedCheckButton.getSelection();
96 96
	            		if (isNaturalOrderActivated && isAlphabeticalOrderActivated){
97 97
	            			isNaturalOrderActivated = false;
98
	            			PreferencesUtil.setSortNodesNaturally(isNaturalOrderActivated);
98

  
99 99
	            		}
100 100
	            		if (isRankAndNameOrderActivated && isAlphabeticalOrderActivated){
101 101
	            			isRankAndNameOrderActivated = false;
102 102
	            		}
103
	                	PreferencesUtil.setSortNodesStrictlyAlphabetically(isAlphabeticalOrderActivated);
103

  
104 104
                        isSelectionChanged = true;
105 105
                    }else{
106 106
                        isSelectionChanged = false;
......
116 116
	            		isRankAndNameOrderActivated = activateRankAndNameOrderActivatedCheckButton.getSelection();
117 117
	            		if (isAlphabeticalOrderActivated && isRankAndNameOrderActivated){
118 118
	            			 isAlphabeticalOrderActivated = false;
119
	            			 isNaturalOrderActivated = false;
119 120
	            		}
120
	            		if (isNaturalOrderActivated && isRankAndNameOrderActivated){
121
	            			isNaturalOrderActivated = false;
122
	            		}
123

  
124
	            		if (isRankAndNameOrderActivated ||(!isNaturalOrderActivated && !isAlphabeticalOrderActivated)){
125
	            			PreferencesUtil.setSortNodesStrictlyAlphabetically(false);
126
	            			PreferencesUtil.setSortNodesNaturally(false);
127
	            		}
128
                        isSelectionChanged = true;
121
	            		isSelectionChanged = true;
129 122
                    }else{
130 123
                        isSelectionChanged = false;
131 124
                    }
......
147 140
		@Override
148 141
		public boolean performOk() {
149 142
	       if(isSelectionChanged){
143
	           PreferencesUtil.setSortNodesStrictlyAlphabetically(isAlphabeticalOrderActivated);
144
	           PreferencesUtil.setSortNodesNaturally(isNaturalOrderActivated);
145
	           PreferencesUtil.setStoreNavigatorState(isRestoreTaxonNavigator);
150 146
	    	  MessageDialog.openInformation(getShell(), null, Messages.OrderPreferencePage_PleaseReopenNavigator);
151 147
	    	  isSelectionChanged = false;
152 148
			return super.performOk();
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java
118 118
	    else{
119 119
    		ICdmRepository controller;
120 120
    		controller = CdmStore.getCurrentApplicationConfiguration();
121
    		PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
121
    		PrefKey key = null;
122
    		try{
123
    		    key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
124
    		}catch (Exception e){
125
    		    System.out.println(e.getStackTrace());
126
    		}
122 127
    		CdmPreference preference = null;
123 128
    		if (controller == null){
124 129
    			return null;
......
1314 1319

  
1315 1320
}
1316 1321

  
1322
/**
1323
 * <p>
1324
 * setPreferredNomenclaturalCode
1325
 * </p>
1326
 *
1327
 * @param preferredCode
1328
 *            a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
1329
 *            object.
1330
 */
1331
public static CdmPreference setPreferredNamedAreasForDistributionEditor(
1332
        String saveCheckedElements, String saveGrayedElements, boolean local) {
1333
    if (local){
1334
        IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
1335
        preferenceStore.setValue(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS, saveCheckedElements);
1336
        preferenceStore.setValue(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS_GRAYED, saveGrayedElements);
1337

  
1338
    }
1339
    else{
1340
        ICdmRepository controller;
1341

  
1342
//        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.AvailableDistributionAreaTerms);
1343
        CdmPreference preference = null;
1344

  
1345
        if (saveCheckedElements == null){
1346
            preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaTerms);
1347
//            preference = controller.getPreferenceService().find(key);
1348
            if (preference == null){
1349
                return null;
1350
            } else{
1351
                String[] uuids = StringUtils.splitByWholeSeparator(saveCheckedElements, ",");
1352
                List<UUID> uuidList = new ArrayList();
1353
                for (String uuidString: uuids){
1354
                    uuidList.add(UUID.fromString(uuidString.trim()));
1355
                }
1356
                getPreferenceStore().setValue(DISTRIBUTION_AREA_OCCURENCE_STATUS,
1357
                        saveCheckedElements);
1358

  
1359
                return preference;
1360
            }
1361
        } else{
1362
            controller = CdmStore.getCurrentApplicationConfiguration();
1363
            preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements);
1364
            controller.getPreferenceService().set(preference);
1365
            getPreferenceStore().setValue(DISTRIBUTION_AREA_OCCURENCE_STATUS,
1366
                    saveCheckedElements);
1367

  
1368
        }
1369
    }
1370
    return null;
1371

  
1372

  
1373

  
1374
}
1375

  
1376

  
1317 1377

  
1318 1378

  
1319 1379
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/menu/CdmPreferencePage.java
8 8
*/
9 9
package eu.etaxonomy.taxeditor.preference.menu;
10 10

  
11
import java.util.Collection;
12
import java.util.List;
13
import java.util.Map;
14

  
15 11
import org.eclipse.jface.preference.PreferencePage;
16 12
import org.eclipse.jface.resource.ImageDescriptor;
17 13

  
18
import eu.etaxonomy.cdm.model.common.CdmBase;
19 14
import eu.etaxonomy.taxeditor.preference.IE4PreferencePage;
20 15
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
21
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
22
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
23
import eu.etaxonomy.taxeditor.store.CdmStore;
24 16

  
25 17
/**
26 18
 * @author cmathew
27 19
 * @date 30 Jul 2015
28 20
 *
29 21
 */
30
public abstract class CdmPreferencePage extends PreferencePage implements ICdmEntitySessionEnabled, IE4PreferencePage {
22
public abstract class CdmPreferencePage extends PreferencePage implements IE4PreferencePage {
31 23

  
32
    private ICdmEntitySession previousCdmEntitySession;
33 24
    private boolean isApply;
34 25

  
35 26
    public CdmPreferencePage() {
......
42 33

  
43 34
    public CdmPreferencePage(String title, ImageDescriptor image) {
44 35
        super(title, image);
45
        initSession();
36

  
46 37
        init();
47 38
    }
48 39

  
......
50 41
        setPreferenceStore(PreferencesUtil.getPreferenceStore());
51 42
    }
52 43

  
53
    private void initSession() {
54
        if (CdmStore.isActive()){
55
            previousCdmEntitySession = CdmStore.getCurrentSessionManager().getActiveSession();
56
            bindNullSession();
57
        }
58

  
59
    }
60

  
61
    private void bindNullSession() {
62
        if(CdmStore.isActive()) {
63
            CdmStore.getCurrentSessionManager().bindNullSession();
64
        }
65
    }
66

  
67 44
    @Override
68 45
    public boolean performOk() {
69
        if(previousCdmEntitySession != null && !isApply) {
70
            previousCdmEntitySession.bind();
71
        }
46

  
72 47
        return super.performOk();
73 48
    }
74 49

  
75 50
    @Override
76 51
    public boolean performCancel() {
77
        if(previousCdmEntitySession != null) {
78
            previousCdmEntitySession.bind();
79
        }
52

  
80 53
        return super.performCancel();
81 54
    }
82 55

  
......
87 60
        isApply = false;
88 61
    }
89 62

  
90
    /* (non-Javadoc)
91
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
92
     */
93
    @Override
94
    public ICdmEntitySession getCdmEntitySession() {
95
        return CdmStore.getCurrentSessionManager().getNullSession();
96
    }
97 63

  
98
    /* (non-Javadoc)
99
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
100
     */
101
    @Override
102
    public <T extends CdmBase> Collection<T> getRootEntities() {
103
        return null;
104
    }
105 64

  
106
    /* (non-Javadoc)
107
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
108
     */
109
    @Override
110
    public Map<Object, List<String>> getPropertyPathsMap() {
111
        return null;
112
    }
65

  
113 66

  
114 67
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionWizard.java
82 82
            String saveCheckedElements = StringUtils.join(listUIIDChecked, ",");
83 83
            String saveGrayedElements = StringUtils.join(listUIIDGrayed, ",");
84 84
            IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
85
            preferenceStore.setValue(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS, saveCheckedElements);
85
            PreferencesUtil.setPreferredNamedAreasForDistributionEditor(saveCheckedElements, saveGrayedElements, false);
86
//            preferenceStore.setValue(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS, saveCheckedElements);
86 87
            preferenceStore.setValue(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS_GRAYED, saveGrayedElements);
87 88
            return true;
88 89
        } else {

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)