Project

General

Profile

Revision da948591

IDda948591f450b04dca2251d92dcd896e2434ed2b
Parent 261ccfdd
Child 3374d46f

Added by Katja Luther over 3 years ago

add abcd import configuration to preferences

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databaseAdmin/wizard/AbstractPreferenceWizard.java
1
/**
2
* Copyright (C) 2017 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 org.eclipse.jface.wizard.WizardPage;
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.layout.GridData;
14
import org.eclipse.swt.layout.GridLayout;
15
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.TabFolder;
17
import org.eclipse.swt.widgets.TabItem;
18

  
19
/**
20
 * @author k.luther
21
 * @date 26.04.2017
22
 *
23
 */
24
public abstract class AbstractPreferenceWizard extends WizardPage {
25
    /**
26
     * @param pageName
27
     */
28
    protected AbstractPreferenceWizard(String pageName) {
29
        super(pageName);
30

  
31
    }
32
    protected TabFolder tabFolder;
33
    protected Composite composite;
34
    /***
35
     * Adds a tab to the page.
36
     * @param text the tab label
37
     */
38
     public Composite addTab(String text)    {
39
         if (tabFolder == null){
40
             // initialize tab folder
41
             if (composite == null) {
42
                 composite = new Composite(getShell(), SWT.NONE);
43
             }
44
             tabFolder = new TabFolder(composite, SWT.NONE);
45
             tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
46
         }
47

  
48
         TabItem item = new TabItem(tabFolder, SWT.NONE);
49
         item.setText(text);
50

  
51
         Composite currentTab = new Composite(tabFolder, SWT.NULL);
52
         GridLayout layout = new GridLayout();
53
         currentTab.setLayout(layout);
54
         currentTab.setFont(composite.getFont());
55
        // currentTab.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
56

  
57
         item.setControl(currentTab);
58
         return currentTab;
59

  
60
     }
61

  
62
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databaseAdmin/wizard/DatabasePreferencesPage.java
13 13
import org.eclipse.jface.preference.IPreferenceStore;
14 14
import org.eclipse.jface.wizard.IWizard;
15 15
import org.eclipse.jface.wizard.IWizardPage;
16
import org.eclipse.jface.wizard.WizardPage;
17 16
import org.eclipse.swt.SWT;
18 17
import org.eclipse.swt.events.SelectionAdapter;
19 18
import org.eclipse.swt.events.SelectionEvent;
20
import org.eclipse.swt.layout.GridData;
21 19
import org.eclipse.swt.layout.GridLayout;
22 20
import org.eclipse.swt.widgets.Button;
23 21
import org.eclipse.swt.widgets.Combo;
24 22
import org.eclipse.swt.widgets.Composite;
25 23
import org.eclipse.swt.widgets.Label;
26
import org.eclipse.swt.widgets.TabFolder;
27
import org.eclipse.swt.widgets.TabItem;
28 24

  
29 25
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
30 26
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
......
40 36
 * @date 01.11.2016
41 37
 *
42 38
 */
43
public class DatabasePreferencesPage extends WizardPage implements IWizardPage{
39
public class DatabasePreferencesPage extends AbstractPreferenceWizard implements IWizardPage{
44 40

  
45 41
    CdmPreference preferedNomenclaturalCode;
46 42
    NameDetailsConfigurator config ;
......
49 45
    CdmPreference showCollectingAreaInGeneralSectionPreference;
50 46
    CdmPreference showTaxonAssociationsPreference;
51 47

  
52

  
53
    TabFolder tabFolder;
54

  
55
    IPreferenceStore preferenceStore;
56
    Composite composite;
57 48
    boolean isSimpleDetailsViewActivated;
58 49

  
59 50
    Composite child ;
......
67 58
    ListComponent biocaseProviderList;
68 59
    Abcd206ImportConfigurator abcdImportConfigurator;
69 60

  
70

  
71
//    private UriWithLabelElement nomenclaturalCodeCombo;
72
//    private Label nomenclaturalCodeLabel;
73

  
74 61
    String[][] labelAndValues;
75 62

  
76 63
    /*
......
83 70
        if (config == null){
84 71
            config = new NameDetailsConfigurator(false);
85 72
        }
86
        setPreferenceStore(PreferencesUtil.getPreferenceStore());
87 73

  
88
    }
89 74

  
90
    protected void setPreferenceStore(IPreferenceStore store){
91
        this.preferenceStore = store;
92 75
    }
93 76

  
94 77

  
95

  
96

  
97
    /***
98
    * Adds a tab to the page.
99
    * @param text the tab label
100
    */
101
    public Composite addTab(String text)    {
102
        if (tabFolder == null){
103
            // initialize tab folder
104
            if (composite == null) {
105
                composite = new Composite(getShell(), SWT.NONE);
106
            }
107
            tabFolder = new TabFolder(composite, SWT.NONE);
108
            tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
109
        }
110

  
111
        TabItem item = new TabItem(tabFolder, SWT.NONE);
112
        item.setText(text);
113

  
114
        Composite currentTab = new Composite(tabFolder, SWT.NULL);
115
        GridLayout layout = new GridLayout();
116
        currentTab.setLayout(layout);
117
        currentTab.setFont(composite.getFont());
118
       // currentTab.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
119

  
120
        item.setControl(currentTab);
121
        return currentTab;
122

  
123
    }
124

  
125

  
126

  
127

  
128 78
    protected IPreferenceStore doGetPreferenceStore() {
129 79
        return PreferencesUtil.getPreferenceStore();
130 80
    }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databaseAdmin/wizard/DatabasePreferencesWizard.java
13 13

  
14 14
import eu.etaxonomy.cdm.api.application.ICdmRepository;
15 15
import eu.etaxonomy.cdm.api.service.IPreferenceService;
16
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
17 16
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
18 17
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
19
import eu.etaxonomy.taxeditor.io.wizard.AbcdImportConfiguratorWizardPage;
20 18
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
21 19
import eu.etaxonomy.taxeditor.store.CdmStore;
22 20

  
......
29 27

  
30 28

  
31 29
    public DatabasePreferencesPage preferencePage;
32
    public AbcdImportConfiguratorWizardPage configAbcdImport;
30

  
33 31

  
34 32

  
35 33
    public DatabasePreferencesWizard() {
36 34
        setWindowTitle("Database Preferences Wizard");
37 35

  
38 36
        preferencePage = new DatabasePreferencesPage("Database Preferences");
39
        configAbcdImport = AbcdImportConfiguratorWizardPage.createPage(Abcd206ImportConfigurator.NewInstance(null, null));
37

  
40 38

  
41 39
    }
42 40

  
......
115 113
    @Override
116 114
    public void addPages() {
117 115
        addPage(preferencePage);
118
        addPage(configAbcdImport);
116

  
119 117
    }
120 118

  
121 119
    @Override
122 120
    public IWizardPage getNextPage(IWizardPage currentPage) {
123
       if (currentPage.equals(preferencePage)){
124
           return configAbcdImport;
125
       }
121

  
126 122
       return null;
127 123
    }
128 124

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databaseAdmin/wizard/ImportPreferencesWizard.java
10 10

  
11 11
import org.eclipse.jface.wizard.Wizard;
12 12

  
13
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
13
import eu.etaxonomy.cdm.api.application.ICdmRepository;
14
import eu.etaxonomy.cdm.api.service.IPreferenceService;
15
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
16
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
14 17
import eu.etaxonomy.taxeditor.io.wizard.AbcdImportConfiguratorWizardPage;
18
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
19
import eu.etaxonomy.taxeditor.store.CdmStore;
15 20

  
16 21
/**
17 22
 * @author k.luther
......
24 29

  
25 30
    public ImportPreferencesWizard() {
26 31
        setWindowTitle("Abcd Import Configuration Wizard");
27
        configPage = AbcdImportConfiguratorWizardPage.createPreferencePage(Abcd206ImportConfigurator.NewInstance(null, null));
28 32

  
29
    }
33
        configPage = AbcdImportConfiguratorWizardPage.createPreferencePage(PreferencesUtil.getAbcdImportConfigurationPreference(false));
30 34

  
35
    }
36
    @Override
37
    public void addPages() {
38
        addPage(configPage);
39
    }
31 40
    /**
32 41
     * {@inheritDoc}
33 42
     */
34 43
    @Override
35 44
    public boolean performFinish() {
45
        String configString = "";
46
        this.configPage.saveConfigToPrefernceStore();
47
        configString = this.configPage.createConfigString();
48

  
49
        CdmPreference pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.AbcdImportConfig, configString);
50
        pref.setAllowOverride(true);
36 51

  
37
        return false;
52
        ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
53
        if (controller == null){
54
            return false;
55
        }
56
        IPreferenceService service = controller.getPreferenceService();
57
        service.set(pref);
58

  
59

  
60
       return true;
38 61
    }
62

  
63

  
64

  
39 65
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/ExportManager.java
11 11

  
12 12
import java.io.File;
13 13
import java.io.FileOutputStream;
14
import java.util.List;
14 15
import java.util.Map;
15 16
import java.util.Set;
16 17

  
......
22 23
import org.eclipse.core.runtime.jobs.Job;
23 24
import org.eclipse.swt.widgets.Display;
24 25
import org.eclipse.ui.IWorkbenchPart;
26
import org.eclipse.ui.PlatformUI;
25 27

  
26 28
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
27 29
import eu.etaxonomy.cdm.api.application.ICdmRepository;
......
38 40
import eu.etaxonomy.cdm.io.service.IIOService;
39 41
import eu.etaxonomy.taxeditor.model.CdmProgressMonitorAdapter;
40 42
import eu.etaxonomy.taxeditor.model.MessagingUtils;
43
import eu.etaxonomy.taxeditor.store.CdmStore;
41 44
import eu.etaxonomy.taxeditor.store.StoreUtil;
42 45
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
46
import eu.etaxonomy.taxeditor.ui.dialog.ReportTextDialog;
43 47

  
44 48
/**
45 49
 * <p>
......
317 321
                     } catch(Exception e){
318 322
                         logger.error(e.getStackTrace());
319 323
                     }
324
                     final StringBuilder reportText = new StringBuilder();
325
                     if(result!=null){
326
                         List<byte[]> reports = result.getErrors();
327
                         reportText.append("Errors:\\r");
328
                         for (byte[] bs : reports) {
329
                             reportText.append(new String(bs));
330
                         }
331
                         List<byte[]> warnings = result.getWarnings();
332
                         reportText.append("Warnings:\\r");
333
                         for (byte[] bs : warnings) {
334
                             reportText.append(new String(bs));
335
                         }
336
                         List<Exception> exceptions = result.getExceptions();
337
                         reportText.append("Exceptions:\\r");
338
                         for (Exception ex : exceptions) {
339
                             reportText.append(ex.getStackTrace());
340
                         }
320 341

  
321 342

  
343
                     }
344
                     final Display display = Display.getDefault();
345
                     display.asyncExec(new Runnable() {
346

  
347
                         @Override
348
                         public void run() {
349
                             // display reports with possibility to save
350
                             ReportTextDialog dialog = new ReportTextDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
351
                             dialog.setTitle(configurator.getClass().getSimpleName()+" Report");
352
                             dialog.setReportText(reportText.toString());
353
                             dialog.open();
354
                             CdmStore.getContextManager().notifyContextRefresh();
355
                         }
356
                     });
357

  
322 358

  
323 359

  
324 360
                 } catch (Exception e) {
......
329 365
                             e,
330 366
                             true);
331 367
                 }
368

  
332 369
                 return Status.OK_STATUS;
333 370
             }
334 371
         };
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/AbcdImportConfiguratorWizardPage.java
13 13
import java.util.ArrayList;
14 14
import java.util.List;
15 15

  
16
import org.eclipse.jface.wizard.WizardPage;
16
import org.eclipse.jface.preference.IPreferenceStore;
17 17
import org.eclipse.swt.SWT;
18 18
import org.eclipse.swt.events.SelectionAdapter;
19 19
import org.eclipse.swt.events.SelectionEvent;
......
22 22
import org.eclipse.swt.widgets.Composite;
23 23

  
24 24
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
25
import eu.etaxonomy.taxeditor.databaseAdmin.wizard.ListComponent;
25
import eu.etaxonomy.taxeditor.databaseAdmin.wizard.AbstractPreferenceWizard;
26
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
27
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
26 28

  
27 29
/**
28 30
 *
29 31
 * @author pplitzner
30 32
 *
31 33
 */
32
public class AbcdImportConfiguratorWizardPage extends WizardPage {
34
public class AbcdImportConfiguratorWizardPage extends AbstractPreferenceWizard {
33 35

  
34 36
	public static final String PAGE_NAME = "AbcdImportConfiguratorWizardPage";
35 37

  
......
70 72
	@Override
71 73
    public void createControl(Composite parent) {
72 74
		final Composite composite = new Composite(parent, SWT.NULL);
73

  
75
		//composite = addTab(Messages.DatabasePreferencesPage_Define_Default_NomenclaturalCode);
74 76
		GridLayout gridLayout = new GridLayout();
75 77
		composite.setLayout(gridLayout);
76
        if (isPreferencePage){
77
            ListComponent list = new ListComponent(composite, composite.getStyle());
78
        }
78
//        if (isPreferencePage){
79
//            ListComponent list = new ListComponent(composite, composite.getStyle());
80
//        }
79 81

  
80 82
		Button checkBoxMediaSpecimen = new Button(composite, SWT.CHECK);
81 83
		checkBoxMediaSpecimen.setSelection(configurator.isAddMediaAsMediaSpecimen());
......
126 128
				configurator.setMapUnitIdToCatalogNumber(!configurator.isMapUnitIdToCatalogNumber());
127 129
			}
128 130
		});
129

  
131
//TODO: only one of the mappings can be checked!
130 132
		Button checkBoxMapUnitIdToAccessionNumber = new Button(composite, SWT.CHECK);
131 133
		checkBoxMapUnitIdToAccessionNumber.setSelection(configurator.isMapUnitIdToAccessionNumber());
132 134
		checkBoxMapUnitIdToAccessionNumber.setText("Map UnitID to accession number");
......
176 178
		checkBoxMoveToDefaultClassification.addSelectionListener(new SelectionAdapter() {
177 179
			@Override
178 180
			public void widgetSelected(SelectionEvent e) {
179
				configurator.setRemoveCountryFromLocalityText(!configurator.isRemoveCountryFromLocalityText());
181
				configurator.setMoveNewTaxaToDefaultClassification(!configurator.isMoveNewTaxaToDefaultClassification());
180 182
			}
181 183
		});
182 184

  
185
		Button checkBoxImportSiblings = new Button(composite, SWT.CHECK);
186
		checkBoxImportSiblings.setSelection(configurator.isGetSiblings());
187
		checkBoxImportSiblings.setText("Import all children of cultures or tissue samples");
188
		checkBoxImportSiblings
189
        .setToolTipText("for a tissue sample or culture all children will be searched and imported");
190
		checkBoxImportSiblings.addSelectionListener(new SelectionAdapter() {
191
            @Override
192
            public void widgetSelected(SelectionEvent e) {
193
                configurator.setGetSiblings(!configurator.isGetSiblings());
194
            }
195
        });
196

  
197
        Button checkBoxAddIndividualsAssociations = new Button(composite, SWT.CHECK);
198
        checkBoxAddIndividualsAssociations.setSelection(configurator.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
199
        checkBoxAddIndividualsAssociations.setText("Create an Individual Association for each Specimen");
200
        checkBoxAddIndividualsAssociations
201
        .setToolTipText("for each specimen associated to a taxon an indiviadual association to this taxon is created");
202
        checkBoxAddIndividualsAssociations.addSelectionListener(new SelectionAdapter() {
203
            @Override
204
            public void widgetSelected(SelectionEvent e) {
205
                configurator.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(!configurator.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
206
            }
207
        });
208

  
209
        Button checkBoxReuseDescriptiveGroups = new Button(composite, SWT.CHECK);
210
        checkBoxReuseDescriptiveGroups.setSelection(configurator.isReuseExistingDescriptiveGroups());
211
        checkBoxReuseDescriptiveGroups.setText("Reuse existing descriptive group");
212
        checkBoxReuseDescriptiveGroups
213
        .setToolTipText("reuse one of the existing descriptive groups or create a new one for every import");
214
        checkBoxReuseDescriptiveGroups.addSelectionListener(new SelectionAdapter() {
215
            @Override
216
            public void widgetSelected(SelectionEvent e) {
217
                configurator.setReuseExistingDescriptiveGroups(!configurator.isReuseExistingDescriptiveGroups());
218
            }
219
        });
220

  
221
        Button checkBoxReuseExistingTaxa = new Button(composite, SWT.CHECK);
222
        checkBoxReuseExistingTaxa.setSelection(configurator.isReuseExistingTaxaWhenPossible());
223
        checkBoxReuseExistingTaxa.setText("Reuse existing taxa when possible");
224
        checkBoxReuseExistingTaxa
225
        .setToolTipText("reuse existing taxa when the name matches the identified name of the specimen");
226
        checkBoxReuseExistingTaxa.addSelectionListener(new SelectionAdapter() {
227
            @Override
228
            public void widgetSelected(SelectionEvent e) {
229
                configurator.setReuseExistingDescriptiveGroups(!configurator.isReuseExistingDescriptiveGroups());
230
            }
231
        });
232

  
233

  
183 234
		setControl(composite);
184 235
	}
185 236

  
237
	 public void saveConfigToPrefernceStore() {
238
	        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS,
239
	                configurator.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
240
	        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN,
241
                    configurator.isAddMediaAsMediaSpecimen());
242
	        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS,
243
                    configurator.isAllowReuseOtherClassifications());
244
	        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS,
245
                    configurator.isDeduplicateClassifications());
246
	        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES,
247
                    configurator.isDeduplicateReferences());
