Project

General

Profile

Revision e056e66e

IDe056e66eb1fd2b32b4f2fa71bed1ce0496c6af22
Parent ae492166
Child 2b4872ec

Added by Katja Luther 8 months ago

fix #8226: add new preferences for modifiers

View differences:

eu.etaxonomy.taxeditor.store/plugin.xml
740 740
   </page>-->
741 741
      <page
742 742
            category="eu.etaxonomy.taxeditor.preferences.general"
743
            class="eu.etaxonomy.taxeditor.preference.FactualDataPreference"
743
            class="eu.etaxonomy.taxeditor.databaseAdmin.preferencePage.FactualDataAdminPreferencePage"
744 744
            id="eu.etaxonomy.taxeditor.preferences.description"
745 745
            name="%page.name.0">
746 746
      </page>
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databaseAdmin/preferencePage/FactualDataAdminPreferencePage.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.databaseAdmin.preferencePage;
10

  
11
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
12
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
13
import eu.etaxonomy.taxeditor.preference.FactualDataPreference;
14
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
15

  
16
/**
17
 * @author k.luther
18
 * @since 25.09.2019
19
 */
20
public class FactualDataAdminPreferencePage extends FactualDataPreference {
21

  
22

  
23
    @Override
24
    public void getValues(){
25
        isAdminPreference = true;
26
        pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowModifier);
27

  
28
        allowOverride = getPrefAllowOverride(pref);
29

  
30
        isShowModifier = getBooleanPrefValue(pref);
31

  
32
        //get modifier freetext values
33
        prefFreeText = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowModifierFreeText);
34

  
35
        allowOverrideFreeText = getPrefAllowOverride(prefFreeText);
36
        isShowModifierFreeText = getBooleanPrefValue(prefFreeText);
37
        }
38

  
39

  
40

  
41
    @Override
42
    public boolean performOk() {
43
        if (isApply()){
44
            pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowModifier, isShowModifier != null? Boolean.toString(this.isShowModifier): null);
45
            pref.setAllowOverride(allowOverride);
46
            PreferencesUtil.setPreferenceToDB(pref);
47

  
48
            prefFreeText = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowModifierFreeText, isShowModifierFreeText != null? Boolean.toString(this.isShowModifierFreeText): null);
49
            prefFreeText.setAllowOverride(allowOverrideFreeText);
50
            PreferencesUtil.setPreferenceToDB(prefFreeText);
51

  
52
            setApply(false);
53
        }
54
        return true;
55
    }
56

  
57

  
58

  
59
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/l10n/Messages.java
689 689
    public static String Preference_update;
690 690

  
691 691

  
692
    public static String FactualData_showModifier;
693
    public static String FactualData_showModifier_FreeText;
694
    public static String FactualData_description;
695

  
696

  
692 697

  
693 698

  
694 699

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/l10n/messages.properties
520 520

  
521 521
OrderPreferencePage_NotAllowed=The DB preference does not allow to edit this preference locally
522 522
Delete=Delete
523
Preference_update=Update
523
Preference_update=Update
524
FactualData_showModifier=Show modifier
525
FactualData_showModifier_FreeText=Show modifier freetext
526
FactualData_description=If a preference is not selectable, there is a serverside preference not allowed to override.
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/l10n/messages_de.properties
521 521
OrderPreferencePage_NotAllowed=Die Datenbank Pr?ferenz erlaub kein Editieren
522 522
Delete=L?schen
523 523
Preference_update=Aktualisieren
524
FactualData_showModifier=Zeige Modifier
525
FactualData_showModifier_FreeText=Zeige Freitext-Modifier
526
FactualData_description=Wenn die Pr?ferenz nicht ausgew?hlt werden kann, dann gibt es eine serverseitige Pr?ferenz, die das ?berschreiben nicht erlaubt.
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/FactualDataPreference.java
8 8
*/
9 9
package eu.etaxonomy.taxeditor.preference;
10 10

  
11
import org.eclipse.swt.SWT;
12
import org.eclipse.swt.events.SelectionAdapter;
13
import org.eclipse.swt.events.SelectionEvent;
14
import org.eclipse.swt.events.SelectionListener;
15
import org.eclipse.swt.widgets.Button;
16
import org.eclipse.swt.widgets.Combo;
11 17
import org.eclipse.swt.widgets.Composite;
12 18
import org.eclipse.swt.widgets.Control;
19
import org.eclipse.swt.widgets.Label;
13 20

  
21
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
22
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
23
import eu.etaxonomy.taxeditor.l10n.Messages;
14 24
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
15 25

  
16 26
/**
......
18 28
 * @since 28 Jan 2019
19 29
 *
20 30
 */
