Project

General

Profile

Download (17.8 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.events.SelectionAdapter;
6
import org.eclipse.swt.events.SelectionEvent;
7
import org.eclipse.swt.layout.GridData;
8
import org.eclipse.swt.layout.GridLayout;
9
import org.eclipse.swt.widgets.Button;
10
import org.eclipse.swt.widgets.Composite;
11
import org.eclipse.swt.widgets.Control;
12
import org.eclipse.swt.widgets.Label;
13

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

    
25

    
26
public class NameDetailsViewConfiguration extends CdmPreferencePage implements IE4AdminPreferencePage{
27

    
28
    boolean isSimpleDetailsViewActivated;
29

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

    
49

    
50
    @Override
51
    protected Control createContents(Composite parent) {
52

    
53
        CdmPreference nameDetailsPref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.NameDetailsView);
54
        isAllowOverride = false;
55
        if (nameDetailsPref != null){
56
            //TODO: create checkbox
57

    
58
            isAllowOverride = nameDetailsPref.isAllowOverride();
59
        }
60

    
61

    
62

    
63
        isSimpleDetailsViewActivated = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_SECTION);
64

    
65
        final Button activateCheckButton = new Button(parent, SWT.CHECK);
66
        activateCheckButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1));
67
        activateCheckButton.setText(Messages.NameDetailsViewConfiguration_activateSimpleDetailsView);
68
        activateCheckButton.setSelection(isSimpleDetailsViewActivated);
69
        activateCheckButton.addSelectionListener(new SelectionAdapter(){
70
        @Override
71
        public void widgetSelected(SelectionEvent e) {
72
            isSimpleDetailsViewActivated = activateCheckButton.getSelection();
73
           //
74
            if(isSimpleDetailsViewActivated){
75
                dbSettings.setVisible(true);
76
                dbSettings.setEnabled(true);
77
            }else{
78
                dbSettings.setVisible(false);
79
                dbSettings.setEnabled(false);
80
            }
81
         }
82
         });
83

    
84

    
85

    
86
        dbSettings  = new Composite(parent, SWT.NONE);
87
        dbSettings.setLayout(new GridLayout());
88
        dbSettings.setVisible(isSimpleDetailsViewActivated);
89
//       Table table = new Table(dbSettings,SWT.BORDER | SWT.CHECK);
90
//       TableColumn tableColumnValue = new TableColumn(table, SWT.CENTER);
91
//
92
//       TableColumn tableColumnAllowOverride = new TableColumn(table, SWT.CENTER);
93

    
94

    
95

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

    
105
            }
106
       });
107
        Label separator= new Label(dbSettings, SWT.HORIZONTAL | SWT.SEPARATOR);
108
        separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
109
        final Button showTaxon = new Button(dbSettings, SWT.CHECK);
110
        isShowTaxon = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_TAXON);
111
        showTaxon.setText(Messages.NameDetailsViewComposite_Show_Taxon);
112
        showTaxon.setSelection(isShowTaxon);
113
        showTaxon.addSelectionListener(new SelectionAdapter(){
114
             @Override
115
             public void widgetSelected(SelectionEvent e) {
116
                 isShowTaxon = showTaxon.getSelection();
117

    
118
              }
119
         });
120

    
121
        final Button showLsid = new Button(dbSettings, SWT.CHECK);
122
        isShowLSID = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_LSID);
123
        showLsid.setText(Messages.NameDetailsViewComposite_Show_LSID);
124
        showLsid.setSelection(isShowLSID);
125
        showLsid.addSelectionListener(new SelectionAdapter(){
126
             @Override
127
             public void widgetSelected(SelectionEvent e) {
128
                 isShowLSID = showLsid.getSelection();
129

    
130
              }
131
         });
132

    
133
        final Button showNomenclaturalCode = new Button(dbSettings, SWT.CHECK);
134
        isShowNomenclaturalCode = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE);
135
        showNomenclaturalCode.setText(Messages.NameDetailsViewComposite_Show_NomenclaturalCode);
136
        showNomenclaturalCode.setSelection(isShowNomenclaturalCode);
