Project

General

Profile

Download (13.1 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.GridLayout;
20
import org.eclipse.swt.widgets.Button;
21
import org.eclipse.swt.widgets.Combo;
22
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.swt.widgets.Label;
24

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

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

    
41
    CdmPreference preferedNomenclaturalCode;
42
    NameDetailsConfigurator config ;
43
    CdmPreference isRedListPreference;
44
    CdmPreference determinationOnlyForFieldUnitsPreference;
45
    CdmPreference showCollectingAreaInGeneralSectionPreference;
46
    CdmPreference showTaxonAssociationsPreference;
47

    
48
    boolean isSimpleDetailsViewActivated;
49

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

    
56
    String selectedPreferenceKey = null;
57

    
58
    ListComponent biocaseProviderList;
59
    Abcd206ImportConfigurator abcdImportConfigurator;
60

    
61
    String[][] labelAndValues;
62

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

    
74

    
75
    }
76

    
77

    
78
    protected IPreferenceStore doGetPreferenceStore() {
79
        return PreferencesUtil.getPreferenceStore();
80
    }
81

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

    
98

    
99

    
100

    
101
    public void createNomenclaturalCodeTab(Composite parent){
102

    
103
        Combo nomenclaturalCodeCombo;
104
        Label nomenclaturalCodeLabel;
105

    
106
        composite = addTab(Messages.DatabasePreferencesPage_Define_Default_NomenclaturalCode);
107
        nomenclaturalCodeCombo = new Combo(composite, SWT.READ_ONLY);
108
        List<NomenclaturalCode> supportedCodes = NomenclaturalCodeHelper
109
              .getSupportedCodes();
110
        for (NomenclaturalCode code: supportedCodes) {
111
           nomenclaturalCodeCombo.add(NomenclaturalCodeHelper
112
                   .getDescription(code));
113

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

    
121
               String name = nomenclaturalCodeCombo.getText();
122

    
123
               for (String[] labelAndValue: labelAndValues){
124
                   if (labelAndValue[0].equals(name)){
125
                       selectedPreferenceKey = labelAndValue[1];
126
                   }
127
               }
128

    
129

    
130
               PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.CDM_NOMENCLATURAL_CODE_KEY, selectedPreferenceKey);
131

    
132
           }
133
       });
134
       nomenclaturalCodeLabel = new Label(composite, SWT.READ_ONLY);
135

    
136

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

    
149

    
150

    
151

    
152
}
153

    
154
    public void createBiocaseProviderTab(Composite parent){
155
        composite = addTab(Messages.DatabasePreferencesPage_Biocase_Provider);
156
        GridLayout gridLayout = new GridLayout();
157
        gridLayout.numColumns = 2;
158
        composite.setLayout(gridLayout);
159
        biocaseProviderList = new ListComponent(composite, SWT.SCROLL_LINE);
160

    
161
 }
162

    
163
    public ListComponent getBiocaseProviderList() {
164
        return biocaseProviderList;
165
    }
166

    
167
    public void createNameDetailsViewConfigurationTab(Composite parent, NameDetailsConfigurator config){
168
        composite = parent;
169
        composite = addTab(Messages.DatabasePreferencesPage_details_view_configuration);
170
        GridLayout gridLayout = new GridLayout();
171
        gridLayout.numColumns = 2;
172
        composite.setLayout(gridLayout);
173
        nameDetailsConfig = new NameDetailsViewComposite(composite, SWT.SCROLL_LINE, config);
174
    }
175

    
176

    
177
    public void createSpecimenOrObservationTab(Composite parent){
178
        composite = addTab(Messages.DatabasePreferencesPage_Specimen_Or_Observation);
179

    
180
        final Button showCollectingAreaInGeneralSectionButton = new Button(composite, SWT.CHECK);
181
        boolean isShowCollectingAreaInGeneralSection = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION);
182
        showCollectingAreaInGeneralSectionButton.setText(Messages.DatabasePreferncesPage_Show_Collecting_Areas_in_general_section);
183
        showCollectingAreaInGeneralSectionButton.setSelection(isShowCollectingAreaInGeneralSection);
184
        showCollectingAreaInGeneralSectionButton.addSelectionListener(new SelectionAdapter(){
185
             @Override
186
             public void widgetSelected(SelectionEvent e) {
187
                 boolean isShowCollectingAreaInGeneralSection = showCollectingAreaInGeneralSectionButton.getSelection();
188
                 PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION, isShowCollectingAreaInGeneralSection);
189
              }
190
         });
191

    
192
        final Button determinationOnlyForFieldUnitsButton = new Button(composite, SWT.CHECK);
193
        boolean isDeterminationOnlyForFieldUnits = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.DETERMINATION_ONLY_FOR_FIELD_UNITS);
194
        determinationOnlyForFieldUnitsButton.setText(Messages.DatabasePreferncesPage_Determination_only_for_field_unnits);
195
        determinationOnlyForFieldUnitsButton.setSelection(isDeterminationOnlyForFieldUnits);
