2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.io
.e4
.in
;
11 import java
.util
.List
;
12 import java
.util
.UUID
;
14 import javax
.inject
.Inject
;
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
;
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
;
37 public class ImportFromFileAndChooseVocIdWizardPageE4
extends ImportFromFileDataSourceWizardPageE4
{
39 private Combo vocabularyCombo
;
41 String
[][] labelAndValues
;
44 public ImportFromFileAndChooseVocIdWizardPageE4() {
46 setTitle("Choose Excel File");
47 setDescription("Please choose an xls file in the Distribution Update format.");
48 setExtensions(new String
[]{"*.xlsx", "*.xls", "*.*"});
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());
67 getLabelAndValues(vocs
);
68 vocabularyCombo
.select(0);
69 vocabularyCombo
.addSelectionListener(new SelectionAdapter(){
72 public void widgetSelected(SelectionEvent e
) {
73 String name
= vocabularyCombo
.getText();
75 for (String
[] labelAndValue
: labelAndValues
){
76 if (labelAndValue
[0].equals(name
)){
77 String uuidString
= labelAndValue
[1];
78 vocUuid
= UUID
.fromString(uuidString
);
79 setPageComplete(isPageComplete());
88 public UUID
getVocUuid() {
92 public void setVocUuid(UUID vocUuid
) {
93 this.vocUuid
= vocUuid
;
96 private String
[][] getLabelAndValues(List
<TermVocabulary
<DefinedTermBase
>> vocs
) {
98 labelAndValues
= new String
[vocs
.size()][2];
99 for (int i
= 0; i
< vocs
.size(); i
++) {
100 labelAndValues
[i
][0] = vocs
.get(i
).getLabel();
101 labelAndValues
[i
][1] = vocs
.get(i
).getUuid().toString();
103 return labelAndValues
;
107 public boolean isPageComplete() {
108 boolean result
= CdmUtils
.isNotBlank(text_source
.getText()) && vocUuid
!= null;