Project

General

Profile

Download (8.82 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, Messages.SupplementalDataSourcePreferences_SHOW_ID,
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, Messages.SupplementalDataSourcePreferences_SHOW_NAMESPACE,
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
            allowOverrideShowIDNamespaceButton.setSelection(isAllowOverrideShowIDNamespace);
102
            allowOverrideShowIDNamespaceButton.addSelectionListener(new SelectionAdapter(){
103
                @Override
104
                public void widgetSelected(SelectionEvent e) {
105
                    isAllowOverrideShowIDNamespace = allowOverrideShowIDNamespaceButton.getSelection();
106
                    setApply(true);
107
                }
108
            });
109
        }
110

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

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

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

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

    
162
    @Override
163
    public void widgetSelected(SelectionEvent e) {
164
        if (e.getSource().equals(this.showIDNamespaceButton)) {
165
            String text = showIDNamespaceButton.getText();
166

    
167
            if (text.startsWith(Messages.Preference_Use_Default)){
168
                isShowIDNamespace = null;
169
                isOverrideShowIDNamespace = false;
170
            }else{
171
                isOverrideShowIDNamespace = true;
172
                if (text.equals(SHOW)){
173
                    isShowIDNamespace = true;
174

    
175
                }else{
176
                    isShowIDNamespace = false;
177
                }
178
            }
179

    
180
        }
181
        if (e.getSource().equals(this.showIDSourceButton)) {
182
            String text = showIDSourceButton.getText();
183
            if (text.startsWith(Messages.Preference_Use_Default)){
184
                isShowIDSource = null;
185
                isOverrideShowIDSource = false;
186
            }else{
187
                isOverrideShowIDSource = true;
188
                if (text.equals(SHOW)){
189
                    isShowIDSource = true;
190
                }else{
191
                    isShowIDSource = false;
192
                }
193
            }
194

    
195
        }
196

    
197
        this.setApply(true);
198
    }
199

    
200
    @Override
201
    public void widgetDefaultSelected(SelectionEvent e) {
202
    }
203

    
204
    @Override
205
    protected void performDefaults() {
206
        showIDNamespaceButton.select(0);
207
        isShowIDNamespace = null;
208
        isAllowOverrideShowIDNamespace=true;
209
        isOverrideShowIDNamespace = false;
210
        isOverrideShowIDSource = false;
211
        if (isAdminPreference){
212
            allowOverrideIDSourceButton.setSelection(true);
213
            allowOverrideShowIDNamespaceButton.setSelection(true);
214

    
215
        }
216

    
217
        showIDSourceButton.select(0);
218
        isShowIDSource = null;
219
        isAllowOverrideShowIDSource=true;
220
        this.setApply(true);
221
        super.performDefaults();
222
    }
223

    
224

    
225

    
226
}
(45-45/52)