Project

General

Profile

Download (5.09 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2013 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.dataimport;
11

    
12
import java.io.IOException;
13
import java.io.InputStream;
14
import java.net.URISyntaxException;
15
import java.util.List;
16

    
17
import org.apache.http.client.ClientProtocolException;
18
import org.apache.log4j.Logger;
19
import org.eclipse.jface.resource.ImageDescriptor;
20
import org.eclipse.swt.widgets.Display;
21
import org.eclipse.ui.IEditorInput;
22
import org.eclipse.ui.IPersistableElement;
23

    
24
import eu.etaxonomy.cdm.ext.biocase.BioCaseQuery;
25
import eu.etaxonomy.cdm.ext.biocase.BioCaseQueryServiceWrapper;
26
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
27
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
28
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
29
import eu.etaxonomy.taxeditor.dataimport.transientServices.TransientCdmRepository;
30
import eu.etaxonomy.taxeditor.store.CdmStore;
31

    
32
/**
33
 * @author pplitzner
34
 * @date 20.09.2013
35
 *
36
 */
37
public class DerivedUnitEditorInput implements IEditorInput {
38

    
39
    private static Logger logger = Logger.getLogger(DerivedUnitEditorInput.class);
40

    
41
    private final BioCaseQuery query;
42

    
43
    private List<SpecimenOrObservationBase> results;
44

    
45
    /**
46
     * @param results
47
     */
48
    public DerivedUnitEditorInput(BioCaseQuery query) {
49
        this.query = query;
50
    }
51

    
52
    public void query(){
53
        String errorMessage = "Could not execute query " + DerivedUnitEditorInput.this.query;
54
        try {
55
            InputStream resultStream = new BioCaseQueryServiceWrapper().query(DerivedUnitEditorInput.this.query);
56
            Abcd206ImportConfigurator configurator = Abcd206ImportConfigurator.NewInstance(resultStream, null, false);
57
            TransientCdmRepository repo =
58
                    new TransientCdmRepository(CdmStore.getCurrentApplicationConfiguration());
59
            configurator.setCdmAppController(repo);
60

    
61
            CdmDefaultImport<Abcd206ImportConfigurator> importer = new CdmDefaultImport<Abcd206ImportConfigurator>();
62
            importer.invoke(configurator);
63
            results = repo.getUnits();
64
            //            Abcd206Import abcd206Import = new Abcd206Import();
65
            //            Abcd206ImportState state = new Abcd206ImportState(configurator);
66
            //            abcd206Import.invoke(state);
67
            //            state.countTrees();
68
        } catch (ClientProtocolException e) {
69
            logger.error(errorMessage, e);
70
        } catch (IOException e) {
71
            logger.error(errorMessage, e);
72
        } catch (URISyntaxException e) {
73
            logger.error(errorMessage, e);
74
        }
75

    
76
        Display.getDefault().asyncExec(new Runnable() {
77

    
78
            @Override
79
            public void run() {
80
                CdmStore.getContextManager().notifyContextRefresh();
81
            }
82
        });
83
    }
84

    
85
    /* (non-Javadoc)
86
     * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
87
     */
88
    @Override
89
    public Object getAdapter(Class adapter) {
90
        // TODO Auto-generated method stub
91
        return null;
92
    }
93

    
94
    /* (non-Javadoc)
95
     * @see org.eclipse.ui.IEditorInput#exists()
96
     */
97
    @Override
98
    public boolean exists() {
99
        return false;
100
    }
101

    
102
    /* (non-Javadoc)
103
     * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
104
     */
105
    @Override
106
    public ImageDescriptor getImageDescriptor() {
107
        // TODO Auto-generated method stub
108
        return null;
109
    }
110

    
111
    /* (non-Javadoc)
112
     * @see org.eclipse.ui.IEditorInput#getName()
113
     */
114
    @Override
115
    public String getName() {
116
        return query.toString();
117
    }
118

    
119
    /* (non-Javadoc)
120
     * @see org.eclipse.ui.IEditorInput#getPersistable()
121
     */
122
    @Override
123
    public IPersistableElement getPersistable() {
124
        return null;
125
    }
126

    
127
    /* (non-Javadoc)
128
     * @see org.eclipse.ui.IEditorInput#getToolTipText()
129
     */
130
    @Override
131
    public String getToolTipText() {
132
        return query.toString();
133
    }
134

    
135
    /**
136
     * @return the results
137
     */
138
    public List<SpecimenOrObservationBase> getResults() {
139
        return results;
140
    }
141

    
142
    /* (non-Javadoc)
143
     * @see java.lang.Object#hashCode()
144
     */
145
    @Override
146
    public int hashCode() {
147
        final int prime = 31;
148
        int result = 1;
149
        result = prime * result + ((query == null) ? 0 : query.hashCode());
150
        return result;
151
    }
152

    
153
    /* (non-Javadoc)
154
     * @see java.lang.Object#equals(java.lang.Object)
155
     */
156
    @Override
157
    public boolean equals(Object obj) {
158
        if (this == obj) {
159
            return true;
160
        }
161
        if (obj == null) {
162
            return false;
163
        }
164
        if (getClass() != obj.getClass()) {
165
            return false;
166
        }
167
        DerivedUnitEditorInput other = (DerivedUnitEditorInput) obj;
168
        if (query == null) {
169
            if (other.query != null) {
170
                return false;
171
            }
172
        } else if (!query.equals(other.query)) {
173
            return false;
174
        }
175
        return true;
176
    }
177

    
178
}
(3-3/3)