Project

General

Profile

Download (16 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2016 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.wizard;
10

    
11
import java.util.List;
12

    
13
import org.eclipse.jface.preference.IPreferenceStore;
14
import org.eclipse.jface.wizard.IWizard;
15
import org.eclipse.jface.wizard.IWizardPage;
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.events.SelectionAdapter;
18
import org.eclipse.swt.events.SelectionEvent;
19
import org.eclipse.swt.layout.GridData;
20
import org.eclipse.swt.layout.GridLayout;
21
import org.eclipse.swt.widgets.Button;
22
import org.eclipse.swt.widgets.Combo;
23
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Label;
25

    
26
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
27
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
28
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
29
import eu.etaxonomy.taxeditor.l10n.Messages;
30
import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
31
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
32
import eu.etaxonomy.taxeditor.preference.NameDetailsConfigurator;
33
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
34

    
35
/**
36
 * @author k.luther
37
 * @date 01.11.2016
38
 *
39
 */
40
public class DatabasePreferencesPage extends AbstractPreferenceWizard implements IWizardPage{
41

    
42
    CdmPreference preferedNomenclaturalCode;
43
    NameDetailsConfigurator config ;
44
    CdmPreference isRedListPreference;
45
    CdmPreference determinationOnlyForFieldUnitsPreference;
46
    CdmPreference showCollectingAreaInGeneralSectionPreference;
47
    CdmPreference showTaxonAssociationsPreference;
48
    CdmPreference setPublishFlagAsDefault;
49

    
50
    boolean isSimpleDetailsViewActivated;
51

    
52
    Composite child ;
53
    NameDetailsViewComposite nameDetailsConfig;
54
    protected NameDetailsViewComposite getNameDetailsConfig() {
55
        return nameDetailsConfig;
56
    }
57

    
58
    String selectedPreferenceKey = null;
59

    
60
    ListComponent biocaseProviderList;
61
    Abcd206ImportConfigurator abcdImportConfigurator;
62

    
63
    String[][] labelAndValues;
64

    
65
    /*
66
     *
67
     */
68
    public DatabasePreferencesPage(String pageName) {
69
        super(pageName);
70
        this.preferedNomenclaturalCode = PreferencesUtil.setPreferredNomenclaturalCode(null, false);
71
        this.config = PreferencesUtil.setPreferredNameDetailsConfiguration( false);
72
        if (config == null){
73
            config = new NameDetailsConfigurator(false);
74
        }
75

    
76

    
77
    }
78

    
79

    
80
    protected IPreferenceStore doGetPreferenceStore() {
81
        return PreferencesUtil.getPreferenceStore();
82
    }
83

    
84
    /**
85
     * @return
86
     */
87
    private String[][] getLabelAndValues() {
88
        List<NomenclaturalCode> supportedCodes = NomenclaturalCodeHelper
89
                .getSupportedCodes();
90
        labelAndValues = new String[supportedCodes.size()][2];
91
        for (int i = 0; i < supportedCodes.size(); i++) {
92
            labelAndValues[i][0] = NomenclaturalCodeHelper
93
                    .getDescription(supportedCodes.get(i));
94
            labelAndValues[i][1] = PreferencesUtil
95
                    .getPreferenceKey(supportedCodes.get(i));
96
        }
97
        return labelAndValues;
98
    }
99

    
100

    
101

    
102

    
103
    public void createNomenclaturalCodeTab(Composite parent){
104

    
105
        Combo nomenclaturalCodeCombo;
106
        Label nomenclaturalCodeLabel;
107

    
108
        composite = addTab(Messages.DatabasePreferencesPage_Define_Default_NomenclaturalCode);
109
        nomenclaturalCodeCombo = new Combo(composite, SWT.DROP_DOWN);
110

    
111
        List<NomenclaturalCode> supportedCodes = NomenclaturalCodeHelper
112
              .getSupportedCodes();
113
        for (NomenclaturalCode code: supportedCodes) {
114
           nomenclaturalCodeCombo.add(NomenclaturalCodeHelper
115
                   .getDescription(code));
116

    
117
       }
118
        nomenclaturalCodeCombo.select(0);
119
       getLabelAndValues();
120
       //get the actual nomenclatural code and set it as selection: doGetPreferenceStore().getString(IPreferenceKeys.CDM_NOMENCLATURAL_CODE_KEY);
121
       nomenclaturalCodeCombo.addSelectionListener(new SelectionAdapter() {
122
           @Override
123
        public void widgetSelected(SelectionEvent evt) {
124

    
125
               String name = nomenclaturalCodeCombo.getText();
126

    
127
               for (String[] labelAndValue: labelAndValues){
128
                   if (labelAndValue[0].equals(name)){
129
                       selectedPreferenceKey = labelAndValue[1];
130
                   }
131
               }
132

    
133

    
134
               PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.CDM_NOMENCLATURAL_CODE_KEY, selectedPreferenceKey);
135

    
136
           }
137
       });
138
       nomenclaturalCodeLabel = new Label(composite, SWT.READ_ONLY);
139

    
140

    
141
        final Button useLocalPreference = new Button(composite, SWT.CHECK);
142
        boolean isUseLocalPreference = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY);
143
        useLocalPreference.setText(Messages.DatabasePreferencesPage_UseLocalPreferences);
144
        useLocalPreference.setSelection(isUseLocalPreference);
145
        useLocalPreference.addSelectionListener(new SelectionAdapter(){
146
             @Override
147
             public void widgetSelected(SelectionEvent e) {
148
                 boolean isUseLocalPreference = useLocalPreference.getSelection();
149
                 PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY, isUseLocalPreference);
150
              }
151
         });