196
        determinationOnlyForFieldUnitsButton.addSelectionListener(new SelectionAdapter(){
197
             @Override
198
             public void widgetSelected(SelectionEvent e) {
199
                 boolean isDeterminationOnlyForFieldUnits = determinationOnlyForFieldUnitsButton.getSelection();
200
                 PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DETERMINATION_ONLY_FOR_FIELD_UNITS, isDeterminationOnlyForFieldUnits);
201
              }
202
         });
203

    
204
        final Button showTaxonAssociationButton = new Button(composite, SWT.CHECK);
205
        boolean isShowTaxonAssociation = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_TAXON_ASSOCIATIONS);
206
        showTaxonAssociationButton.setText(Messages.DatabasePreferncesPage_Taxon_Associations);
207
        showTaxonAssociationButton.setSelection(isShowTaxonAssociation);
208
        showTaxonAssociationButton.addSelectionListener(new SelectionAdapter(){
209
             @Override
210
             public void widgetSelected(SelectionEvent e) {
211
                 boolean isShowTaxonAssociation = showTaxonAssociationButton.getSelection();
212
                 PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_TAXON_ASSOCIATIONS, isShowTaxonAssociation);
213
              }
214
         });
215

    
216

    
217

    
218
 }
219

    
220
/**
221
 * {@inheritDoc}
222
 */
223
@Override
224
public boolean canFlipToNextPage() {
225
    // TODO Auto-generated method stub
226
    return false;
227
}
228

    
229

    
230

    
231
/**
232
 * {@inheritDoc}
233
 */
234
@Override
235
public String getName() {
236
    // TODO Auto-generated method stub
237
    return null;
238
}
239

    
240

    
241

    
242
/**
243
 * {@inheritDoc}
244
 */
245
@Override
246
public IWizardPage getNextPage() {
247
    // TODO Auto-generated method stub
248
    return null;
249
}
250

    
251

    
252

    
253
/**
254
 * {@inheritDoc}
255
 */
256
@Override
257
public IWizardPage getPreviousPage() {
258
    // TODO Auto-generated method stub
259
    return null;
260
}
261

    
262

    
263

    
264
/**
265
 * {@inheritDoc}
266
 */
267
@Override
268
public IWizard getWizard() {
269
    // TODO Auto-generated method stub
270
    return null;
271
}
272

    
273

    
274

    
275
/**
276
 * {@inheritDoc}
277
 */
278
@Override
279
public boolean isPageComplete() {
280

    
281
    return true;
282
}
283

    
284

    
285

    
286
/**
287
 * {@inheritDoc}
288
 */
289
@Override
290
public void setPreviousPage(IWizardPage page) {
291
    // TODO Auto-generated method stub
292

    
293
}
294

    
295

    
296

    
297
/**
298
 * {@inheritDoc}
299
 */
300
@Override
301
public void setWizard(IWizard newWizard) {
302
    // TODO Auto-generated method stub
303

    
304
}
305

    
306
/**
307
 * {@inheritDoc}
308
 */
309
@Override
310
public void createControl(Composite parent) {
311
    createNameDetailsViewConfigurationTab(parent, config);
312
    createNomenclaturalCodeTab(parent);
313

    
314
    createSpecimenOrObservationTab(parent);
315
    createBiocaseProviderTab(parent);
316
    setControl(parent);
317
}
318

    
319
/**
320
 * @return
321
 */
322
public NameDetailsConfigurator getConfig() {
323
    return config;
324
}
325

    
326
/**
327
 *
328
 */
329
public Abcd206ImportConfigurator getAbcdImportConfig() {
330
    return abcdImportConfigurator;
331

    
332
}
333

    
334
/**
335
 * @return
336
 */
337
public void createAbcdImportConfig() {
338
    this.abcdImportConfigurator.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS));
339
    this.abcdImportConfigurator.setAddMediaAsMediaSpecimen(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN));
340
    this.abcdImportConfigurator.setAllowReuseOtherClassifications(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS));
341
    //this.abcdImportConfigurator.setClassificationUuid(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_CLASSIFICATION_UUID));
342
    this.abcdImportConfigurator.setDeduplicateClassifications(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS));
343
    this.abcdImportConfigurator.setDeduplicateReferences(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES));
344
   // this.abcdImportConfigurator.setDefaultAuthor(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEFAULT_AUTHOR));
345
    this.abcdImportConfigurator.setGetSiblings(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS));
346
    this.abcdImportConfigurator.setIgnoreAuthorship(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP));
347
    this.abcdImportConfigurator.setIgnoreImportOfExistingSpecimen(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN));
348
    this.abcdImportConfigurator.setMapUnitIdToAccessionNumber(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER));
349
    this.abcdImportConfigurator.setMapUnitIdToBarcode(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE));
350
    this.abcdImportConfigurator.setMapUnitIdToCatalogNumber(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER));
351
    this.abcdImportConfigurator.setMoveNewTaxaToDefaultClassification(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION));
352
    this.abcdImportConfigurator.setReuseExistingDescriptiveGroups(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS));
353
    this.abcdImportConfigurator.setReuseExistingTaxaWhenPossible(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE));
354

    
355
}
356

    
357

    
358

    
359

    
360

    
361

    
362

    
363
}
(2-2/12)