Project

General

Profile

Download (7.99 KB) Statistics
| Branch: | Tag: | Revision:
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.preference;
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.layout.GridData;
16
import org.eclipse.swt.widgets.Button;
17
import org.eclipse.swt.widgets.Combo;
18
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.Control;
20
import org.eclipse.swt.widgets.Label;
21

    
22
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
23
import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
24
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
25
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
26
import eu.etaxonomy.taxeditor.l10n.Messages;
27
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
28

    
29
/**
30
 * @author k.luther
31
 * @since 18.01.2019
32
 *
33
 */
34
public class SupplementalDataSourcePreferences extends CdmPreferencePage implements SelectionListener{
35

    
36
    protected Boolean isShowIDNamespace;
37
    protected Boolean isShowIDSource;
38

    
39
    protected boolean isAllowOverrideShowIDNamespace;
40
    protected boolean isAllowOverrideShowIDSource;
41

    
42
    protected boolean isOverrideShowIDNamespace;
43
    protected boolean isOverrideShowIDSource;
44

    
45
    protected Combo showIDNamespaceButton;
46
    protected Button allowOverrideShowIDNamespaceButton;
47
    protected Combo showIDSourceButton;
48
    protected Button allowOverrideIDSourceButton;
49

    
50
    final String SHOW = Messages.GeneralPreference_yes;
51
    final String DO_NOT_SHOW = Messages.GeneralPreference_no;
52

    
53
    @Override
54
    protected Control createContents(Composite parent) {
55
        getValues();
56
        final Composite composite = createComposite(parent);
57

    
58
        GridData gridData = createTextGridData();
59

    
60
        Label separator= new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
61
        separator.setLayoutData(gridData);
62
        separator.setVisible(false);
63

    
64
        showIDSourceButton = createBooleanCombo(composite, SHOW, DO_NOT_SHOW, PreferencePredicate.ShowIdInSource, "Show ID in Source",
65
                isAdminPreference);
66
        showIDSourceButton.addSelectionListener(this);
67
        if (isShowIDSource == null || (!isOverrideShowIDSource && !isAdminPreference)){
68
            showIDSourceButton.select(0);
69
        }else if (isShowIDSource){
70
            showIDSourceButton.select(1);
71
        }else{
72
            showIDSourceButton.select(2);
73
        }
74

    
75
        if (isAdminPreference){
76
            allowOverrideIDSourceButton = createAllowOverrideButton(composite);
77
            allowOverrideIDSourceButton.setSelection(isAllowOverrideShowIDSource);
78
            allowOverrideIDSourceButton.addSelectionListener(new SelectionAdapter(){
79
                @Override
80
                public void widgetSelected(SelectionEvent e) {
81
                    isAllowOverrideShowIDSource = allowOverrideIDSourceButton.getSelection();
82
                    setApply(true);
83
                }
84
            });
85
        }
86

    
87
        showIDNamespaceButton = createBooleanCombo(composite, SHOW, DO_NOT_SHOW, PreferencePredicate.ShowNamespaceInSource, "Show ID Namespace in Source",
88
                isAdminPreference);
89

    
90
        showIDNamespaceButton.addSelectionListener(this);
91

    
92
        if (isShowIDNamespace == null || (!isOverrideShowIDNamespace && !isAdminPreference)){
93
            showIDNamespaceButton.select(0);
94
        }else if (isShowIDNamespace){
95
            showIDNamespaceButton.select(1);
96
        }else{
97
            showIDNamespaceButton.select(2);
98
        }
99
        if (isAdminPreference){
100
            allowOverrideShowIDNamespaceButton = createAllowOverrideButton(composite);
101

    
102
            allowOverrideShowIDNamespaceButton.setSelection(isAllowOverrideShowIDNamespace);
103
            allowOverrideShowIDNamespaceButton.addSelectionListener(new SelectionAdapter(){
104
                @Override
105
                public void widgetSelected(SelectionEvent e) {
106
                    isAllowOverrideShowIDNamespace = allowOverrideShowIDNamespaceButton.getSelection();
107
                    setApply(true);
108
                }
109
            });
110
        }
111

    
112
        if (!isAllowOverrideShowIDNamespace && !isAdminPreference){
113
            showIDNamespaceButton.setEnabled(false);
114
        }
115
        if (!isAllowOverrideShowIDSource && !isAdminPreference){
116
            showIDSourceButton.setEnabled(false);
117
        }
118
        return composite;
119
    }
120

    
121
    @Override
122
    public boolean performOk() {
123
        if (isAllowOverrideShowIDSource){
124
            PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowIdInSource.getKey()), isOverrideShowIDSource);
125
            PreferencesUtil.setBooleanValue(PreferencePredicate.ShowIdInSource.getKey(), isShowIDSource);
126
        }
127
        if (isAllowOverrideShowIDNamespace){
128
            PreferencesUtil.setBooleanValue(PreferencePredicate.ShowNamespaceInSource.getKey(), isShowIDNamespace);
129
            PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowNamespaceInSource.getKey()), isOverrideShowIDNamespace);
130
        }
131
       return true;
132
   }
133
    @Override
134
    protected void getValues(){
135
        isAdminPreference = false;
136

    
137
        CdmPreferenceCache cache = CdmPreferenceCache.instance();
138
        isShowIDSource = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowIdInSource.getKey(), true);
139
        isOverrideShowIDSource = PreferencesUtil.getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowIdInSource.getKey()), true) != null?PreferencesUtil.getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowIdInSource.getKey()), true): false;
140
        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowIdInSource);
141
        CdmPreference pref = cache.findBestMatching(key);
142
        if (pref != null){
143
            isAllowOverrideShowIDSource = pref.isAllowOverride();
144
        }else{
145
            isAllowOverrideShowIDSource = true;
146
        }
147

    
148
        isShowIDNamespace = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowNamespaceInSource.getKey(), true);
149
        isOverrideShowIDNamespace = PreferencesUtil.getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowNamespaceInSource.getKey()), true) != null? PreferencesUtil.getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowNamespaceInSource.getKey()), true):false;
150
        key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowNamespaceInSource);
151
        pref = cache.findBestMatching(key);
152
        if (pref != null){
153
            isAllowOverrideShowIDNamespace= pref.isAllowOverride();
154
        }else{
155
            isAllowOverrideShowIDNamespace = true;
156
        }
157
    }
158

    
159
    @Override
160
    public void widgetSelected(SelectionEvent e) {
161
        if (e.getSource().equals(this.showIDNamespaceButton)) {
162
            String text = showIDNamespaceButton.getText();
163
           // text = text.replace(Messages.Preference_Use_Default, "");
164
            if (text.equals(Messages.Preference_Use_Default)){
165
                isOverrideShowIDNamespace = false;
166
            }else{
167
                isOverrideShowIDNamespace = true;
168
            }
169
            if (text.equals(SHOW)){
170
                isShowIDNamespace = true;
171

    
172
            }else{
173
                isShowIDNamespace = false;
174
            }
175
        }
176
        if (e.getSource().equals(this.showIDSourceButton)) {
177
            String text = showIDSourceButton.getText();
178
            if (text.equals(Messages.Preference_Use_Default)){
179
                isOverrideShowIDSource = false;
180
            }else{
181
                isOverrideShowIDSource = true;
182
            }
183
            if (text.equals(SHOW)){
184
                isShowIDSource = true;
185
            }else{
186
                isShowIDSource = false;
187
            }
188
        }
189

    
190
        this.setApply(true);
191
    }
192

    
193
    @Override
194
    public void widgetDefaultSelected(SelectionEvent e) {
195
    }
196

    
197
}
(41-41/48)