Project

General

Profile

Download (17.2 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.taxeditor.databaseAdmin.preferencePage;
2

    
3

    
4
import org.eclipse.swt.SWT;
5
import org.eclipse.swt.custom.CLabel;
6
import org.eclipse.swt.events.SelectionAdapter;
7
import org.eclipse.swt.events.SelectionEvent;
8
import org.eclipse.swt.layout.GridData;
9
import org.eclipse.swt.layout.GridLayout;
10
import org.eclipse.swt.widgets.Button;
11
import org.eclipse.swt.widgets.Composite;
12
import org.eclipse.swt.widgets.Control;
13
import org.eclipse.swt.widgets.Label;
14

    
15
import eu.etaxonomy.cdm.api.application.ICdmRepository;
16
import eu.etaxonomy.cdm.api.service.IPreferenceService;
17
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
18
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
19
import eu.etaxonomy.taxeditor.l10n.Messages;
20
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
21
import eu.etaxonomy.taxeditor.preference.NameDetailsConfigurator;
22
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
23
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
25

    
26

    
27
public class NameDetailsViewConfiguration extends CdmPreferencePage implements IE4AdminPreferencePage{
28

    
29
    boolean isSimpleDetailsViewActivated;
30

    
31
    Composite dbSettings ;
32
    boolean isAllowOverride;
33
    boolean isShowTaxon;
34
    boolean isShowLSID;
35
    boolean isShowNomenclaturalCode;
36
    boolean isShowNameCache;
37
    boolean isShowAppendedPhrase;
38
    boolean isShowRank;
39
    boolean isShowEpithets;
40
    boolean isShowAuthorCache;
41
    boolean isShowAuthorship;
42
    boolean isShowNomenclaturalRef;
43
    boolean isShowNomenclaturalStatus;
44
    boolean isShowProtologue;
45
    boolean isShowTypeDesignation;
46
    boolean isShowNameRelationship;
47
    boolean isShowHybrid;
48
    boolean isShowNameApprobiation;
49
    NameDetailsConfigurator nameDetailsConfig = null;
50

    
51
    @Override
52
    protected Control createContents(Composite parent) {
53
        final CLabel description = new CLabel(parent, SWT.NULL);
54
        description.setText(Messages.NameDetailsViewConfiguration_description);
55
        nameDetailsConfig = PreferencesUtil.getPreferredNameDetailsConfiguration(false);
56
        if (nameDetailsConfig == null){
57
            nameDetailsConfig = new NameDetailsConfigurator(false);
58
        }
59
        final Button activateCheckButton = new Button(parent, SWT.CHECK);
60
        activateCheckButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1));
61
        activateCheckButton.setText(Messages.NameDetailsViewConfiguration_activateSimpleDetailsView);
62
        isSimpleDetailsViewActivated = nameDetailsConfig.isSimpleDetailsViewActivated();
63
        activateCheckButton.setSelection(isSimpleDetailsViewActivated);
64
        activateCheckButton.addSelectionListener(new SelectionAdapter(){
65
            @Override
66
            public void widgetSelected(SelectionEvent e) {
67
                isSimpleDetailsViewActivated = activateCheckButton.getSelection();
68
               //
69
                if(isSimpleDetailsViewActivated){
70
                    dbSettings.setVisible(true);
71
                    dbSettings.setEnabled(true);
72
                }else{
73
                    dbSettings.setVisible(false);
74
                    dbSettings.setEnabled(false);
75
                }
76
             }
77
         });
78

    
79

    
80

    
81
        dbSettings  = new Composite(parent, SWT.NONE);
82
        dbSettings.setLayout(new GridLayout());
83
        dbSettings.setVisible(isSimpleDetailsViewActivated);
84
//       Table table = new Table(dbSettings,SWT.BORDER | SWT.CHECK);
85
//       TableColumn tableColumnValue = new TableColumn(table, SWT.CENTER);
86
//
87
//       TableColumn tableColumnAllowOverride = new TableColumn(table, SWT.CENTER);
88

    
89

    
90

    
91
        final Button allowLocalPreference = new Button(dbSettings, SWT.CHECK);
92
//      boolean isUseLocalPreference = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ALLOW_OVERRIDE_NAME_DETAILS);
93
        allowLocalPreference.setText(Messages.DatabasePreferencesPage_UseLocalPreferences);
94
        isAllowOverride = nameDetailsConfig.isAllowOverride();
95
        allowLocalPreference.setSelection(isAllowOverride);
96
        allowLocalPreference.addSelectionListener(new SelectionAdapter(){
97
           @Override
98
           public void widgetSelected(SelectionEvent e) {
99
               isAllowOverride = allowLocalPreference.getSelection();
100

    
101
            }
102
        });
103
        Label separator= new Label(dbSettings, SWT.HORIZONTAL | SWT.SEPARATOR);
104
        separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
105
        final Button showTaxon = new Button(dbSettings, SWT.CHECK);
106
        showTaxon.setText(Messages.NameDetailsViewComposite_Show_Taxon);
107
        isShowTaxon = nameDetailsConfig.isTaxonSectionActivated();
108
        showTaxon.setSelection(isShowTaxon);
109
        showTaxon.addSelectionListener(new SelectionAdapter(){
110
             @Override
111
             public void widgetSelected(SelectionEvent e) {
112
                 isShowTaxon = showTaxon.getSelection();
113

    
114
              }
115
         });
116

    
117
        final Button showLsid = new Button(dbSettings, SWT.CHECK);
118
        showLsid.setText(Messages.NameDetailsViewComposite_Show_LSID);
119
        isShowLSID = nameDetailsConfig.isLSIDActivated();
120
        showLsid.setSelection(isShowLSID);
121
        showLsid.addSelectionListener(new SelectionAdapter(){
122
             @Override
123
             public void widgetSelected(SelectionEvent e) {
124
                 isShowLSID = showLsid.getSelection();
125

    
126
              }
127
         });
128

    
129
        final Button showNomenclaturalCode = new Button(dbSettings, SWT.CHECK);
130
        showNomenclaturalCode.setText(Messages.NameDetailsViewComposite_Show_NomenclaturalCode);
131
        isShowNomenclaturalCode = nameDetailsConfig.isNomenclaturalCodeActived();
132
        showNomenclaturalCode.setSelection(isShowNomenclaturalCode);
133
        showNomenclaturalCode.addSelectionListener(new SelectionAdapter(){
134
             @Override
135
             public void widgetSelected(SelectionEvent e) {
136
                 isShowNomenclaturalCode = showNomenclaturalCode.getSelection();
137

    
138
              }
139
         });
140

    
141
        final Button showNameCache = new Button(dbSettings, SWT.CHECK);
142
        showNameCache.setText(Messages.NameDetailsViewComposite_Show_NameCache);
143
        isShowNameCache = nameDetailsConfig.isNameCacheActivated();
144
        showNameCache.setSelection(isShowNameCache);
145
        showNameCache.addSelectionListener(new SelectionAdapter(){
146
             @Override
147
             public void widgetSelected(SelectionEvent e) {
148
                isShowNameCache = showNameCache.getSelection();
149

    
150
              }
151
         });
152
        final Button showAppendedPhrase = new Button(dbSettings, SWT.CHECK);
153
        isShowAppendedPhrase= nameDetailsConfig.isAppendedPhraseActivated();
154
        showAppendedPhrase.setText(Messages.NameDetailsViewComposite_Show_AppendedPhrase);
155
        showAppendedPhrase.setSelection(isShowAppendedPhrase);
156
        showAppendedPhrase.addSelectionListener(new SelectionAdapter(){
157
             @Override
158
             public void widgetSelected(SelectionEvent e) {
159
                isShowAppendedPhrase = showAppendedPhrase.getSelection();
160

    
161
              }
162
         });
163

    
164
        final Button showRank = new Button(dbSettings, SWT.CHECK);
165
        isShowRank = nameDetailsConfig.isRankActivated();
166
        showRank.setText(Messages.NameDetailsViewComposite_Show_Rank);
167
        showRank.setSelection(isShowRank);
168
        showRank.addSelectionListener(new SelectionAdapter(){
169
             @Override
170
             public void widgetSelected(SelectionEvent e) {
171
                 isShowRank = showRank.getSelection();
172

    
173
              }
174
         });
175
        final Button showEpithets = new Button(dbSettings, SWT.CHECK);
176
        isShowEpithets = nameDetailsConfig.isAtomisedEpithetsActivated();
177
        showEpithets.setText(Messages.NameDetailsViewComposite_Show_AtomisedEpithets);
178
        showEpithets.setSelection(isShowEpithets);
179
        showEpithets.addSelectionListener(new SelectionAdapter(){
180
             @Override
181
             public void widgetSelected(SelectionEvent e) {
182
                 isShowEpithets = showEpithets.getSelection();
183

    
184
              }
185
         });
186

    
187
        final Button showAuthorCache = new Button(dbSettings, SWT.CHECK);
188
        isShowAuthorCache = nameDetailsConfig.isAuthorCacheActivated();
189
        showAuthorCache.setText(Messages.NameDetailsViewComposite_Show_AuthorCache);
190
        showAuthorCache.setSelection(isShowAuthorCache);
191
        showAuthorCache.addSelectionListener(new SelectionAdapter(){
192
             @Override
193
             public void widgetSelected(SelectionEvent e) {
194
                 isShowAuthorCache = showAuthorCache.getSelection();
195

    
196
              }
197
         });
198

    
199
        final Button showAuthorship = new Button(dbSettings, SWT.CHECK);
200
        isShowAuthorship = nameDetailsConfig.isAuthorshipSectionActivated();
201
        showAuthorship.setText(Messages.NameDetailsViewComposite_Show_Author);
202
        showAuthorship.setSelection(isShowAuthorship);
203
        showAuthorship.addSelectionListener(new SelectionAdapter(){
204
             @Override
205
             public void widgetSelected(SelectionEvent e) {
206
                 isShowAuthorship = showAuthorship.getSelection();
207

    
208
              }
209
         });
210

    
211
        final Button showNomenclaturalRef = new Button(dbSettings, SWT.CHECK);
212
        isShowNomenclaturalRef = nameDetailsConfig.isNomenclaturalReferenceSectionActivated();
213
        showNomenclaturalRef.setText(Messages.NameDetailsViewComposite_Show_NomenclaturalReference);
214
        showNomenclaturalRef.setSelection(isShowNomenclaturalRef);
215
        showNomenclaturalRef.addSelectionListener(new SelectionAdapter(){
216
             @Override
217
             public void widgetSelected(SelectionEvent e) {
218
                 isShowNomenclaturalRef = showNomenclaturalRef.getSelection();
219

    
220
              }
221
         });
222

    
223
        final Button showNomenclaturalStatus = new Button(dbSettings, SWT.CHECK);
224
        isShowNomenclaturalStatus = nameDetailsConfig.isNomenclaturalStatusSectionActivated();
225
        showNomenclaturalStatus.setText(Messages.NameDetailsViewComposite_Show_NomenclaturalStatus);
226
        showNomenclaturalStatus.setSelection(isShowNomenclaturalStatus);
227
        showNomenclaturalStatus.addSelectionListener(new SelectionAdapter(){
228
             @Override
229
             public void widgetSelected(SelectionEvent e) {
230
                 isShowNomenclaturalStatus = showNomenclaturalStatus.getSelection();
231

    
232
              }
233
         });
234

    
235
        final Button showProtologue = new Button(dbSettings, SWT.CHECK);
236
        isShowProtologue = nameDetailsConfig.isProtologueActivated();
237
        showProtologue.setText(Messages.NameDetailsViewComposite_Show_Protologue);
238
        showProtologue.setSelection(isShowProtologue);
239
        showProtologue.addSelectionListener(new SelectionAdapter(){
240
             @Override
241
             public void widgetSelected(SelectionEvent e) {
242
                 isShowProtologue = showProtologue.getSelection();
243

    
244
              }
245
         });
246

    
247
        final Button showTypeDesignation = new Button(dbSettings, SWT.CHECK);
248
        isShowTypeDesignation = nameDetailsConfig.isTypeDesignationSectionActivated();
249
        showTypeDesignation.setText(Messages.NameDetailsViewComposite_Show_TypeDesignation);
250
        showTypeDesignation.setSelection(isShowTypeDesignation);
251
        showTypeDesignation.addSelectionListener(new SelectionAdapter(){
252
             @Override
253
             public void widgetSelected(SelectionEvent e) {
254
                 isShowTypeDesignation = showTypeDesignation.getSelection();
255

    
256
              }
257
         });
258

    
259

    
260
        final Button showNameRelationship = new Button(dbSettings, SWT.CHECK);
261
        isShowNameRelationship = nameDetailsConfig.isNameRelationsSectionActivated();
262
        showNameRelationship.setText(Messages.NameDetailsViewComposite_Show_Namerelationships);
263
        showNameRelationship.setSelection(isShowNameRelationship);
264
        showNameRelationship.addSelectionListener(new SelectionAdapter(){
265
             @Override
266
             public void widgetSelected(SelectionEvent e) {
267
                 isShowNameRelationship = showNameRelationship.getSelection();
268

    
269
              }
270
         });
271

    
272
        final Button showHybrid = new Button(dbSettings, SWT.CHECK);
273
        isShowHybrid = nameDetailsConfig.isHybridActivated();
274
        showHybrid.setText(Messages.NameDetailsViewComposite_Show_Hybrid);
275
        showHybrid.setSelection(isShowHybrid);
276
        showHybrid.addSelectionListener(new SelectionAdapter(){
277
             @Override
278
             public void widgetSelected(SelectionEvent e) {
279
                 isShowHybrid = showHybrid.getSelection();
280

    
281
              }
282
         });
283
        final Button showNameApprobiation = new Button(dbSettings, SWT.CHECK);
284
        isShowNameApprobiation = nameDetailsConfig.isNameApprobiationActivated();
285
        showNameApprobiation.setText(Messages.NameDetailsViewComposite_Show_NameApprobiation);
286
        showNameApprobiation.setSelection(isShowNameApprobiation);
287
        showNameApprobiation.addSelectionListener(new SelectionAdapter(){
288
             @Override
289
             public void widgetSelected(SelectionEvent e) {
290
                 isShowNameApprobiation = showNameApprobiation.getSelection();
291
                //PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_APPROBATION, isShowNameApprobiation);
292
              }
293
         });
294

    
295

    
296

    
297

    
298
        return dbSettings;
299
	}