21
public class FactualDataPreference extends CdmPreferencePage {
31
public class FactualDataPreference extends CdmPreferencePage implements SelectionListener{
22 32

  
33

  
34
    protected Boolean isShowModifier;
35

  
36
    protected Combo comboShowModifier;
37
    protected CdmPreference pref = null;
38
    Button allowOverrideButton;
39

  
40
    protected boolean allowOverride;
41
    private boolean isOverride = true;
42

  
43
    protected Boolean isShowModifierFreeText;
44

  
45
    protected Combo comboShowModifierFreeText;
46
    protected CdmPreference prefFreeText = null;
47
    Button allowOverrideFreeTextButton;
48

  
49
    protected boolean allowOverrideFreeText;
50
    private boolean isOverrideFreeText = true;
51

  
52

  
53
   @Override
54
   public void init() {
55
       super.init();
56

  
57

  
58
   }
23 59
    /**
24 60
     * {@inheritDoc}
25 61
     */
26 62
    @Override
27 63
    protected Control createContents(Composite parent) {
28
        noDefaultAndApplyButton();
29
        return null;
64
        getValues();
65

  
66
        Composite composite = createComposite(parent);
67
        Label description = new Label(composite, SWT.NULL);
68
        description.setText(Messages.FactualData_description);
69

  
70
        comboShowModifier = createBooleanCombo(composite, SHOW, DO_NOT_SHOW, PreferencePredicate.ShowModifier, Messages.FactualData_showModifier, isAdminPreference);
71
        comboShowModifier.addSelectionListener(this);
72
        if (this.isAdminPreference){
73
            allowOverrideButton = createAllowOverrideButton(composite);
74
            allowOverrideButton.setSelection(allowOverride);
75
            allowOverrideButton.addSelectionListener(new SelectionAdapter(){
76
                @Override
77
                public void widgetSelected(SelectionEvent e) {
78
                    allowOverride = !allowOverride;
79
                    setApply(true);
80
                    }
81
            });
82
        }
83
        int index = 0;
84
        if(isShowModifier==null){
85
            comboShowModifier.select(0);
86
        } else{
87
            for (String itemLabel : comboShowModifier.getItems()){
88
                if (itemLabel.startsWith(this.SHOW) && isShowModifier){
89
                    comboShowModifier.select(index);
90
                    break;
91
                }
92
                if (itemLabel.startsWith(DO_NOT_SHOW) && !isShowModifier){
93
                    comboShowModifier.select(index);
94
                    break;
95
                }
96
                index++;
97
            }
98
        }
99
        if (!isAdminPreference){
100
            comboShowModifier.setEnabled(allowOverride);
101
        }
102

  
103
        comboShowModifierFreeText = createBooleanCombo(composite, SHOW, DO_NOT_SHOW, PreferencePredicate.ShowModifierFreeText, Messages.FactualData_showModifier_FreeText, isAdminPreference);
104
        comboShowModifierFreeText.addSelectionListener(this);
105
        if (this.isAdminPreference){
106
            allowOverrideFreeTextButton = createAllowOverrideButton(composite);
107
            allowOverrideFreeTextButton.setSelection(allowOverrideFreeText);
108
            allowOverrideFreeTextButton.addSelectionListener(new SelectionAdapter(){
109
                @Override
110
                public void widgetSelected(SelectionEvent e) {
111
                    allowOverrideFreeText = !allowOverrideFreeText;
112
                    setApply(true);
113
                    }
114
            });
115
        }
116
        index = 0;
117
        if(isShowModifierFreeText==null){
118
            comboShowModifierFreeText.select(0);
119
        } else{
120
            for (String itemLabel : comboShowModifierFreeText.getItems()){
121
                if (itemLabel.startsWith(this.SHOW) && isShowModifierFreeText){
122
                    comboShowModifierFreeText.select(index);
123
                    break;
124
                }
125
                if (itemLabel.startsWith(DO_NOT_SHOW) && !isShowModifierFreeText){
126
                    comboShowModifierFreeText.select(index);
127
                    break;
128
                }
129
                index++;
130
            }
131
        }
132
        if (!isAdminPreference){
133
            comboShowModifierFreeText.setEnabled(allowOverrideFreeText);
134
        }
135
        return composite;
136

  
137
    }
138

  
139

  
140
    @Override
141
    public boolean performOk() {
142
        if (isApply()){
143
            if (isShowModifier != null){
144
                PreferencesUtil.setStringValue(PreferencePredicate.ShowModifier.getKey(), Boolean.toString(isShowModifier));
145
                PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowModifier.getKey()), true);
146

  
147
            }else{
148
                PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowModifier.getKey()), false);
149
            }