152

    
153

    
154

    
155

    
156
    }
157
    public void createSetPublishFlagTab(Composite parent){
158
        composite = addTab(Messages.DatabasePreferencesPage_SetPublishFlag);
159
        GridLayout gridLayout = new GridLayout();
160
        gridLayout.numColumns = 2;
161
        composite.setLayout(gridLayout);
162
        //radio buttons for set publish as default, set not publish as default and inherit from parent
163

    
164
    }
165

    
166

    
167
    public void createBiocaseProviderTab(Composite parent){
168
        composite = addTab(Messages.DatabasePreferencesPage_Biocase_Provider);
169
        GridLayout gridLayout = new GridLayout();
170
        gridLayout.numColumns = 2;
171
        composite.setLayout(gridLayout);
172
        biocaseProviderList = new ListComponent(composite, SWT.SCROLL_LINE);
173

    
174
    }
175

    
176
    public ListComponent getBiocaseProviderList() {
177
        return biocaseProviderList;
178
    }
179

    
180
    public void createNameDetailsViewConfigurationTab(Composite parent, NameDetailsConfigurator config){
181
    	composite = parent;
182
        composite = addTab(Messages.DatabasePreferencesPage_details_view_configuration);
183
        GridLayout gridLayout = new GridLayout();
184
        gridLayout.numColumns = 1;
185

    
186
        composite.setLayout(gridLayout);
187
        nameDetailsConfig = new NameDetailsViewComposite(composite, SWT.SCROLL_LINE, config);
188

    
189
        final Button useLocalPreference = new Button(composite, SWT.CHECK);
190
        boolean isUseLocalPreference = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ALLOW_OVERRIDE_NAME_DETAILS);
191
        useLocalPreference.setText(Messages.DatabasePreferencesPage_UseLocalPreferences);
192
        useLocalPreference.setSelection(isUseLocalPreference);
193
        useLocalPreference.addSelectionListener(new SelectionAdapter(){
194
             @Override
195
             public void widgetSelected(SelectionEvent e) {
196
                 boolean isUseLocalPreference = useLocalPreference.getSelection();
197
                 PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.ALLOW_OVERRIDE_NAME_DETAILS, isUseLocalPreference);
198
              }
199
         });
200
    }
201

    
202

    
203
    public void createSpecimenOrObservationTab(Composite parent){
204
        composite = addTab(Messages.DatabasePreferencesPage_Specimen_Or_Observation);
205

    
206
        final Button showCollectingAreaInGeneralSectionButton = new Button(composite, SWT.CHECK);
207
        boolean isShowCollectingAreaInGeneralSection = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION);