300

    
301
    /**
302
    *
303
    */
304
   protected NameDetailsConfigurator createNameDetailsViewConfig() {
305
       NameDetailsConfigurator config = new NameDetailsConfigurator(isSimpleDetailsViewActivated);
306

    
307
      config.setAppendedPhraseActivated(isShowAppendedPhrase);
308
      config.setAtomisedEpithetsActivated(isShowEpithets);
309
      config.setAuthorshipSectionActivated(isShowAuthorship);
310
      config.setAuthorCacheActivated(isShowAuthorCache);
311
      config.setLSIDActivated(isShowLSID);
312
      config.setNameApprobiationActivated(isShowNameApprobiation);
313
      config.setNameCacheActivated(isShowNameCache);
314
      config.setNameRelationsSectionActivated(isShowNameRelationship);
315
      config.setNomenclaturalCodeActived(isShowNomenclaturalCode);
316
      config.setNomenclaturalStatusSectionActivated(isShowNomenclaturalStatus);
317
      config.setNomenclaturalReferenceSectionActivated(isShowNomenclaturalRef);
318
      config.setProtologueActivated(isShowProtologue);
319
      config.setRankActivated(isShowRank);
320
      config.setTaxonSectionActivated(isShowTaxon);
321
      config.setTypeDesignationSectionActivated(isShowTypeDesignation);
322
      config.setHybridActivated(isShowHybrid);
323

    
324

    
325
      return config;
326
   }
