- moved transient interfaces to taxeditor.editor
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / dataimport / SpecimenImportEditorInput.java
1 // $Id$
2 /**
3 * Copyright (C) 2014 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.editor.view.dataimport;
11
12 import java.util.ArrayList;
13 import java.util.Collection;
14
15 import org.eclipse.swt.widgets.Display;
16
17 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
18 import eu.etaxonomy.cdm.ext.biocase.BioCaseQuery;
19 import eu.etaxonomy.cdm.model.location.NamedArea;
20 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
21 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
22 import eu.etaxonomy.taxeditor.store.CdmStore;
23
24 /**
25 * @author pplitzner
26 * @date 25.02.2014
27 *
28 */
29 public class SpecimenImportEditorInput extends DataImportEditorInput<SpecimenOrObservationBase> {
30
31 private final BioCaseQuery query;
32
33 /**
34 * @param results
35 */
36 public SpecimenImportEditorInput(BioCaseQuery query) {
37 super();
38 this.query = query;
39 }
40
41 public void query(){
42 String errorMessage = "Could not execute query " + SpecimenImportEditorInput.this.query;
43
44 Collection<SpecimenOrObservationBase> results = new ArrayList<SpecimenOrObservationBase>();
45 DerivedUnitFacade unit1 = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
46 // newInstance.setTitleCache("Test Specimen", true);
47 unit1.setCollectingMethod("Collected from the ground");
48 unit1.setAccessionNumber("ACC-12345");
49 unit1.setLocality("locality");
50 unit1.setCountry(NamedArea.EUROPE());
51
52 DerivedUnitFacade unit2 = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
53 unit2.setTitleCache("Test Specimen 2", false);
54 unit2.setCollectingMethod("Collected from the ground");
55 unit2.setAccessionNumber("ACC-67890");
56 unit2.setLocality("solid ground close to car park");
57 unit2.setCountry(NamedArea.ASIA_TEMPERATE());
58
59 DerivedUnitFacade unit3 = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
60 unit3.setTitleCache("Test Specimen 3", false);
61 unit3.setCollectingMethod("Collected from the air");
62 unit3.setAccessionNumber("ACC-999");
63 unit3.setLocality("thin air");
64 unit3.setCountry(NamedArea.SOUTHERNOCEAN());
65
66 results.add(unit1.innerDerivedUnit());
67 results.add(unit2.innerDerivedUnit());
68 results.add(unit3.innerDerivedUnit());
69 results.add(unit1.innerDerivedUnit());
70 setResults(results);
71 // try {
72 // InputStream resultStream = new BioCaseQueryServiceWrapper().query(DataImportEditorInput.this.query);
73 // Abcd206ImportConfigurator configurator = Abcd206ImportConfigurator.NewInstance(resultStream, null, false);
74 // TransientCdmRepository repo =
75 // new TransientCdmRepository(CdmStore.getCurrentApplicationConfiguration());
76 // configurator.setCdmAppController(repo);
77 //
78 // CdmDefaultImport<Abcd206ImportConfigurator> importer = new CdmDefaultImport<Abcd206ImportConfigurator>();
79 // importer.invoke(configurator);
80 // results = repo.getUnits();
81 // } catch (ClientProtocolException e) {
82 // logger.error(errorMessage, e);
83 // } catch (IOException e) {
84 // logger.error(errorMessage, e);
85 // } catch (URISyntaxException e) {
86 // logger.error(errorMessage, e);
87 // }
88
89 Display.getDefault().asyncExec(new Runnable() {
90
91 @Override
92 public void run() {
93 CdmStore.getContextManager().notifyContextRefresh();
94 }
95 });
96 }
97
98 /* (non-Javadoc)
99 * @see org.eclipse.ui.IEditorInput#getName()
100 */
101 @Override
102 public String getName() {
103 return query.toString();
104 }
105
106 /* (non-Javadoc)
107 * @see org.eclipse.ui.IEditorInput#getToolTipText()
108 */
109 @Override
110 public String getToolTipText() {
111 return query.toString();
112 }
113
114 /* (non-Javadoc)
115 * @see java.lang.Object#hashCode()
116 */
117 @Override
118 public int hashCode() {
119 final int prime = 31;
120 int result = 1;
121 result = prime * result + ((query == null) ? 0 : query.hashCode());
122 return result;
123 }
124
125 /* (non-Javadoc)
126 * @see java.lang.Object#equals(java.lang.Object)
127 */
128 @Override
129 public boolean equals(Object obj) {
130 if (this == obj) {
131 return true;
132 }
133 if (obj == null) {
134 return false;
135 }
136 if (getClass() != obj.getClass()) {
137 return false;
138 }
139 SpecimenImportEditorInput other = (SpecimenImportEditorInput) obj;
140 if (query == null) {
141 if (other.query != null) {
142 return false;
143 }
144 } else if (!query.equals(other.query)) {
145 return false;
146 }
147 return true;
148 }
149 }