248
	        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS,
249
                    configurator.isGetSiblings());
250
	        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP,
251
                    configurator.isIgnoreAuthorship());
252
	        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN,
253
                    configurator.isIgnoreImportOfExistingSpecimen());
254
	        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER,
255
                    configurator.isMapUnitIdToAccessionNumber());
256
	        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE,
257
                    configurator.isMapUnitIdToBarcode());
258
	        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER,
259
                    configurator.isMapUnitIdToCatalogNumber());
260
	        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION,
261
                    configurator.isMoveNewTaxaToDefaultClassification());
262
	        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN,
263
                    configurator.isOverwriteExistingSpecimens());
264
	        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS,
265
                    configurator.isReuseExistingDescriptiveGroups());
266
	        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA,
267
                    configurator.isReuseExistingMetaData());
268
	        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE,
269
                    configurator.isReuseExistingTaxaWhenPossible());
270

  
271
	    }
272

  
273
	 public String createConfigString(){
274
	    return configurator.toString();
275

  
276
	 }
277

  
278
	 protected IPreferenceStore doGetPreferenceStore() {
279
	        return PreferencesUtil.getPreferenceStore();
280
	    }
186 281
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/AbcdImportWizard.java
19 19
import eu.etaxonomy.cdm.database.DbSchemaValidation;
20 20
import eu.etaxonomy.cdm.io.common.IImportConfigurator.SOURCE_TYPE;
21 21
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
22
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
22 23
import eu.etaxonomy.taxeditor.store.CdmStore;
23 24

  
24 25
/**
......
52 53
	    }
53 54

  
54 55
	    CdmStore.getImportManager().runMoniteredOperation(configurator, new File(source), SOURCE_TYPE.INPUTSTREAM);
55
	    
56

  
56 57
	    return true;
57 58

  
58 59
	}
......
61 62
	@Override
62 63
    public void init(IWorkbench workbench, IStructuredSelection selection) {
63 64
		super.init(workbench, selection);
64
		configurator =  CdmStore.getImportManager().AbcdConfigurator();
65
		configurator =  PreferencesUtil.getAbcdImportConfigurationPreference(true);
65 66
	}
66
	
67

  
67 68
	@Override
68 69
	protected void addConfiguratorPage() {
69 70
		AbcdImportConfiguratorWizardPage configuratorWizardPage = AbcdImportConfiguratorWizardPage.createPage(configurator);
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java
26 26
import java.util.UUID;
27 27

  
28 28
import org.apache.commons.lang.StringUtils;
29
import org.apache.log4j.Logger;
29 30
import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement;
30 31
import org.eclipse.jface.preference.IPreferenceStore;
31 32
import org.eclipse.jface.window.Window;
......
42 43
import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;
43 44
import eu.etaxonomy.cdm.common.CdmUtils;
44 45
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
46
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
45 47
import eu.etaxonomy.cdm.model.common.ICdmBase;
46 48
import eu.etaxonomy.cdm.model.common.IDefinedTerm;
47 49
import eu.etaxonomy.cdm.model.common.ISimpleTerm;
......
85 87
	public static final String P2_REPOSITORIES_DELIM = ",";
86 88
	public static final String P2_REPOSITORY_FIELDS_DELIM = ";";
87 89

  
88

  
90
	private final static Logger logger = Logger.getLogger(PreferencesUtil.class);
89 91

  
90 92
	/**
91 93
	 * <p>
......
1104 1106
     *            a {@link eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator}
1105 1107
     *            object.
1106 1108
     */
