Project

General

Profile

Download (3.85 KB) Statistics
| Branch: | Tag: | Revision:
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.io.e4.in;
10

    
11
import java.util.List;
12
import java.util.UUID;
13

    
14
import javax.inject.Inject;
15

    
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.widgets.Combo;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Label;
23

    
24
import eu.etaxonomy.cdm.api.service.IVocabularyService;
25
import eu.etaxonomy.cdm.common.CdmUtils;
26
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
27
import eu.etaxonomy.cdm.model.common.TermType;
28
import eu.etaxonomy.cdm.model.common.TermVocabulary;
29
import eu.etaxonomy.taxeditor.l10n.Messages;
30
import eu.etaxonomy.taxeditor.store.CdmStore;
31

    
32
/**
33
 * @author k.luther
34
 * @date 04.05.2017
35
 *
36
 */
37
public class ImportFromFileAndChooseVocIdWizardPageE4 extends ImportFromFileDataSourceWizardPageE4 {
38

    
39
    private Combo vocabularyCombo;
40
    UUID vocUuid;
41
    String[][] labelAndValues;
42

    
43
    @Inject
44
    public ImportFromFileAndChooseVocIdWizardPageE4() {
45
        super();
46
        setTitle("Choose Excel File");
47
        setDescription("Please choose an xls file in the Distribution Update format.");
48
        setExtensions(new String[]{"*.xlsx", "*.xls", "*.*"});
49

    
50
    }
51

    
52
    @Override
53
    public void createControl(Composite parent) {
54
        super.createControl(parent);
55
        Composite composite = (Composite)getControl();
56
      //  final Composite composite = new Composite(parent, SWT.NULL);
57
        GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false);
58
        composite.setLayoutData(gridData);
59
        Label label = new Label(composite, SWT.NONE);
60
        label.setText(Messages.ImportFromFileAndChooseVocIdWizardPage_AreaVoc);
61
        label.setToolTipText(Messages.ImportFromFileAndChooseVocIdWizardOage_AreaVoc_toolTip);
62
        vocabularyCombo = new Combo(composite, SWT.DROP_DOWN);
63
        List<TermVocabulary<DefinedTermBase>> vocs = CdmStore.getService(IVocabularyService.class).findByTermType(TermType.NamedArea, null);
64
        for(TermVocabulary voc: vocs){
65
            vocabularyCombo.add(voc.getLabel());
66
        }
67
        getLabelAndValues(vocs);
68
        vocabularyCombo.select(0);
69
        setVocUuidFromVocCombo();
70
        vocabularyCombo.addSelectionListener(new SelectionAdapter(){
71

    
72
            @Override
73
            public void widgetSelected(SelectionEvent e) {
74
                String name = vocabularyCombo.getText();
75
                setVocUuidFromVocCombo();
76
                if (vocUuid != null){
77
                    setPageComplete(isPageComplete());
78
                }
79
            }
80

    
81
        });
82
    }
83

    
84
    /**
85
     * @return
86
     */
87
    private void setVocUuidFromVocCombo() {
88
        String name = vocabularyCombo.getText();
89

    
90
        for (String[] labelAndValue: labelAndValues){
91
            if (labelAndValue[0].equals(name)){
92
                String uuidString = labelAndValue[1];
93
                vocUuid = UUID.fromString(uuidString);
94
            }
95
        }
96

    
97
    }
98

    
99
    public UUID getVocUuid() {
100
        return vocUuid;
101
    }
102

    
103
    public void setVocUuid(UUID vocUuid) {
104
        this.vocUuid = vocUuid;
105
    }
106

    
107
    private String[][] getLabelAndValues(List<TermVocabulary<DefinedTermBase>> vocs) {
108

    
109
        labelAndValues = new String[vocs.size()][2];
110
        for (int i = 0; i < vocs.size(); i++) {
111
            labelAndValues[i][0] = vocs.get(i).getLabel();
112
            labelAndValues[i][1] = vocs.get(i).getUuid().toString();
113
        }
114
        return labelAndValues;
115
    }
116

    
117
    @Override
118
    public boolean isPageComplete() {
119
        boolean result = CdmUtils.isNotBlank(text_source.getText()) && vocUuid != null;
120

    
121
        return result;
122
    }
123

    
124
}
(4-4/6)