137
        showNomenclaturalCode.addSelectionListener(new SelectionAdapter(){
138
             @Override
139
             public void widgetSelected(SelectionEvent e) {
140
                 isShowNomenclaturalCode = showNomenclaturalCode.getSelection();
141

    
142
              }
143
         });
144

    
145
        final Button showNameCache = new Button(dbSettings, SWT.CHECK);
146
        isShowNameCache = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAMECACHE);
147
        showNameCache.setText(Messages.NameDetailsViewComposite_Show_NameCache);
148
        showNameCache.setSelection(isShowNameCache);
149
        showNameCache.addSelectionListener(new SelectionAdapter(){
150
             @Override
151
             public void widgetSelected(SelectionEvent e) {
152
                isShowNameCache = showNameCache.getSelection();
153

    
154
              }
155
         });
156
        final Button showAppendedPhrase = new Button(dbSettings, SWT.CHECK);
157
        isShowAppendedPhrase= PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE);
158
        showAppendedPhrase.setText(Messages.NameDetailsViewComposite_Show_AppendedPhrase);
159
        showAppendedPhrase.setSelection(isShowAppendedPhrase);
160
        showAppendedPhrase.addSelectionListener(new SelectionAdapter(){
161
             @Override
162
             public void widgetSelected(SelectionEvent e) {
163
                isShowAppendedPhrase = showAppendedPhrase.getSelection();
164

    
165
              }
166
         });
167

    
168
        final Button showRank = new Button(dbSettings, SWT.CHECK);
169
        isShowRank = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_RANK);
170
        showRank.setText(Messages.NameDetailsViewComposite_Show_Rank);
171
        showRank.setSelection(isShowRank);
172
        showRank.addSelectionListener(new SelectionAdapter(){
173
             @Override
174
             public void widgetSelected(SelectionEvent e) {
175
                 isShowRank = showRank.getSelection();
176

    
177
              }
178
         });
179
        final Button showEpithets = new Button(dbSettings, SWT.CHECK);
180
        isShowEpithets = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS);
181
        showEpithets.setText(Messages.NameDetailsViewComposite_Show_AtomisedEpithets);
182
        showEpithets.setSelection(isShowEpithets);
183
        showEpithets.addSelectionListener(new SelectionAdapter(){
184
             @Override
185
             public void widgetSelected(SelectionEvent e) {
186
                 isShowEpithets = showEpithets.getSelection();
187

    
188
              }
189
         });
190

    
191
        final Button showAuthorCache = new Button(dbSettings, SWT.CHECK);
192
        isShowAuthorCache = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP_CACHE);
193
        showAuthorCache.setText(Messages.NameDetailsViewComposite_Show_AuthorCache);
194
        showAuthorCache.setSelection(isShowAuthorCache);
195
        showAuthorCache.addSelectionListener(new SelectionAdapter(){
196
             @Override
197
             public void widgetSelected(SelectionEvent e) {
198
                 isShowAuthorCache = showAuthorCache.getSelection();
199

    
200
              }
201
         });
202

    
203
        final Button showAuthorship = new Button(dbSettings, SWT.CHECK);
204
        isShowAuthorship = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP);
205
        showAuthorship.setText(Messages.NameDetailsViewComposite_Show_Author);
206
        showAuthorship.setSelection(isShowAuthorship);
207
        showAuthorship.addSelectionListener(new SelectionAdapter(){
208
             @Override
209
             public void widgetSelected(SelectionEvent e) {
210
                 isShowAuthorship = showAuthorship.getSelection();
211

    
212
              }
213
         });
214

    
215
        final Button showNomenclaturalRef = new Button(dbSettings, SWT.CHECK);
216
        isShowNomenclaturalRef = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE);
217
        showNomenclaturalRef.setText(Messages.NameDetailsViewComposite_Show_NomenclaturalReference);
218
        showNomenclaturalRef.setSelection(isShowNomenclaturalRef);
219
        showNomenclaturalRef.addSelectionListener(new SelectionAdapter(){
220
             @Override
221
             public void widgetSelected(SelectionEvent e) {
222
                 isShowNomenclaturalRef = showNomenclaturalRef.getSelection();
223

    
224
              }
225
         });