1107
//    public static CdmPreference setAbcdImportConfigurationPreference(
1108
//            Abcd206ImportConfigurator preferredConfiguration, boolean local) {
1109
//        if (local){
1110
//            /*
1111
//             *
1112
//    public static final String ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS = "eu.etaxonomy.taxeditor.abcd_import_configurator.doSiblings";
1113
//    public static final String ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN= "eu.etaxonomy.taxeditor.abcd_import_configurator.ignoreImportOfExistingSpecimen";
1114
//    public static final String ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE= "eu.etaxonomy.taxeditor.abcd_import_configurator.reuseExistingTaxaWhenPossible";
1115
//    public static final String ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP= "eu.etaxonomy.taxeditor.abcd_import_configurator.ignoreAuthorship";
1116
//    public static final String ABCD_IMPORT_CONFIGURATOR_REMOVE_COUNTRY_FROM_LOCALITY_TEXT= "eu.etaxonomy.taxeditor.abcd_import_configurator.removeCountryFromLocalityText";
1117
//    public static final String ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN= "eu.etaxonomy.taxeditor.abcd_import_configurator.addMediaAsMediaSpecimen";
1118
//    public static final String ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA= "eu.etaxonomy.taxeditor.abcd_import_configurator.reuseExistingMetaData";
1119
//    public static final String ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS= "eu.etaxonomy.taxeditor.abcd_import_configurator.addIndividualsAssociationsSuchAsSpecimenAndObservations";
1120
//    public static final String ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS= "eu.etaxonomy.taxeditor.abcd_import_configurator.reuseExistingDescriptiveGroups";
1121
//    public static final String ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS= "eu.etaxonomy.taxeditor.abcd_import_configurator.allowReuseOtherClassifications";
1122
//    public static final String ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES= "eu.etaxonomy.taxeditor.abcd_import_configurator.deduplicateReferences";
1123
//    public static final String ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS= "eu.etaxonomy.taxeditor.abcd_import_configurator.deduplicateClassifications";
1124
//    public static final String ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION= "eu.etaxonomy.taxeditor.abcd_import_configurator.moveNewTaxaToDefaultClassification";
1125
//    public static final String ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER= "eu.etaxonomy.taxeditor.abcd_import_configurator.mapUnitIdToCatalogNumber";
1126
//    public static final String ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER= "eu.etaxonomy.taxeditor.abcd_import_configurator.mapUnitIdToAccessionNumber";
1127
//    public static final String ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE= "eu.etaxonomy.taxeditor.abcd_import_configurator.mapUnitIdToBarcode";
1128
//    public static final String ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN= "eu.etaxonomy.taxeditor.abcd_import_configurator.overwriteExistingSpecimens";
1129
//
1130
//             */
1131
//
1132
//            getPreferenceStore().setValue(ABCD_IMPORT_CONFIGURATOR_SOURCE_URI,
1133
//                    getPreferenceKey(preferredConfiguration.getSourceUri()));
1134
//        }
1135
//        else{
1136
//            ICdmRepository controller;
1137
//            controller = CdmStore.getCurrentApplicationConfiguration();
1138
//            PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
1139
//            CdmPreference preference = null;
1140
//            if (controller == null){
1141
//                return null;
1142
//            }
1143
//            if (preferredCode == null){
1144
//                preference = controller.getPreferenceService().find(key);
1145
//                if (preference == null){
1146
//                    return null;
1147
//                } else{
1148
//                    int index = StringUtils.lastIndexOf(preference.getValue(), ".");
1149
//                    UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length()));
1150
//                    preferredCode = NomenclaturalCode.getByUuid(uuid);
1151
//
1152
//                    getPreferenceStore().setValue(CDM_NOMENCLATURAL_CODE_KEY,
1153
//                            getPreferenceKey(preferredCode));
1154
//                    getPreferenceStore().setValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY,preference.isAllowOverride());
1155
//                    return preference;
1156
//                }
1157
//            } else{
1158
//                preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferredCode.getKey());
1159
//                controller.getPreferenceService().set(preference);
1160
//
1161
//            }
1162
//        }
1163
//        return null;
1164
//
1165
//
1166
//
1167
//    }
1109
    public static Abcd206ImportConfigurator getAbcdImportConfigurationPreference(boolean useLocal) {
1110

  
1111
        Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
1112

  
1113
        if (useLocal){
1114
            config.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS));
