Project

General

Profile

Download (3.15 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.wizard;
10

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

    
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.events.SelectionAdapter;
16
import org.eclipse.swt.events.SelectionEvent;
17
import org.eclipse.swt.widgets.Combo;
18
import org.eclipse.swt.widgets.Composite;
19

    
20
import eu.etaxonomy.cdm.api.service.IVocabularyService;
21
import eu.etaxonomy.cdm.common.CdmUtils;
22
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
23
import eu.etaxonomy.cdm.model.common.TermType;
24
import eu.etaxonomy.cdm.model.common.TermVocabulary;
25
import eu.etaxonomy.taxeditor.store.CdmStore;
26

    
27
/**
28
 * @author k.luther
29
 * @date 04.05.2017
30
 *
31
 */
32
public class ImportFromFileAndChooseVocIdWizardOage extends ImportFromFileDataSourceWizardPage {
33

    
34
    private Combo vocabularyCombo;
35
    UUID vocUuid;
36
    String[][] labelAndValues;
37
    /**
38
     * @param title
39
     * @param description
40
     * @param extensions
41
     */
42
    protected ImportFromFileAndChooseVocIdWizardOage(String title, String description, String[] extensions) {
43
        super(title, description, extensions);
44

    
45
    }
46

    
47
    @Override
48
    public void createControl(Composite parent) {
49
        super.createControl(parent);
50
        Composite composite = (Composite)getControl();
51
      //  final Composite composite = new Composite(parent, SWT.NULL);
52

    
53
        vocabularyCombo = new Combo(composite, SWT.DROP_DOWN);
54
        List<TermVocabulary<DefinedTermBase>> vocs = CdmStore.getService(IVocabularyService.class).findByTermType(TermType.NamedArea);
55
        for(TermVocabulary voc: vocs){
56
            vocabularyCombo.add(voc.getLabel());
57
        }
58
        getLabelAndValues(vocs);
59
        vocabularyCombo.addSelectionListener(new SelectionAdapter(){
60

    
61
            @Override
62
            public void widgetSelected(SelectionEvent e) {
63
                String name = vocabularyCombo.getText();
64

    
65
                for (String[] labelAndValue: labelAndValues){
66
                    if (labelAndValue[0].equals(name)){
67
                        String uuidString = labelAndValue[1];
68
                        vocUuid = UUID.fromString(uuidString);
69
                        setPageComplete(isPageComplete());
70
                    }
71
                }
72

    
73
            }
74

    
75
        });
76
        //setControl(composite);
77
    }
78

    
79
    public UUID getVocUuid() {
80
        return vocUuid;
81
    }
82

    
83
    public void setVocUuid(UUID vocUuid) {
84
        this.vocUuid = vocUuid;
85
    }
86

    
87
    /**
88
     * @return
89
     */
90
    private String[][] getLabelAndValues(List<TermVocabulary<DefinedTermBase>> vocs) {
91

    
92
        labelAndValues = new String[vocs.size()][2];
93
        for (int i = 0; i < vocs.size(); i++) {
94
            labelAndValues[i][0] = vocs.get(i).getLabel();
95
            labelAndValues[i][1] = vocs.get(i).getUuid().toString();
96
        }
97
        return labelAndValues;
98
    }
99

    
100
    @Override
101
    public boolean isPageComplete() {
102
        boolean result = CdmUtils.isNotBlank(text_source.getText()) && vocUuid != null;
103

    
104
        return result;
105
    }
106

    
107
}
(18-18/29)