327

    
328

    
329
    @Override
330
    public boolean performOk() {
331
        if (nameDetailsConfig == null){
332
            return true;
333
        }
334
        ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
335
        if (controller == null){
336
            return false;
337
        }
338
        IPreferenceService service = controller.getPreferenceService();
339
        NameDetailsConfigurator config = createNameDetailsViewConfig();
340
        String value = config.toString();
341
//        boolean allowOverride = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ALLOW_OVERRIDE_NAME_DETAILS);
342

    
343
        CdmPreference pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.NameDetailsView, value);
344
        pref.setAllowOverride(isAllowOverride);
345
        service.set(pref);
346
        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_TAXON, isShowTaxon);
347
        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_LSID, isShowLSID);
348
        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE, isShowNomenclaturalCode);
349
        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAMECACHE, isShowNameCache);
350
        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE, isShowAppendedPhrase);
351
        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_RANK, isShowRank);
352
        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS, isShowEpithets);
353
        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP, isShowAuthorship);
354
        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP_CACHE, isShowAuthorCache);
355
        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE, isShowNomenclaturalRef);
356
        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS, isShowNomenclaturalStatus);
357
        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_PROTOLOGUE, isShowProtologue);
358
        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION, isShowTypeDesignation);
359
        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP, isShowNameRelationship);
360
        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_HYBRID, isShowHybrid);
361
        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.ALLOW_OVERRIDE_NAME_DETAILS, isAllowOverride);
362
        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_SECTION, isSimpleDetailsViewActivated);
363
        return true;
364
    }
365

    
366
}
(8-8/12)