1115

  
1116
            config.setAddMediaAsMediaSpecimen(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN));
1117

  
1118
            config.setAllowReuseOtherClassifications(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS));
1119
            config.setDeduplicateClassifications(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS));
1120
            config.setDeduplicateReferences(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES));
1121

  
1122
            config.setGetSiblings(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS));
1123
            config.setIgnoreAuthorship(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP));
1124
            config.setIgnoreImportOfExistingSpecimen(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN));
1125
            config.setMapUnitIdToAccessionNumber(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER));
1126
            config.setMapUnitIdToBarcode(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE));
1127
            config.setMapUnitIdToCatalogNumber(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER));
1128
            config.setMoveNewTaxaToDefaultClassification(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION));
1129
            config.setOverwriteExistingSpecimens(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN));
1130
            config.setReuseExistingDescriptiveGroups(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS));
1131
            config.setReuseExistingMetaData(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA));
1132
            config.setReuseExistingTaxaWhenPossible(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE));
1133
            return config;
1134

  
1135
        }
1136
            ICdmRepository controller;
1137
            controller = CdmStore.getCurrentApplicationConfiguration();
1138
            PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.AbcdImportConfig);
1139
            CdmPreference preference = null;
1140
            if (controller == null){
1141
                return null;
1142
            }