150
            if (isShowModifierFreeText != null){
151
                PreferencesUtil.setStringValue(PreferencePredicate.ShowModifierFreeText.getKey(), Boolean.toString(isShowModifierFreeText));
152
                PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowModifierFreeText.getKey()), true);
153

  
154
            }else{
155
                PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowModifierFreeText.getKey()), false);
156
            }
157

  
158
        }
159
        return true;
160
    }
161

  
162
    @Override
163
    public void getValues(){
164
        // get modifier values
165
        pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowModifier);
166
        if (pref == null){
167
            pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowModifier, PreferencePredicate.ShowModifier.getDefaultValue().toString());
168
        }
169
        allowOverride = pref.isAllowOverride();
170
        isShowModifier = null;
171
        String showModifierString = PreferencesUtil.getStringValue(PreferencePredicate.ShowModifier.getKey(), true);
172
        if (showModifierString != null){
173
            isShowModifier = Boolean.valueOf(showModifierString);
174
        }
175

  
176
        isOverride = PreferencesUtil.getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowModifier.getKey()));
177
        if (!isOverride){
178
           isShowModifier = null;
179
        }
180

  
181
        //get modifier freetext values
182
        prefFreeText = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowModifierFreeText);
183
        if (prefFreeText == null){
184
            prefFreeText = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowModifierFreeText, PreferencePredicate.ShowModifierFreeText.getDefaultValue().toString());
185
        }
186
        allowOverrideFreeText = prefFreeText.isAllowOverride();
187
        isShowModifierFreeText = null;
188
        String showModifierStringFreeText = PreferencesUtil.getStringValue(PreferencePredicate.ShowModifierFreeText.getKey(), true);
189
        if (showModifierStringFreeText != null){
190
            isShowModifierFreeText = Boolean.valueOf(showModifierStringFreeText);
191
        }
192

  
193
        isOverrideFreeText = PreferencesUtil.getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowModifierFreeText.getKey()));
194
        if (!isOverrideFreeText){
195
           isShowModifierFreeText = null;
196
        }
197

  
30 198
    }
31 199

  
200
    @Override