226

    
227
        final Button showNomenclaturalStatus = new Button(dbSettings, SWT.CHECK);
228
        isShowNomenclaturalStatus = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS);
229
        showNomenclaturalStatus.setText(Messages.NameDetailsViewComposite_Show_NomenclaturalStatus);
230
        showNomenclaturalStatus.setSelection(isShowNomenclaturalStatus);
231
        showNomenclaturalStatus.addSelectionListener(new SelectionAdapter(){
232
             @Override
233
             public void widgetSelected(SelectionEvent e) {
234
                 isShowNomenclaturalStatus = showNomenclaturalStatus.getSelection();
235

    
236
              }
237
         });
238

    
239
        final Button showProtologue = new Button(dbSettings, SWT.CHECK);
240
        isShowProtologue = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_PROTOLOGUE);
241
        showProtologue.setText(Messages.NameDetailsViewComposite_Show_Protologue);
242
        showProtologue.setSelection(isShowProtologue);
243
        showProtologue.addSelectionListener(new SelectionAdapter(){
244
             @Override
245
             public void widgetSelected(SelectionEvent e) {
246
                 isShowProtologue = showProtologue.getSelection();
247

    
248
              }
249
         });
250

    
251
        final Button showTypeDesignation = new Button(dbSettings, SWT.CHECK);
252
        isShowTypeDesignation = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION);
253
        showTypeDesignation.setText(Messages.NameDetailsViewComposite_Show_TypeDesignation);
254
        showTypeDesignation.setSelection(isShowTypeDesignation);
255
        showTypeDesignation.addSelectionListener(new SelectionAdapter(){
256
             @Override
257
             public void widgetSelected(SelectionEvent e) {
258
                 isShowTypeDesignation = showTypeDesignation.getSelection();
259

    
260
              }
261
         });
262

    
263

    
264
        final Button showNameRelationship = new Button(dbSettings, SWT.CHECK);
265
        isShowNameRelationship = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP);
266
        showNameRelationship.setText(Messages.NameDetailsViewComposite_Show_Namerelationships);
267
        showNameRelationship.setSelection(isShowNameRelationship);
268
        showNameRelationship.addSelectionListener(new SelectionAdapter(){
269
             @Override
270
             public void widgetSelected(SelectionEvent e) {
271
                 isShowNameRelationship = showNameRelationship.getSelection();
272

    
273
              }
274
         });
275

    
276
        final Button showHybrid = new Button(dbSettings, SWT.CHECK);
277
        isShowHybrid = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_HYBRID);
278
        showHybrid.setText(Messages.NameDetailsViewComposite_Show_Hybrid);
279
        showHybrid.setSelection(isShowHybrid);
280
        showHybrid.addSelectionListener(new SelectionAdapter(){
281
             @Override
282
             public void widgetSelected(SelectionEvent e) {
283
                 isShowHybrid = showHybrid.getSelection();
284

    
285
              }
286
         });
287
        final Button showNameApprobiation = new Button(dbSettings, SWT.CHECK);
288
        isShowNameApprobiation = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_APPROBATION);
289
        showNameApprobiation.setText(Messages.NameDetailsViewComposite_Show_NameApprobiation);
290
        showNameApprobiation.setSelection(isShowNameApprobiation);
291
        showNameApprobiation.addSelectionListener(new SelectionAdapter(){
292
             @Override
293
             public void widgetSelected(SelectionEvent e) {
294
                 isShowNameApprobiation = showNameApprobiation.getSelection();
295
                 PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_APPROBATION, isShowNameApprobiation);
296
              }
297
         });
298

    
299

    
300

    
301

    
302
        return dbSettings;
303
	}
304

    
305
    /**
306
    *
307
    */
308
   protected NameDetailsConfigurator createNameDetailsViewConfig() {
309
       NameDetailsConfigurator config = new NameDetailsConfigurator(isSimpleDetailsViewActivated);
310

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

    
328

    
329
      return config;
330
   }
331

    
332

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

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

    
367
}
(4-4/5)