1143
            preference = controller.getPreferenceService().find(key);
1144
            if (preference == null){
1145
                return config;
1146
             } else{
1147
             String configString = preference.getValue();
1148
             String[] configArray = configString.split(";");
1149

  
1150
             for (String configItem: configArray){
1151
                 String[] keyValue = configItem.split(":");
1152
                 String keyString = keyValue[0];
1153
                 String valueString = keyValue[1];
1154
                 if (keyString.equals("ignoreImportOfExistingSpecimen")){
1155
                     config.setIgnoreImportOfExistingSpecimen(Boolean.valueOf(valueString));
1156
                 }else if (keyString.equals("addIndividualsAssociationsSuchAsSpecimenAndObservations")){
1157
                     config.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(Boolean.valueOf(valueString));
1158
                 }else if (keyString.equals("reuseExistingTaxaWhenPossible")){
1159
                     config.setReuseExistingTaxaWhenPossible(Boolean.valueOf(valueString));
1160
                 }else if (keyString.equals("ignoreAuthorship")){
1161
                     config.setIgnoreAuthorship(Boolean.valueOf(valueString));
1162
                 }else if (keyString.equals("addMediaAsMediaSpecimen")){
1163
                     config.setAddMediaAsMediaSpecimen(Boolean.valueOf(valueString));
1164
                 }else if (keyString.equals("reuseExistingMetaData")){
1165
                     config.setReuseExistingMetaData(Boolean.valueOf(valueString));
1166
                 }else if (keyString.equals("reuseExistingDescriptiveGroups")){
1167
                     config.setReuseExistingDescriptiveGroups(Boolean.valueOf(valueString));
1168
                 }else if (keyString.equals("allowReuseOtherClassifications")){
1169
                     config.setAllowReuseOtherClassifications(Boolean.valueOf(valueString));
1170
                 }else if (keyString.equals("deduplicateReferences")){
1171
                     config.setDeduplicateReferences(Boolean.valueOf(valueString));
1172
                 }else if (keyString.equals("deduplicateClassifications")){
1173
                     config.setDeduplicateClassifications(Boolean.valueOf(valueString));
1174
                 }else if (keyString.equals("moveNewTaxaToDefaultClassification")){
1175
                     config.setMoveNewTaxaToDefaultClassification(Boolean.valueOf(valueString));
1176
                 }else if (keyString.equals("mapUnitIdToCatalogNumber")){
1177
                     config.setMapUnitIdToCatalogNumber(Boolean.valueOf(valueString));
1178
                 }else if (keyString.equals("mapUnitIdToAccessionNumber")){
1179
                     config.setMapUnitIdToAccessionNumber(Boolean.valueOf(valueString));
1180
                 }else if (keyString.equals("mapUnitIdToBarcode")){
1181
                     config.setMapUnitIdToBarcode(Boolean.valueOf(valueString));
1182
                 }else if (keyString.equals("overwriteExistingSpecimens")){
1183
                     config.setOverwriteExistingSpecimens(Boolean.valueOf(valueString));
1184
                 }else{
1185
                     logger.debug("This key of the abcd configurator needs to be added to the transformer: " + keyString);
1186
                 }
1187

  
1188
            }
1189
        }
1190
        return config;
1191

  
1192

  
1193

  
1194
    }
1168 1195

  
1169 1196

  
1170 1197

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java
280 280

  
281 281
    }
282 282

  
283
    private CdmStore(ICdmRepository applicationController,
283
    private CdmStore(ICdmRepository repository,
284 284
            ICdmSource cdmSource) {
285
        CdmApplicationState.setCurrentAppConfig(applicationController);
285
        CdmApplicationState.setCurrentAppConfig(repository);
286 286
        CdmApplicationState.setCurrentDataChangeService(new CdmUIDataChangeService());
287 287
        this.cdmSource = cdmSource;
288 288
        isConnected = true;

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)