201
    protected void performDefaults() {
202
       isShowModifier = null;
203
       allowOverride = true;
204

  
205
       comboShowModifier.select(0);
206
       if (isAdminPreference){
207
            allowOverrideButton.setSelection(allowOverride);
208
        }
209

  
210
       isShowModifierFreeText = null;
211
       allowOverrideFreeText = true;
212

  
213
       comboShowModifierFreeText.select(0);
214
       if (isAdminPreference){
215
            allowOverrideFreeTextButton.setSelection(allowOverrideFreeText);
216
        }
217

  
218
        setApply(true);
219
        super.performDefaults();
220
    }
221
    @Override
222
    public void widgetSelected(SelectionEvent e) {
223
        if (e.getSource().equals(this.comboShowModifier)) {
224
            String text = comboShowModifier.getText();
225
            if (text.startsWith(Messages.Preference_Use_Default)){
226
                isOverride = false;
227
                isShowModifier = null;
228

  
229
            }else if (text.equals(SHOW)){
230
                isShowModifier = true;
231
                isOverride = true;
232
            }else{
233
                isShowModifier = false;
234
                isOverride = true;
235
            }
236

  
237
        }
238

  
239
        if (e.getSource().equals(this.comboShowModifierFreeText)) {
240
            String text = comboShowModifierFreeText.getText();
241
            if (text.startsWith(Messages.Preference_Use_Default)){
242
                isOverrideFreeText = false;
243
                isShowModifierFreeText = null;
244

  
245
            }else if (text.equals(SHOW)){
246
                isShowModifierFreeText = true;
247
                isOverrideFreeText = true;
248
            }else{
249
                isShowModifierFreeText = false;
250
                isOverrideFreeText = true;
251
            }
252

  
253
        }
254
        setApply(true);
255

  
256
    }
257

  
258
    @Override
259
    public void widgetDefaultSelected(SelectionEvent e) {
260

  
261

  
262

  
263
    }
264

  
265

  
32 266
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/OrderPreferences.java
38 38
	    protected boolean isAllowOverrideShowTaxonNodeWizard;
39 39
	    protected Boolean isShowTaxonNodeWizard;
40 40

  
41
	    final String SHOW = Messages.GeneralPreference_yes;
42
	    final String DO_NOT_SHOW = Messages.GeneralPreference_no;
43 41

  
44 42

  
45 43
	    @Override
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/menu/CdmPreferencePage.java
39 39

  
40 40
    private boolean isApply;
41 41

  
42

  
42
    protected final String SHOW = Messages.GeneralPreference_yes;
43
    protected final String DO_NOT_SHOW = Messages.GeneralPreference_no;
43 44

  
44 45
    public CdmPreferencePage() {
45 46
        this(null, null);
......
236 237

  
237 238
    }
238 239

  
240
    public Boolean getBooleanPrefValue(CdmPreference pref) {
241
        return pref != null? (pref.getValue()!= null?Boolean.valueOf(pref.getValue()): null): null;
242
    }
243

  
244
    public String getStringPrefValue(CdmPreference pref) {
245
        return pref != null? (pref.getValue()!= null? pref.getValue(): null): null;
246
    }
247

  
248
    public boolean getPrefAllowOverride(CdmPreference pref) {
249
        return pref != null? pref.isAllowOverride(): true;
250
    }
251

  
252

  
239 253

  
240 254

  
241 255

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/StateDataElement.java
18 18
import eu.etaxonomy.cdm.model.common.LanguageString;
19 19
import eu.etaxonomy.cdm.model.description.State;
20 20
import eu.etaxonomy.cdm.model.description.StateData;
21
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
21 22
import eu.etaxonomy.cdm.model.term.TermType;
22 23
import eu.etaxonomy.cdm.model.term.TermVocabulary;
24
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
23 25
import eu.etaxonomy.taxeditor.store.CdmStore;
24 26
import eu.etaxonomy.taxeditor.store.StoreUtil;
25 27
import eu.etaxonomy.taxeditor.ui.combo.term.TermComboElement;
......
69 71
        }
70 72
		combo_state.setTerms(stateTerms);
