Project

General

Profile

Download (4.61 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2013 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.view.dataimport.e4;
10

    
11
import java.net.MalformedURLException;
12
import java.net.URI;
13
import java.net.URISyntaxException;
14
import java.net.URL;
15

    
16
import javax.inject.Inject;
17

    
18
import org.apache.commons.lang3.StringUtils;
19
import org.eclipse.jface.wizard.WizardPage;
20
import org.eclipse.swt.widgets.Composite;
21

    
22
import eu.etaxonomy.cdm.ext.common.ServiceWrapperBase;
23
import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper;
24
import eu.etaxonomy.taxeditor.view.dataimport.QueryType;
25
import eu.etaxonomy.taxeditor.view.search.specimen.SpecimenProviderSelectionController;
26

    
27

    
28
/**
29
 * Wizard page for selecting the specimen provider
30
 * @author pplitzner
31
 * @date 12.09.2013
32
 *
33
 */
34
public class SpecimenProviderSelectionWizardPageE4 extends WizardPage{
35

    
36
    private SpecimenProviderSelectionController specimenProviderSelectionController;
37
    private URI endPoint;
38
    private String dataSet;
39
    private ServiceWrapperBase serviceWrapper;
40

    
41
    @Inject
42
    public SpecimenProviderSelectionWizardPageE4() {
43
        super("Select specimen provider");
44
        setTitle("Select Specimen Provider");
45
        setDescription("Select the provider to query for specimens.\nTo query a BioCASE " +
46
        		"provider the access point URL must be entered.");
47
    }
48

    
49
    /* (non-Javadoc)
50
     * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
51
     */
52
    @Override
53
    public void createControl(Composite parent) {
54
        specimenProviderSelectionController = SpecimenProviderSelectionController.getInstance(parent, getWizard());
55
        setControl(specimenProviderSelectionController.getComposite());
56
        //serviceWrapper = new BioCaseQueryServiceWrapper();
57

    
58
    }
59

    
60
    public QueryType getQueryType(){
61
        if(specimenProviderSelectionController.getComposite().getBtnBioCaseProvider().getSelection()){
62
            return QueryType.BIOCASE;
63
        }
64
        else {// if(specimenProviderSelectionController.getComposite().getBtnGbif().getSelection()){
65
            return QueryType.GBIF;
66
        }
67
    }
68

    
69
    /**
70
     * @return
71
     * @throws URISyntaxException
72
     */
73
    public URI getEndPoint() {
74
        return endPoint;
75
    }
76

    
77
    /* (non-Javadoc)
78
     * @see org.eclipse.jface.wizard.WizardPage#isPageComplete()
79
     */
80
    @Override
81
    public boolean isPageComplete() {
82
        if(specimenProviderSelectionController.getComposite().getBtnBioCaseProvider().getSelection()){
83
            endPoint = null;
84
            try {
85
                String dataSetAccesPoint = specimenProviderSelectionController.getComposite().getTxtAccessPoint().getText();
86
                if (StringUtils.isNotBlank(dataSetAccesPoint)){
87
                    String accessPoint = dataSetAccesPoint;
88
                    if (dataSetAccesPoint.contains(" - ")){
89
                        dataSet = dataSetAccesPoint.substring(0, dataSetAccesPoint.indexOf(" - "));
90
                        accessPoint = dataSetAccesPoint.substring(dataSetAccesPoint.indexOf(" - ") + 3);
91

    
92
                    }
93

    
94
                    endPoint = new URL(accessPoint).toURI();
95
                    serviceWrapper = new BioCaseQueryServiceWrapper();
96
                    serviceWrapper.setBaseUrl(specimenProviderSelectionController.getComposite().getTxtAccessPoint().getText());
97
                    this.setErrorMessage(null);
98
                    return true;
99
                }
100

    
101

    
102

    
103
            } catch (MalformedURLException e) {
104
                setErrorMessage("A valid URL has to be entered.");
105
                return false;
106
            } catch (URISyntaxException e) {
107
                setErrorMessage("A valid URL has to be entered.");
108
                return false;
109
            }
110
        }
111
        else if(specimenProviderSelectionController.getComposite().getBtnGbif().getSelection()){
112
            this.setErrorMessage(null);
113
            return true;
114
        }
115
        return false;
116
    }
117

    
118
    /**
119
     * @return the bioCaseQueryServiceWrapper
120
     */
121
    public ServiceWrapperBase getQueryServiceWrapper() {
122
        return serviceWrapper;
123
    }
124

    
125
    /**
126
     * @param bioCaseQueryServiceWrapper the bioCaseQueryServiceWrapper to set
127
     */
128
    public void setQueryServiceWrapper(ServiceWrapperBase queryServiceWrapper) {
129
        this.serviceWrapper = queryServiceWrapper;
130
    }
131

    
132
    /**
133
     * @return
134
     */
135
    public SpecimenProviderSelectionController getController() {
136
        return specimenProviderSelectionController;
137
    }
138

    
139

    
140

    
141

    
142
}
(5-5/7)