208
        showCollectingAreaInGeneralSectionButton.setText(Messages.DatabasePreferncesPage_Show_Collecting_Areas_in_general_section);
209
        showCollectingAreaInGeneralSectionButton.setSelection(isShowCollectingAreaInGeneralSection);
210
        showCollectingAreaInGeneralSectionButton.addSelectionListener(new SelectionAdapter(){
211
             @Override
212
             public void widgetSelected(SelectionEvent e) {
213
                 boolean isShowCollectingAreaInGeneralSection = showCollectingAreaInGeneralSectionButton.getSelection();
214
                 PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION, isShowCollectingAreaInGeneralSection);
215
              }
216
         });
217

    
218
        final Button determinationOnlyForFieldUnitsButton = new Button(composite, SWT.CHECK);
219
        boolean isDeterminationOnlyForFieldUnits = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.DETERMINATION_ONLY_FOR_FIELD_UNITS);
220
        determinationOnlyForFieldUnitsButton.setText(Messages.DatabasePreferncesPage_Determination_only_for_field_unnits);
221
        determinationOnlyForFieldUnitsButton.setSelection(isDeterminationOnlyForFieldUnits);
222
        determinationOnlyForFieldUnitsButton.addSelectionListener(new SelectionAdapter(){
223
             @Override
224
             public void widgetSelected(SelectionEvent e) {
225
                 boolean isDeterminationOnlyForFieldUnits = determinationOnlyForFieldUnitsButton.getSelection();
226
                 PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DETERMINATION_ONLY_FOR_FIELD_UNITS, isDeterminationOnlyForFieldUnits);
227
              }
228
         });
229

    
230
        final Button showTaxonAssociationButton = new Button(composite, SWT.CHECK);
231
        boolean isShowTaxonAssociation = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_TAXON_ASSOCIATIONS);
232
        showTaxonAssociationButton.setText(Messages.DatabasePreferncesPage_Taxon_Associations);
233
        showTaxonAssociationButton.setSelection(isShowTaxonAssociation);
234
        showTaxonAssociationButton.addSelectionListener(new SelectionAdapter(){
235
             @Override
236
             public void widgetSelected(SelectionEvent e) {
237
                 boolean isShowTaxonAssociation = showTaxonAssociationButton.getSelection();
238
                 PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_TAXON_ASSOCIATIONS, isShowTaxonAssociation);
239
              }
240
         });
241

    
242
        final Button showLifeFormButton = new Button(composite, SWT.CHECK);
243
        boolean isShowLifeForm = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_LIFE_FORM);
244
        showLifeFormButton.setText(Messages.DatabasePreferncesPage_Life_Form);
245
        showLifeFormButton.setSelection(isShowLifeForm);
246
        showLifeFormButton.addSelectionListener(new SelectionAdapter(){
247
             @Override
248
             public void widgetSelected(SelectionEvent e) {
249
                 boolean isShowLifeForm = showLifeFormButton.getSelection();
250
                 PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_LIFE_FORM, isShowLifeForm);
251
              }
252
         });
253

    
254
//        Composite useLocalComp = new Composite(composite, SWT.NONE);
255

    
256

    
257
        final Button useLocalPreference = new Button(composite, SWT.CHECK);
258
        boolean isUseLocalPreference = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ALLOW_OVERRIDE_SPECIMEN_PREF);
259
        useLocalPreference.setText(Messages.DatabasePreferencesPage_UseLocalPreferences);
260
        GridData gridData = new GridData(SWT.FILL, SWT.BOTTOM, false, false);
261
        gridData.verticalIndent = 10;
262
        useLocalPreference.setLayoutData(gridData);
263

    
264
        useLocalPreference.setSelection(isUseLocalPreference);
265
        useLocalPreference.addSelectionListener(new SelectionAdapter(){
266
             @Override
267
             public void widgetSelected(SelectionEvent e) {
268
                 boolean isUseLocalPreference = useLocalPreference.getSelection();
269
                 PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.ALLOW_OVERRIDE_SPECIMEN_PREF, isUseLocalPreference);
270
              }
271
         });