71 73
		combo_state.setSelection(entity.getState());
72
		section_modifiers.setEntity(entity);
73
		section_modifiers.setExpanded(!entity.getModifiers().isEmpty());
74
		if(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()) != null) {
74
		if (section_modifiers != null){
75
    		section_modifiers.setEntity(entity);
76
    		section_modifiers.setExpanded(!entity.getModifiers().isEmpty());
77
		}
78
		if(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()) != null && text_modifyingText != null) {
75 79
            text_modifyingText.setText(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()).getText());
76 80
        }
77 81
		if(getEntity().getId()>0){
......
83 87
	@Override
84 88
	public void createControls(ICdmFormElement element, int style) {
85 89
		combo_state = formFactory.createDefinedTermComboElement(TermType.State, element, "State", null, style);
86
		section_modifiers = formFactory.createModifierSection(getConversationHolder(), element, StoreUtil.getSectionStyle(ModifierSection.class, StateData.class.getCanonicalName(), true));
87
		section_modifiers.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
88
		text_modifyingText = formFactory.createTextWithLabelElement(element, "Modifying Text", null, style);
90
		if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowModifier.getKey())){
91
		    section_modifiers = formFactory.createModifierSection(getConversationHolder(), element, StoreUtil.getSectionStyle(ModifierSection.class, StateData.class.getCanonicalName(), true));
92
		    section_modifiers.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
93
		}
94
		if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowModifierFreeText.getKey())){
95
		    text_modifyingText = formFactory.createTextWithLabelElement(element, "Modifying Text", null, style);
96
		}
97

  
89 98
	}
90 99

  
91 100
	/** {@inheritDoc} */
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/detail/AbstractDetailedDescriptionDetailElement.java
13 13

  
14 14
import eu.etaxonomy.cdm.model.common.LanguageString;
15 15
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
16
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
17
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
16 18
import eu.etaxonomy.taxeditor.store.CdmStore;
17 19
import eu.etaxonomy.taxeditor.store.StoreUtil;
18 20
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
......
61 63
    protected void createModifier(ICdmFormElement formElement, DescriptionElementBase entity,
62 64
            int style) {
63 65

  
64
        section_modifiers = formFactory.createModifierSection(getConversationHolder(), this, StoreUtil.getSectionStyle(ModifierSection.class, entity.getClass().getCanonicalName(), true));
65
        section_modifiers.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
66
        section_modifiers.setEntity(entity);
67

  
68
        text_modifyingText = formFactory.createTextWithLabelElement(this, "Modifying Text", null, style);
69
        if(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()) != null) {
70
            text_modifyingText.setText(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()).getText());
66
        if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowModifier.getKey())){
67
            section_modifiers = formFactory.createModifierSection(getConversationHolder(), this, StoreUtil.getSectionStyle(ModifierSection.class, entity.getClass().getCanonicalName(), true));
68
            section_modifiers.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
69
            section_modifiers.setEntity(entity);
70
        }
71
        if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowModifierFreeText.getKey())){
72
            text_modifyingText = formFactory.createTextWithLabelElement(this, "Modifying Text", null, style);
73
            if(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()) != null) {
74
                text_modifyingText.setText(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()).getText());
75
            }
71 76
        }
72 77
    }
73 78

  
74 79
    protected void createFreetextModifier(ICdmFormElement formElement, DescriptionElementBase entity,
75 80
            int style) {
76

  
77
        text_modifyingText = formFactory.createTextWithLabelElement(this, "Modifying Text", null, style);
78
        if(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()) != null) {
79
            text_modifyingText.setText(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()).getText());
81
        if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowModifierFreeText.getKey())){
82
            text_modifyingText = formFactory.createTextWithLabelElement(this, "Modifying Text", null, style);
83
            if(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()) != null) {
84
                text_modifyingText.setText(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()).getText());
85
            }
80 86
        }
81 87
    }
82 88

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)