272

    
273

    
274

    
275
 }
276

    
277
/**
278
 * {@inheritDoc}
279
 */
280
@Override
281
public boolean canFlipToNextPage() {
282
    // TODO Auto-generated method stub
283
    return false;
284
}
285

    
286

    
287

    
288
/**
289
 * {@inheritDoc}
290
 */
291
@Override
292
public String getName() {
293
    // TODO Auto-generated method stub
294
    return null;
295
}
296

    
297

    
298

    
299
/**
300
 * {@inheritDoc}
301
 */
302
@Override
303
public IWizardPage getNextPage() {
304
    // TODO Auto-generated method stub
305
    return null;
306
}
307

    
308

    
309

    
310
/**
311
 * {@inheritDoc}
312
 */
313
@Override
314
public IWizardPage getPreviousPage() {
315
    // TODO Auto-generated method stub
316
    return null;
317
}
318

    
319

    
320

    
321
/**
322
 * {@inheritDoc}
323
 */
324
@Override
325
public IWizard getWizard() {
326
    // TODO Auto-generated method stub
327
    return null;
328
}
329

    
330

    
331

    
332
/**
333
 * {@inheritDoc}
334
 */
335
@Override
336
public boolean isPageComplete() {
337

    
338
    return true;
339
}
340

    
341

    
342

    
343
/**
344
 * {@inheritDoc}
345
 */
346
@Override
347
public void setPreviousPage(IWizardPage page) {
348
    // TODO Auto-generated method stub
349

    
350
}
351

    
352

    
353

    
354
/**
355
 * {@inheritDoc}
356
 */
357
@Override
358
public void setWizard(IWizard newWizard) {
359
    // TODO Auto-generated method stub
360

    
361
}
362

    
363
/**
364
 * {@inheritDoc}
365
 */
366
@Override
367
public void createControl(Composite parent) {
368
    createNameDetailsViewConfigurationTab(parent, config);
369
    createNomenclaturalCodeTab(parent);
370

    
371
    createSpecimenOrObservationTab(parent);
372
    createBiocaseProviderTab(parent);
373
    setControl(parent);
374
}
375

    
376
/**
377
 * @return
378
 */
379
public NameDetailsConfigurator getConfig() {
380
    return config;
381
}
382

    
383
/**
384
 *
385
 */
386
public Abcd206ImportConfigurator getAbcdImportConfig() {
387
    return abcdImportConfigurator;
388

    
389
}
390

    
391
/**
392
 * @return
393
 */
394
public void createAbcdImportConfig() {
395
    this.abcdImportConfigurator.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS));
396
    this.abcdImportConfigurator.setAddMediaAsMediaSpecimen(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN));
397
    this.abcdImportConfigurator.setAllowReuseOtherClassifications(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS));
398
    //this.abcdImportConfigurator.setClassificationUuid(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_CLASSIFICATION_UUID));
399
    this.abcdImportConfigurator.setDeduplicateClassifications(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS));
400
    this.abcdImportConfigurator.setDeduplicateReferences(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES));
401
   // this.abcdImportConfigurator.setDefaultAuthor(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEFAULT_AUTHOR));
402
    this.abcdImportConfigurator.setGetSiblings(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS));
403
    this.abcdImportConfigurator.setIgnoreAuthorship(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP));
404
    this.abcdImportConfigurator.setIgnoreImportOfExistingSpecimen(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN));
405
    this.abcdImportConfigurator.setMapUnitIdToAccessionNumber(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER));
406
    this.abcdImportConfigurator.setMapUnitIdToBarcode(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE));
407
    this.abcdImportConfigurator.setMapUnitIdToCatalogNumber(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER));
408
    this.abcdImportConfigurator.setMoveNewTaxaToDefaultClassification(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION));
409
    this.abcdImportConfigurator.setReuseExistingDescriptiveGroups(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS));
410
    this.abcdImportConfigurator.setReuseExistingTaxaWhenPossible(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE));
411

    
412
}
413

    
414

    
415

    
416

    
417

    
418

    
419

    
420
}
(2-2/12)